SUDOERS(5)
β¨ NAME β¨
Okay so bestie, this is the sudoers(5) manual from sudo-rs, and the NAME section is literally sudoers β sudo-compatible security configuration. That's the whole vibe: it's the policy config that tells sudo-rs who gets to do what. π«Ά
π DESCRIPTION π
The sudo-rs policy decides a user's sudo privileges. It's driven by the /etc/sudoers file. The whole policy format is described in detail in the SUDOERS FILE FORMAT section (coming at you later). β¨
The format sudo-rs uses is a subset of the one used by the sudo-project as maintained by Todd Miller, but it's syntax-compatible. So yeah, it's giving "same language, smaller vocabulary." π
π User Authentication π
The sudoers security policy requires that most users authenticate themselves before they can use sudo. But no password is required if:
- the invoking user is root,
- the target user is the same as the invoking user, or
- 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. You can change that 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).
Then the user can 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 a user's login sessions are authenticated separately. No sharing tickets between terminals, bestie. ποΈ
π Logging π
By default, sudo-rs logs both successful and unsuccessful attempts (as well as errors). Messages are logged to syslog(3). So yes, the receipts are being kept. π
π± 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. It's not being shady, it's just protecting the vibe. π‘οΈ
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
PATHandTERMvariables are not preserved from the user's environment, they will be set to default values. LOGNAMEandUSERare handled as a single entity. If one of them is preserved (or removed) from the user's environment, the other will be as well. IfLOGNAMEandUSERare 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 thebashshell.
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. PAM is just trying to contribute, but env_keep has main character energy here. π
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, includingsudo. 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 beforesudoeven begins execution and, as such, it is not possible forsudoto preserve them. So don't come for sudo about those β it literally never saw 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. Periodt. π
π¦ 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). That's it. Two flavors. π
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). So order matters, bestie β don't assume the fanciest match wins. π
The sudoers file grammar will be described below in Extended Backus-Naur Form (EBNF) borrowed from Todd Miller's sudoers documentation. It's giving formal, but we'll get through it together. π«Ά
π 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.
Okay so the list built-in is iconic because it lets a user list another userβs privileges with sudoβs -U option β like sudo -l -U otheruser. A user with the list privilege can 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 what lets a user 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. iykyk
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 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. main character energy
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. slay
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. be careful, bestie π
π¦ 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). Thatβs the whole assignment, bestie. π¦
πΈ Wildcards πΈ
okay so 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. periodt. π
π¦ 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,sudoerswill log commands allowed by the policy to the system log. This flag is on by default. πnoexecβ if set, all commands run viasudowill behave as if theNOEXECtag has been set, unless overridden by anEXECtag. See the description ofEXECandNOEXECas 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 (whensudoβs-noption 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,visudowill use the value of theSUDO_EDITOR,VISUALorEDITORenvironment variables before falling back on the default editor list. Note thatvisudois typically run as root so this flag may allow a user withvisudoprivileges to run arbitrary commands as root without logging. An alternative is to place a colon-separated list of βsafeβ editors in theeditorsetting.visudowill then only useSUDO_EDITOR,VISUALorEDITORif they match a value specified ineditor. If theenv_resetflag is enabled, theSUDO_EDITOR,VISUALand/orEDITORenvironment variables must be present in theenv_keeplist for theenv_editorflag to function whenvisudois invoked viasudo. This flag is on by default.pwfeedbackβ by default,sudoreads 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 thatsudohas hung at this point. Whenpwfeedbackis set,sudowill 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,sudowill 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 byenv_check,env_delete, orenv_keep. As such, only trusted users should be allowed to set variables in this manner. This flag is off by default.targetpwβ if set,sudowill prompt for the password of the user specified by the-uoption (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 thepasswddatabase as an argument to the-uoption. This flag is off by default.umask_overrideumask_overrideβ bestie, if this is set,sudowill 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. Ifumask_overrideis not set,sudowill set the umask to be the union of the userβs umask and what is specified insudoers. This flag is off by default. πuse_ptyβ if set, andsudois running in a terminal, the command will be run in a pseudo-terminal (even if no I/O logging is being done). If thesudoprocess is not attached to a terminal,use_ptyhas no effect. A malicious program run undersudomay 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 their password beforesudologs the failure and exits. The default is3. π
Integers that can be used in a boolean context: π«Ά
timestamp_timeoutβ number of minutes that can elapse beforesudowill ask for a passwd again. The timeout may include a fractional component if minute granularity is insufficient, for example2.5. The default is15. Set this to0to always prompt for a password. β³umaskβ file mode creation mask to use when running the command. Negate this option or set it to0777to preventsudofrom changing the umask. Unless theumask_overrideflag is set, the actual umask will be the union of the userβs umask and the value of theumasksetting, which defaults to0022. This guarantees thatsudonever lowers the umask when running a command. Ifumaskis explicitly set, it will override any umask setting in PAM. Ifumaskis not set, the umask specified by PAM will take precedence. Theumasksetting in PAM is not used forsudoedit, which does not create a new PAM session. πΈ
Strings π
editorβ a colon (:) separated list of editor path names used bysudoeditandvisudo. Forsudoedit, this list is used to find an editor when none of theSUDO_EDITOR,VISUALorEDITORenvironment variables are set to an editor that exists and is executable. Forvisudo, it is used as a white list of allowed editors;visudowill choose the editor that matches the userβsSUDO_EDITOR,VISUALorEDITORenvironment variable if possible, or the first editor in the list that exists and is executable if not. Unless invoked assudoedit,sudodoes not preserve theSUDO_EDITOR,VISUALorEDITORenvironment variables unless they are present in theenv_keeplist. 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-rsuses per-user timestamp files for credential caching. Thetimestamp_typeoption can be used to specify the type of timestamp record used. It has two possible values:ttyandppid. 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 (seetimestamp_timeout). Commands run viasudowith 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 asppid. 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 defaultapparmor_profilecan be overridden for individual sudoers entries by specifying theAPPARMOR_PROFILEoption. This option is only available whensudo-rsis built with AppArmor support. This option is not set by default. π§runcwdβ if set,sudowill use this value for the working directory when running a command. The special value*will allow the user to specify the working directory viasudoβs-Doption. See theChdir_Specsection for more details. πsecure_pathβ if set,sudowill use this value in place of the userβsPATHenvironment variable. This option can be used to reset thePATHto 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 exceptTZ, β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. TheTZvariable 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 thezoneinfodirectory. - It contains a
..path element. - It contains white space or non-printable characters.
- It is longer than the value of
PATH_MAX.
- It consists of a fully-qualified path name, optionally prefixed with a colon (
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 theenv_resetoption is in effect. This allows fine-grained control over the environmentsudo-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 whensudois run by root with the-Voption. Preserving theHOMEenvironment variable has security implications since many programs use it when searching for configuration or data files. AddingHOMEtoenv_keepmay enable a user to run unrestricted commands viasudoand is strongly discouraged. Users wishing to edit files withsudoshould runsudoedit(orsudo -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 ofsudo-rsand Todd Miller'ssudo)/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.NOEXECis 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 anexec()like the proposedio_uringexec feature in Linux. And it also doesnβt protect against honest programs that intentionally or not allow the user to write to/proc/self/memfor the same reasons as that it doesnβt protect against malicious programs. You should always try out ifnoexecindeed prevents shell escapes for the programs it is intended to be used with. π€
β° Timestamp file checks β°
okay so this part is important, bestie, listen up πβ¨ sudo-rs is gonna check who owns its timestamp directory (/run/sudo/ts by default) and if that directory isn't owned by root β or if it's writable by any user who isn't root β it just ignores everything inside it. like, full on "i don't know her" energy π
and yeah, that directory should get cleared at reboot time, but to avoid potential problems, sudo-rs will ignore timestamp files that date from before the machine booted β but only on systems where the boot time is actually available. no cap π«Ά
now here's the spicy bit πΆοΈ some systems with graphical desktop environments let unprivileged users change the system clock. and 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, iconic behavior honestly) for its timestamps if the system supports it. also, sudo-rs will not honor timestamps set far in the future. not today, satan π
ββοΈ
π SEE ALSO π
β οΈ CAVEATS β οΈ
the sudoers file should always be edited by the visudo utility, which locks the file and checks for syntax errors. this is not a drill, bestie π¨ if sudoers contains syntax errors, you may lock yourself out of being able to use sudo. literally you. locked out. by yourself. the audacity of it π
π 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/ β she reads those, fr fr π
π 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. giving credit where credit is due, we love that πΈ
π«Ά 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. translation: no promises, take it as it is, that's the vibe π
and that's a wrap on the whole page, bestie!! π this little beauty is from sudo-rs 0.2.15 and it's the SUDOERS(5) man page β go forth and configure responsibly, mwah πβ¨
π¦ where this page comes from
- arch rolling: sudo-rs 0.2.15-1 Β· Apache-2.0 AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms