···22222323- [`sudo-rs`], a reimplementation of `sudo` in Rust, is now supported.
2424 An experimental new module `security.sudo-rs` was added.
2525- Switching to it (via `security.sudo.enable = false; security.sudo-rs.enable = true;`) introduces
2525+ Switching to it (via ` security.sudo-rs.enable = true;`) introduces
2626 slight changes in sudo behaviour, due to `sudo-rs`' current limitations:
2727 - terminfo-related environment variables aren't preserved for `root` and `wheel`;
2828 - `root` and `wheel` are not given the ability to set (or preserve)
2929 arbitrary environment variables.
30303131-- [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.
3131+ **Note:** The `sudo-rs` module only takes configuration through `security.sudo-rs`,
3232+ and in particular does not automatically use previously-set rules; this could be
3333+ achieved with `security.sudo-rs.extraRules = security.sudo.extraRules;` for instance.
32343335[`sudo-rs`]: https://github.com/memorysafety/sudo-rs/
3636+3737+- [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.
34383539- `linuxPackages_testing_bcachefs` is now soft-deprecated by `linuxPackages_testing`.
3640 - 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
···943943 value.source = pkgs.writeText "${name}.pam" service.text;
944944 };
945945946946+ optionalSudoConfigForSSHAgentAuth = optionalString config.security.pam.enableSSHAgentAuth ''
947947+ # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
948948+ Defaults env_keep+=SSH_AUTH_SOCK
949949+ '';
950950+946951in
947952948953{
···15321537 concatLines
15331538 ]);
1534153915351535- security.sudo.extraConfig = optionalString config.security.pam.enableSSHAgentAuth ''
15361536- # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
15371537- Defaults env_keep+=SSH_AUTH_SOCK
15381538- '';
15391539- };
15401540+ security.sudo.extraConfig = optionalSudoConfigForSSHAgentAuth;
15411541+ security.sudo-rs.extraConfig = optionalSudoConfigForSSHAgentAuth;
15421542+ };
15401543}
+26-51
nixos/modules/security/sudo-rs.nix
···4455let
6677- inherit (pkgs) sudo sudo-rs;
88-97 cfg = config.security.sudo-rs;
1081111- enableSSHAgentAuth =
1212- with config.security;
1313- pam.enableSSHAgentAuth && pam.sudo.sshAgentAuth;
1414-1515- usingMillersSudo = cfg.package.pname == sudo.pname;
1616- usingSudoRs = cfg.package.pname == sudo-rs.pname;
99+ inherit (config.security.pam) enableSSHAgentAuth;
17101811 toUserString = user: if (isInt user) then "#${toString user}" else "${user}";
1912 toGroupString = group: if (isInt group) then "%#${toString group}" else "%${group}";
···41344235 defaultOptions = mkOption {
4336 type = with types; listOf str;
4444- default = optional usingMillersSudo "SETENV";
4545- defaultText = literalMD ''
4646- `[ "SETENV" ]` if using the default `sudo` implementation
4747- '';
3737+ default = [];
4838 description = mdDoc ''
4939 Options used for the default rules, granting `root` and the
5040 `wheel` group permission to run any command as any user.
5141 '';
5242 };
53435454- enable = mkOption {
5555- type = types.bool;
5656- default = false;
5757- description = mdDoc ''
5858- Whether to enable the {command}`sudo` command, which
5959- allows non-root users to execute commands as root.
6060- '';
6161- };
4444+ enable = mkEnableOption (mdDoc ''
4545+ a memory-safe implementation of the {command}`sudo` command,
4646+ which allows non-root users to execute commands as root.
4747+ '');
62486363- package = mkOption {
6464- type = types.package;
6565- default = pkgs.sudo-rs;
6666- defaultText = literalExpression "pkgs.sudo-rs";
6767- description = mdDoc ''
6868- Which package to use for `sudo`.
6969- '';
7070- };
4949+ package = mkPackageOption pkgs "sudo-rs" { };
71507251 wheelNeedsPassword = mkOption {
7352 type = types.bool;
···208187 ###### implementation
209188210189 config = mkIf cfg.enable {
190190+ assertions = [ {
191191+ assertion = ! config.security.sudo.enable;
192192+ message = "`security.sudo` and `security.sudo-rs` cannot both be enabled";
193193+ }];
194194+ security.sudo.enable = mkDefault false;
195195+211196 security.sudo-rs.extraRules =
212197 let
213198 defaultRule = { users ? [], groups ? [], opts ? [] }: [ {
···235220 # Don't edit this file. Set the NixOS options ‘security.sudo-rs.configFile’
236221 # or ‘security.sudo-rs.extraRules’ instead.
237222 ''
238238- (optionalString enableSSHAgentAuth ''
239239- # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
240240- Defaults env_keep+=SSH_AUTH_SOCK
241241- '')
242242- (concatStringsSep "\n" (
243243- lists.flatten (
244244- map (
245245- rule: optionals (length rule.commands != 0) [
246246- (map (user: "${toUserString user} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.users)
247247- (map (group: "${toGroupString group} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.groups)
248248- ]
249249- ) cfg.extraRules
250250- )
251251- ) + "\n")
223223+ (pipe cfg.extraRules [
224224+ (filter (rule: length rule.commands != 0))
225225+ (map (rule: [
226226+ (map (user: "${toUserString user} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.users)
227227+ (map (group: "${toGroupString group} ${rule.host}=(${rule.runAs}) ${toCommandsString rule.commands}") rule.groups)
228228+ ]))
229229+ flatten
230230+ (concatStringsSep "\n")
231231+ ])
232232+ "\n"
252233 (optionalString (cfg.extraConfig != "") ''
253234 # extraConfig
254235 ${cfg.extraConfig}
···265246 source = "${cfg.package.out}/bin/sudo";
266247 inherit owner group setuid permissions;
267248 };
268268- # sudo-rs does not yet ship a sudoedit (as of v0.2.0)
269269- sudoedit = mkIf usingMillersSudo {
270270- source = "${cfg.package.out}/bin/sudoedit";
271271- inherit owner group setuid permissions;
272272- };
273249 };
274250275275- environment.systemPackages = [ sudo ];
251251+ environment.systemPackages = [ cfg.package ];
276252277253 security.pam.services.sudo = { sshAgentAuth = true; usshAuth = true; };
278278- security.pam.services.sudo-i = mkIf usingSudoRs
279279- { sshAgentAuth = true; usshAuth = true; };
254254+ security.pam.services.sudo-i = { sshAgentAuth = true; usshAuth = true; };
280255281256 environment.etc.sudoers =
282257 { source =
···285260 src = pkgs.writeText "sudoers-in" cfg.configFile;
286261 preferLocalBuild = true;
287262 }
288288- "${pkgs.buildPackages."${cfg.package.pname}"}/bin/visudo -f $src -c && cp $src $out";
263263+ "${pkgs.buildPackages.sudo-rs}/bin/visudo -f $src -c && cp $src $out";
289264 mode = "0440";
290265 };
291266