-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[24.05] backport fcgiwrap instances fix for local privilege escalation issue #331465
Merged
emilazy
merged 7 commits into
NixOS:release-24.05
from
pacien:release-24.05-backport-fcgiwrap-instances
Aug 31, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aaa0457
nixos/fcgiwrap-instances: backport isolated multi-instance module
pacien 0cb1143
nixos/fcgiwrap: add deprecation notice and security warning
pacien 6a8e124
nixos/smokeping: use isolated fcgiwrap instance
pacien 483dd7e
nixos/zoneminder: use isolated fcgiwrap instance
pacien 31cdff5
nixos/cgit: use isolated fcgiwrap instance, add user/group options
pacien fee11ef
nixos/fcgiwrap: fail eval with security assertion
pacien 8931f18
nixos/fcgiwrap: add security advisory links to messages
pacien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
nixos/modules/services/web-servers/fcgiwrap-instances.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
forEachInstance = f: flip mapAttrs' config.services.fcgiwrap.instances ( | ||
name: cfg: nameValuePair "fcgiwrap-${name}" (f cfg) | ||
); | ||
|
||
in { | ||
options.services.fcgiwrap.instances = mkOption { | ||
description = "Configuration for fcgiwrap instances."; | ||
default = { }; | ||
type = types.attrsOf (types.submodule ({ config, ... }: { options = { | ||
process.prefork = mkOption { | ||
type = types.ints.positive; | ||
default = 1; | ||
description = "Number of processes to prefork."; | ||
}; | ||
|
||
process.user = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = '' | ||
User as which this instance of fcgiwrap will be run. | ||
Set to `null` (the default) to use a dynamically allocated user. | ||
''; | ||
}; | ||
|
||
process.group = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = "Group as which this instance of fcgiwrap will be run."; | ||
}; | ||
|
||
socket.type = mkOption { | ||
type = types.enum [ "unix" "tcp" "tcp6" ]; | ||
default = "unix"; | ||
description = "Socket type: 'unix', 'tcp' or 'tcp6'."; | ||
}; | ||
|
||
socket.address = mkOption { | ||
type = types.str; | ||
default = "/run/fcgiwrap-${config._module.args.name}.sock"; | ||
example = "1.2.3.4:5678"; | ||
description = '' | ||
Socket address. | ||
In case of a UNIX socket, this should be its filesystem path. | ||
''; | ||
}; | ||
|
||
socket.user = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = '' | ||
User to be set as owner of the UNIX socket. | ||
''; | ||
}; | ||
|
||
socket.group = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = '' | ||
Group to be set as owner of the UNIX socket. | ||
''; | ||
}; | ||
|
||
socket.mode = mkOption { | ||
type = types.nullOr types.str; | ||
default = if config.socket.type == "unix" then "0600" else null; | ||
defaultText = literalExpression '' | ||
if config.socket.type == "unix" then "0600" else null | ||
''; | ||
description = '' | ||
Mode to be set on the UNIX socket. | ||
Defaults to private to the socket's owner. | ||
''; | ||
}; | ||
}; })); | ||
}; | ||
|
||
config = { | ||
assertions = concatLists (mapAttrsToList (name: cfg: [ | ||
{ | ||
assertion = cfg.socket.type == "unix" -> cfg.socket.user != null; | ||
message = "Socket owner is required for the UNIX socket type."; | ||
} | ||
{ | ||
assertion = cfg.socket.type == "unix" -> cfg.socket.group != null; | ||
message = "Socket owner is required for the UNIX socket type."; | ||
} | ||
{ | ||
assertion = cfg.socket.user != null -> cfg.socket.type == "unix"; | ||
message = "Socket owner can only be set for the UNIX socket type."; | ||
} | ||
{ | ||
assertion = cfg.socket.group != null -> cfg.socket.type == "unix"; | ||
message = "Socket owner can only be set for the UNIX socket type."; | ||
} | ||
{ | ||
assertion = cfg.socket.mode != null -> cfg.socket.type == "unix"; | ||
message = "Socket mode can only be set for the UNIX socket type."; | ||
} | ||
]) config.services.fcgiwrap.instances); | ||
|
||
systemd.services = forEachInstance (cfg: { | ||
after = [ "nss-user-lookup.target" ]; | ||
wantedBy = optional (cfg.socket.type != "unix") "multi-user.target"; | ||
|
||
serviceConfig = { | ||
ExecStart = '' | ||
${pkgs.fcgiwrap}/sbin/fcgiwrap ${cli.toGNUCommandLineShell {} ({ | ||
c = cfg.process.prefork; | ||
} // (optionalAttrs (cfg.socket.type != "unix") { | ||
s = "${cfg.socket.type}:${cfg.socket.address}"; | ||
}))} | ||
''; | ||
} // (if cfg.process.user != null then { | ||
User = cfg.process.user; | ||
Group = cfg.process.group; | ||
} else { | ||
DynamicUser = true; | ||
}); | ||
}); | ||
|
||
systemd.sockets = forEachInstance (cfg: mkIf (cfg.socket.type == "unix") { | ||
wantedBy = [ "sockets.target" ]; | ||
socketConfig = { | ||
ListenStream = cfg.socket.address; | ||
SocketUser = cfg.socket.user; | ||
SocketGroup = cfg.socket.group; | ||
SocketMode = cfg.socket.mode; | ||
}; | ||
}); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it's usual to post an advisory link in evaluation warnings, but it seems useful to me.
Nevertheless, here's a draft for the advisory:
https://gist.github.com/pacien/82119f8e1a6569c5b12bf0f75ecc3b9a
I'd appreciate a review for it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this. I think linking to the advisory is great; we should certainly post it on Discourse and arguably https://github.com/NixOS/nixpkgs/security/advisories (as‐yet unused).
I personally feel that a warning is not sufficient and that insecure configurations should be a hard error, because otherwise it’s likely they won’t be surfaced through automatic update pipelines etc.; however I realize there is a compatibility cost here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the biggest issue with that, especially on the stable channel, is that for people using the auto-upgrade and not really monitoring their machine, it would block other compatible security upgrades. Like for example the recent curl CVE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s lots of circumstances where that would bite you. Packages do break unexpectedly. You need monitoring of failures to have security; Nix warnings, on the other hand, are rarely security‐relevant, and are trickier to automatically detect and monitor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, you definitely should monitor your machines. But I think lots of people still don't.
But it's true that warnings would be harder to detect, hmm…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could just add a
services.fcgiwrap.allowLocalPrivilegeEscalationUntilNextStableRelease
option or something if we want an escape hatch.I agree that the systemd service failure option is not ideal.
The GitHub advisory tab lets us assign CVEs, as I understand it, so it would actually be quite nice to use. But only repository admins can post stuff; we’d probably need to organize procedures and someone to be responsible for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the Github advisory then?
Would it be possible to reserve a number and URL to put it in the warnings and errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GHA are not really adequate in our situation with the current way the permissions are handled. Creation and publication needs to be handled by repo admins and cannot be delegated :/ (also not sure if tying more things with the GH ecosystem is a good play here).
In this specific case at this point the cat is out of the bag so I suggest to go ahead and publish the advisory on https://discourse.nixos.org/c/announcements/security/56 when this is ready to be merged to get the final link so it can be added to the messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Discourse will be okay, but there’s indeed a bit of a race condition there. Maybe we can post something set to private and then let it go public once we merge? I’m not sure who has that kind of access on Discourse other than the moderation team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a commit which causes an evaluation failure, with a new option
services.fcgiwrap.allowGlobalInstanceLocalPrivilegeEscalation
as an escapehatch.
I'm not sure of the consensus of whether to have this or not, so feel free
to include or not this latest commit.
The error should be clear enough nevertheless.
Regarding the Discourse advisory: making a private post and then making it
public might break notifications.
I'll make the post and update the link in the PR whenever someone will tell me
to.