Debian Codegraph @

docs/man/sudoers.5.md

raw symbols SCIP
1 ---
2 title: SUDOERS(5) sudo-rs 0.2.14 | sudo-rs
3 ---
4
5 # NAME
6
7 `sudoers` - sudo-compatible security configuration
8
9 # DESCRIPTION
10
11 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.
12
13 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.
14
15 ## User Authentication
16
17 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.
18
19 `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.
20
21 ## Logging
22
23 By default, `sudo-rs` logs both successful and unsuccessful attempts (as well as errors). Messages are logged to syslog(3).
24
25 ## Command environment
26
27 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.
28
29 In `sudo-rs`, the *env_reset* flag cannot be disabled. This causes commands to be executed with a new, minimal environment.
30 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.
31 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.
32 Environment variables with a value beginning with `()` are removed, as they may be interpreted as functions by the bash shell.
33
34 Environment variables specified by *env_check* or *env_keep* may include one or more ‘\*’ characters which will match zero or more characters.
35 No other wildcard characters are supported. Other sudoers options may influence the command environment, such as *secure_path*.
36
37 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.
38
39 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.
40
41 ## Resource limits
42
43 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.
44
45 # SUDOERS FILE FORMAT
46
47 The sudoers file is composed of two types of entries: aliases (basically variables) and user specifications (which specify who may run what).
48
49 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).
50
51 The sudoers file grammar will be described below in Extended Backus-Naur Form (EBNF) borrowed from Todd Miller's sudoers documentation.
52
53 ## Quick guide to EBNF
54
55 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.,
56
57 symbol ::= definition | alternate1 | alternate2 ...
58
59 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.
60
61 ? Means that the preceding symbol (or group of symbols) is optional. That is, it may appear once or not at all.
62
63 * Means that the preceding symbol (or group of symbols) may appear zero or more times.
64
65 + Means that the preceding symbol (or group of symbols) may appear one or more times.
66
67 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).
68
69 ## Aliases
70
71 There are four kinds of aliases: User_Alias, Runas_Alias, Host_Alias and Cmnd_Alias.
72
73 Alias ::= 'User_Alias' User_Alias_Spec (':' User_Alias_Spec)* |
74 'Runas_Alias' Runas_Alias_Spec (':' Runas_Alias_Spec)* |
75 'Host_Alias' Host_Alias_Spec (':' Host_Alias_Spec)* |
76 'Cmnd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)* |
77 'Cmd_Alias' Cmnd_Alias_Spec (':' Cmnd_Alias_Spec)*
78
79 User_Alias ::= NAME
80
81 User_Alias_Spec ::= User_Alias '=' User_List
82
83 Runas_Alias ::= NAME
84
85 Runas_Alias_Spec ::= Runas_Alias '=' Runas_List
86
87 Host_Alias ::= NAME
88
89 Host_Alias_Spec ::= Host_Alias '=' Host_List
90
91 Cmnd_Alias ::= NAME
92
93 Cmnd_Alias_Spec ::= Cmnd_Alias '=' Cmnd_List
94
95 NAME ::= [A-Z]([A-Z][0-9]_)*
96
97 Each alias definition is of the form
98
99 Alias_Type NAME = item1, item2, ...
100
101 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.,
102
103 Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
104
105 The definitions of what constitutes a valid alias member follow.
106
107 User_List ::= User |
108 User ',' User_List
109
110 User ::= '!'* user name |
111 '!'* #user-ID |
112 '!'* %group |
113 '!'* %#group-ID |
114 '!'* User_Alias
115
116 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)
117 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.
118
119 Runas_List ::= Runas_Member |
120 Runas_Member ',' Runas_List
121
122 Runas_Member ::= '!'* user name |
123 '!'* #user-ID |
124 '!'* %group |
125 '!'* %#group-ID |
126 '!'* Runas_Alias
127
128 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).
129
130 Host_List ::= Host |
131 Host ',' Host_List
132
133 Host ::= '!'* host name |
134 '!'* Host_Alias
135
136 A Host_List is made up of one or more host names. Again, the value of an item may be negated with the ‘!’ operator.
137
138 Cmnd_List ::= Cmnd |
139 Cmnd ',' Cmnd_List
140
141 command name ::= file name |
142 file name args ['*'] |
143 file name '""'
144
145 Cmnd ::= '!'* command name |
146 '!'* directory |
147 '!'* Cmnd_Alias
148 '!'* "list"
149 '!'* "sudoedit" [file name]
150
151 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).
152
153 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.
154 Note that the following characters must be escaped with a ‘\\’ if they are used in command arguments: ‘,’, ‘:’, ‘=’, ‘\\’.
155
156 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.
157
158 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
159 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
160 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
161 be specified with the “list” built-in.
162
163 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.
164 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.
165
166 ## Defaults
167
168 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.
169
170 Default_Type ::= 'Defaults' |
171 'Defaults' '@' Host_List |
172 'Defaults' ':' User_List |
173 'Defaults' '!' Cmnd_List |
174 'Defaults' '>' Runas_List
175
176 Default_Entry ::= Default_Type Parameter_List
177
178 Parameter_List ::= Parameter |
179 Parameter ',' Parameter_List
180
181 Parameter ::= Parameter '=' Value |
182 Parameter '+=' Value |
183 Parameter '-=' Value |
184 '!'* Parameter
185
186 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 (‘\\’).
187
188 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.
189
190 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.
191
192 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.
193
194 See **SUDOERS OPTIONS** for a list of supported Defaults parameters.
195
196 ## User specification
197
198 User_Spec ::= User_List Host_List '=' Cmnd_Spec_List \
199 (':' Host_List '=' Cmnd_Spec_List)*
200
201 Cmnd_Spec_List ::= Cmnd_Spec |
202 Cmnd_Spec ',' Cmnd_Spec_List
203
204 Cmnd_Spec ::= Runas_Spec? Chdir_Spec? Tag_Spec* Cmnd
205
206 Runas_Spec ::= '(' Runas_List? (':' Runas_List)? ')'
207
208 Chdir_Spec ::= 'CWD=directory'
209
210 Tag_Spec ::= ('PASSWD:' | 'NOPASSWD:' |
211 'SETENV:' | 'NOSETENV:'
212 'EXEC:' | 'NOEXEC')
213
214 AppArmor_Spec ::= 'APPARMOR_PROFILE=profile'
215
216 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.
217
218 The basic structure of a user specification is “who where = (as_whom) what”. Let's break that down into its constituent parts:
219
220 ## Runas_Spec
221
222 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.
223
224 A Runas_Spec sets the default for the commands that follow it. What this means is that for the entry:
225
226 dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/lprm
227
228 The user dgb may run /bin/ls, /bin/kill, and /usr/bin/lprm on the host boulder—but only as operator. E.g.,
229
230 $ sudo -u operator /bin/ls
231
232 It is also possible to override a Runas_Spec later on in an entry. If we modify the entry like so:
233
234 dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
235
236 Then user dgb is now allowed to run /bin/ls as operator, but /bin/kill and /usr/bin/lprm as root.
237
238 We can extend this to allow dgb to run /bin/ls with either the user or group set to operator:
239
240 dgb boulder = (operator : operator) /bin/ls, (root) /bin/kill,\
241 /usr/bin/lprm
242
243 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:
244
245 $ sudo -u operator /bin/ls
246 $ sudo -u operator -g operator /bin/ls
247 $ sudo -g operator /bin/ls
248
249 In the following example, user tcm may run commands that access a modem device file with the dialer group.
250
251 tcm boulder = (:dialer) /usr/bin/tip, /usr/bin/cu,\
252 /usr/local/bin/minicom
253
254 Note that in this example only the group will be set, the command still runs as user tcm. E.g.
255
256 $ sudo -g dialer /usr/bin/cu
257
258 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:
259
260 alan ALL = (root, bin : operator, system) ALL
261
262 user alan may run any command as either user root or bin, optionally setting the group to operator or system.
263
264 ## Chdir_Spec
265
266 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.
267
268 ## Tag_Spec
269
270 A command may have zero or more tags associated with it. The following tag values are supported: PASSWD, NOPASSWD, SETENV, and NOSETENV.
271 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).
272
273 ### EXEC and NOEXEC
274
275 On Linux systems, the NOEXEC tag can be used to prevent an executable from running further commands itself.
276
277 In the following example, user aaron may run /usr/bin/more and /usr/bin/vi but shell escapes will be disabled.
278
279 aaron shanty = NOEXEC: /usr/bin/more, /usr/bin/vi
280
281 See the *Preventing shell escapes* section below for more details on how NOEXEC works and whether or not it suits your purpose.
282
283 ### PASSWD and NOPASSWD
284
285 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:
286
287 queen rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
288
289 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:
290
291 queen rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
292
293 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.
294
295 ### SETENV and NOSETENV
296
297 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.
298
299 ## AppArmor_Spec
300 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.
301
302 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.
303
304 AppArmor profiles can be specified in any way that complies with the rules of `aa_change_profile(2)`.
305
306 ## Wildcards
307
308 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”).
309
310 * Matches any set of zero or more characters (including white space).
311
312 ? Matches any single character (including white space).
313
314 [...] Matches any character in the specified range.
315
316 [!...] Matches any character not in the specified range.
317
318 \x For any character ‘x’, evaluates to ‘x’. This is used to escape special characters such as: ‘*’, ‘?’, ‘[’, and ‘]’.
319
320 Note that these are not regular expressions. Unlike a regular expression there is no way to match one or more characters within a range.
321
322 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.
323
324 ## Including other files from within sudoers
325
326 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.
327
328 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:
329
330 @include /etc/sudoers.local
331
332 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.
333
334 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:
335
336 @include sudoers.local
337
338 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:
339
340 @includedir /etc/sudoers.d
341
342 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.
343
344 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.
345
346 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:
347
348 @socket /var/run/providers/sudoers.socket
349
350 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.
351
352 Please note that the contents read from a socket are immutable from sudo's point of view and visudo will not be able to edit them.
353
354 ## Other special characters and reserved words
355
356 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.
357
358 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.
359
360 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:
361
362 ALL,!root
363
364 If the ALL, is omitted, as in:
365
366 !root
367
368 it would explicitly deny root but not match any other users. This is different from a true “negation” operator.
369
370 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).
371
372 White space between elements in a list as well as special syntactic characters in a User Specification (‘=’, ‘:’, ‘(’, ‘)’) is optional.
373
374 The following characters must be escaped with a backslash (‘\\’) when used as part of a word (e.g., a user name or host name): ‘!’, ‘=’, ‘:’, ‘,’, ‘(’, ‘)’, ‘\\’.
375
376 ## SUDOERS OPTIONS
377
378 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.
379
380 ### Boolean Flags:
381
382 * noexec
383
384 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.
385
386 * noninteractive_auth
387 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.
388
389 * env_editor
390
391 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.
392
393 * pwfeedback
394
395 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.
396
397 * rootpw
398
399 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.
400
401 * setenv
402
403 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.
404
405 * targetpw
406
407 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.
408
409 * umask_override
410
411 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.
412
413 * use_pty
414
415 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.
416
417 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.
418
419 ## Integers:
420
421 * passwd_tries
422
423 The number of tries a user gets to enter his/her password before sudo logs the failure and exits. The default is 3.
424
425 ## Integers that can be used in a boolean context:
426
427 * timestamp_timeout
428
429 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.
430
431 * umask
432
433 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.
434
435 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.
436
437 ## Strings
438
439 * editor
440
441 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_.
442
443 ## Strings that can be used in a boolean context:
444
445 * apparmor_profile
446
447 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.
448
449 * runcwd
450
451 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.
452
453 * secure_path
454
455 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.
456
457 ## Lists that can be used in a boolean context:
458
459 * env_check
460
461 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:
462
463 • It consists of a fully-qualified path name, optionally prefixed with a colon (‘:’), that does not match the location of the zoneinfo directory.
464
465 • It contains a .. path element.
466
467 • It contains white space or non-printable characters.
468
469 • It is longer than the value of PATH_MAX.
470
471 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.
472
473 * env_keep
474
475 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.
476
477 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.
478
479 ## LOG FORMAT
480
481 sudo-rs logs events via syslog(3).
482
483 ## FILES
484
485 /etc/sudoers-rs List of who can run what (for co-existence of sudo-rs and Todd Miller's sudo)
486
487 /etc/sudoers List of who can run what (sudo-compatible)
488
489 /run/sudo/ts Directory containing timestamps for the sudoers security policy
490
491 ## SECURITY NOTES
492
493 ### Limitations of the ‘!’ operator
494
495 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:
496
497 bill ALL = ALL, !SU, !SHELLS
498
499 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).
500
501 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.
502
503 ### Security implications of `fast_glob`
504
505 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.
506
507 For example, given the following sudoers file entry:
508
509 john ALL = /usr/bin/passwd [a-zA-Z0-9]*, /usr/bin/chsh [a-zA-Z0-9]*,\
510 /usr/bin/chfn [a-zA-Z0-9]*, !/usr/bin/* root
511
512 User john can still run /usr/bin/passwd root if fast_glob is enabled by changing to /usr/bin and running ./passwd root instead.
513
514 ### Preventing shell escapes
515
516 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.
517
518 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
519 in sudo-rs is different than in Todd Miller's sudo, and should also work on statically linked binaries.
520
521 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.
522 You should always try out if **noexec** indeed prevents shell escapes for the programs it is intended to be used with.
523
524 ### Timestamp file checks
525
526 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.
527
528 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.
529
530 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.
531
532 ## SEE ALSO
533
534 su(1), fnmatch(3), glob(3), sudo(8), visudo(8)
535
536 ## CAVEATS
537
538 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.
539
540 ## BUGS
541
542 If you feel you have found a bug in sudo-rs, please submit a bug report at https://github.com/trifectatechfoundation/sudo-rs/issues/
543
544 # AUTHORS
545
546 This man page is a modified version of the sudoers(5) documentation written by Todd Miller; see https://www.sudo.ws/ for the original.
547
548 ## DISCLAIMER
549
550 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.