## File: README.md # sudo-rs A safety oriented and memory safe implementation of sudo and su written in Rust. ## Status of this project Sudo-rs is being actively maintained; features you might expect from original sudo may still be unimplemented or not planned. Also note our [frequently asked questions](FAQ.md). If there is an important one you need, please request it using the issue tracker. If you encounter any usability bugs, also please report them on the [issue tracker](https://github.com/trifectatechfoundation/sudo-rs/issues). Suspected vulnerabilities can be reported on our [security page](https://github.com/trifectatechfoundation/sudo-rs/security). Sudo-rs has been audited twice: an audit of version 0.2.0 was performed in August 2023, and a second audit of version 0.2.8 in August 2025. The audit reports can be found [here](docs/audit). Sudo-rs currently is targeted for FreeBSD and Linux-based operating systems only. ## Installing sudo-rs You can install sudo-rs using the package manager of your Linux distribution. Many Linux distributions will also keep original sudo installed and so offer sudo-rs using modified command names. You can work around that by creating e.g. an `alias`, but that will only change your own invocations of `sudo` to sudo-rs and not affect other programs and scripts that use `sudo`. To avoid that and/or to get the latest version, you can use our prepackaged binaries (see below). ### Ubuntu 25.10 (Questing Quokka) and 26.04 (Resolute Raccoon) sudo-rs is installed and enabled by default; you can control which sudo version is being used by running ```sh update-alternatives --config sudo ``` #### Versions The sudo-rs package in Ubuntu 25.10 is based on v0.2.8 with additional bug fixes backported from newer versions. The package in Ubuntu 26.04 LTS is based on v0.2.13 with additional bug fixes. ### Arch Linux sudo-rs can be installed from the distribution repositories: ```sh pacman -S sudo-rs ``` This will offer the functionality using the commands `sudo-rs`, `sudoedit-rs`, `visudo-rs` and `su-rs` to avoid conflicts. The sudo-rs package on Arch Linux is typically up-to-date. ### Fedora On Fedora you can use: ```sh dnf install sudo-rs ``` This will offer the functionality using the commands `sudo-rs`, `visudo-rs` and `su-rs` to avoid conflicts. The version packaged in Fedora is usually the latest. ### Debian If you are running Debian 13 (trixie) or later you can use: ```sh apt-get install sudo-rs ``` This will offer the functionality using the commands `sudo-rs`, `visudo-rs`. If you want to invoke sudo-rs via the usual commands `sudo` and `visudo` instead, prepend `/usr/lib/cargo/bin` to your current `$PATH` variable. The sudo-rs version packaged in Debian 13 (trixie) is based on release 0.2.5 from April 2025 which is missing `sudoedit`, `NOEXEC:`, and many other usability and compatibility improvements, but is up-to-date with respect to security patches. Due to a misconfiguration in this package, `su-rs` cannot be used because it does not have the setuid flag set. Debian unstable (sid) may have a newer version. ### FreeBSD We are maintaining the FreeBSD port of sudo-rs ourselves, which is available in the ports tree. Sudo-rs is available in two flavours: ```sh pkg install sudo-rs ``` To get sudo-rs using the commands `sudo`, `visudo` and `sudoedit`. This conflicts with the `security/sudo` package and so you cannot have both installed at the same time. Alternatively, ```sh pkg install sudo-rs-coexist ``` Installs the commands as `sudo-rs`, `visudo-rs`' and `sudoedit-rs` and does not conflict with the `security/sudo` package. To run these commands, the `pkg` utility needs to be using the `2025Q4` quarterly version (or later) of the ports tree. To use the absolute latest version, you can [switch from quarterly to `latest`](https://wiki.freebsd.org/Ports/QuarterlyBranch#How_to_switch_from_quarterly_to_latest). ### NixOS On NixOS sudo-rs can be installed by adding the following to your configuration: ```nix security.sudo-rs.enable = true; ``` This will replace the usual `sudo` and `sudoedit` commands. ### Alpine Linux On Alpine Linux, sudo-rs is in the *community* repository, and can be installed as: ```sh apk add sudo-rs ``` This will install the `sudo`, `visudo` and `sudoedit` commands (but not replace `su`, which is still offered through BusyBox). To install the `sudo-rs` version of `su`, which is packaged separately, run: ```sh apk add sudo-rs-su ``` #### postmarketOS On postmarketOS, sudo-rs is installed and enabled by default on all new installs. ### Installing our pre-compiled x86-64 binaries You can also switch to sudo-rs manually by using our pre-compiled tarballs. We currently only offer these for x86-64 Linux systems. We recommend installing sudo-rs and su-rs in your `/usr/local` hierarchy so it does not affect the integrity of the package manager of your Linux distribution. You can achieve this using the commands: ```sh sudo tar -C /usr/local -xvf sudo-0.2.14.tar.gz ``` and for su-rs: ```sh sudo tar -C /usr/local -xvf su-0.2.14.tar.gz ``` This will install sudo-rs and su-rs in `/usr/local/bin` using the usual commands `sudo`, `visudo`, `sudoedit` and `su`. Please double check that in your default `PATH`, the folders `/usr/local/bin` and `/usr/local/sbin` have priority over `/usr/bin` and `/usr/sbin`. If you **don't** have Todd Miller's `sudo` installed, you also have to make sure that: * You manually create a `/etc/sudoers` or `/etc/sudoers-rs` file, this could be as simple as: Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" %sudo ALL=(ALL:ALL) ALL `sudo-rs` will try to process `/etc/sudoers-rs` if it exists, otherwise it will use `/etc/sudoers`. For an explanation of the sudoers syntax you can look at the [sudoers man page](https://www.sudo.ws/docs/man/sudoers.man/). * (Strongly recommended) You create `/etc/pam.d/sudo` and `/etc/pam.d/sudo-i` files that contain (for Debian/Ubuntu): session required pam_limits.so @include common-auth @include common-account @include common-session-noninteractive If you don't do this, either a "fallback" PAM policy will be used or `sudo-rs` will simply refuse to run since it cannot initialize PAM. On Fedora, the syntax for PAM configuration is slightly different, but the correct PAM configuration files will most likely be already installed. On FreeBSD, you may want to put these files in `/usr/local/etc/pam.d` instead. ### Building from source Sudo-rs is written in Rust. The minimum required Rust version is 1.85. If your Linux distribution does not package that version (or a later one), you can always install the most recent version through [rustup]. You also need the C development files for PAM (`libpam0g-dev` on Debian, `pam-devel` on Fedora). If you want to install translated messages, you also need gettext tools for `msgfmt` (`gettext` on Debian and Ubuntu). On Ubuntu or Debian-based systems, use the following command to install the PAM development library: ```sh sudo apt-get install libpam0g-dev ``` On Fedora, CentOS and other Red Hat-based systems, you can use the following command: ```sh sudo yum install pam-devel ``` With dependencies installed, building sudo-rs is a simple matter of: ```sh cargo build --release ``` This produces a binary `target/release/sudo`. However, this binary must have the setuid flag set and must be owned by the root user in order to provide any useful functionality. Consult your operating system manual for details. Sudo-rs then also needs the configuration files; please follow the installation suggestions in the previous section. ### Feature flags #### --features pam-login By default, sudo-rs will use the PAM service name `sudo`. On Debian and Fedora systems, it is customary that the name `sudo-i` is used when the `-i / --login` command line option is used. To get this behaviour, enable the `pam-login` feature when building: ```sh cargo build --release --features pam-login ``` This feature is enabled on our pre-supplied binaries. #### --features apparmor sudo-rs has support for selecting AppArmor profile on Linux distributions that support AppArmor such as Debian and Ubuntu. To enable this feature, build sudo-rs with apparmor support enabled: ```sh cargo build --release --features apparmor ``` This feature is disabled on our pre-supplied binaries. #### --features gettext sudo-rs has support for translated user-facing messages. To enable this feature, build sudo-rs with gettext support enabled: ```sh cargo build --release --features gettext ``` You can install the translation files from `po/*.po` using: ```sh sudo make install-mo ``` This uses `msgfmt` to compile each `.po` file to `/usr/share/locale//LC_MESSAGES/sudo-rs.mo`. If needed, you can override the install location by setting `LOCALEDIR` when invoking `make`. [rustup]: https://rustup.rs/ ## Differences from original sudo sudo-rs supports less functionality than sudo. Some of this is by design. In most cases you will get a clear error if you try something that is not supported (e.g. use a configuration flag or command line option that is not implemented). Exceptions to the above, with respect to your `/etc/sudoers` configuration: * `use_pty` is enabled by default, but can be disabled. * `env_reset` is ignored --- this is always enabled. * `visiblepw` is ignored --- this is always disabled. * `pwfeedback` is enabled by default, but can be disabled. * `verifypw` is ignored --- this is always set to `all` (the default) * the (NO)PASSWD tag on the "list" pseudocommand will determine whether a password is required for the `sudo -U --list` command, instead of `listpw`. * `mail_badpass`, `always_set_home`, `always_query_group_plugin` and `match_group_by_gid` are not applicable to our implementation, but ignored for compatibility reasons. * `timestamp_type` can only be set to `tty` and `ppid`. * `sudoedit_checkdir` is always `on`, and `sudoedit_follow` is always `off`. * `logfile` is not supported --- logging is always done via syslog. * `log_denied` is ignored -- denied invocations are always logged. Some other notable restrictions to be aware of: * Some functionality is not supported, such as preventing shell escapes using `INTERCEPT` and storing config in LDAP using `sudoers.ldap`, and `cvtsudoers`. This includes `sudo -E`, which is [discouraged](https://www.sudo.ws/docs/troubleshooting/#why-does-sudo-modify-the-commands-environment) in original sudo. * Sudo-rs always uses PAM for authentication, so your system must be set up for PAM. Sudo-rs will use the `sudo` and `sudo-i` service configuration. This also means that resource limits, umasks, etc have to be configured via PAM and not through the sudoers file. * sudo-rs will not include the sendmail support of original sudo. * The sudoers file must be valid UTF-8. * To prevent a common configuration mistake in the sudoers file, wildcards are only supported in *argument positions* for a command as the final argument. E.g., `%sudoers ALL = /sbin/fsck*` will allow `sudo fsck` and `sudo fsck_exfat` as expected, and `%sudoers ALL = /sbin/service ntp *` will allow a user to control the `ntp` service. but `%sudoers ALL = /bin/rm *.txt` will not allow an operator to run `sudo rm README.txt`, nor `sudo rm -rf /home .txt`, as with original sudo. If you find a common use case for original sudo missing, please create a feature request for it in our issue tracker. ## Aim of the project Our current target is to build a drop-in replacement for all common use cases of sudo. For the sudoers config syntax this means that we support the default configuration files of common Linux distributions. Our implementation should support all commonly used command line options from the original sudo implementation. Some parts of the original sudo are explicitly not in scope. Sudo has a large and rich history and some of the features available in the original sudo implementation are largely unused or only available for legacy platforms. In order to determine which features make it we both consider whether the feature is relevant for modern systems, and whether it will receive at very least decent usage. Finally, of course, a feature should not compromise the safety of the whole program. Our `su` implementation is made using the building blocks we created for our sudo implementation. It is a suitable replacement for the `su` distributed by [util-linux]. [util-linux]: https://github.com/util-linux/util-linux ## Future work While our initial target is a drop-in replacement for most basic use cases of sudo, our work may evolve beyond that target. We are also looking into alternative ways to configure sudo without the sudoers config file syntax and to extract parts of our work in usable crates for other people. ## History The initial development of sudo-rs was started and funded by the [Internet Security Research Group](https://www.abetterinternet.org/) as part of the [Prossimo project](https://www.memorysafety.org/) ## Acknowledgements Sudo-rs is an independent implementation, but it incorporates documentation and Rust translations of code from [sudo](https://www.sudo.ws/), maintained by Todd C. Miller. We thank Todd and the other sudo contributors for their work. An independent security audit of sudo-rs was made possible by the [NLNet Foundation](https://nlnet.nl/), who also [sponsored](https://nlnet.nl/project/sudo-rs/) work on increased compatibility with the original sudo and the FreeBSD port. The sudo-rs project would not have existed without the support of its sponsors, a full overview is maintained at --- ## File: docs/man/su.1.md --- title: SU(1) sudo-rs 0.2.14 | sudo-rs --- # NAME `su` - run a shell or command as another user # SYNOPSIS `su` [options] [-] [<*user*> [<*argument*>...]] # OPTIONS `-c` *command*, `--command`=*command* : Pass a single command to the shell with `-c`. `-g` *group*, `--group`=*group* : Specify the primary group `-G` *group*, `--supp-group`=*group* : Specify a supplemental group `-h`, `--help` : Show a help message. `-`, `-l`, `--login` : Make the shell a login shell `-m`, `-p`, `--preserve-environment` : Do not reset environment variables `-P`, `--pty` : Ignored for backwards compatibility. This version of su always creates a new pseudo-terminal if it is attached to a TTY `-w` *list*, `--whitelist-environment`=*list* : Do not reset the environment variables specified by the *list*. Multiple variables can be separated by commas `-s` *shell*, `--shell`=*shell* : Run *shell* if `/etc/shells` allows running as that shell instead of the default shell for the user `-V`, `--version` : Show the program version # SEE ALSO [sudo(8)](sudo.8.md) --- ## File: docs/man/sudo.8.md --- title: SUDO(8) sudo-rs 0.2.14 | sudo-rs --- # NAME `sudo`, `sudoedit` - execute a command as another user # SYNOPSIS `sudo` `-h` | `-K` | `-k` | `-V`\ `sudo` \[`-u` *user*\] \[`-g` *group*\] \[`-D` *directory*\] \[`-BbknS`\] \[`-i` | `-s`\] \[`VAR=value`\] \[<*command*>\]\ `sudo` `-v` \[`-BknS`\] \[`-u` *user*\] \[`-g` *group*\]\ `sudo` `-l` \[`-BknS`\] \[`-U` *user*\] \[`-u` *user*\] \[`-g` *group*\] \[command \[arg ...\]\]\ `sudo` `-e` \[`-BknS`\] \[`-u` *user*\] \[`-g` *group*\] file ...\ `sudoedit` \[`-BknS`\] \[`-u` *user*\] \[`-g` *group*\] file ... # DESCRIPTION `sudo` allows a user that is permitted to do so to execute a *command* as another user (for example *root*). Permissions are specified by a security policy specified in `/etc/sudoers` (see sudoers(5)). Sudo-rs is a safety oriented and memory safe re-implementation of the original sudo implementation by Todd Miller. When a command is run, a session record is stored for that specific session allowing users to run additional commands without having to re-authenticate. The timeout for session records can be specified in the policy. Some care is taken to pass signals received by sudo-rs to the child process, even if that process runs in its own pseudo terminal. On systems where sudo is the primary method of gaining superuser privileges, it is imperative to avoid syntax errors in the `/etc/sudoers` file. Changes to this file should be made using the visudo(8) utility which will ensure that no syntax errors are introduced. # OPTIONS `-A`, `--askpass` : Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. If no askpass program is available, sudo will exit with an error. `-B`, `--bell` : Ring the bell as part of the password prompt when a terminal is present. `-b`, `--background` : Run the given *command* in the background. It is not possible to use shell job control to manipulate background processes started by sudo-rs. Most interactive *command*s will fail to work properly in background mode. `-D` *directory*, `--chdir`=*directory* : Run the *command* in the specified *directory* instead of the current working directory. The security policy may return an error if the user does not have the permission to specify the working directory. `-g` *group*, `--group`=*group* : Use this *group* as the primary group instead of using the primary group specified in the password database for the target user. `-h`, `--help` : Show a help message. `-i`, `--login` : Run the shell specified by the target user's password database entry as a login shell. This means that login-specific resource files such as *.profile*, *.bash_profile* or *.login* will be read by the shell. If a *command* is specified, it is passed to the shell using the `-c` option. `-K`, `--remove-timestamp` : Removes every cached session record for the user, regardless of where the command is executed. The next time sudo-rs is run, authentication will take place if the policy requires it. No password is required to run this command. `-k`, `--reset-timestamp` : When used without a command, invalidates the user's session record for the current session. The next time sudo-rs is run, authentication will take place if the policy requires it. When used in conjunction with a *command* or an option that may require a password, this option will cause sudo-rs to ignore the user's session record. As a result, authentication will take place if the policy requires it. When used in conjunction with a *command* no invalidation of existing session records will take place. `-n`, `--non-interactive` : Avoid prompting the user for input of any kind. If any input is required for the *command* to run, sudo-rs will display an error message and exit. `-p`, `--prompt`=*prompt* : Use a custom authentication prompt with optional escape sequences. The following percent (‘%’) escape sequences are supported: %H expanded to the local host name %h expanded to the local host name without the domain name %p expanded to the name of the user whose password is being requested (this respects the rootpw, targetpw flags) %U expanded to the login name of the user the command will be run as (defaults to root unless the -u option is also specified) %u expanded to the invoking user's login name %% two consecutive ‘%’ characters are collapsed into a single ‘%’ character The custom prompt will override the default prompt or the one specified by the SUDO_PROMPT environment variable. No *prompt* will suppress the prompt provided by PAM, unless the requested *prompt* is empty (`""`) `-S`, `--stdin` : Read from standard input instead of using the terminal device. `-s`, `--shell` : Run the shell specified by the `SHELL` environment variable. If no shell was specified, the shell from the user's password database entry will be used instead. If a *command* is specified, it is passed to the shell using the `-c` option. `--preserve-env=list` : Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those preserved from the user's environment. The security policy may return an error if the user does not have permission to preserve the environment. This option may be specified multiple times. `-e`, `--edit`, `sudoedit` : Edit one or more files instead of running a command. In lieu of a path name, the string "sudoedit" is used when consulting the security policy. If the user is authorized by the policy, the following steps are taken: 1. Temporary copies are made of the files to be edited with the owner set to the invoking user. 2. The editor specified by the policy is run to edit the temporary files. The sudoers policy uses the SUDO_EDITOR, VISUAL and EDITOR environment variables (in that order). If none of SUDO_EDITOR, VISUAL or EDITOR are set, the first program listed in the editor sudoers(5) option is used. 3. If they have been modified, the content of the temporary files is copied back to the originals and the temporary versions are removed. To help prevent the editing of unauthorized files, the following restrictions are enforced (unless the user is root): * Symbolic links may not be edited. * If any component of the path leading to the file is writable by the invoking user, the file may not be edited. * Users are never allowed to edit device special files. If the specified file does not exist, it will be created. Unlike most commands run by sudo, the editor is run with the invoking user's environment unmodified. If the temporary file becomes empty after editing, the user will be prompted before it is installed. `-u` *user*, `--user`=*user* : Run the *command* as another user than the default (**root**). `-V`, `--version` : Display the current version of sudo-rs. `-v`, `--validate` : Update the session record for the current session, authenticating the user if necessary. `-l`, `--list` : List user's privileges or check a specific command; use twice for longer format `-U`, `--other-user`=*user* : Used in list mode, display privileges for another user `--` : Indicates the end of the sudo-rs options and start of the *command*. Environment variables to be set for the command may be passed on the command line in the form of VAR=value. Variables passed on the command line are subject to restrictions imposed by the security policy. Variables passed on the command line are subject to the same restrictions as normal environment variables with one important exception: If the command to be run has the SETENV tag set or the command matched is ALL, the user may set variables that would otherwise be forbidden. See [sudoers(5)](sudoers.5.md) for more information. # SEE ALSO [su(1)](su.1.md), [sudoers(5)](sudoers.5.md), [visudo(8)](visudo.8.md) --- ## File: docs/man/sudoers.5.md --- title: SUDOERS(5) sudo-rs 0.2.14 | sudo-rs --- # NAME `sudoers` - sudo-compatible security configuration # DESCRIPTION The `sudo-rs` policy determines a user's sudo privileges. The policy is driven by the */etc/sudoers file*. The policy format is described in detail in the **SUDOERS FILE FORMAT** section. The format used by sudo-rs is a subset of the one used by the sudo-project as maintained by Todd Miller, but syntax-compatible. ## User Authentication The sudoers security policy requires that most users authenticate themselves before they can use sudo. A password is not required if the invoking user is root, if the target user is the same as the invoking user, or if the policy has disabled authentication for the user or command. Unlike `su`, when `sudo-rs` requires authentication, it validates the invoking user's credentials, not the target user's (or root's) credentials. This can be changed via the *rootpw* flag, described later. `sudo-rs` uses per-user timestamp files for credential caching. Once a user has been authenticated, a record is written containing the user-ID that was used to authenticate, the terminal session ID, the start time of the session leader (or parent process) and a timestamp (using a monotonic clock if one is available). The user may then use sudo without a password for a short period of time (15 minutes unless overridden by the timestamp_timeout option). `sudo-rs` uses a separate record for each terminal, which means that a user's login sessions are authenticated separately. ## Logging By default, `sudo-rs` logs both successful and unsuccessful attempts (as well as errors). Messages are logged to syslog(3). ## Command environment Since environment variables can influence program behavior, `sudo-rs` restricts which variables from the user's environment are inherited by the command to be run. In `sudo-rs`, the *env_reset* flag cannot be disabled. This causes commands to be executed with a new, minimal environment. The `HOME`, `SHELL`, `LOGNAME` and `USER` environment variables are initialized based on the target user and the `SUDO_*` variables are set based on the invoking user. Additional variables, such as `DISPLAY`, `PATH` and `TERM`, are preserved from the invoking user's environment if permitted by the *env_check* or *env_keep* options. A few environment variables are treated specially. If the `PATH` and `TERM` variables are not preserved from the user's environment, they will be set to default values. The `LOGNAME` and `USER` are handled as a single entity. If one of them is preserved (or removed) from the user's environment, the other will be as well. If `LOGNAME` and `USER` are to be preserved but only one of them is present in the user's environment, the other will be set to the same value. This avoids an inconsistent environment where one of the variables describing the user name is set to the invoking user and one is set to the target user. Environment variables with a value beginning with `()` are removed, as they may be interpreted as functions by the bash shell. Environment variables specified by *env_check* or *env_keep* may include one or more ‘\*’ characters which will match zero or more characters. No other wildcard characters are supported. Other sudoers options may influence the command environment, such as *secure_path*. Variables in the PAM environment may be merged in to the environment. If a variable in the PAM environment is already present in the user's environment, the value will only be overridden if the variable was not preserved by `sudo-rs`. Variables preserved from the invoking user's environment by the *env_keep* list take precedence over those in the PAM environment. Note that the dynamic linker on most operating systems will remove variables that can control dynamic linking from the environment of set-user-ID executables, including sudo. Depending on the operating system this may include `_RLD*`, `DYLD_*`, `LD_*`, `LDR_*`, `LIBPATH`, `SHLIB_PATH`, and others. These type of variables are removed from the environment before sudo even begins execution and, as such, it is not possible for sudo to preserve them. ## Resource limits sudo uses the operating system's native method of setting resource limits for the target user. On Linux systems, resource limits are usually set by the *pam_limits.so* PAM module. On some BSD systems, the */etc/login.conf* file specifies resource limits for the user. If there is no system mechanism to set per-user resource limits, the command will run with the same limits as the invoking user. # SUDOERS FILE FORMAT The sudoers file is composed of two types of entries: aliases (basically variables) and user specifications (which specify who may run what). When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match). The sudoers file grammar will be described below in Extended Backus-Naur Form (EBNF) borrowed from Todd Miller's sudoers documentation. ## Quick guide to EBNF EBNF is a concise and exact way of describing the grammar of a language. Each EBNF definition is made up of production rules. E.g., symbol ::= definition | alternate1 | alternate2 ... Each production rule references others and thus makes up a grammar for the language. EBNF also contains the following operators, which many readers will recognize from regular expressions. Do not, however, confuse them with “wildcard” characters, which have different meanings. ? Means that the preceding symbol (or group of symbols) is optional. That is, it may appear once or not at all. * Means that the preceding symbol (or group of symbols) may appear zero or more times. + Means that the preceding symbol (or group of symbols) may appear one or more times. Parentheses may be used to group symbols together. For clarity, we will use single quotes ('') to designate what is a verbatim character string (as opposed to a symbol name). ## Aliases There are four kinds of aliases: User_Alias, Runas_Alias, Host_Alias and Cmnd_Alias. Alias ::= 'User_Alias' User_Alias_Spec (':' User_Alias_Spec)* | 'Runas_Alias' Runas_Alias_Spec (':' Runas_Alias_Spec)* | 'Host_Alias' Host_Alias_Spec (':' Host_Alias_Spec)* | 'Cmnd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)* | 'Cmd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)* User_Alias ::= NAME User_Alias_Spec ::= User_Alias '=' User_List Runas_Alias ::= NAME Runas_Alias_Spec ::= Runas_Alias '=' Runas_List Host_Alias ::= NAME Host_Alias_Spec ::= Host_Alias '=' Host_List Cmnd_Alias ::= NAME Cmnd_Alias_Spec ::= Cmnd_Alias '=' Cmnd_List NAME ::= [A-Z]([A-Z][0-9]_)* Each alias definition is of the form Alias_Type NAME = item1, item2, ... where *Alias_Type* is one of User_Alias, Runas_Alias, Host_Alias, or Cmnd_Alias. A NAME is a string of uppercase letters, numbers, and underscore characters (‘_’). A NAME must start with an uppercase letter. It is possible to put several alias definitions of the same type on a single line, joined by a colon (‘:’). E.g., Alias_Type NAME = item1, item2, item3 : NAME = item4, item5 The definitions of what constitutes a valid alias member follow. User_List ::= User | User ',' User_List User ::= '!'* user name | '!'* #user-ID | '!'* %group | '!'* %#group-ID | '!'* User_Alias A User_List is made up of one or more user names, user-IDs (prefixed with ‘#’), system group names and IDs (prefixed with ‘%’ and ‘%#’ respectively) and User_Aliases. Each list item may be prefixed with zero or more ‘!’ operators. An odd number of ‘!’ operators negate the value of the item; an even number just cancel each other out. Runas_List ::= Runas_Member | Runas_Member ',' Runas_List Runas_Member ::= '!'* user name | '!'* #user-ID | '!'* %group | '!'* %#group-ID | '!'* Runas_Alias A Runas_List is similar to a User_List except that instead of User_Aliases it can contain Runas_Aliases. Note that user names and groups are matched as strings. In other words, two users (groups) with the same user (group) ID are considered to be distinct. If you wish to match all user names with the same user-ID (e.g., root and toor), you can use a user-ID instead of a name (`#0` in the example given). Host_List ::= Host | Host ',' Host_List Host ::= '!'* host name | '!'* Host_Alias A Host_List is made up of one or more host names. Again, the value of an item may be negated with the ‘!’ operator. Cmnd_List ::= Cmnd | Cmnd ',' Cmnd_List command name ::= file name | file name args ['*'] | file name '""' Cmnd ::= '!'* command name | '!'* directory | '!'* Cmnd_Alias '!'* "list" '!'* "sudoedit" [file name] A Cmnd_List is a list of one or more command names, directories, and other aliases. A command name is a fully qualified file name which may include shell-style wildcards (see the *Wildcards* section below). A simple file name allows the user to run the command with any arguments they wish. However, you may also specify command line arguments that have to be used, in which case the command line has to match exactly. You can use the special argument "" to indicate that the command may only be run *without* command line arguments, or the argument ‘*’ to match any trailing arguments. You cannot use wildcards inside the argument list. A directory is a fully qualified path name ending in a ‘/’. When you specify a directory in a Cmnd_List, the user will be able to run any file within that directory (but not in any sub-directories therein). If a Cmnd has associated command line arguments, then the arguments in the Cmnd must match exactly those given by the user on the command line. Note that the following characters must be escaped with a ‘\\’ if they are used in command arguments: ‘,’, ‘:’, ‘=’, ‘\\’. There are two commands built into sudo itself: “list” and “sudoedit”. Unlike other commands, these two must be specified in the sudoers file without a leading path. The “list” built-in can be used to permit a user to list another user's privileges with sudo's -U option. For example, “sudo -l -U otheruser”. A user with the “list” privilege is able to list another user's privileges even if they don't have permission to run commands as that user. By default, only root or a user with the ability to run any command as either root or the specified user on the current host may use the -U option. No command line arguments may be specified with the “list” built-in. The “sudoedit” built-in is used to permit a user to run sudo with the -e option (or as sudoedit). It may take command line arguments just as a normal command does. Unlike other commands, “sudoedit” is built into sudo itself and must be specified in the sudoers file without a leading path. If a leading path is present, for example /usr/bin/sudoedit, this will not give the user permissions to use sudoedit. If no arguments are provided, “sudoedit” will give the user the permission to edit any files; if an argument is present it must be an absolute path name that does not contain symbolic links, or the command will not be matched. ## Defaults Certain configuration options may be changed from their default values at run-time via one or more Default_Entry lines. These may affect all users on any host, all users on a specific host, a specific user, a specific command, or commands being run as a specific user. Note that per-command entries may not include command line arguments. If you need to specify arguments, define a Cmnd_Alias and reference that instead. Default_Type ::= 'Defaults' | 'Defaults' '@' Host_List | 'Defaults' ':' User_List | 'Defaults' '!' Cmnd_List | 'Defaults' '>' Runas_List Default_Entry ::= Default_Type Parameter_List Parameter_List ::= Parameter | Parameter ',' Parameter_List Parameter ::= Parameter '=' Value | Parameter '+=' Value | Parameter '-=' Value | '!'* Parameter Parameters may be flags, integer values, strings, or lists. Flags are implicitly boolean and can be turned off via the ‘!’ operator. Some integer, string and list parameters may also be used in a boolean context to disable them. Values may be enclosed in double quotes ("") when they contain multiple words. Special characters may be escaped with a backslash (‘\\’). To include a literal backslash character in a command line argument you must escape the backslash twice. For example, to match ‘\\n’ as part of a command line argument, you must use ‘\\\\\\\\n’ in the sudoers file. This is due to there being two levels of escaping, one in the sudoers parser itself and another when command line arguments are matched by the fnmatch(3) function. Lists have two additional assignment operators, *+=* and *-=*. These operators are used to add to and delete from a list respectively. It is not an error to use the -= operator to remove an element that does not exist in a list. Defaults entries are parsed in the following order: generic, host, user, and runas Defaults are processed in the order they appear, with per-command defaults being processed in a second pass after that. See **SUDOERS OPTIONS** for a list of supported Defaults parameters. ## User specification User_Spec ::= User_List Host_List '=' Cmnd_Spec_List \ (':' Host_List '=' Cmnd_Spec_List)* Cmnd_Spec_List ::= Cmnd_Spec | Cmnd_Spec ',' Cmnd_Spec_List Cmnd_Spec ::= Runas_Spec? Chdir_Spec? Tag_Spec* Cmnd Runas_Spec ::= '(' Runas_List? (':' Runas_List)? ')' Chdir_Spec ::= 'CWD=directory' Tag_Spec ::= ('PASSWD:' | 'NOPASSWD:' | 'SETENV:' | 'NOSETENV:' 'EXEC:' | 'NOEXEC') AppArmor_Spec ::= 'APPARMOR_PROFILE=profile' A user specification determines which commands a user may run (and as what user) on specified hosts. By default, commands are run as root, but this can be changed on a per-command basis. The basic structure of a user specification is “who where = (as_whom) what”. Let's break that down into its constituent parts: ## Runas_Spec A Runas_Spec determines the user and/or the group that a command may be run as. A fully-specified Runas_Spec consists of two Runas_Lists (as defined above) separated by a colon (‘:’) and enclosed in a set of parentheses. The first Runas_List indicates which users the command may be run as via the -u option. The second defines a list of groups that may be specified via the -g option (in addition to any of the target user's groups). If both Runas_Lists are specified, the command may be run with any combination of users and groups listed in their respective Runas_Lists. If only the first is specified, the command may be run as any user in the list and, optionally, with any group the target user belongs to. If the first Runas_List is empty but the second is specified, the command may be run as the invoking user with the group set to any listed in the Runas_List. If both Runas_Lists are empty, the command may only be run as the invoking user and the group, if specified, must be one that the invoking user is a member of. If no Runas_Spec is specified, the command may only be run as root and the group, if specified, must be one that root is a member of. A Runas_Spec sets the default for the commands that follow it. What this means is that for the entry: dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm The user dgb may run /bin/ls, /bin/kill, and /usr/bin/lprm on the host boulder—but only as operator. E.g., $ sudo -u operator /bin/ls It is also possible to override a Runas_Spec later on in an entry. If we modify the entry like so: dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm Then user dgb is now allowed to run /bin/ls as operator, but /bin/kill and /usr/bin/lprm as root. We can extend this to allow dgb to run /bin/ls with either the user or group set to operator: dgb boulder = (operator : operator) /bin/ls, (root) /bin/kill,\ /usr/bin/lprm Note that while the group portion of the Runas_Spec permits the user to run as command with that group, it does not force the user to do so. If no group is specified on the command line, the command will run with the group listed in the target user's password database entry. The following would all be permitted by the sudoers entry above: $ sudo -u operator /bin/ls $ sudo -u operator -g operator /bin/ls $ sudo -g operator /bin/ls In the following example, user tcm may run commands that access a modem device file with the dialer group. tcm boulder = (:dialer) /usr/bin/tip, /usr/bin/cu,\ /usr/local/bin/minicom Note that in this example only the group will be set, the command still runs as user tcm. E.g. $ sudo -g dialer /usr/bin/cu Multiple users and groups may be present in a Runas_Spec, in which case the user may select any combination of users and groups via the -u and -g options. In this example: alan ALL = (root, bin : operator, system) ALL user alan may run any command as either user root or bin, optionally setting the group to operator or system. ## Chdir_Spec The working directory that the command will be run in can be specified using the CWD setting. The directory must be a fully-qualified path name beginning with a ‘/’ or ‘~’ character, or the special value “\*”. A value of “\*” indicates that the user may specify the working directory by running sudo with the -D option. By default, commands are run from the invoking user's current working directory, unless the -i option is given. Path names of the form ~user/path/name are interpreted as being relative to the named user's home directory. If the user name is omitted, the path will be relative to the runas user's home directory. ## Tag_Spec A command may have zero or more tags associated with it. The following tag values are supported: PASSWD, NOPASSWD, SETENV, and NOSETENV. Once a tag is set on a Cmnd, subsequent Cmnds in the Cmnd_Spec_List, inherit the tag unless it is overridden by the opposite tag (in other words, PASSWD overrides NOPASSWD and NOSETENV overrides SETENV). ### EXEC and NOEXEC On Linux systems, the NOEXEC tag can be used to prevent an executable from running further commands itself. In the following example, user aaron may run /usr/bin/more and /usr/bin/vi but shell escapes will be disabled. aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi See the *Preventing shell escapes* section below for more details on how NOEXEC works and whether or not it suits your purpose. ### PASSWD and NOPASSWD By default, sudo requires that a user authenticate before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List. Conversely, the PASSWD tag can be used to reverse things. For example: queen rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm would allow the user queen to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine “rushmore” without authenticating himself. If we only want queen to be able to run /bin/kill without a password the entry would be: queen rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm By default, if the NOPASSWD tag is applied to any of a user's entries for the current host, the user will be able to run “sudo -l” without a password. Additionally, a user may only run “sudo -v” without a password if all of the user's entries for the current host have the NOPASSWD tag. ### SETENV and NOSETENV These tags override the value of the setenv flag on a per-command basis. Note that if SETENV has been set for a command, the user may disable the env_reset flag from the command line via the -E option. Additionally, environment variables set on the command line are not subject to the restrictions imposed by env_check, env_delete, or env_keep. As such, only trusted users should be allowed to set variables in this manner. If the command matched is ALL, the SETENV tag is implied for that command; this default may be overridden by use of the NOSETENV tag. ## AppArmor_Spec When sudo-rs is built with support for AppArmor, sudoers file entries may specify an AppArmor profile that should be used to confine a command. If an AppArmor profile is specified with the command, it will override any default values specified in sudoers. Appropriate profile transition rules must be defined to support the profile change specified for a user. AppArmor profiles can be specified in any way that complies with the rules of `aa_change_profile(2)`. ## Wildcards sudo allows shell-style wildcards (aka meta or glob characters) to be used in host names, path names, and command line arguments in the sudoers file. Wildcard matching is done via the glob(3) and fnmatch(3) functions as specified by IEEE Std 1003.1 (“POSIX.1”). * Matches any set of zero or more characters (including white space). ? Matches any single character (including white space). [...] Matches any character in the specified range. [!...] Matches any character not in the specified range. \x For any character ‘x’, evaluates to ‘x’. This is used to escape special characters such as: ‘*’, ‘?’, ‘[’, and ‘]’. Note that these are not regular expressions. Unlike a regular expression there is no way to match one or more characters within a range. Wildcards in command line arguments are not supported---using these in original versions of sudo was usually a sign of mis-configuration and consequently sudo-rs simply forbids using them. The only supported use is ‘*’ as the final argument to indicate "zero or more subsequent arguments" as noted above. ## Including other files from within sudoers It is possible to include other sudoers files from within the sudoers file currently being parsed using the *@include* and *@includedir* directives; or the contents provided by an application over a unix domain socket using the *@socket* directive. For compatibility with Todd Miller's sudo versions prior to 1.9.1, *#include* and *#includedir* are also accepted. An include file can be used, for example, to keep a site-wide sudoers file in addition to a local, per-machine file. For the sake of this example the site-wide sudoers file will be /etc/sudoers and the per-machine one will be /etc/sudoers.local. To include /etc/sudoers.local from within /etc/sudoers one would use the following line in /etc/sudoers: @include /etc/sudoers.local When sudo reaches this line it will suspend processing of the current file (/etc/sudoers) and switch to /etc/sudoers.local. Upon reaching the end of /etc/sudoers.local, the rest of /etc/sudoers will be processed. Files that are included may themselves include other files. A hard limit of 128 nested include files is enforced to prevent include file loops. The path to the include file may contain white space if it is escaped with a backslash (‘\\’). Alternately, the entire path may be enclosed in double quotes (""), in which case no escaping is necessary. To include a literal backslash in the path, ‘\\\\’ should be used. If the path to the include file is not fully-qualified (does not begin with a ‘/’), it must be located in the same directory as the sudoers file it was included from. For example, if /etc/sudoers contains the line: @include sudoers.local The @includedir directive can be used to create a sudoers.d directory that the system package manager can drop sudoers file rules into as part of package installation. For example, given: @includedir /etc/sudoers.d sudo will suspend processing of the current file and read each file in /etc/sudoers.d, skipping file names that end in ‘~’ or contain a ‘.’ character to avoid causing problems with package manager or editor temporary/backup files. Files are parsed in sorted lexical order. That is, /etc/sudoers.d/01_first will be parsed before /etc/sudoers.d/10_second. Be aware that because the sorting is lexical, not numeric, /etc/sudoers.d/1_whoops would be loaded after /etc/sudoers.d/10_second. Using a consistent number of leading zeroes in the file names can be used to avoid such problems. After parsing the files in the directory, control returns to the file that contained the @includedir directive. Note that unlike files included via @include, visudo will not edit the files in a @includedir directory unless one of them contains a syntax error. It is still possible to run visudo with the -f flag to edit the files directly, but this will not catch the redefinition of an alias that is also present in a different file. When managing enterprise-wide sudoers rules, it is sometimes preferable to store them in a centralized repository. The @socket directive can be used to include the contents provided by a server application over a Unix domain socket. For example, providing: @socket (sssd:sssd) /var/run/providers/sudoers.socket will make sudo open that socket, read the rules, and close it, as if it was an included file. The rules must follow the same syntax used in the sudoers files. There is, however, one exception: when reading from a socket, the @include, @includedir, and @socket directives are not accepted. For security reasons, a user and optionally a group must be given, enclosed in parentheses and separated by a colon. Users and groups can be specified either by their name or by their numeric id preceded by a hash sign (#). When the socket is opened, and before any interaction with it, sudo will check that the peer process at the other side of the socket runs as the declared user and group (if the latter was provided). If any of these conditions fail, the socket is immediately closed and discarded. Only POSIX groups can be used. Please note that visudo cannot read from a socket. Furthermore, the contents retrieved from a socket are considered immutable by sudo. ## Other special characters and reserved words The pound sign (‘#’) is used to indicate a comment (unless it is part of a #include directive or unless it occurs in the context of a user name and is followed by one or more digits, in which case it is treated as a user-ID). Both the comment character and any text after it, up to the end of the line, are ignored. The reserved word *ALL* is a built-in alias that always causes a match to succeed. It can be used wherever one might otherwise use a Cmnd_Alias, User_Alias, Runas_Alias, or Host_Alias. Attempting to define an alias named ALL will result in a syntax error. Please note that using ALL can be dangerous since in a command context, it allows the user to run any command on the system. An exclamation point (‘!’) can be used as a logical not operator in a list or alias as well as in front of a Cmnd. This allows one to exclude certain values. For the ‘!’ operator to be effective, there must be something for it to exclude. For example, to match all users except for root one would use: ALL,!root If the ALL, is omitted, as in: !root it would explicitly deny root but not match any other users. This is different from a true “negation” operator. Note, however, that using a ‘!’ in conjunction with the built-in ALL alias to allow a user to run “all but a few” commands rarely works as intended (see SECURITY NOTES below). White space between elements in a list as well as special syntactic characters in a User Specification (‘=’, ‘:’, ‘(’, ‘)’) is optional. The following characters must be escaped with a backslash (‘\\’) when used as part of a word (e.g., a user name or host name): ‘!’, ‘=’, ‘:’, ‘,’, ‘(’, ‘)’, ‘\\’. ## SUDOERS OPTIONS sudo's behavior can be modified by Default_Entry lines, as explained earlier. A list of all supported Defaults parameters, grouped by type, are listed below. ### Boolean Flags: * log_allowed If set, sudoers will log commands allowed by the policy to the system log. This flag is on by default. * noexec If set, all commands run via sudo will behave as if the NOEXEC tag has been set, unless overridden by an EXEC tag. See the description of EXEC and NOEXEC as well as the *Preventing shell escapes* section at the end of this manual. This flag is off by default. * noninteractive_auth If set, authentication will be attempted even in non-interactive mode (when sudo's -n option is specified). This allows authentication methods that don't require user interaction to succeed. Authentication methods that require input from the user's terminal will still fail. If disabled, authentication will not be attempted in non-interactive mode. This flag is off by default. * env_editor If set, visudo will use the value of the SUDO_EDITOR, VISUAL or EDITOR environment variables before falling back on the default editor list. Note that visudo is typically run as root so this flag may allow a user with visudo privileges to run arbitrary commands as root without logging. An alternative is to place a colon-separated list of “safe” editors int the editor setting. visudo will then only use SUDO_EDITOR, VISUAL or EDITOR if they match a value specified in editor. If the env_reset flag is enabled, the SUDO_EDITOR, VISUAL and/or EDITOR environment variables must be present in the env_keep list for the env_editor flag to function when visudo is invoked via sudo. This flag is on by default. * pwfeedback By default, sudo reads the password like most other Unix programs, by turning off echo until the user hits the return (or enter) key. Some users become confused by this as it appears to them that sudo has hung at this point. When pwfeedback is set, sudo will provide visual feedback when the user presses a key. Feedback can always be turned off by using the TAB key. This flag is on by default. * rootpw If set, sudo will prompt for the root password instead of the password of the invoking user when running a command or editing a file. This flag is off by default. * setenv Allow the user to set environment variables set via the command line that are not subject to the restrictions imposed by env_check, env_delete, or env_keep. As such, only trusted users should be allowed to set variables in this manner. This flag is off by default. * targetpw If set, sudo will prompt for the password of the user specified by the -u option (defaults to root) instead of the password of the invoking user when running a command or editing a file. Note that this flag precludes the use of a user-ID not listed in the passwd database as an argument to the -u option. This flag is off by default. * umask_override If set, sudo will set the umask as specified in the sudoers file without modification. This makes it possible to specify a umask in the sudoers file that is more permissive than the user's own umask. If umask_override is not set, sudo will set the umask to be the union of the user's umask and what is specified in sudoers. This flag is off by default. * use_pty If set, and sudo is running in a terminal, the command will be run in a pseudo-terminal (even if no I/O logging is being done). If the sudo process is not attached to a terminal, use_pty has no effect. A malicious program run under sudo may be capable of injecting commands into the user's terminal or running a background process that retains access to the user's terminal device even after the main program has finished executing. By running the command in a separate pseudo-terminal, this attack is no longer possible. This flag is on by default. ## Integers: * passwd_tries The number of tries a user gets to enter his/her password before sudo logs the failure and exits. The default is 3. ## Integers that can be used in a boolean context: * timestamp_timeout Number of minutes that can elapse before sudo will ask for a passwd again. The timeout may include a fractional component if minute granularity is insufficient, for example 2.5. The default is 15. Set this to 0 to always prompt for a password. * umask File mode creation mask to use when running the command. Negate this option or set it to 0777 to prevent sudo from changing the umask. Unless the umask_override flag is set, the actual umask will be the union of the user's umask and the value of the umask setting, which defaults to 0022. This guarantees that sudo never lowers the umask when running a command. If umask is explicitly set, it will override any umask setting in PAM. If umask is not set, the umask specified by PAM will take precedence. The umask setting in PAM is not used for sudoedit, which does not create a new PAM session. ## Strings * editor A colon (‘:’) separated list of editor path names used by **sudoedit** and **visudo**. For **sudoedit**, this list is used to find an editor when none of the SUDO_EDITOR, VISUAL or EDITOR environment variables are set to an editor that exists and is executable. For **visudo**, it is used as a white list of allowed editors; **visudo** will choose the editor that matches the user's SUDO_EDITOR, VISUAL or EDITOR environment variable if possible, or the first editor in the list that exists and is executable if not. Unless invoked as **sudoedit**, sudo does not preserve the SUDO_EDITOR, VISUAL or EDITOR environment variables unless they are present in the **env_keep** list. The default on Linux is _/usr/bin/editor:/usr/bin/nano:/usr/bin/vi_. On FreeBSD the default is _/usr/bin/vi_. * timestamp_type sudo-rs uses per-user timestamp files for credential caching. The *timestamp_type* option can be used to specify the type of timestamp record used. It has two possible values: _tty_ and _ppid_. There is no support for a _global_ or _kernel_ setting. - _ppid_: A single timestamp record is used for all processes with the same parent process ID (usually the shell). Commands run from the same shell (or other common parent process) will not require a password while the timestamp is valid (see *timestamp_timeout*). Commands run via sudo with a different parent process ID, for example from a shell script, must be authenticated separately. - _tty_: One timestamp record is used for each terminal, which means that a user's login sessions are authenticated separately. If no terminal is present, the behavior is the same as _ppid_. Commands run from the same terminal will not require a password while the timestamp is valid. The default value is **tty**. ## Strings that can be used in a boolean context: * apparmor_profile The default AppArmor profile to transition into when executing a command. The default apparmor_profile can be overridden for individual sudoers entries by specifying the APPARMOR_PROFILE option. This option is only available when sudo-rs is built with AppArmor support. This option is not set by default. * runcwd If set, sudo will use this value for the working directory when running a command. The special value “\*” will allow the user to specify the working directory via sudo's -D option. See the *Chdir_Spec* section for more details. * secure_path If set, sudo will use this value in place of the user's PATH environment variable. This option can be used to reset the PATH to a known good value that contains directories for system administrator commands such as /usr/sbin. This option is not set by default. ## Lists that can be used in a boolean context: * env_check Environment variables to be removed from the user's environment unless they are considered “safe”. For all variables except TZ, “safe” means that the variable's value does not contain any ‘%’ or ‘/’ characters. This can be used to guard against printf-style format vulnerabilities in poorly-written programs. The TZ variable is considered unsafe if any of the following are true: • It consists of a fully-qualified path name, optionally prefixed with a colon (‘:’), that does not match the location of the zoneinfo directory. • It contains a .. path element. • It contains white space or non-printable characters. • It is longer than the value of PATH_MAX. The argument may be a double-quoted, space-separated list or a single value without double-quotes. The list can be replaced, added to, deleted from, or disabled by using the =, +=, -=, and ! operators respectively. Regardless of whether the env_reset option is enabled or disabled, variables specified by env_check will be preserved in the environment if they pass the aforementioned check. The global list of environment variables to check is displayed when sudo is run by root with the -V option. * env_keep Environment variables to be preserved in the user's environment when the env_reset option is in effect. This allows fine-grained control over the environment sudo-spawned processes will receive. The argument may be a double-quoted, space-separated list or a single value without double-quotes. The list can be replaced, added to, deleted from, or disabled by using the =, +=, -=, and ! operators respectively. The global list of variables to keep is displayed when sudo is run by root with the -V option. Preserving the HOME environment variable has security implications since many programs use it when searching for configuration or data files. Adding HOME to env_keep may enable a user to run unrestricted commands via sudo and is strongly discouraged. Users wishing to edit files with sudo should run **sudoedit** (or **sudo -e**) to get their accustomed editor configuration instead of invoking the editor directly. ## LOG FORMAT sudo-rs logs events via syslog(3). ## FILES /etc/sudoers-rs List of who can run what (for co-existence of sudo-rs and Todd Miller's sudo) /etc/sudoers List of who can run what (sudo-compatible) /run/sudo/ts Directory containing timestamps for the sudoers security policy ## SECURITY NOTES ### Limitations of the ‘!’ operator It is generally not effective to “subtract” commands from ALL using the ‘!’ operator. A user can trivially circumvent this by copying the desired command to a different name and then executing that. For example: bill ALL = ALL, !SU, !SHELLS Doesn't really prevent bill from running the commands listed in SU or SHELLS since he can simply copy those commands to a different name, or use a shell escape from an editor or other program. Therefore, these kind of restrictions should be considered advisory at best (and reinforced by policy). In general, if a user has sudo ALL there is nothing to prevent them from creating their own program that gives them a root shell (or making their own copy of a shell) regardless of any ‘!’ elements in the user specification. ### Security implications of `fast_glob` sudo-rs uses `fast_glob, which further means it is not possible to reliably negate commands where the path name includes globbing (aka wildcard) characters. This is because the Rust library's fnmatch function cannot resolve relative paths. While this is typically only an inconvenience for rules that grant privileges, it can result in a security issue for rules that subtract or revoke privileges. For example, given the following sudoers file entry: john ALL = /usr/bin/passwd [a-zA-Z0-9]*, /usr/bin/chsh [a-zA-Z0-9]*,\ /usr/bin/chfn [a-zA-Z0-9]*, !/usr/bin/* root User john can still run /usr/bin/passwd root if fast_glob is enabled by changing to /usr/bin and running ./passwd root instead. ### Preventing shell escapes Once sudo executes a program, that program is free to do whatever it pleases, including run other programs. This can be a security issue since it is not uncommon for a program to allow shell escapes, which lets a user bypass sudo's access control and logging. Common programs that permit shell escapes include shells (obviously), editors, paginators (such as *less*), mail, and terminal programs. On Linux, sudo-rs has sudo's **noexec** functionality, based on a seccomp() filter. Programs that are run in **noexec** mode cannot run other programs. The implementation in sudo-rs is different than in Todd Miller's sudo, and should also work on statically linked binaries. Note that restricting shell escapes is not a panacea. Programs running as root are still capable of many potentially hazardous operations (such as changing or overwriting files) that could lead to unintended privilege escalation. NOEXEC is also not a protection against malicious programs. It doesn't prevent mapping memory as executable, nor does it protect against future syscalls that can do an exec() like the proposed `io_uring` exec feature in Linux. And it also doesn't protect against honest programs that intentionally or not allow the user to write to /proc/self/mem for the same reasons as that it doesn't protect against malicious programs. You should always try out if **noexec** indeed prevents shell escapes for the programs it is intended to be used with. ### Timestamp file checks sudo-rs will check the ownership of its timestamp directory (/run/sudo/ts by default) and ignore the directory's contents if it is not owned by root or if it is writable by a user other than root. While the timestamp directory should be cleared at reboot time, to avoid potential problems, sudo-rs will ignore timestamp files that date from before the machine booted on systems where the boot time is available. Some systems with graphical desktop environments allow unprivileged users to change the system clock. Since sudo-rs relies on the system clock for timestamp validation, it may be possible on such systems for a user to run sudo for longer than *timestamp_timeout* by setting the clock back. To combat this, `sudo-rs` uses a monotonic clock (which never moves backwards) for its timestamps if the system supports it. sudo-rs will not honor timestamps set far in the future. ## SEE ALSO su(1), fnmatch(3), glob(3), sudo(8), visudo(8) ## CAVEATS The sudoers file should always be edited by the visudo utility which locks the file and checks for syntax errors. If sudoers contains syntax errors, you may lock yourself out of being able to use sudo. ## BUGS If you feel you have found a bug in sudo-rs, please submit a bug report at https://github.com/trifectatechfoundation/sudo-rs/issues/ # AUTHORS This man page is a modified version of the sudoers(5) documentation written by Todd Miller; see https://www.sudo.ws/ for the original. ## DISCLAIMER sudo-rs is provided “AS IS” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. --- ## File: docs/man/visudo.8.md --- title: VISUDO(8) sudo-rs 0.2.14 | sudo-rs --- # NAME `visudo` - safely edit the sudoers file # SYNOPSIS `visudo` [`-chqsV`] [[`-f`] *sudoers*] # DESCRIPTION `visudo` edits the *sudoers* file in a safe manner, similar to vipw(8). # OPTIONS `-c`, `--check` : Only check if there are errors in the existing sudoers file. `-f` *sudoers*, `--file`=*sudoers* : Instead of editing the default `/etc/sudoers`, edit the file specified as *sudoers* instead. `-h`, `--help` : Show a help message. `-V`, `--version` : Display version information and exit. # SEE ALSO [sudo(8)](sudo.8.md), sudoers(5) --- ## File: docs/sudo-cve.md # Past sudo CVEs This listing contains security issues originally found in sudo but which could also be relevant for sudo-rs. ## Possibly relevant CVEs / advisories These CVEs/advisories are possibly relevant to sudo-rs: | CVE | Tests | Sudo Advisory / Attack notes | | ---------------------- | ----- | --------------------------------------------------------------------------- | | CVE-1999-0958 [^1] | | Relative path attack (.. attack) | | CVE-1999-1496 [^2] | | Information leakage on which commands exist | | - [^rust] | | https://www.sudo.ws/security/advisories/heap_corruption/ | | CVE-2002-0184 [^rust] | | https://www.sudo.ws/security/advisories/prompt/ | | CVE-2004-1051 [^4] | | https://www.sudo.ws/security/advisories/bash_functions/ | | CVE-2004-1689 [^22] | | https://www.sudo.ws/security/advisories/sudoedit/ | | CVE-2005-1119 [^5] | | Corrupt arbitrary files via a symlink attack | | CVE-2005-1993 [^6] | | https://www.sudo.ws/security/advisories/path_race/ | | CVE-2005-4890 [^7] | | TTY hijacking when a privileged user uses sudo to run unprivileged commands | | - [^9] | | https://www.sudo.ws/security/advisories/cmnd_alias_negation/ | | CVE-2010-0426 [^23] | | https://www.sudo.ws/security/advisories/sudoedit_escalate/ | | CVE-2010-1163 [^23] | | https://www.sudo.ws/security/advisories/sudoedit_escalate2/ | | CVE-2010-1646 [^10] | | https://www.sudo.ws/security/advisories/secure_path/ | | CVE-2010-2956 [^11] | | https://www.sudo.ws/security/advisories/runas_group/ | | CVE-2011-0010 [^12] | | https://www.sudo.ws/security/advisories/runas_group_pw/ | | CVE-2012-0809 [^13] | | https://www.sudo.ws/security/advisories/sudo_debug/ | | CVE-2013-1775 [^14] | | https://www.sudo.ws/security/advisories/epoch_ticket/ | | CVE-2013-1776 [^15] | | https://www.sudo.ws/security/advisories/tty_tickets/ | | CVE-2013-2776 [^15] | | https://www.sudo.ws/security/advisories/tty_tickets/ | | CVE-2013-2777 [^15] | | https://www.sudo.ws/security/advisories/tty_tickets/ | | CVE-2014-9680 [^16] | | https://www.sudo.ws/security/advisories/tz/ | | CVE-2015-5602 [^24] | | https://bugzilla.sudo.ws/show_bug.cgi?id=707 | | CVE-2016-7032 [^17] | | https://www.sudo.ws/security/advisories/noexec_bypass/ | | CVE-2016-7076 [^17] | | https://www.sudo.ws/security/advisories/noexec_wordexp/ | | CVE-2017-1000367 [^18] | | https://www.sudo.ws/security/advisories/linux_tty/ | | CVE-2017-1000368 [^18] | | https://www.sudo.ws/security/advisories/linux_tty/ | | CVE-2019-18634 [^rust] | | https://www.sudo.ws/security/advisories/pwfeedback/ | | CVE-2021-3156 [^21] | | https://www.sudo.ws/security/advisories/unescape_overflow/ | | CVE-2021-23239 [^25] | | https://www.sudo.ws/releases/stable/#1.9.5 | | CVE-2023-22809 [^20] | | https://www.sudo.ws/security/advisories/sudoedit_any/ | | CVE-2023-28486 [^19] | | Syslog messages do not escape control characters | [^1]: All our path checks should only ever be done with absolute paths [^2]: We try to take care to only expose relevant information to the user [^rust]: Our usage of Rust should mostly prevent heap corruption bugs from occurring [^4]: env_reset is always enabled in sudo-rs, additionally we apply filtering to several variables to prevent any additional attack paths [^5]: - [^6]: Sudo-rs uses the suggested realpath function, as it is considered available enough for our target systems [^7]: To prevent attacks, a PTY must be used when running commands within a TTY, which is enabled by default in sudo-rs [^9]: - [^10]: - [^11]: - [^12]: - [^13]: - [^14]: - [^15]: - [^16]: - [^17]: Sudo-rs uses seccomp filtering rather than libc function interception through LD_PRELOAD. [^18]: - [^19]: - [^20]: Sudo-rs doesn't use a "stringly typed" interface between the execution and policy modules. [^21]: Rust memory safety should prevent this, sudo-rs doesn't allow `-s` and `-e` to be combined, and sudo-rs doesn't "unescape" program arguments in the sudoers module [^22]: Reading the changed temporary file back is done by an unprivileged helper process. [^23]: Sudo-rs matches commands based on (canonicalized and absolute) path names, so `sudoedit` never matches; furthermore, invoking `sudo /path/to/sudoedit` will instead run `sudoedit` as the current user. [^24]: Sudo-rs doesn't allow wildcards or symlinks in configuration arguments to sudoedit, and checks that all path components are not writable by the calling user. [^25]: Sudo-rs opens all components of the path to be edited exactly once, and checks that all path components are not writable by the calling user. ## Non-applicable CVEs These CVEs are almost entirely not applicable in the current sudo-rs codebase, mainly because the feature they relate to is not implemented. Sometimes this is done purposefully, because the feature has security implications. Sometimes the feature will be implemented at a later time, these CVEs might become relevant at that time. | CVE | Reason | | -------------- | ----------------------------------------------------------------------------------------------------------- | | CVE-2002-0043 | mail functionality is not implemented, https://www.sudo.ws/security/advisories/postfix/ | | CVE-2005-2959 | env_reset is always enabled / blacklist is not supported, https://www.sudo.ws/security/advisories/bash_env/ | | CVE-2005-4158 | env_reset is always enabled / blacklist is not supported, https://www.sudo.ws/security/advisories/perl_env/ | | CVE-2006-0151 | env_reset is always enabled / blacklist is not supported | | CVE-2007-3149 | Kerberos functionality is not implemented, https://www.sudo.ws/security/advisories/kerberos5/ | | CVE-2009-0034 | The group matching logic does not have this bug, https://www.sudo.ws/security/advisories/group_vector/ | | CVE-2010-0427 | runas_default is not implemented | | CVE-2012-2337 | No host ip-based rule matching is currently implemented, https://www.sudo.ws/security/advisories/netmask/ | | CVE-2012-3440 | Related to Red Hat specific script and not sudo directly | | CVE-2014-0106 | Disabling env_reset is not supported, https://www.sudo.ws/security/advisories/env_add/ | | CVE-2015-8239 | The sha2 digest feature is not implemented | | CVE-2019-14287 | This bug is not present, https://www.sudo.ws/security/advisories/minus_1_uid/ | | CVE-2021-23240 | sudo-rs does not have SELinux support, https://www.sudo.ws/security/advisories/sudoedit_selinux/ | | CVE-2022-43995 | crypt/password backend is not implemented, only PAM | | CVE-2023-27320 | The chroot functionality is not implemented, https://www.sudo.ws/security/advisories/double_free/ | | CVE-2023-28487 | Sudoreplay is not implemented | | CVE-2025-32462 | `sudo -h` is not implemented, https://www.sudo.ws/security/advisories/host_any/ | | CVE-2025-32463 | The chroot functionality is not implemented, https://www.sudo.ws/security/advisories/chroot_bug/ | ## Disputed CVEs While these CVEs are related to sudo, they are disputed as security issues. Either the behavior described in the CVE is intended behavior, or the issue cannot be replicated. | CVE | Notes | | -------------- | ----- | | CVE-2005-1831 | | | CVE-2019-18684 | | | CVE-2019-19234 | | | CVE-2019-19232 | | --- ## File: docs/undocumented-ogsudo-behavior.md This internal document describes ogsudo behavior that's not documented in its man pages. Where possible, this document is formatted as a list of "diffs" on top of version 1.9.5 of the man pages. # [`man sudo`](https://www.sudo.ws/docs/man/1.9.5/sudo.man/) ## [`-D` *directory*, `--chdir` *directory*](https://www.sudo.ws/docs/man/1.9.5/sudo.man/#D) The `--chdir` flag is ignored if its value matches the current working directory. This applies regardless of what the `CWD` policy in the sudoers file specifies for the invoking user. That is, `sudo --chdir=$(pwd) true` is equivalent to `sudo true`. ## [Environment](https://www.sudo.ws/docs/man/1.9.5/sudo.man/#ENVIRONMENT) ### [`SUDO_PS1`](https://www.sudo.ws/docs/man/1.9.5/sudo.man/#SUDO_PS1) The `SUDO_PS1` mechanism has precedence over the `env_keep` and `env_check` mechanisms. If `PS1` is in either of those lists and `PS1` and `SUDO_PS1` are both set in the invoking sure environment, then `PS1` will be set to the value of `SUDO_PS1`. In other words: given `Defaults env_keep = PS1`, `env PS1=a SUDO_PS1=b sudo printenv PS1` prints `b`. ## Miscellaneous This section contains information that can't be placed in any of the existing man page sections. ### Command-Line Interface In the case of short flags that accept a value, the space between the flag and the value is not required. That is, `sudo -u root true` and `sudo -uroot true` are equivalent. # [`man sudoers`](https://www.sudo.ws/docs/man/1.9.5/sudoers.man/) ## [Sudoers file format](https://www.sudo.ws/docs/man/1.9.5/sudoers.man/#SUDOERS_FILE_FORMAT) ### [Aliases](https://www.sudo.ws/docs/man/1.9.5/sudoers.man/#Aliases) The manual states that the allowed syntax for aliases is: > `NAME ::= A-Z*` but that is incorrect; the allowed syntax is actually: `NAME ::= [A-Z]([A-Z][0-9]_)*`. That is, aliases can contain digits and underscores but must start with an uppercase letter. ## [Command environment](https://www.sudo.ws/docs/man/1.9.5/sudoers.man/#Command_environment) ### `VARIABLE=value` matching The manual says: > By default, environment variables are matched by name. However, if the pattern includes an equal > sign (`=`), both the variables name and value must match but does not mention that the equal sign can only be used when surrounded by double quotes. That is, `Defaults env_check = "VARIABLE=value"` is correct syntax. Whereas, `Defaults env_check = VARIABLE=value` is invalid syntax. ### `SUDO_PS1` The manual says: > Environment variables with a value beginning with `()` are removed unless both the name and value > parts are matched by `env_keep` or `env_check`, as they may be interpreted as functions by the > bash shell This does not affect the operation of the `SUDO_PS1` environment variable. That is, `SUDO_PS1="() abc" sudo printenv PS1` prints `() abc` ## [Sudoers options](https://www.sudo.ws/docs/man/1.9.5/sudoers.man/#SUDOERS_OPTIONS) ### `env_keep` The `env_keep` list is not empty by default and contains the following environment variables by name: - `DISPLAY` - `PATH` These variables can be removed from the list using either the override (`=`) or remove (`-=`) operators. ### `env_check` The `env_check` list is not empty by default and contains the following environment variables by name: - `TERM` - `TZ` These variables can be removed from the list using either the override (`=`) or remove (`-=`) operators. ### Applies to both `env_keep` and `env_check` #### `!` clears the list The manual says that the `!` operator "disables" the list but it would be more accurate to say that it *clears* the list. After clearing the list with `Defaults !env_keep` (`Defaults !env_check`), it's possible to override its contents and/or add items to it. #### Error handling The manual says that the `env_keep` (`env_check`) accepts a list of space-separated variables but does not mention how errors within the list are handled. sudo skips / ignores malformed items and updates the list using only the well-formed items. That is, given `Defaults env_keep += "A.* VARIABLE"` sudo adds `VARIABLE` to the `env_keep` list. #### `SUDO_` variables This is not explicit in the manual: it's not possible to preserve the following variables from the invoking user's environment as they'll be set by sudo. - `SUDO_COMMAND` - `SUDO_GID` - `SUDO_UID` - `SUDO_USER`