···2223- [`sudo-rs`], a reimplementation of `sudo` in Rust, is now supported.
24 An experimental new module `security.sudo-rs` was added.
25- Switching to it (via `security.sudo.enable = false; security.sudo-rs.enable = true;`) introduces
26 slight changes in sudo behaviour, due to `sudo-rs`' current limitations:
27 - terminfo-related environment variables aren't preserved for `root` and `wheel`;
28 - `root` and `wheel` are not given the ability to set (or preserve)
29 arbitrary environment variables.
3031-- [glibc](https://www.gnu.org/software/libc/) has been updated from version 2.37 to 2.38, see [the release notes](https://sourceware.org/glibc/wiki/Release/2.38) for what was changed.
003233[`sudo-rs`]: https://github.com/memorysafety/sudo-rs/
003435- `linuxPackages_testing_bcachefs` is now soft-deprecated by `linuxPackages_testing`.
36 - Please consider changing your NixOS configuration's `boot.kernelPackages` to `linuxPackages_testing` until a stable kernel with bcachefs support is released.
···2223- [`sudo-rs`], a reimplementation of `sudo` in Rust, is now supported.
24 An experimental new module `security.sudo-rs` was added.
25+ Switching to it (via ` security.sudo-rs.enable = true;`) introduces
26 slight changes in sudo behaviour, due to `sudo-rs`' current limitations:
27 - terminfo-related environment variables aren't preserved for `root` and `wheel`;
28 - `root` and `wheel` are not given the ability to set (or preserve)
29 arbitrary environment variables.
3031+ **Note:** The `sudo-rs` module only takes configuration through `security.sudo-rs`,
32+ and in particular does not automatically use previously-set rules; this could be
33+ achieved with `security.sudo-rs.extraRules = security.sudo.extraRules;` for instance.
3435[`sudo-rs`]: https://github.com/memorysafety/sudo-rs/
36+37+- [glibc](https://www.gnu.org/software/libc/) has been updated from version 2.37 to 2.38, see [the release notes](https://sourceware.org/glibc/wiki/Release/2.38) for what was changed.
3839- `linuxPackages_testing_bcachefs` is now soft-deprecated by `linuxPackages_testing`.
40 - Please consider changing your NixOS configuration's `boot.kernelPackages` to `linuxPackages_testing` until a stable kernel with bcachefs support is released.
+8-5
nixos/modules/security/pam.nix
···943 value.source = pkgs.writeText "${name}.pam" service.text;
944 };
94500000946in
947948{
···1532 concatLines
1533 ]);
15341535- security.sudo.extraConfig = optionalString config.security.pam.enableSSHAgentAuth ''
1536- # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
1537- Defaults env_keep+=SSH_AUTH_SOCK
1538- '';
1539- };
1540}
···943 value.source = pkgs.writeText "${name}.pam" service.text;
944 };
945946+ optionalSudoConfigForSSHAgentAuth = optionalString config.security.pam.enableSSHAgentAuth ''
947+ # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
948+ Defaults env_keep+=SSH_AUTH_SOCK
949+ '';
950+951in
952953{
···1537 concatLines
1538 ]);
15391540+ security.sudo.extraConfig = optionalSudoConfigForSSHAgentAuth;
1541+ security.sudo-rs.extraConfig = optionalSudoConfigForSSHAgentAuth;
1542+ };
001543}
+26-51
nixos/modules/security/sudo-rs.nix
···45let
67- inherit (pkgs) sudo sudo-rs;
8-9 cfg = config.security.sudo-rs;
1011- enableSSHAgentAuth =
12- with config.security;
13- pam.enableSSHAgentAuth && pam.sudo.sshAgentAuth;
14-15- usingMillersSudo = cfg.package.pname == sudo.pname;
16- usingSudoRs = cfg.package.pname == sudo-rs.pname;
1718 toUserString = user: if (isInt user) then "#${toString user}" else "${user}";
19 toGroupString = group: if (isInt group) then "%#${toString group}" else "%${group}";
···4142 defaultOptions = mkOption {
43 type = with types; listOf str;
44- default = optional usingMillersSudo "SETENV";
45- defaultText = literalMD ''
46- `[ "SETENV" ]` if using the default `sudo` implementation
47- '';
48 description = mdDoc ''
49 Options used for the default rules, granting `root` and the
50 `wheel` group permission to run any command as any user.
51 '';
52 };
5354- enable = mkOption {
55- type = types.bool;
56- default = false;
57- description = mdDoc ''
58- Whether to enable the {command}`sudo` command, which
59- allows non-root users to execute commands as root.
60- '';
61- };
6263- package = mkOption {
64- type = types.package;
65- default = pkgs.sudo-rs;
66- defaultText = literalExpression "pkgs.sudo-rs";
67- description = mdDoc ''
68- Which package to use for `sudo`.
69- '';
70- };
7172 wheelNeedsPassword = mkOption {
73 type = types.bool;
···208 ###### implementation
209210 config = mkIf cfg.enable {
000000211 security.sudo-rs.extraRules =
212 let
213 defaultRule = { users ? [], groups ? [], opts ? [] }: [ {
···235 # Don't edit this file. Set the NixOS options ‘security.sudo-rs.configFile’
236 # or ‘security.sudo-rs.extraRules’ instead.
237 ''
238- (optionalString enableSSHAgentAuth ''
239- # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
240- Defaults env_keep+=SSH_AUTH_SOCK
241- '')
242- (concatStringsSep "\n" (
243- lists.flatten (
244- map (
245- rule: optionals (length rule.commands != 0) [
246- (map (user: "${toUserString user} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.users)
247- (map (group: "${toGroupString group} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.groups)
248- ]
249- ) cfg.extraRules
250- )
251- ) + "\n")
252 (optionalString (cfg.extraConfig != "") ''
253 # extraConfig
254 ${cfg.extraConfig}
···265 source = "${cfg.package.out}/bin/sudo";
266 inherit owner group setuid permissions;
267 };
268- # sudo-rs does not yet ship a sudoedit (as of v0.2.0)
269- sudoedit = mkIf usingMillersSudo {
270- source = "${cfg.package.out}/bin/sudoedit";
271- inherit owner group setuid permissions;
272- };
273 };
274275- environment.systemPackages = [ sudo ];
276277 security.pam.services.sudo = { sshAgentAuth = true; usshAuth = true; };
278- security.pam.services.sudo-i = mkIf usingSudoRs
279- { sshAgentAuth = true; usshAuth = true; };
280281 environment.etc.sudoers =
282 { source =
···285 src = pkgs.writeText "sudoers-in" cfg.configFile;
286 preferLocalBuild = true;
287 }
288- "${pkgs.buildPackages."${cfg.package.pname}"}/bin/visudo -f $src -c && cp $src $out";
289 mode = "0440";
290 };
291
···45let
6007 cfg = config.security.sudo-rs;
89+ inherit (config.security.pam) enableSSHAgentAuth;
000001011 toUserString = user: if (isInt user) then "#${toString user}" else "${user}";
12 toGroupString = group: if (isInt group) then "%#${toString group}" else "%${group}";
···3435 defaultOptions = mkOption {
36 type = with types; listOf str;
37+ default = [];
00038 description = mdDoc ''
39 Options used for the default rules, granting `root` and the
40 `wheel` group permission to run any command as any user.
41 '';
42 };
4344+ enable = mkEnableOption (mdDoc ''
45+ a memory-safe implementation of the {command}`sudo` command,
46+ which allows non-root users to execute commands as root.
47+ '');
00004849+ package = mkPackageOption pkgs "sudo-rs" { };
00000005051 wheelNeedsPassword = mkOption {
52 type = types.bool;
···187 ###### implementation
188189 config = mkIf cfg.enable {
190+ assertions = [ {
191+ assertion = ! config.security.sudo.enable;
192+ message = "`security.sudo` and `security.sudo-rs` cannot both be enabled";
193+ }];
194+ security.sudo.enable = mkDefault false;
195+196 security.sudo-rs.extraRules =
197 let
198 defaultRule = { users ? [], groups ? [], opts ? [] }: [ {
···220 # Don't edit this file. Set the NixOS options ‘security.sudo-rs.configFile’
221 # or ‘security.sudo-rs.extraRules’ instead.
222 ''
223+ (pipe cfg.extraRules [
224+ (filter (rule: length rule.commands != 0))
225+ (map (rule: [
226+ (map (user: "${toUserString user} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.users)
227+ (map (group: "${toGroupString group} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.groups)
228+ ]))
229+ flatten
230+ (concatStringsSep "\n")
231+ ])
232+ "\n"
0000233 (optionalString (cfg.extraConfig != "") ''
234 # extraConfig
235 ${cfg.extraConfig}
···246 source = "${cfg.package.out}/bin/sudo";
247 inherit owner group setuid permissions;
248 };
00000249 };
250251+ environment.systemPackages = [ cfg.package ];
252253 security.pam.services.sudo = { sshAgentAuth = true; usshAuth = true; };
254+ security.pam.services.sudo-i = { sshAgentAuth = true; usshAuth = true; };
0255256 environment.etc.sudoers =
257 { source =
···260 src = pkgs.writeText "sudoers-in" cfg.configFile;
261 preferLocalBuild = true;
262 }
263+ "${pkgs.buildPackages.sudo-rs}/bin/visudo -f $src -c && cp $src $out";
264 mode = "0440";
265 };
266