From: Todd C. Miller Date: Thu, 26 Aug 1999 09:00:59 +0000 (+0000) Subject: new sudoers(8) man page X-Git-Tag: SUDO_1_6_0~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a84959b41b40257b83f1419e213c46f319a8577;p=sudo new sudoers(8) man page --- diff --git a/sudoers.cat b/sudoers.cat index 9adeec73b..1e4c85a73 100644 --- a/sudoers.cat +++ b/sudoers.cat @@ -1,155 +1,279 @@ -sudoers(5) FILE FORMATS sudoers(5) +SUDOERS(5) FILE FORMATS SUDOERS(5) NNNNAAAAMMMMEEEE - sudoers - list of which users may execute what as root + sudoers - list of which users may execute what DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN - The _s_u_d_o_e_r_s file is composed of an optional host alias - section, an optional command alias section and the user - specification section. All command or host aliases need - to start with their respective keywords (ie: Host_Alias, - User_Alias, Runas_Alias or Cmnd_Alias). If there are - multiple occurrences of a user, the logical union of the - entries will be used. Note that if there is an entry that - denies access to a command that is followed by an entry - that grants access the user will be allowed to run the - command. + The _s_u_d_o_e_r_s file is composed two types of entries: aliases + (basically variables) and user specifications (which + specify who may run what). The grammar of _s_u_d_o_e_r_s will be + described below in Extended Backus-Naur Form (EBNF). + Don't despair if you don't know what EBNF is, it is fairly + simple and the definitions below are annotated. - uuuusssseeeerrrr ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn ffffoooorrrrmmmmaaaatttt:::: + QQQQuuuuiiiicccckkkk gggguuuuiiiiddddeeee ttttoooo EEEEBBBBNNNNFFFF + EBNF is a concise and exact way of describing the grammar + of a language. Each EBNF definition is made up of + _p_r_o_d_u_c_t_i_o_n _r_u_l_e_s. Eg. - user access_group [: access_group] ... + symbol ::= definition | alternate1 | alternate2 ... - access_group ::= host-list = [(runas-list)] [NOPASSWD:] [op]cmnd_type - [,[(user-list)] [NOPASSWD|PASSWD:] [op]cmnd_type] ... - cmnd_type ::= a command OR a command alias. - op ::= the logical "!" NOT operator. + Each _p_r_o_d_u_c_t_i_o_n _r_u_l_e 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. - hhhhoooosssstttt aaaalllliiiiaaaassss sssseeeeccccttttiiiioooonnnn ffffoooorrrrmmmmaaaatttt:::: + * 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. - Host_Alias HOSTALIAS = host-list + 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). - Host_Alias ::= a keyword. - HOSTALIAS ::= an upper-case alias name. - host-list ::= a comma separated list of hosts, netgroups, - ip addresses, networks. A logical "!" - NOT operator may be prefixed to any of these. + AAAAlllliiiiaaaasssseeeessss + There are four kinds of aliases: the User_Alias, + Runas_Alias, Host_Alias and Cmnd_Alias. - uuuusssseeeerrrr aaaalllliiiiaaaassss sssseeeeccccttttiiiioooonnnn ffffoooorrrrmmmmaaaatttt:::: + Alias ::= User_Alias = User_Alias (':' User_Alias)* | + Runas_Alias (':' Runas_Alias)* | + Host_Alias (':' Host_Alias)* | + Cmnd_Alias (':' Cmnd_Alias)* + User_Alias ::= NAME '=' User_List - User_Alias USERALIAS = user-list + Runas_Alias ::= NAME '=' Runas_User_List - User_Alias ::= a keyword. - USERALIAS ::= an upper-case alias name. - user-list ::= a comma separated list of users, groups, netgroups. - A logical "!" NOT operator may be prefixed to any - of these. - rrrruuuunnnnaaaassss aaaalllliiiiaaaassss sssseeeeccccttttiiiioooonnnn ffffoooorrrrmmmmaaaatttt:::: +25/Aug/1999 1.6 1 - Runas_Alias RUNASALIAS = runas-list -22/Jun/1999 1.6 1 +SUDOERS(5) FILE FORMATS SUDOERS(5) + Host_Alias ::= NAME '=' Host_List + Cmnd_Alias ::= NAME '=' Cmnd_List -sudoers(5) FILE FORMATS sudoers(5) + NAME ::= [A-Z]([A-Z][0-9]_)* + Each _a_l_i_a_s definition is of the form - Runas_Alias ::= a keyword. - RUNASALIAS ::= an upper-case alias name. - runas-list ::= a comma separated list of users, groups, netgroups. - A logical "!" NOT operator may be prefixed to any - of these. + Alias_Type NAME = item1, item2, ... + where _A_l_i_a_s___T_y_p_e is one of User_Alias, Runas_Alias, + Host_Alias, or Cmnd_Alias. A NAME is a string of upper + case letters, numbers, and the underscore characters + ('_'). A NAME mmmmuuuusssstttt start with an upper case letter. It + is possible to put several alias definitions of the same + type on a single line, joined by a semicolon (':'). Eg. - ccccoooommmmmmmmaaaannnndddd aaaalllliiiiaaaassss sssseeeeccccttttiiiioooonnnn ffffoooorrrrmmmmaaaatttt:::: + Alias_Type NAME = item1, item2, item3 : NAME = item4, item5 + The definitions of what constitutes a valid _a_l_i_a_s member + follow. - Cmnd_Alias CMNDALIAS = cmnd-list + User_List ::= User | + User ',' User_List - Cmnd_Alias ::= a keyword. - CMNDALIAS ::= an upper-case alias name. - cmnd-list ::= a comma separated list commands. - A logical "!" NOT operator may be prefixed to any - of these. + User ::= '!'* username | + '!'* '#'uid | + '!'* '%'group | + '!'* '+'netgroup | + '!'* User_Alias + A User_List is made up of one or more usernames, uids + (prefixed with '#'), System groups (prefixed with '%'), + netgroups (prefixed with '+') and other aliases. Each + list item may be prefixed with one or more '!' operators. + An odd number of '!' operators negates the value of the + item; an even number just cancel each other out. - ccccoooommmmmmmmaaaannnndddd ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn:::: + Runas_List ::= Runas_User | + Runas_User ',' Runas_List + Runas_User ::= '!'* username | + '!'* '#'uid | + '!'* '%'group | + '!'* +netgroup | + '!'* Runas_Alias - path arg1 arg2 .. argn = command + Likewise, a Runas_List has the same possible elements as a + User_List, except that it can include a Runas_Alias, + instead of a User_Alias. - path ::= a fully qualified pathname. - arg[1..n] ::= optional command line arguments. + Host_List ::= Host | + Host ',' Host_List - ppppeeeerrrrssssiiiisssstttteeeennnncccceeee ooooffff mmmmooooddddiiiiffffiiiieeeerrrrssss - When a _r_u_n_a_s_-_l_i_s_t is specified for an _a_c_c_e_s_s___g_r_o_u_p, it - affects all commands in the _a_c_c_e_s_s___g_r_o_u_p. For example, - given: - oper bigserver = (root, sysadm) /usr/bin/kill, /bin/rm +25/Aug/1999 1.6 2 - User oper will be able to run /usr/bin/kill and /bin/rm as - rrrrooooooootttt or ssssyyyyssssaaaaddddmmmm on the machine, bigserver. The _r_u_n_a_s_-_l_i_s_t - is "sticky" across entries in the comma-separated - _a_c_c_e_s_s___g_r_o_u_p. You can override the _r_u_n_a_s_-_l_i_s_t with - another one, at which point the new _r_u_n_a_s_-_l_i_s_t becomes the - default for that _a_c_c_e_s_s___g_r_o_u_p. For example, given: - oper bigserver = (root, sysadm) /usr/bin/kill, (root) /bin/rm, \ - /bin/rmdir - User oper can still run /usr/bin/kill as rrrrooooooootttt or ssssyyyyssssaaaaddddmmmm - but can only run /bin/rm and /bin/rmdir as rrrrooooooootttt. - Similarly, the NNNNOOOOPPPPAAAASSSSSSSSWWWWDDDD modifier is also persistent across - an _a_c_c_e_s_s___g_r_o_u_p. For example given: - oper bigserver = NOPASSWD: /usr/bin/kill, /bin/rm, /bin/rmdir +SUDOERS(5) FILE FORMATS SUDOERS(5) + Host ::= '!'* hostname | + '!'* ip_addr | + '!'* network(/netmask)? | + '!'* '+'netgroup | + '!'* Host_Alias + A Host_List is made up of one or more hostnames, IP + addresses, network numbers, netgroups (prefixed with '+') + and other aliases. Again, the value of an item may be + negated with the '!' operator. If you do not specify a + netmask with a network number, the netmask of the host's + ethernet _i_n_t_e_r_f_a_c_e(s) will be used when matching. The + netmask may be specified either in dotted quad notation + (eg. 255.255.255.0) or CIDR notation (number of bits, eg. + 24). -22/Jun/1999 1.6 2 + Cmnd_List ::= Cmnd | + Cmnd ',' Cmnd_List + commandname ::= filename | + filename args | + filename '""' + Cmnd ::= '!'* commandname | + '!'* directory | + '!'* Cmnd_Alias + A Cmnd_List is a list of one or more commandnames, + directories, and other aliases. A commandname is a fully- + qualified filename which may include shell-style wildcards + (see `Wildcards' section below). A simple filename allows + the user to run the command with any arguments he/she + wishes. However, you may also command line arguments + (including wildcards). Alternately, you can specify "" to + indicate that the command may only be run wwwwiiiitttthhhhoooouuuutttt command + line arguments. A directory is a fully qualified pathname + 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 subdirectories 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 (or match the wildcards if + there are any). Note that the following characters must + be escaped with a '\' if they are used in command + arguments: ',', ':', '=', '\\'. -sudoers(5) FILE FORMATS sudoers(5) + UUUUsssseeeerrrr SSSSppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn - User oper will be able to run /usr/bin/kill, /bin/rm, and - /bin/rmdir as rrrrooooooootttt without a password. If we change that - to: + Runas_Spec ::= '(' Runas_List ')' - oper bigserver = NOPASSWD: /usr/bin/kill, PASSWD: /bin/rm, /bin/rmdir + Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd - User oper can still run /usr/bin/kill without a password - but must give a password to run /bin/rm and /bin/rmdir. - wwwwiiiillllddddccccaaaarrrrddddssss ((((aaaakkkkaaaa mmmmeeeettttaaaa cccchhhhaaaarrrraaaacccctttteeeerrrrssss)))):::: - ssssuuuuddddoooo allows shell-style _w_i_l_d_c_a_r_d_s along with command - arguments in the _s_u_d_o_e_r_s file. Wildcard matching is done - via the PPPPOOOOSSSSIIIIXXXX fnmatch(3) routine. + +25/Aug/1999 1.6 3 + + + + + +SUDOERS(5) FILE FORMATS SUDOERS(5) + + + Cmnd_Spec_List ::= Cmnd_Spec | + Cmnd_Spec ',' Cmnd_Spec_List + + User_Spec ::= User_list Cmnd_Spec_List (':' User_Spec)* + + A uuuusssseeeerrrr ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn determines which commands a user may + run (and as what user) on specified hosts. By default, + commands are run as rrrrooooooootttt but this can be changed on a per- + command basis. + + Let's break that down into its constituent parts: + + RRRRuuuunnnnaaaassss____SSSSppppeeeecccc + + A Runas_Spec is simply a Runas_List (as defined above) + enclosed in a set of parentheses. If you do not specify a + Runas_Spec in the user specification, a default Runas_Spec + of rrrrooooooootttt will be used. A Runas_Spec sets the default for + commands that follow it. What this means is that for the + entry: + + dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who + + The user ddddggggbbbb may run _/_b_i_n_/_l_s, _/_b_i_n_/_k_i_l_l, and _/_u_s_r_/_b_i_n_/_l_p_r_m + -- but only as ooooppppeeeerrrraaaattttoooorrrr. Eg. + + 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 ddddggggbbbb is now allowed to run _/_b_i_n_/_l_s as ooooppppeeeerrrraaaattttoooorrrr, + but _/_b_i_n_/_k_i_l_l and _/_u_s_r_/_b_i_n_/_l_p_r_m as rrrrooooooootttt. + + NNNNOOOOPPPPAAAASSSSSSSSWWWWDDDD aaaannnndddd PPPPAAAASSSSSSSSWWWWDDDD + + By default, ssssuuuuddddoooo requires that a user authenticate him or + herself 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: + + ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm + + would allow the user rrrraaaayyyy to run _/_b_i_n_/_k_i_l_l, _/_b_i_n_/_l_s, and + _/_u_s_r_/_b_i_n_/_l_p_r_m as root on the machine rushmore as rrrrooooooootttt + without authenticating himself. If we only want rrrraaaayyyy to be + able to run _/_b_i_n_/_k_i_l_l without a password the entry would + be: + + ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm + + + +25/Aug/1999 1.6 4 + + + + + +SUDOERS(5) FILE FORMATS SUDOERS(5) + + + WWWWiiiillllddddccccaaaarrrrddddssss ((((aaaakkkkaaaa mmmmeeeettttaaaa cccchhhhaaaarrrraaaacccctttteeeerrrrssss)))):::: + + ssssuuuuddddoooo allows shell-style _w_i_l_d_c_a_r_d_s to be used in pathnames + as well as command line arguments in the _s_u_d_o_e_r_s file. + Wildcard matching is done via the PPPPOOOOSSSSIIIIXXXX fnmatch(3) + routine. Note that these are _n_o_t regular expressions. * Matches any set of zero or more characters. @@ -163,213 +287,282 @@ sudoers(5) FILE FORMATS sudoers(5) used to escape special characters such as: "*", "?", "[", and "}". - eeeexxxxcccceeeeppppttttiiiioooonnnnssss ttttoooo wwwwiiiillllddddccccaaaarrrrdddd rrrruuuulllleeeessss:::: + Note that a forward slash ('/') will nnnnooootttt be matched by + wildcards used in the pathname. When matching the command + line arguments, however, as slash ddddooooeeeessss get matched by + wildcards. This is to make a path like: + + /usr/bin/* + + match /usr/bin/who but not /usr/bin/X11/xterm. + + EEEExxxxcccceeeeppppttttiiiioooonnnnssss ttttoooo wwwwiiiillllddddccccaaaarrrrdddd rrrruuuulllleeeessss:::: The following exceptions apply to the above rules: - " If the empty string "" is the only command line + "" If the empty string "" is the only command line argument in the _s_u_d_o_e_r_s entry it means that - command may take nnnnoooo arguments. + command is not allowed to be run with aaaannnnyyyy + arguments. - ooootttthhhheeeerrrr ssssppppeeeecccciiiiaaaallll cccchhhhaaaarrrraaaacccctttteeeerrrrssss aaaannnndddd rrrreeeesssseeeerrrrvvvveeeedddd wwwwoooorrrrddddssss:::: + OOOOtttthhhheeeerrrr ssssppppeeeecccciiiiaaaallll cccchhhhaaaarrrraaaacccctttteeeerrrrssss aaaannnndddd rrrreeeesssseeeerrrrvvvveeeedddd wwwwoooorrrrddddssss:::: - Text after a pound sign (####) is considered a comment. - Words that begin with a percent sign (%%%%) are assumed to be - UN*X groups (%staff refers to users in the group _s_t_a_f_f). - Words that begin with a plus sign (++++) are assumed to be - netgroups (++++ccccsssshhhhoooossssttttssss refers to the netgroup _c_s_h_o_s_t_s). Long - lines can be newline escaped with the backslash \\\\ - character. + The pound sign ('#') is used to indicate a comment (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 uid). + Both the comment character and any text after it, up to + the end of the line, are ignored. - The reserved word NNNNOOOOPPPPAAAASSSSSSSSWWWWDDDD indicates that a user need not - enter a password for the command listed in that entry. - The NNNNOOOOPPPPAAAASSSSSSSSWWWWDDDD modifier is persistent across entries in a - _u_s_e_r_-_l_i_s_t and can be reversed with the PPPPAAAASSSSSSSSWWWWDDDD modifier. + The reserved word AAAALLLLLLLL is a a built in _a_l_i_a_s 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. You should not try to define your own + _a_l_i_a_s called AAAALLLLLLLL as the built in alias will be used in + preference to your own. - The reserved alias _A_L_L can be used for both - {Host,User,Cmnd}_Alias. DDDDOOOO NNNNOOOOTTTT define an alias of _A_L_L, it - will NNNNOOOOTTTT be used. Note that _A_L_L implies the entire - universe of hosts/users/commands. You can subtract + An exclamation point ('!') can be used as a logical _n_o_t + operator both in an _a_l_i_a_s and in front of a Cmnd. This -22/Jun/1999 1.6 3 +25/Aug/1999 1.6 5 -sudoers(5) FILE FORMATS sudoers(5) +SUDOERS(5) FILE FORMATS SUDOERS(5) - elements from the universe by using the syntax: + allows one to exclude certain values. 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). - user host=ALL,!ALIAS1,!/sbin/halt... + Long lines can be continued with a backslash ('\\') as the + last character on the line. - Commands may have optional command line arguments. If - they do, then the arguments in the _s_u_d_o_e_r_s file must - exactly match those on the command line. It is also - possible to have a command's arguments span multiple lines - as long as the line continuance character "\" is used. - The following characters must be escaped with a "\" if - used in command arguments: ",", ":", "=", "\". + Whitespace between elements in a list as well as specicial + syntactic characters in a _U_s_e_r _S_p_e_c_i_f_i_c_a_t_i_o_n ('=', ':', + '(', ')') is optional. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS - # Host alias specification - Host_Alias HUB=houdini:\ - REMOTE=merlin,kodiakthorn,spirit - Host_Alias SERVERS=houdini,merlin,kodiakthorn,spirit - Host_Alias CUNETS=128.138.0.0/255.255.0.0 - Host_Alias CSNETS=128.138.243.0,128.138.204.0,\ - 128.138.205.192 + Below are example _s_u_d_o_e_r_s entries. Admittedly, some of + these are a bit contrived. First, we define our _a_l_i_a_s_e_s: + + # User alias specification + User_Alias FULLTIMERS = millert, mikef, dowdy + User_Alias PARTTIMERS = bostley, jwfox, crawl + User_Alias WEBMASTERS = will, wendy, wim + + # Runas alias specification + Runas_Alias OP = root, operator + Runas_Alias DB = oracle, sybase + + # Host alias specification + Host_Alias SPARC = bigtime, eclipse, moet, anchor :\ + SGI = grolsch, dandelion, black :\ + ALPHA = widget, thalamus, foobar :\ + HPPA = boa, nag, python + Host_Alias CUNETS = 128.138.0.0/255.255.0.0 + Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0 + Host_Alias SERVERS = master, mail, www, ns + Host_Alias CDROM = orion, perseus, hercules + + # Cmnd alias specification + Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\ + /usr/sbin/restore, /usr/sbin/rrestore + Cmnd_Alias KILL = /usr/bin/kill + Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm + Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown + Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt + Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot + Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \ + /usr/local/bin/tcsh, /usr/bin/rsh, \ + /usr/local/bin/zsh + Cmnd_Alias SU = /usr/bin/su + + The _U_s_e_r _s_p_e_c_i_f_i_c_a_t_i_o_n is the part that actually + determines who may run what. + + root ALL = (ALL) ALL + %wheel ALL = (ALL) ALL + + + + +25/Aug/1999 1.6 6 + + + + + +SUDOERS(5) FILE FORMATS SUDOERS(5) + - # User alias specification - User_Alias FULLTIME=millert,dowdy,mikef - User_Alias PARTTIME=juola,mccreary,tor + We let rrrrooooooootttt and any user in group wwwwhhhheeeeeeeellll run any command on + any host as any user. - # Runas alias specification - Runas_Alias OP=root,operator + FULLTIMERS ALL = NOPASSWD: ALL - # Command alias specification - Cmnd_Alias LPCS=/usr/sbin/lpc,/usr/bin/lprm - Cmnd_Alias SHELLS=/bin/sh,/bin/csh,/bin/tcsh,/bin/ksh - Cmnd_Alias SU=/usr/bin/su - Cmnd_Alias MISC=/bin/rm,/bin/cat:\ - SHUTDOWN=/sbin/halt,/sbin/shutdown + Full time sysadmins (mmmmiiiilllllllleeeerrrrtttt, mmmmiiiikkkkeeeeffff, and ddddoooowwwwddddyyyy) may run + any command on any host without authenticating themselves. - # User specification - FULLTIME ALL=(ALL) NOPASSWD: ALL - %wheel ALL=ALL - PARTTIME ALL=ALL,!SHELLS,!SU - +interns +openlabs=ALL,!SHELLS,!SU - britt REMOTE=SHUTDOWN:ALL=LPCS - jimbo CUNETS=/usr/bin/su [!-]*,!/usr/bin/su *root* - nieusma SERVERS=SHUTDOWN,/sbin/reboot:\ - HUB=ALL,!SHELLS - jill houdini=/sbin/shutdown -[hr] now,MISC - markm HUB=ALL,!MISC,!/sbin/shutdown,!/sbin/halt - davehieb merlin=(OP) ALL:SERVERS=/sbin/halt:\ - kodiakthorn=NOPASSWD: ALL - steve CSNETS=(operator) /usr/op_commands/ + PARTTIMERS ALL = ALL + Part time sysadmins (bbbboooossssttttlllleeeeyyyy, jjjjwwwwffffooooxxxx, and ccccrrrraaaawwwwllll) may run + any command on any host but they must authenticate + themselves first (since the entry lacks the NOPASSWD tag). + jack CSNETS = ALL + The user jjjjaaaacccckkkk may run any command on the machines in the + _C_S_N_E_T_S alias (the networks 128.138.243.0, 128.138.204.0, + and 128.138.242.0). Of those networks, only + <128.138.204.0> has an explicit netmask (in CIDR notation) + indicating it is a class C network. For the other + networks in _C_S_N_E_T_S, the local machine's netmask will be + used during matching. + lisa CUNETS = ALL + The user lllliiiissssaaaa may run any command on any host in the + _C_U_N_E_T_S alias (the class B network 128.138.0.0). + operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\ + /usr/oper/bin/ + The ooooppppeeeerrrraaaattttoooorrrr user may run commands limited to simple + maintenance. Here, those are commands related to backups, + killing processes, the printing system, shutting down the + system, and any commands in the directory _/_u_s_r_/_o_p_e_r_/_b_i_n_/. -22/Jun/1999 1.6 4 + joe ALL = /usr/bin/su operator + The user jjjjooooeeee may only _s_u(1) to operator. + pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root + The user ppppeeeetttteeee is allowed to change anyone's password + except for root on the _H_P_P_A machines. Note that this + assumes _p_a_s_s_w_d(1) does not take multiple usernames on the + command line. + bob SPARC = (OP) ALL : SGI = (OP) ALL -sudoers(5) FILE FORMATS sudoers(5) + The user bbbboooobbbb may run anything on the _S_P_A_R_C and _S_G_I + machines as any user listed in the _O_P Runas_Alias (rrrrooooooootttt + and ooooppppeeeerrrraaaattttoooorrrr). - HHHHoooosssstttt AAAAlllliiiiaaaassss ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss:::: - The are four _h_o_s_t _a_l_i_a_s_e_s. The first actually contains - two _a_l_i_a_s_e_s. It sets HUB to be houdini and REMOTE to the - three machines merlin, kodiakthorn and spirit. Similarly, - SERVERS is set to the machines houdini, merlin, - kodiakthorn and spirit. The CSNETS alias will match any - host on the 128.138.243.0, 128.138.204.0, or - 128.138.205.192 nets. The CUNETS alias will match any - host on the 128.138.0.0 (class B) network. Note that - these are nnnneeeettttwwwwoooorrrrkkkk addresses, not ip addresses. Unless an - explicit netmask is given, the local _n_e_t_m_a_s_k is used to - determine whether or not the current host belongs to a - network. - UUUUsssseeeerrrr AAAAlllliiiiaaaassss ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss:::: +25/Aug/1999 1.6 7 - The two _u_s_e_r _a_l_i_a_s_e_s simply groups the FULLTIME and - PARTTIME folks into two separate aliases. - CCCCoooommmmmmmmaaaannnndddd aaaalllliiiiaaaassss ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss:::: - Command aliases are lists of commands with or without - associated command line arguments. The entries above - should be self-explanatory. - UUUUsssseeeerrrr ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss:::: +SUDOERS(5) FILE FORMATS SUDOERS(5) - FULLTIME Full-time sysadmins in the FULLTIME alias - may run any command on any host as any - user without a password. - %wheel Any user in the UN*X group wheel may run - any command on any host. + jim +biglab = ALL - PARTTIME Part-time sysadmins in the PARTTIME alias - may run any command except those in the - SHELLS and SU aliases on any host. + The user jjjjiiiimmmm may run any command on machines in the _b_i_g_l_a_b + netgroup. SSSSuuuuddddoooo knows that "biglab" is a netgroup due to + the '+' prefix. - +interns Any user in the netgroup interns may run - any command except those in the SHELLS and - SU aliases on any host that is in the - openlabs netgroup. + +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser - britt The user britt may run commands in the - SHUTDOWN alias on the REMOTE machines and - commands in the LPCS alias on any machine. + Users in the sssseeeeccccrrrreeeettttaaaarrrriiiieeeessss netgroup need to help manage the + printers as well as add and remove users, so they are + allowed to run those commands on all machines. - jimbo The user jimbo may su to any user save - root on the machines on CUNETS (which is - explicitly listed as a class B network). + fred ALL = (DB) NOPASSWD: ALL + The user ffffrrrreeeedddd can run commands as any user in the _D_B + Runas_Alias (oooorrrraaaacccclllleeee or ssssyyyybbbbaaaasssseeee) without giving a password. + john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root* + On the _A_L_P_H_A machines, user jjjjoooohhhhnnnn may su to anyone except + root but he is not allowed to give _s_u(1) any flags. + jen ALL, !SERVERS = ALL -22/Jun/1999 1.6 5 + The user jjjjeeeennnn may run any command on any machine except for + those in the _S_E_R_V_E_R_S Host_Alias (master, mail, www and + ns). + jill SERVERS = /usr/bin/, !SU, !SHELLS + For any machine in the _S_E_R_V_E_R_S Host_Alias, jjjjiiiillllllll may run + any commands in the directory /usr/bin/ except for those + commands belonging to the _S_U and _S_H_E_L_L_S Cmnd_Aliases. + steve CSNETS = (operator) /usr/local/op_commands/ + The user sssstttteeeevvvveeee may run any command in the directory + /usr/local/op_commands/ but only as user operator. -sudoers(5) FILE FORMATS sudoers(5) + matt valkyrie = KILL + On his personal workstation, valkyrie, mmmmaaaatttttttt needs to be + able to kill hung processes. - nieusma The user nieusma may run commands in the - SHUTDOWN alias as well as _/_s_b_i_n_/_r_e_b_o_o_t on - the SERVER machines and any command except - those in the SHELLS alias on the HUB - machines. + WEBMASTERS www = (www) ALL, (root) /usr/bin/su www - jill The user jill may run /sbin/shutdown -h - now or /sbin/shutdown -r now as well as - the commands in the MISC alias on houdini. + On the host www, any user in the _W_E_B_M_A_S_T_E_R_S User_Alias + (will, wendy, and wim), may run any command as user www + (which owns the web pages) or simply _s_u(1) to www. - markm The user markm may run any command on the - HUB machines except _/_s_b_i_n_/_s_h_u_t_d_o_w_n, - _/_s_b_i_n_/_h_a_l_t, and commands listed in the - MISC alias. + ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\ + /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM - davehieb The user davehieb may run any command on - merlin as any user in the Runas_Alias OP - (ie: root or operator). He may also run - _/_s_b_i_n_/_h_a_l_t on the SERVERS and any command - on kodiakthorn (no password required on - kodiakthorn). + Any user may mount or unmount a CD-ROM on the machines in - steve The user steve may run any command in the - _/_u_s_r_/_o_p___c_o_m_m_a_n_d_s_/ directory as user - operator on the machines on CSNETS. + + +25/Aug/1999 1.6 8 + + + + + +SUDOERS(5) FILE FORMATS SUDOERS(5) + + + the CDROM Host_Alias (orion, perseus, hercules) without + entering a password. This is a bit tedious for users to + type, so it is a prime candiate for encapsulating in a + shell script. + +SSSSEEEECCCCUUUURRRRIIIITTTTYYYY NNNNOOOOTTTTEEEESSSS + 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 bbbbiiiillllllll from running the commands + listed in _S_U or _S_H_E_L_L_S 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). CCCCAAAAVVVVEEEEAAAATTTTSSSS The _s_u_d_o_e_r_s file should aaaallllwwwwaaaayyyyssss be edited by the vvvviiiissssuuuuddddoooo command which locks the file and does grammatical - checking. It is imperative that the _s_u_d_o_e_r_s be free of - syntax errors since sudo will not run with a syntactically + checking. It is imperative that _s_u_d_o_e_r_s be free of syntax + errors since ssssuuuuddddoooo will not run with a syntactically incorrect _s_u_d_o_e_r_s file. FFFFIIIILLLLEEEESSSS - /etc/sudoers file of authorized users. - /etc/netgroup list of network groups. + /etc/sudoers List of who can run what + /etc/group Local groups file + /etc/netgroup List of network groups SSSSEEEEEEEE AAAALLLLSSSSOOOO @@ -391,13 +584,18 @@ SSSSEEEEEEEE AAAALLLLSSSSOOOO -22/Jun/1999 1.6 6 -sudoers(5) FILE FORMATS sudoers(5) +25/Aug/1999 1.6 9 + + + + + +SUDOERS(5) FILE FORMATS SUDOERS(5) @@ -457,6 +655,6 @@ sudoers(5) FILE FORMATS sudoers(5) -22/Jun/1999 1.6 7 +25/Aug/1999 1.6 10 diff --git a/sudoers.html b/sudoers.html index abaa56140..c1839697c 100644 --- a/sudoers.html +++ b/sudoers.html @@ -14,27 +14,18 @@
  • DESCRIPTION
  • EXAMPLES - - +
  • SECURITY NOTES
  • CAVEATS
  • FILES
  • SEE ALSO @@ -46,147 +37,266 @@

    NAME

    -sudoers - list of which users may execute what as root +sudoers - list of which users may execute what


    DESCRIPTION

    -The sudoers file is composed of an optional host alias section, an optional command -alias section and the user specification section. All command or host -aliases need to start with their respective keywords (ie: Host_Alias, -User_Alias, Runas_Alias or Cmnd_Alias). If there are multiple occurrences -of a user, the logical union of the entries will be used. Note that if -there is an entry that denies access to a command that is followed by an -entry that grants access the user will be allowed to run the command. +The sudoers file is composed two types of entries: aliases (basically variables) and +user specifications (which specify who may run what). The grammar of sudoers +will be described below in Extended Backus-Naur Form (EBNF). Don't despair +if you don't know what EBNF is, it is fairly simple and the definitions +below are annotated.


    -

    user specification format:

    +

    Quick guide to EBNF

    -

      user access_group [: access_group] ...
    -
    +EBNF is a concise and exact way of describing the grammar of a language. +Each EBNF definition is made up of production rules. Eg. +

    -

        access_group ::= host-list = [(runas-list)] [NOPASSWD:] [op]cmnd_type
    -                     [,[(user-list)] [NOPASSWD|PASSWD:] [op]cmnd_type] ... 
    -       cmnd_type ::= a command OR a command alias.
    -              op ::= the logical "!" NOT operator.
    +
     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). +


    -

    host alias section format:

    +

    Aliases

    -

      Host_Alias HOSTALIAS = host-list
    +There are four kinds of aliases: the User_Alias, Runas_Alias,
    +Host_Alias and Cmnd_Alias.
    +
    +

    +

     Alias ::= User_Alias = User_Alias (':' User_Alias)* |
    +           Runas_Alias (':' Runas_Alias)* |
    +           Host_Alias (':' Host_Alias)* |
    +           Cmnd_Alias (':' Cmnd_Alias)*
     

    -

          Host_Alias ::= a keyword.
    -       HOSTALIAS ::= an upper-case alias name.
    -       host-list ::= a comma separated list of hosts, netgroups,
    -                     ip addresses, networks.  A logical "!"
    -                     NOT operator may be prefixed to any of these.
    +
     User_Alias ::= NAME '=' User_List
     

    -


    -

    user alias section format:

    +
     Runas_Alias ::= NAME '=' Runas_User_List
    +

    -

      User_Alias USERALIAS = user-list
    +
     Host_Alias ::= NAME '=' Host_List
     

    -

          User_Alias ::= a keyword.
    -       USERALIAS ::= an upper-case alias name.
    -       user-list ::= a comma separated list of users, groups, netgroups.
    -                     A logical "!" NOT operator may be prefixed to any
    -                     of these.
    +
     Cmnd_Alias ::= NAME '=' Cmnd_List
     

    -


    -

    runas alias section format:

    +
     NAME ::= [A-Z]([A-Z][0-9]_)*
    +

    -

      Runas_Alias RUNASALIAS = runas-list
    +Each alias definition is of the form
    +
    +

    +

     Alias_Type NAME = item1, item2, ...
     

    -

          Runas_Alias ::= a keyword.
    -       RUNASALIAS ::= an upper-case alias name.
    -       runas-list ::= a comma separated list of users, groups, netgroups.
    -                      A logical "!" NOT operator may be prefixed to any
    -                      of these.
    +where Alias_Type is one of User_Alias, Runas_Alias, Host_Alias, or Cmnd_Alias. A NAME is a string of upper case letters, numbers, and the underscore characters
    +('_'). A NAME  must start with an upper case letter. It is possible to put several alias
    +definitions of the same type on a single line, joined by a semicolon (':').
    +Eg.
    +
    +

    +

     Alias_Type NAME = item1, item2, item3 : NAME = item4, item5
     

    -


    -

    command alias section format:

    +The definitions of what constitutes a valid alias member follow. +

    -

      Cmnd_Alias CMNDALIAS = cmnd-list
    +
     User_List ::= User |
    +               User ',' User_List
     

    -

          Cmnd_Alias ::= a keyword.
    -       CMNDALIAS ::= an upper-case alias name.
    -       cmnd-list ::= a comma separated list commands.
    -                     A logical "!" NOT operator may be prefixed to any
    -                     of these.
    +
     User ::= '!'* username |
    +          '!'* '#'uid |
    +          '!'* '%'group |
    +          '!'* '+'netgroup |
    +          '!'* User_Alias
     

    -


    -

    command specification:

    +A User_List is made up of one or more usernames, uids (prefixed with '#'), System +groups (prefixed with '%'), netgroups (prefixed with '+') and other +aliases. Each list item may be prefixed with one or more '!' operators. An +odd number of '!' operators negates the value of the item; an even number +just cancel each other out. +

    -

      path arg1 arg2 .. argn = command
    +
     Runas_List ::= Runas_User |
    +                Runas_User ',' Runas_List
     

    -

                path ::= a fully qualified pathname.
    -       arg[1..n] ::= optional command line arguments.
    +
     Runas_User ::= '!'* username |
    +                '!'* '#'uid |
    +                '!'* '%'group |
    +                '!'* +netgroup |
    +                '!'* Runas_Alias
     

    -


    -

    persistence of modifiers

    +Likewise, a Runas_List has the same possible elements as a User_List, except that it can include a Runas_Alias, instead of a User_Alias. + +

    +

     Host_List ::= Host |
    +               Host ',' Host_List
    +
    +

    +

     Host ::= '!'* hostname |
    +          '!'* ip_addr |
    +          '!'* network(/netmask)? |
    +          '!'* '+'netgroup |
    +          '!'* Host_Alias
    +

    -When a runas-list is specified for an access_group, it affects all commands in the access_group. For example, given: +A Host_List is made up of one or more hostnames, IP addresses, network numbers, +netgroups (prefixed with '+') and other aliases. Again, the value of an +item may be negated with the '!' operator. If you do not specify a netmask +with a network number, the netmask of the host's ethernet +interface(s) will be used when matching. The netmask may be +specified either in dotted quad notation (eg. 255.255.255.0) or CIDR +notation (number of bits, eg. 24).

    -

        oper bigserver = (root, sysadm) /usr/bin/kill, /bin/rm
    +
     Cmnd_List ::= Cmnd |
    +               Cmnd ',' Cmnd_List
    +
    +

    +

     commandname ::= filename |
    +                 filename args |
    +                 filename '""'
    +
    +

    +

     Cmnd ::= '!'* commandname |
    +          '!'* directory |
    +          '!'* Cmnd_Alias
     

    -User oper will be able to run /usr/bin/kill and /bin/rm -as root or sysadm on the machine, bigserver. The -runas-list is ``sticky'' across entries in the comma-separated -access_group. You can override the runas-list with another one, at which point the new runas-list becomes the default for that access_group. For example, given: +A Cmnd_List is a list of one or more commandnames, directories, and other aliases. A +commandname is a fully-qualified filename which may include shell-style +wildcards (see `Wildcards' section below). A simple filename allows the +user to run the command with any arguments he/she wishes. However, you may +also command line arguments (including wildcards). Alternately, you can +specify "" to indicate that the command may only be run without command line arguments. A directory is a fully qualified pathname 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 subdirectories therein).

    -

        oper bigserver = (root, sysadm) /usr/bin/kill, (root) /bin/rm, \
    -        /bin/rmdir
    +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 (or match
    +the wildcards if there are any). Note that the following characters must be
    +escaped with a '\' if they are used in command arguments: ',', ':', '=',
    +'\\'.
    +
    +

    +


    +

    User Specification

    +

    +

     Runas_Spec ::= '(' Runas_List ')'
     

    -User oper can still run /usr/bin/kill as root or sysadm but can only run /bin/rm and /bin/rmdir as root. +

     Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd
    +
    +

    +

     Cmnd_Spec_List ::= Cmnd_Spec |
    +                    Cmnd_Spec ',' Cmnd_Spec_List
    +
    +

    +

     User_Spec ::= User_list Cmnd_Spec_List (':' User_Spec)*
    +
    +

    +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. + +

    +Let's break that down into its constituent parts:

    -Similarly, the NOPASSWD modifier is also persistent across an -access_group. For example given: +


    +

    Runas_Spec

    +

    +A Runas_Spec is simply a Runas_List (as defined above) enclosed in a set of parentheses. If you do not specify +a +Runas_Spec in the user specification, a default Runas_Spec +of root will be used. A Runas_Spec sets the default for commands that follow it. What this means is that for +the entry: + +

    +

     dgb    boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who
    +
    +

    +The user dgb may run /bin/ls, /bin/kill, and +/usr/bin/lprm -- but only as operator. Eg.

    -

        oper bigserver = NOPASSWD: /usr/bin/kill, /bin/rm, /bin/rmdir
    +
        sudo -u operator /bin/ls.
     

    -User oper will be able to run /usr/bin/kill, /bin/rm, and -/bin/rmdir as root without a password. If we change that to: +It is also possible to override a Runas_Spec later on in an entry. If we modify the entry like so:

    -

        oper bigserver = NOPASSWD: /usr/bin/kill, PASSWD: /bin/rm, /bin/rmdir
    +
     dgb    boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
     

    -User oper can still run /usr/bin/kill without a password but must give a password to run /bin/rm and /bin/rmdir. +Then user dgb is now allowed to run /bin/ls as operator, but /bin/kill and /usr/bin/lprm as root.


    -

    wildcards (aka meta characters):

    +

    NOPASSWD and PASSWD

    -sudo allows shell-style wildcards along with command arguments in the sudoers file. Wildcard matching is done via the POSIX +By default, sudo requires that a user authenticate him or herself 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: -fnmatch(3) routine. +

    +

     ray    rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
    +
    +

    +would allow the user ray to run /bin/kill, /bin/ls, and +/usr/bin/lprm as root on the machine rushmore as root without authenticating himself. If we only want ray to be able to run /bin/kill without a password the entry would be: + +

    +

     ray    rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
    +
    +

    +


    +

    Wildcards (aka meta characters):

    +

    +sudo allows shell-style wildcards to be used in pathnames as well as command line arguments in the sudoers file. Wildcard matching is done via the POSIX fnmatch(3) routine. Note that these are not regular expressions.

    • Matches any set of zero or more characters. -

      ?
      +
      ?

      Matches any single character. @@ -204,9 +314,19 @@ For any character ``x'', evaluates to ``x''. This is used to escape special characters such as: ``*'', ``?'', ``['', and ``}''.

    +

    +Note that a forward slash ('/') will not be matched by wildcards used in the pathname. When matching the command +line arguments, however, as slash does get matched by wildcards. This is to make a path like: + +

    +

        /usr/bin/*
    +
    +

    +match /usr/bin/who but not /usr/bin/X11/xterm. +


    -

    exceptions to wildcard rules:

    +

    Exceptions to wildcard rules:

    The following exceptions apply to the above rules: @@ -214,175 +334,246 @@ The following exceptions apply to the above rules:

    ""

    If the empty string "" is the only command line argument in the -sudoers entry it means that command may take no arguments. +sudoers entry it means that command is not allowed to be run with any arguments.


    -

    other special characters and reserved words:

    +

    Other special characters and reserved words:

    -Text after a pound sign (#) is considered a comment. Words that begin with a percent sign (%) are assumed to be UN*X groups (%staff refers to users in the group staff). Words that begin with a plus sign (+) are assumed to be netgroups (+cshosts refers to the netgroup cshosts). Long lines can be newline escaped with the backslash \ character. +The pound sign ('#') is used to indicate a comment (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 uid). Both the comment character and any text after it, +up to the end of the line, are ignored.

    -The reserved word NOPASSWD indicates that a user need not enter a password for the command listed in -that entry. The -NOPASSWD modifier is persistent across entries in a user-list -and can be reversed with the PASSWD modifier. +The reserved word ALL is a 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. You should not try to define your own alias called ALL as the built in alias will be used in preference to your own.

    -The reserved alias ALL can be used for both {Host,User,Cmnd}_Alias. -DO NOT define an alias of ALL, it will NOT be used. Note that ALL implies the entire universe of hosts/users/commands. You can subtract -elements from the universe by using the syntax: +An exclamation point ('!') can be used as a logical not operator both in an alias and in front of a Cmnd. This allows one to exclude certain values. 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).

    -

       user  host=ALL,!ALIAS1,!/sbin/halt...
    -
    +Long lines can be continued with a backslash ('\\') as the last character +on the line. +

    -Commands may have optional command line arguments. If they do, then the -arguments in the sudoers file must exactly match those on the command line. It is also possible to -have a command's arguments span multiple lines as long as the line -continuance character ``\'' is used. The following characters must be -escaped with a ``\'' if used in command arguments: ``,'', ``:'', ``='', -``\''. +Whitespace between elements in a list as well as specicial syntactic +characters in a User Specification ('=', ':', '(', ')') is optional.


    EXAMPLES

    -

        # Host alias specification
    -    Host_Alias  HUB=houdini:\
    -                REMOTE=merlin,kodiakthorn,spirit
    -    Host_Alias  SERVERS=houdini,merlin,kodiakthorn,spirit
    -    Host_Alias  CUNETS=128.138.0.0/255.255.0.0
    -    Host_Alias  CSNETS=128.138.243.0,128.138.204.0,\
    -                       128.138.205.192
    +Below are example sudoers entries. Admittedly, some of these are a bit contrived. First, we define
    +our aliases:
    +
    +

    +

     # User alias specification
    + User_Alias     FULLTIMERS = millert, mikef, dowdy
    + User_Alias     PARTTIMERS = bostley, jwfox, crawl
    + User_Alias     WEBMASTERS = will, wendy, wim
     

    -

        # User alias specification
    -    User_Alias  FULLTIME=millert,dowdy,mikef
    -    User_Alias  PARTTIME=juola,mccreary,tor
    +
     # Runas alias specification
    + Runas_Alias    OP = root, operator
    + Runas_Alias    DB = oracle, sybase
     

    -

        # Runas alias specification
    -    Runas_Alias OP=root,operator
    +
     # Host alias specification
    + Host_Alias     SPARC = bigtime, eclipse, moet, anchor :\
    +                SGI = grolsch, dandelion, black :\
    +                ALPHA = widget, thalamus, foobar :\
    +                HPPA = boa, nag, python
    + Host_Alias     CUNETS = 128.138.0.0/255.255.0.0
    + Host_Alias     CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
    + Host_Alias     SERVERS = master, mail, www, ns
    + Host_Alias     CDROM = orion, perseus, hercules
     

    -

        # Command alias specification
    -    Cmnd_Alias  LPCS=/usr/sbin/lpc,/usr/bin/lprm
    -    Cmnd_Alias  SHELLS=/bin/sh,/bin/csh,/bin/tcsh,/bin/ksh
    -    Cmnd_Alias  SU=/usr/bin/su
    -    Cmnd_Alias  MISC=/bin/rm,/bin/cat:\
    -                SHUTDOWN=/sbin/halt,/sbin/shutdown
    +
     # Cmnd alias specification
    + Cmnd_Alias     DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\
    +                        /usr/sbin/restore, /usr/sbin/rrestore
    + Cmnd_Alias     KILL = /usr/bin/kill
    + Cmnd_Alias     PRINTING = /usr/sbin/lpc, /usr/bin/lprm
    + Cmnd_Alias     SHUTDOWN = /usr/sbin/shutdown
    + Cmnd_Alias     HALT = /usr/sbin/halt, /usr/sbin/fasthalt
    + Cmnd_Alias     REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot
    + Cmnd_Alias     SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
    +                         /usr/local/bin/tcsh, /usr/bin/rsh, \
    +                         /usr/local/bin/zsh
    + Cmnd_Alias     SU = /usr/bin/su
     

    -

        # User specification
    -    FULLTIME    ALL=(ALL) NOPASSWD: ALL
    -    %wheel      ALL=ALL
    -    PARTTIME    ALL=ALL,!SHELLS,!SU
    -    +interns    +openlabs=ALL,!SHELLS,!SU
    -    britt       REMOTE=SHUTDOWN:ALL=LPCS
    -    jimbo       CUNETS=/usr/bin/su [!-]*,!/usr/bin/su *root*
    -    nieusma     SERVERS=SHUTDOWN,/sbin/reboot:\
    -                HUB=ALL,!SHELLS
    -    jill        houdini=/sbin/shutdown -[hr] now,MISC
    -    markm       HUB=ALL,!MISC,!/sbin/shutdown,!/sbin/halt
    -    davehieb    merlin=(OP) ALL:SERVERS=/sbin/halt:\
    -                kodiakthorn=NOPASSWD: ALL
    -    steve       CSNETS=(operator) /usr/op_commands/
    +The User specification is the part that actually determines who may run what.
    +
    +

    +

     root           ALL = (ALL) ALL
    + %wheel         ALL = (ALL) ALL
     

    -


    -

    Host Alias specifications:

    +We let root and any user in group wheel run any command on any host as any user. + +

    +

     FULLTIMERS     ALL = NOPASSWD: ALL
    +

    -The are four host aliases. The first actually contains two aliases. It sets HUB to be houdini and REMOTE -to the three machines merlin, kodiakthorn and spirit. Similarly, SERVERS is set to the machines houdini, merlin, -kodiakthorn and spirit. The CSNETS alias will match any host on the 128.138.243.0, 128.138.204.0, or -128.138.205.192 nets. The CUNETS alias will match any host on the 128.138.0.0 (class B) network. Note that -these are network addresses, not ip addresses. Unless an explicit netmask is given, the local netmask -is used to determine whether or not the current host belongs to a network. +Full time sysadmins (millert, mikef, and dowdy) may run any command on any host without authenticating themselves.

    -


    -

    User Alias specifications:

    +
     PARTTIMERS     ALL = ALL
    +

    -The two user aliases simply groups the FULLTIME and -PARTTIME folks into two separate aliases. +Part time sysadmins (bostley, jwfox, and crawl) may run any command on any host but they must authenticate themselves +first (since the entry lacks the NOPASSWD tag).

    -


    -

    Command alias specifications:

    +
     jack           CSNETS = ALL
    +

    -Command aliases are lists of commands with or without associated command -line arguments. The entries above should be self-explanatory. +The user jack may run any command on the machines in the CSNETS alias (the networks 128.138.243.0, 128.138.204.0, and 128.138.242.0). Of those networks, only <128.138.204.0> has an explicit netmask (in CIDR notation) indicating it +is a class C network. For the other networks in CSNETS, the local machine's netmask will be used during matching.

    -


    -

    User specifications:

    -
    -
    FULLTIME
    +
     lisa           CUNETS = ALL
    +
    +

    +The user lisa may run any command on any host in the CUNETS alias (the class B network 128.138.0.0). + +

    +

     operator       ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\
    +                /usr/oper/bin/
    +
    +

    +The operator user may run commands limited to simple maintenance. Here, those are +commands related to backups, killing processes, the printing system, +shutting down the system, and any commands in the directory /usr/oper/bin/. + +

    +

     joe            ALL = /usr/bin/su operator
    +
    +

    +The user joe may only su(1) to operator. +

    -Full-time sysadmins in the FULLTIME alias may run any command on any host as any user without a password. +

     pete           HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root
    +
    +

    +The user pete is allowed to change anyone's password except for root on the HPPA machines. Note that this assumes passwd(1) does not take +multiple usernames on the command line. -

    %wheel

    -Any user in the UN*X group wheel may run any command on any host. +

     bob            SPARC = (OP) ALL : SGI = (OP) ALL
    +
    +

    +The user bob may run anything on the SPARC and SGI machines as any user listed in the OP Runas_Alias (root and operator). -

    PARTTIME

    -Part-time sysadmins in the PARTTIME alias may run any command except those in the SHELLS and SU aliases on any host. +

     jim            +biglab = ALL
    +
    +

    +The user jim may run any command on machines in the biglab netgroup. +Sudo knows that ``biglab'' is a netgroup due to the '+' prefix. -

    +interns

    -Any user in the netgroup interns may run any command except those in the SHELLS and SU aliases on any host that is in the openlabs netgroup. +

     +secretaries   ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
    +
    +

    +Users in the secretaries netgroup need to help manage the printers as well as add and remove users, +so they are allowed to run those commands on all machines. -

    britt

    -The user britt may run commands in the SHUTDOWN alias on the REMOTE machines and commands in the LPCS alias on any machine. +

     fred           ALL = (DB) NOPASSWD: ALL
    +
    +

    +The user fred can run commands as any user in the DB Runas_Alias +(oracle or sybase) without giving a password. -

    jimbo

    -The user jimbo may su to any user save root on the machines on CUNETS (which is explicitly listed as a class B network). +

     john           ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
    +
    +

    +On the ALPHA machines, user john may su to anyone except root but he is not allowed to give +su(1) any flags. -

    nieusma

    -The user nieusma may run commands in the SHUTDOWN alias as well as /sbin/reboot on the SERVER machines and any command except those in the SHELLS alias on the HUB -machines. +

     jen            ALL, !SERVERS = ALL
    +
    +

    +The user jen may run any command on any machine except for those in the SERVERS Host_Alias (master, mail, www and ns). -

    jill

    -The user jill may run /sbin/shutdown -h now or -/sbin/shutdown -r now as well as the commands in the -MISC alias on houdini. +

     jill           SERVERS = /usr/bin/, !SU, !SHELLS
    +
    +

    +For any machine in the SERVERS Host_Alias, jill may run any commands in the directory /usr/bin/ except for those commands +belonging to the SU and SHELLS Cmnd_Aliases. -

    markm

    -The user markm may run any command on the HUB machines except /sbin/shutdown, /sbin/halt, and commands listed in the MISC alias. +

     steve          CSNETS = (operator) /usr/local/op_commands/
    +
    +

    +The user steve may run any command in the directory /usr/local/op_commands/ but only as +user operator. -

    davehieb

    -The user davehieb may run any command on merlin as any user in the Runas_Alias OP (ie: root or operator). He may also run /sbin/halt on the SERVERS and any command on kodiakthorn (no password required on kodiakthorn). +

     matt           valkyrie = KILL
    +
    +

    +On his personal workstation, valkyrie, matt needs to be able to kill hung processes. -

    steve

    -The user steve may run any command in the /usr/op_commands/ -directory as user operator on the machines on CSNETS. +

     WEBMASTERS     www = (www) ALL, (root) /usr/bin/su www
    +
    +

    +On the host www, any user in the WEBMASTERS User_Alias (will, wendy, and wim), may run any command as user www (which owns the web +pages) or simply su(1) to www. + +

    +

     ALL            CDROM = NOPASSWD: /sbin/umount /CDROM,\
    +                /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
    +
    +

    +Any user may mount or unmount a CD-ROM on the machines in the CDROM +Host_Alias (orion, perseus, hercules) without entering a password. This is a bit +tedious for users to type, so it is a prime candiate for encapsulating in a +shell script. + +

    +


    +

    SECURITY NOTES

    +

    +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). -


    CAVEATS

    The sudoers file should always be edited by the visudo command which locks the file and does grammatical checking. It is -imperative that the sudoers be free of syntax errors since sudo will not run with a syntactically -incorrect sudoers file. +imperative that sudoers be free of syntax errors since sudo +will not run with a syntactically incorrect sudoers file.


    FILES

    -

     /etc/sudoers           file of authorized users.
    - /etc/netgroup          list of network groups.
    +
     /etc/sudoers           List of who can run what
    + /etc/group             Local groups file
    + /etc/netgroup          List of network groups
     


    diff --git a/sudoers.man b/sudoers.man index 18aa96893..64374408f 100644 --- a/sudoers.man +++ b/sudoers.man @@ -2,8 +2,8 @@ ''' $RCSfile$$Revision$$Date$ ''' ''' $Log$ -''' Revision 1.10 1999/06/22 10:38:38 millert -''' typos +''' Revision 1.11 1999/08/26 09:00:58 millert +''' new sudoers(8) man page ''' ''' .de Sh @@ -96,7 +96,7 @@ .nr % 0 .rr F .\} -.TH sudoers 5 "1.6" "22/Jun/1999" "FILE FORMATS" +.TH SUDOERS 5 "1.6" "25/Aug/1999" "FILE FORMATS" .UC .if n .hy 0 .if n .na @@ -191,123 +191,230 @@ .\} .rm #[ #] #H #V #F C .SH "NAME" -sudoers \- list of which users may execute what as root +sudoers \- list of which users may execute what .SH "DESCRIPTION" -The \fIsudoers\fR file is composed of an optional host alias section, -an optional command alias section and the user specification section. -All command or host aliases need to start with their respective keywords -(ie: Host_Alias, User_Alias, Runas_Alias or Cmnd_Alias). -If there are multiple occurrences of a user, the logical union of the -entries will be used. Note that if there is an entry that denies access -to a command that is followed by an entry that grants access the user -will be allowed to run the command. -.Sh "user specification format:" +The \fIsudoers\fR file is composed two types of entries: +aliases (basically variables) and user specifications +(which specify who may run what). The grammar of \fIsudoers\fR +will be described below in Extended Backus-Naur Form (EBNF). +Don't despair if you don't know what EBNF is, it is fairly +simple and the definitions below are annotated. +.Sh "Quick guide to \s-1EBNF\s0" +\s-1EBNF\s0 is a concise and exact way of describing the grammar of a language. +Each \s-1EBNF\s0 definition is made up of \fIproduction rules\fR. Eg. .PP .Vb 1 -\& user access_group [: access_group] ... +\& symbol ::= definition | alternate1 | alternate2 ... .Ve +Each \fIproduction rule\fR references others and thus makes up a +grammar for the language. \s-1EBNF\s0 also contains the following +operators, which many readers will recognize from regular +expressions. Do not, however, confuse them with \*(L"wildcard\*(R" +characters, which have different meanings. +.Ip "\f(CW?\fR" 8 +Means that the preceding symbol (or group of symbols) is optional. +That is, it may appear once or not at all. +.Ip "\f(CW*\fR" 8 +Means that the preceding symbol (or group of symbols) may appear +zero or more times. +.Ip "\f(CW+\fR" 8 +Means that the preceding symbol (or group of symbols) may appear +one or more times. +.PP +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). +.Sh "Aliases" +There are four kinds of aliases: the \f(CWUser_Alias\fR, \f(CWRunas_Alias\fR, +\f(CWHost_Alias\fR and \f(CWCmnd_Alias\fR. +.PP .Vb 4 -\& access_group ::= host-list = [(runas-list)] [NOPASSWD:] [op]cmnd_type -\& [,[(user-list)] [NOPASSWD|PASSWD:] [op]cmnd_type] ... -\& cmnd_type ::= a command OR a command alias. -\& op ::= the logical "!" NOT operator. +\& Alias ::= User_Alias = User_Alias (':' User_Alias)* | +\& Runas_Alias (':' Runas_Alias)* | +\& Host_Alias (':' Host_Alias)* | +\& Cmnd_Alias (':' Cmnd_Alias)* .Ve -.Sh "host alias section format:" -.PP .Vb 1 -\& Host_Alias HOSTALIAS = host-list +\& User_Alias ::= NAME '=' User_List .Ve -.Vb 5 -\& Host_Alias ::= a keyword. -\& HOSTALIAS ::= an upper-case alias name. -\& host-list ::= a comma separated list of hosts, netgroups, -\& ip addresses, networks. A logical "!" -\& NOT operator may be prefixed to any of these. +.Vb 1 +\& Runas_Alias ::= NAME '=' Runas_User_List +.Ve +.Vb 1 +\& Host_Alias ::= NAME '=' Host_List .Ve -.Sh "user alias section format:" +.Vb 1 +\& Cmnd_Alias ::= NAME '=' Cmnd_List +.Ve +.Vb 1 +\& NAME ::= [A-Z]([A-Z][0-9]_)* +.Ve +Each \fIalias\fR definition is of the form .PP .Vb 1 -\& User_Alias USERALIAS = user-list +\& Alias_Type NAME = item1, item2, ... +.Ve +where \fIAlias_Type\fR is one of \f(CWUser_Alias\fR, \f(CWRunas_Alias\fR, \f(CWHost_Alias\fR, +or \f(CWCmnd_Alias\fR. A \f(CWNAME\fR is a string of upper case letters, numbers, +and the underscore characters ('_'). A \f(CWNAME\fR \fBmust\fR start with an +upper case letter. It is possible to put several alias definitions +of the same type on a single line, joined by a semicolon (':'). Eg. +.PP +.Vb 1 +\& Alias_Type NAME = item1, item2, item3 : NAME = item4, item5 +.Ve +The definitions of what constitutes a valid \fIalias\fR member follow. +.PP +.Vb 2 +\& User_List ::= User | +\& User ',' User_List .Ve .Vb 5 -\& User_Alias ::= a keyword. -\& USERALIAS ::= an upper-case alias name. -\& user-list ::= a comma separated list of users, groups, netgroups. -\& A logical "!" NOT operator may be prefixed to any -\& of these. +\& User ::= '!'* username | +\& '!'* '#'uid | +\& '!'* '%'group | +\& '!'* '+'netgroup | +\& '!'* User_Alias .Ve -.Sh "runas alias section format:" +A \f(CWUser_List\fR is made up of one or more usernames, uids +(prefixed with \*(L'#'), System groups (prefixed with \*(L'%'), +netgroups (prefixed with \*(L'+') and other aliases. Each list +item may be prefixed with one or more \*(L'!\*(R' operators. An odd number +of \*(L'!\*(R' operators negates the value of the item; an even number +just cancel each other out. .PP -.Vb 1 -\& Runas_Alias RUNASALIAS = runas-list +.Vb 2 +\& Runas_List ::= Runas_User | +\& Runas_User ',' Runas_List .Ve .Vb 5 -\& Runas_Alias ::= a keyword. -\& RUNASALIAS ::= an upper-case alias name. -\& runas-list ::= a comma separated list of users, groups, netgroups. -\& A logical "!" NOT operator may be prefixed to any -\& of these. +\& Runas_User ::= '!'* username | +\& '!'* '#'uid | +\& '!'* '%'group | +\& '!'* +netgroup | +\& '!'* Runas_Alias .Ve -.Sh "command alias section format:" +Likewise, a \f(CWRunas_List\fR has the same possible elements +as a \f(CWUser_List\fR, except that it can include a \f(CWRunas_Alias\fR, +instead of a \f(CWUser_Alias\fR. .PP -.Vb 1 -\& Cmnd_Alias CMNDALIAS = cmnd-list +.Vb 2 +\& Host_List ::= Host | +\& Host ',' Host_List .Ve .Vb 5 -\& Cmnd_Alias ::= a keyword. -\& CMNDALIAS ::= an upper-case alias name. -\& cmnd-list ::= a comma separated list commands. -\& A logical "!" NOT operator may be prefixed to any -\& of these. +\& Host ::= '!'* hostname | +\& '!'* ip_addr | +\& '!'* network(/netmask)? | +\& '!'* '+'netgroup | +\& '!'* Host_Alias +.Ve +A \f(CWHost_List\fR is made up of one or more hostnames, \s-1IP\s0 addresses, +network numbers, netgroups (prefixed with \*(L'+') and other aliases. +Again, the value of an item may be negated with the \*(L'!\*(R' operator. +If you do not specify a netmask with a network number, the netmask +of the host's ethernet \fIinterface\fR\|(s) will be used when matching. +The netmask may be specified either in dotted quad notation (eg. +255.255.255.0) or \s-1CIDR\s0 notation (number of bits, eg. 24). +.PP +.Vb 2 +\& Cmnd_List ::= Cmnd | +\& Cmnd ',' Cmnd_List +.Ve +.Vb 3 +\& commandname ::= filename | +\& filename args | +\& filename '""' +.Ve +.Vb 3 +\& Cmnd ::= '!'* commandname | +\& '!'* directory | +\& '!'* Cmnd_Alias .Ve -.Sh "command specification:" +A \f(CWCmnd_List\fR is a list of one or more commandnames, directories, and other +aliases. A commandname is a fully-qualified filename which may include +shell-style wildcards (see `Wildcards\*(R' section below). A simple +filename allows the user to run the command with any arguments he/she +wishes. However, you may also command line arguments (including wildcards). +Alternately, you can specify \f(CW""\fR to indicate that the command +may only be run \fBwithout\fR command line arguments. A directory is a +fully qualified pathname ending in a \*(L'/\*(R'. When you specify a directory +in a \f(CWCmnd_List\fR, the user will be able to run any file within that directory +(but not in any subdirectories therein). +.PP +If a \f(CWCmnd\fR has associated command line arguments, then the arguments +in the \f(CWCmnd\fR must match exactly those given by the user on the command line +(or match the wildcards if there are any). Note that the following +characters must be escaped with a \*(L'\e\*(R' if they are used in command +arguments: \*(L',\*(R', \*(L':\*(R', \*(L'=\*(R', \*(L'\e\e\*(R'. +.Sh "User Specification" .PP .Vb 1 -\& path arg1 arg2 .. argn = command +\& Runas_Spec ::= '(' Runas_List ')' +.Ve +.Vb 1 +\& Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd .Ve .Vb 2 -\& path ::= a fully qualified pathname. -\& arg[1..n] ::= optional command line arguments. +\& Cmnd_Spec_List ::= Cmnd_Spec | +\& Cmnd_Spec ',' Cmnd_Spec_List .Ve -.Sh "persistence of modifiers" -When a \fIrunas-list\fR is specified for an \fIaccess_group\fR, it -affects all commands in the \fIaccess_group\fR. For example, given: +.Vb 1 +\& User_Spec ::= User_list Cmnd_Spec_List (':' User_Spec)* +.Ve +A \fBuser specification\fR determines which commands a user may run +(and as what user) on specified hosts. By default, commands are +run as \fBroot\fR but this can be changed on a per-command basis. +.PP +Let's break that down into its constituent parts: +.Sh "Runas_Spec" +A \f(CWRunas_Spec\fR is simply a \f(CWRunas_List\fR (as defined above) +enclosed in a set of parentheses. If you do not specify a +\f(CWRunas_Spec\fR in the user specification, a default \f(CWRunas_Spec\fR +of \fBroot\fR will be used. A \f(CWRunas_Spec\fR sets the default for +commands that follow it. What this means is that for the entry: .PP .Vb 1 -\& oper bigserver = (root, sysadm) /usr/bin/kill, /bin/rm +\& dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who .Ve -User \f(CWoper\fR will be able to run \f(CW/usr/bin/kill\fR and \f(CW/bin/rm\fR -as \fBroot\fR or \fBsysadm\fR on the machine, \f(CWbigserver\fR. The -\fIrunas-list\fR is \*(L"sticky\*(R" across entries in the comma-separated -\fIaccess_group\fR. You can override the \fIrunas-list\fR with another -one, at which point the new \fIrunas-list\fR becomes the default for -that \fIaccess_group\fR. For example, given: +The user \fBdgb\fR may run \fI/bin/ls\fR, \fI/bin/kill\fR, and +\fI/usr/bin/lprm\fR -- but only as \fBoperator\fR. Eg. .PP -.Vb 2 -\& oper bigserver = (root, sysadm) /usr/bin/kill, (root) /bin/rm, \e -\& /bin/rmdir +.Vb 1 +\& sudo -u operator /bin/ls. .Ve -User \f(CWoper\fR can still run \f(CW/usr/bin/kill\fR as \fBroot\fR or \fBsysadm\fR but -can only run \f(CW/bin/rm\fR and \f(CW/bin/rmdir\fR as \fBroot\fR. +It is also possible to override a \f(CWRunas_Spec\fR later on in an +entry. If we modify the entry like so: .PP -Similarly, the \fB\s-1NOPASSWD\s0\fR modifier is also persistent across an -\fIaccess_group\fR. For example given: +.Vb 1 +\& dgb boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm +.Ve +Then user \fBdgb\fR is now allowed to run \fI/bin/ls\fR as \fBoperator\fR, +but \fI/bin/kill\fR and \fI/usr/bin/lprm\fR as \fBroot\fR. +.Sh "\s-1NOPASSWD\s0 and \s-1PASSWD\s0" +By default, \fBsudo\fR requires that a user authenticate him or herself +before running a command. This behavior can be modified via the +\f(CWNOPASSWD\fR tag. Like a \f(CWRunas_Spec\fR, the \f(CWNOPASSWD\fR tag sets +a default for the commands that follow it in the \f(CWCmnd_Spec_List\fR. +Conversely, the \f(CWPASSWD\fR tag can be used to reverse things. +For example: .PP .Vb 1 -\& oper bigserver = NOPASSWD: /usr/bin/kill, /bin/rm, /bin/rmdir +\& ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm .Ve -User \f(CWoper\fR will be able to run \f(CW/usr/bin/kill\fR, \f(CW/bin/rm\fR, and -\f(CW/bin/rmdir\fR as \fBroot\fR without a password. If we change that to: +would allow the user \fBray\fR to run \fI/bin/kill\fR, \fI/bin/ls\fR, and +\fI/usr/bin/lprm\fR as root on the machine rushmore as \fBroot\fR without +authenticating himself. If we only want \fBray\fR to be able to +run \fI/bin/kill\fR without a password the entry would be: .PP .Vb 1 -\& oper bigserver = NOPASSWD: /usr/bin/kill, PASSWD: /bin/rm, /bin/rmdir +\& ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm .Ve -User \f(CWoper\fR can still run \f(CW/usr/bin/kill\fR without a password but -must give a password to run \f(CW/bin/rm\fR and \f(CW/bin/rmdir\fR. -.Sh "wildcards (aka meta characters):" -\fBsudo\fR allows shell-style \fIwildcards\fR along with command arguments -in the \fIsudoers\fR file. Wildcard matching is done via the \fB\s-1POSIX\s0\fR -\f(CWfnmatch(3)\fR routine. +.Sh "Wildcards (aka meta characters):" +\fBsudo\fR allows shell-style \fIwildcards\fR to be used in pathnames +as well as command line arguments in the \fIsudoers\fR file. Wildcard +matching is done via the \fB\s-1POSIX\s0\fR \f(CWfnmatch(3)\fR routine. Note that +these are \fInot\fR regular expressions. .Ip "\f(CW*\fR" 8 Matches any set of zero or more characters. .Ip "\f(CW?\fR" 8 @@ -319,180 +426,272 @@ Matches any character \fBnot\fR in the specified range. .Ip "\f(CW\ex\fR" 8 For any character \*(L"x\*(R", evaluates to \*(L"x\*(R". This is used to escape special characters such as: \*(L"*\*(R", \*(L"?\*(R", \*(L"[\*(R", and \*(L"}\*(R". -.Sh "exceptions to wildcard rules:" +.PP +Note that a forward slash ('/') will \fBnot\fR be matched by +wildcards used in the pathname. When matching the command +line arguments, however, as slash \fBdoes\fR get matched by +wildcards. This is to make a path like: +.PP +.Vb 1 +\& /usr/bin/* +.Ve +match \f(CW/usr/bin/who\fR but not \f(CW/usr/bin/X11/xterm\fR. +.Sh "Exceptions to wildcard rules:" The following exceptions apply to the above rules: -.Ip "\f(CW""\fR" 8 +.Ip \f(CW""\fR 8 If the empty string \f(CW""\fR is the only command line argument in the -\fIsudoers\fR entry it means that command may take \fBno\fR arguments. -.Sh "other special characters and reserved words:" -Text after a pound sign (\fB#\fR) is considered a comment. -Words that begin with a percent sign (\fB%\fR) are assumed to -be \s-1UN\s0*X groups (%staff refers to users in the group \fIstaff\fR). -Words that begin with a plus sign (\fB+\fR) are assumed to -be netgroups (\fB+cshosts\fR refers to the netgroup \fIcshosts\fR). -Long lines can be newline escaped with the backslash \fB\e\fR character. -.PP -The reserved word \fB\s-1NOPASSWD\s0\fR indicates that a user need not -enter a password for the command listed in that entry. The -\fB\s-1NOPASSWD\s0\fR modifier is persistent across entries in a \fIuser-list\fR -and can be reversed with the \fB\s-1PASSWD\s0\fR modifier. -.PP -The reserved alias \fI\s-1ALL\s0\fR can be used for both {Host,User,Cmnd}_Alias. -\fB\s-1DO\s0 \s-1NOT\s0\fR define an alias of \fI\s-1ALL\s0\fR, it will \fB\s-1NOT\s0\fR be used. -Note that \fI\s-1ALL\s0\fR implies the entire universe of hosts/users/commands. -You can subtract elements from the universe by using the syntax: -.PP -.Vb 1 -\& user host=ALL,!ALIAS1,!/sbin/halt... -.Ve -Commands may have optional command line arguments. If they do, -then the arguments in the \fIsudoers\fR file must exactly match those -on the command line. It is also possible to have a command's -arguments span multiple lines as long as the line continuance -character \*(L"\e\*(R" is used. The following characters must be escaped -with a \*(L"\e\*(R" if used in command arguments: \*(L",\*(R", \*(L":\*(R", \*(L"=\*(R", \*(L"\e\*(R". +\fIsudoers\fR entry it means that command is not allowed to be run +with \fBany\fR arguments. +.Sh "Other special characters and reserved words:" +The pound sign ('#') is used to indicate a comment (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 uid). Both the +comment character and any text after it, up to the end of the line, +are ignored. +.PP +The reserved word \fB\s-1ALL\s0\fR is a a built in \fIalias\fR that always causes +a match to succeed. It can be used wherever one might otherwise +use a \f(CWCmnd_Alias\fR, \f(CWUser_Alias\fR, \f(CWRunas_Alias\fR, or \f(CWHost_Alias\fR. +You should not try to define your own \fIalias\fR called \fB\s-1ALL\s0\fR as the +built in alias will be used in preference to your own. +.PP +An exclamation point (\*(R'!') can be used as a logical \fInot\fR operator +both in an \fIalias\fR and in front of a \f(CWCmnd\fR. This allows one to +exclude certain values. Note, however, that using a \f(CW!\fR in +conjunction with the built in \f(CWALL\fR alias to allow a user to +run \*(L"all but a few\*(R" commands rarely works as intended (see \s-1SECURITY\s0 +\s-1NOTES\s0 below). +.PP +Long lines can be continued with a backslash (\*(R'\e\e') as the last +character on the line. +.PP +Whitespace between elements in a list as well as specicial syntactic +characters in a \fIUser Specification\fR ('=\*(R', \*(L':\*(R', \*(L'(\*(R', \*(L')') is optional. .SH "EXAMPLES" +Below are example \fIsudoers\fR entries. Admittedly, some of +these are a bit contrived. First, we define our \fIaliases\fR: .PP -.Vb 7 -\& # Host alias specification -\& Host_Alias HUB=houdini:\e -\& REMOTE=merlin,kodiakthorn,spirit -\& Host_Alias SERVERS=houdini,merlin,kodiakthorn,spirit -\& Host_Alias CUNETS=128.138.0.0/255.255.0.0 -\& Host_Alias CSNETS=128.138.243.0,128.138.204.0,\e -\& 128.138.205.192 +.Vb 4 +\& # User alias specification +\& User_Alias FULLTIMERS = millert, mikef, dowdy +\& User_Alias PARTTIMERS = bostley, jwfox, crawl +\& User_Alias WEBMASTERS = will, wendy, wim .Ve .Vb 3 -\& # User alias specification -\& User_Alias FULLTIME=millert,dowdy,mikef -\& User_Alias PARTTIME=juola,mccreary,tor +\& # Runas alias specification +\& Runas_Alias OP = root, operator +\& Runas_Alias DB = oracle, sybase .Ve +.Vb 9 +\& # Host alias specification +\& Host_Alias SPARC = bigtime, eclipse, moet, anchor :\e +\& SGI = grolsch, dandelion, black :\e +\& ALPHA = widget, thalamus, foobar :\e +\& HPPA = boa, nag, python +\& Host_Alias CUNETS = 128.138.0.0/255.255.0.0 +\& Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0 +\& Host_Alias SERVERS = master, mail, www, ns +\& Host_Alias CDROM = orion, perseus, hercules +.Ve +.Vb 12 +\& # Cmnd alias specification +\& Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\e +\& /usr/sbin/restore, /usr/sbin/rrestore +\& Cmnd_Alias KILL = /usr/bin/kill +\& Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm +\& Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown +\& Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt +\& Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot +\& Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \e +\& /usr/local/bin/tcsh, /usr/bin/rsh, \e +\& /usr/local/bin/zsh +\& Cmnd_Alias SU = /usr/bin/su +.Ve +The \fIUser specification\fR is the part that actually determines who may +run what. +.PP .Vb 2 -\& # Runas alias specification -\& Runas_Alias OP=root,operator -.Ve -.Vb 6 -\& # Command alias specification -\& Cmnd_Alias LPCS=/usr/sbin/lpc,/usr/bin/lprm -\& Cmnd_Alias SHELLS=/bin/sh,/bin/csh,/bin/tcsh,/bin/ksh -\& Cmnd_Alias SU=/usr/bin/su -\& Cmnd_Alias MISC=/bin/rm,/bin/cat:\e -\& SHUTDOWN=/sbin/halt,/sbin/shutdown -.Ve -.Vb 14 -\& # User specification -\& FULLTIME ALL=(ALL) NOPASSWD: ALL -\& %wheel ALL=ALL -\& PARTTIME ALL=ALL,!SHELLS,!SU -\& +interns +openlabs=ALL,!SHELLS,!SU -\& britt REMOTE=SHUTDOWN:ALL=LPCS -\& jimbo CUNETS=/usr/bin/su [!-]*,!/usr/bin/su *root* -\& nieusma SERVERS=SHUTDOWN,/sbin/reboot:\e -\& HUB=ALL,!SHELLS -\& jill houdini=/sbin/shutdown -[hr] now,MISC -\& markm HUB=ALL,!MISC,!/sbin/shutdown,!/sbin/halt -\& davehieb merlin=(OP) ALL:SERVERS=/sbin/halt:\e -\& kodiakthorn=NOPASSWD: ALL -\& steve CSNETS=(operator) /usr/op_commands/ -.Ve -.Sh "Host Alias specifications:" -The are four \fIhost aliases\fR. The first actually contains -two \fIaliases\fR. It sets \f(CWHUB\fR to be \f(CWhoudini\fR and \f(CWREMOTE\fR -to the three machines \f(CWmerlin\fR, \f(CWkodiakthorn\fR and \f(CWspirit\fR. -Similarly, \f(CWSERVERS\fR is set to the machines \f(CWhoudini\fR, \f(CWmerlin\fR, -\f(CWkodiakthorn\fR and \f(CWspirit\fR. The \f(CWCSNETS\fR alias will match -any host on the 128.138.243.0, 128.138.204.0, or 128.138.205.192 -nets. The \f(CWCUNETS\fR alias will match any host on the 128.138.0.0 -(class B) network. Note that these are \fBnetwork\fR addresses, not ip -addresses. Unless an explicit netmask is given, the local \fInetmask\fR -is used to determine whether or not the current host belongs to a network. -.Sh "User Alias specifications:" -The two \fIuser aliases\fR simply groups the \f(CWFULLTIME\fR and -\f(CWPARTTIME\fR folks into two separate aliases. -.Sh "Command alias specifications:" -Command aliases are lists of commands with or without associated -command line arguments. The entries above should be self-explanatory. -.Sh "User specifications:" -.Ip "\s-1FULLTIME\s0" 16 -Full-time sysadmins in the \f(CWFULLTIME\fR alias may run any -command on any host as any user without a password. -.Ip "%wheel" 16 -Any user in the \s-1UN\s0*X group \f(CWwheel\fR may run any -command on any host. -.Ip "\s-1PARTTIME\s0" 16 -Part-time sysadmins in the \f(CWPARTTIME\fR alias may run any -command except those in the \f(CWSHELLS\fR and \f(CWSU\fR aliases -on any host. -.Ip "+interns" 16 -Any user in the netgroup \f(CWinterns\fR may run any -command except those in the \f(CWSHELLS\fR and \f(CWSU\fR aliases -on any host that is in the \f(CWopenlabs\fR netgroup. -.Ip "britt" 16 -The user \f(CWbritt\fR may run commands in the \f(CWSHUTDOWN\fR alias -on the \f(CWREMOTE\fR machines and commands in the \f(CWLPCS\fR alias -on any machine. -.Ip "jimbo" 16 -The user \f(CWjimbo\fR may \f(CWsu\fR to any user save root on the -machines on \f(CWCUNETS\fR (which is explicitly listed as a class -B network). -.Ip "nieusma" 16 -The user \f(CWnieusma\fR may run commands in the \f(CWSHUTDOWN\fR alias -as well as \fI/sbin/reboot\fR on the \f(CWSERVER\fR machines and -any command except those in the \f(CWSHELLS\fR alias on the \f(CWHUB\fR -machines. -.Ip "jill" 16 -The user \f(CWjill\fR may run \f(CW/sbin/shutdown -h now\fR or -\f(CW/sbin/shutdown -r now\fR as well as the commands in the -\f(CWMISC\fR alias on houdini. -.Ip "markm" 16 -The user \f(CWmarkm\fR may run any command on the \f(CWHUB\fR machines -except \fI/sbin/shutdown\fR, \fI/sbin/halt\fR, and commands listed -in the \f(CWMISC\fR alias. -.Ip "davehieb" 16 -The user \f(CWdavehieb\fR may run any command on \f(CWmerlin\fR as any -user in the Runas_Alias \s-1OP\s0 (ie: root or operator). He may -also run \fI/sbin/halt\fR on the \f(CWSERVERS\fR and any command -on \f(CWkodiakthorn\fR (no password required on \f(CWkodiakthorn\fR). -.Ip "steve" 16 -The user \f(CWsteve\fR may run any command in the \fI/usr/op_commands/\fR -directory as user \f(CWoperator\fR on the machines on \f(CWCSNETS\fR. +\& root ALL = (ALL) ALL +\& %wheel ALL = (ALL) ALL +.Ve +We let \fBroot\fR and any user in group \fBwheel\fR run any command on any +host as any user. +.PP +.Vb 1 +\& FULLTIMERS ALL = NOPASSWD: ALL +.Ve +Full time sysadmins (\fBmillert\fR, \fBmikef\fR, and \fBdowdy\fR) may run any +command on any host without authenticating themselves. +.PP +.Vb 1 +\& PARTTIMERS ALL = ALL +.Ve +Part time sysadmins (\fBbostley\fR, \fBjwfox\fR, and \fBcrawl\fR) may run any +command on any host but they must authenticate themselves first +(since the entry lacks the \f(CWNOPASSWD\fR tag). +.PP +.Vb 1 +\& jack CSNETS = ALL +.Ve +The user \fBjack\fR may run any command on the machines in the \fICSNETS\fR alias +(the networks \f(CW128.138.243.0\fR, \f(CW128.138.204.0\fR, and \f(CW128.138.242.0\fR). +Of those networks, only <128.138.204.0> has an explicit netmask (in +CIDR notation) indicating it is a class C network. For the other +networks in \fICSNETS\fR, the local machine's netmask will be used +during matching. +.PP +.Vb 1 +\& lisa CUNETS = ALL +.Ve +The user \fBlisa\fR may run any command on any host in the \fICUNETS\fR alias +(the class B network \f(CW128.138.0.0\fR). +.PP +.Vb 2 +\& operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\e +\& /usr/oper/bin/ +.Ve +The \fBoperator\fR user may run commands limited to simple maintenance. +Here, those are commands related to backups, killing processes, the +printing system, shutting down the system, and any commands in the +directory \fI/usr/oper/bin/\fR. +.PP +.Vb 1 +\& joe ALL = /usr/bin/su operator +.Ve +The user \fBjoe\fR may only \fIsu\fR\|(1) to operator. +.PP +.Vb 1 +\& pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root +.Ve +The user \fBpete\fR is allowed to change anyone's password except for +root on the \fIHPPA\fR machines. Note that this assumes \fIpasswd\fR\|(1) +does not take multiple usernames on the command line. +.PP +.Vb 1 +\& bob SPARC = (OP) ALL : SGI = (OP) ALL +.Ve +The user \fBbob\fR may run anything on the \fISPARC\fR and \fISGI\fR machines +as any user listed in the \fIOP\fR \f(CWRunas_Alias\fR (\fBroot\fR and \fBoperator\fR). +.PP +.Vb 1 +\& jim +biglab = ALL +.Ve +The user \fBjim\fR may run any command on machines in the \fIbiglab\fR netgroup. +\fBSudo\fR knows that \*(L"biglab\*(R" is a netgroup due to the \*(L'+\*(R' prefix. +.PP +.Vb 1 +\& +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser +.Ve +Users in the \fBsecretaries\fR netgroup need to help manage the printers +as well as add and remove users, so they are allowed to run those +commands on all machines. +.PP +.Vb 1 +\& fred ALL = (DB) NOPASSWD: ALL +.Ve +The user \fBfred\fR can run commands as any user in the \fIDB\fR \f(CWRunas_Alias\fR +(\fBoracle\fR or \fBsybase\fR) without giving a password. +.PP +.Vb 1 +\& john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root* +.Ve +On the \fIALPHA\fR machines, user \fBjohn\fR may su to anyone except root +but he is not allowed to give \fIsu\fR\|(1) any flags. +.PP +.Vb 1 +\& jen ALL, !SERVERS = ALL +.Ve +The user \fBjen\fR may run any command on any machine except for those +in the \fISERVERS\fR \f(CWHost_Alias\fR (master, mail, www and ns). +.PP +.Vb 1 +\& jill SERVERS = /usr/bin/, !SU, !SHELLS +.Ve +For any machine in the \fISERVERS\fR \f(CWHost_Alias\fR, \fBjill\fR may run +any commands in the directory /usr/bin/ except for those commands +belonging to the \fISU\fR and \fISHELLS\fR \f(CWCmnd_Aliases\fR. +.PP +.Vb 1 +\& steve CSNETS = (operator) /usr/local/op_commands/ +.Ve +The user \fBsteve\fR may run any command in the directory /usr/local/op_commands/ +but only as user operator. +.PP +.Vb 1 +\& matt valkyrie = KILL +.Ve +On his personal workstation, valkyrie, \fBmatt\fR needs to be able to +kill hung processes. +.PP +.Vb 1 +\& WEBMASTERS www = (www) ALL, (root) /usr/bin/su www +.Ve +On the host www, any user in the \fIWEBMASTERS\fR \f(CWUser_Alias\fR (will, +wendy, and wim), may run any command as user www (which owns the +web pages) or simply \fIsu\fR\|(1) to www. +.PP +.Vb 2 +\& ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\e +\& /sbin/mount -o nosuid\e,nodev /dev/cd0a /CDROM +.Ve +Any user may mount or unmount a CD\-ROM on the machines in the CDROM +\f(CWHost_Alias\fR (orion, perseus, hercules) without entering a password. +This is a bit tedious for users to type, so it is a prime candiate +for encapsulating in a shell script. +.SH "SECURITY NOTES" +It is generally not effective to \*(L"subtract\*(R" commands from \f(CWALL\fR +using the \*(L'!\*(R' operator. A user can trivially circumvent this +by copying the desired command to a different name and then +executing that. For example: +.PP +.Vb 1 +\& bill ALL = ALL, !SU, !SHELLS +.Ve +Doesn't really prevent \fBbill\fR from running the commands listed in +\fISU\fR or \fISHELLS\fR 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). .SH "CAVEATS" The \fIsudoers\fR file should \fBalways\fR be edited by the \fBvisudo\fR command which locks the file and does grammatical checking. It is -imperative that the \fIsudoers\fR be free of syntax errors since sudo +imperative that \fIsudoers\fR be free of syntax errors since \fBsudo\fR will not run with a syntactically incorrect \fIsudoers\fR file. .SH "FILES" .PP -.Vb 2 -\& /etc/sudoers file of authorized users. -\& /etc/netgroup list of network groups. +.Vb 3 +\& /etc/sudoers List of who can run what +\& /etc/group Local groups file +\& /etc/netgroup List of network groups .Ve .SH "SEE ALSO" \fIsudo\fR\|(8), \fIvisudo\fR\|(8), \fIsu\fR\|(1), \fIfnmatch\fR\|(3). .rn }` '' -.IX Title "sudoers 5" -.IX Name "sudoers - list of which users may execute what as root" +.IX Title "SUDOERS 5" +.IX Name "sudoers - list of which users may execute what" .IX Header "NAME" .IX Header "DESCRIPTION" -.IX Subsection "user specification format:" +.IX Subsection "Quick guide to \s-1EBNF\s0" + +.IX Item "\f(CW?\fR" -.IX Subsection "host alias section format:" +.IX Item "\f(CW*\fR" -.IX Subsection "user alias section format:" +.IX Item "\f(CW+\fR" -.IX Subsection "runas alias section format:" +.IX Subsection "Aliases" -.IX Subsection "command alias section format:" +.IX Subsection "User Specification" -.IX Subsection "command specification:" +.IX Subsection "Runas_Spec" -.IX Subsection "persistence of modifiers" +.IX Subsection "\s-1NOPASSWD\s0 and \s-1PASSWD\s0" -.IX Subsection "wildcards (aka meta characters):" +.IX Subsection "Wildcards (aka meta characters):" .IX Item "\f(CW*\fR" @@ -504,43 +703,15 @@ will not run with a syntactically incorrect \fIsudoers\fR file. .IX Item "\f(CW\ex\fR" -.IX Subsection "exceptions to wildcard rules:" +.IX Subsection "Exceptions to wildcard rules:" .IX Item "\f(CW""\fR" -.IX Subsection "other special characters and reserved words:" +.IX Subsection "Other special characters and reserved words:" .IX Header "EXAMPLES" -.IX Subsection "Host Alias specifications:" - -.IX Subsection "User Alias specifications:" - -.IX Subsection "Command alias specifications:" - -.IX Subsection "User specifications:" - -.IX Item "\s-1FULLTIME\s0" - -.IX Item "%wheel" - -.IX Item "\s-1PARTTIME\s0" - -.IX Item "+interns" - -.IX Item "britt" - -.IX Item "jimbo" - -.IX Item "nieusma" - -.IX Item "jill" - -.IX Item "markm" - -.IX Item "davehieb" - -.IX Item "steve" +.IX Header "SECURITY NOTES" .IX Header "CAVEATS" diff --git a/sudoers.pod b/sudoers.pod index deb901c55..654d89b0c 100644 --- a/sudoers.pod +++ b/sudoers.pod @@ -1,116 +1,261 @@ =cut +Copyright (c) 1994-1996,1998-1999 Todd C. Miller +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission + from the author. + +4. Products derived from this software may not be called "Sudo" nor + may "Sudo" appear in their names without specific prior written + permission from the author. + +THIS SOFTWARE 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. IN NO EVENT SHALL +THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + $Sudo$ =pod =head1 NAME -sudoers - list of which users may execute what as root +sudoers - list of which users may execute what =head1 DESCRIPTION -The I file is composed of an optional host alias section, -an optional command alias section and the user specification section. -All command or host aliases need to start with their respective keywords -(ie: Host_Alias, User_Alias, Runas_Alias or Cmnd_Alias). -If there are multiple occurrences of a user, the logical union of the -entries will be used. Note that if there is an entry that denies access -to a command that is followed by an entry that grants access the user -will be allowed to run the command. +The I file is composed two types of entries: +aliases (basically variables) and user specifications +(which specify who may run what). The grammar of I +will be described below in Extended Backus-Naur Form (EBNF). +Don't despair if you don't know what EBNF is, it is fairly +simple and the definitions below are annotated. + +=head2 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 I. Eg. + + symbol ::= definition | alternate1 | alternate2 ... + +Each I 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. + +=over 8 + +=item C + +Means that the preceding symbol (or group of symbols) is optional. +That is, it may appear once or not at all. + +=item C<*> + +Means that the preceding symbol (or group of symbols) may appear +zero or more times. + +=item C<+> + +Means that the preceding symbol (or group of symbols) may appear +one or more times. + +=back + +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). + +=head2 Aliases + +There are four kinds of aliases: the C, C, +C and C. + + Alias ::= User_Alias = User_Alias (':' User_Alias)* | + Runas_Alias (':' Runas_Alias)* | + Host_Alias (':' Host_Alias)* | + Cmnd_Alias (':' Cmnd_Alias)* + + User_Alias ::= NAME '=' User_List + + Runas_Alias ::= NAME '=' Runas_User_List + + Host_Alias ::= NAME '=' Host_List + + Cmnd_Alias ::= NAME '=' Cmnd_List + + NAME ::= [A-Z]([A-Z][0-9]_)* -=head2 user specification format: +Each I definition is of the form - user access_group [: access_group] ... + Alias_Type NAME = item1, item2, ... - access_group ::= host-list = [(runas-list)] [NOPASSWD:] [op]cmnd_type - [,[(user-list)] [NOPASSWD|PASSWD:] [op]cmnd_type] ... - cmnd_type ::= a command OR a command alias. - op ::= the logical "!" NOT operator. +where I is one of C, C, C, +or C. A C is a string of upper case letters, numbers, +and the underscore characters ('_'). A C B start with an +upper case letter. It is possible to put several alias definitions +of the same type on a single line, joined by a semicolon (':'). Eg. -=head2 host alias section format: + Alias_Type NAME = item1, item2, item3 : NAME = item4, item5 - Host_Alias HOSTALIAS = host-list +The definitions of what constitutes a valid I member follow. - Host_Alias ::= a keyword. - HOSTALIAS ::= an upper-case alias name. - host-list ::= a comma separated list of hosts, netgroups, - ip addresses, networks. A logical "!" - NOT operator may be prefixed to any of these. + User_List ::= User | + User ',' User_List -=head2 user alias section format: + User ::= '!'* username | + '!'* '#'uid | + '!'* '%'group | + '!'* '+'netgroup | + '!'* User_Alias - User_Alias USERALIAS = user-list +A C is made up of one or more usernames, uids +(prefixed with '#'), System groups (prefixed with '%'), +netgroups (prefixed with '+') and other aliases. Each list +item may be prefixed with one or more '!' operators. An odd number +of '!' operators negates the value of the item; an even number +just cancel each other out. - User_Alias ::= a keyword. - USERALIAS ::= an upper-case alias name. - user-list ::= a comma separated list of users, groups, netgroups. - A logical "!" NOT operator may be prefixed to any - of these. + Runas_List ::= Runas_User | + Runas_User ',' Runas_List -=head2 runas alias section format: + Runas_User ::= '!'* username | + '!'* '#'uid | + '!'* '%'group | + '!'* +netgroup | + '!'* Runas_Alias - Runas_Alias RUNASALIAS = runas-list +Likewise, a C has the same possible elements +as a C, except that it can include a C, +instead of a C. - Runas_Alias ::= a keyword. - RUNASALIAS ::= an upper-case alias name. - runas-list ::= a comma separated list of users, groups, netgroups. - A logical "!" NOT operator may be prefixed to any - of these. + Host_List ::= Host | + Host ',' Host_List -=head2 command alias section format: + Host ::= '!'* hostname | + '!'* ip_addr | + '!'* network(/netmask)? | + '!'* '+'netgroup | + '!'* Host_Alias - Cmnd_Alias CMNDALIAS = cmnd-list +A C is made up of one or more hostnames, IP addresses, +network numbers, netgroups (prefixed with '+') and other aliases. +Again, the value of an item may be negated with the '!' operator. +If you do not specify a netmask with a network number, the netmask +of the host's ethernet interface(s) will be used when matching. +The netmask may be specified either in dotted quad notation (eg. +255.255.255.0) or CIDR notation (number of bits, eg. 24). - Cmnd_Alias ::= a keyword. - CMNDALIAS ::= an upper-case alias name. - cmnd-list ::= a comma separated list commands. - A logical "!" NOT operator may be prefixed to any - of these. + Cmnd_List ::= Cmnd | + Cmnd ',' Cmnd_List -=head2 command specification: + commandname ::= filename | + filename args | + filename '""' - path arg1 arg2 .. argn = command + Cmnd ::= '!'* commandname | + '!'* directory | + '!'* Cmnd_Alias - path ::= a fully qualified pathname. - arg[1..n] ::= optional command line arguments. +A C is a list of one or more commandnames, directories, and other +aliases. A commandname is a fully-qualified filename which may include +shell-style wildcards (see `Wildcards' section below). A simple +filename allows the user to run the command with any arguments he/she +wishes. However, you may also command line arguments (including wildcards). +Alternately, you can specify C<""> to indicate that the command +may only be run B command line arguments. A directory is a +fully qualified pathname ending in a '/'. When you specify a directory +in a C, the user will be able to run any file within that directory +(but not in any subdirectories therein). -=head2 persistence of modifiers +If a C has associated command line arguments, then the arguments +in the C must match exactly those given by the user on the command line +(or match the wildcards if there are any). Note that the following +characters must be escaped with a '\' if they are used in command +arguments: ',', ':', '=', '\\'. -When a I is specified for an I, it -affects all commands in the I. For example, given: +=head2 User Specification - oper bigserver = (root, sysadm) /usr/bin/kill, /bin/rm + Runas_Spec ::= '(' Runas_List ')' -User C will be able to run C and C -as B or B on the machine, C. The -I is "sticky" across entries in the comma-separated -I. You can override the I with another -one, at which point the new I becomes the default for -that I. For example, given: + Cmnd_Spec ::= Runas_Spec? ('NOPASSWD:' | 'PASSWD:')? Cmnd - oper bigserver = (root, sysadm) /usr/bin/kill, (root) /bin/rm, \ - /bin/rmdir + Cmnd_Spec_List ::= Cmnd_Spec | + Cmnd_Spec ',' Cmnd_Spec_List -User C can still run C as B or B but -can only run C and C as B. + User_Spec ::= User_list Cmnd_Spec_List (':' User_Spec)* -Similarly, the B modifier is also persistent across an -I. For example given: +A B determines which commands a user may run +(and as what user) on specified hosts. By default, commands are +run as B but this can be changed on a per-command basis. - oper bigserver = NOPASSWD: /usr/bin/kill, /bin/rm, /bin/rmdir +Let's break that down into its constituent parts: -User C will be able to run C, C, and -C as B without a password. If we change that to: +=head2 Runas_Spec - oper bigserver = NOPASSWD: /usr/bin/kill, PASSWD: /bin/rm, /bin/rmdir +A C is simply a C (as defined above) +enclosed in a set of parentheses. If you do not specify a +C in the user specification, a default C +of B will be used. A C sets the default for +commands that follow it. What this means is that for the entry: -User C can still run C without a password but -must give a password to run C and C. + dgb boulder = (operator) /bin/ls, /bin/kill, /usr/bin/who -=head2 wildcards (aka meta characters): +The user B may run F, F, and +F -- but only as B. Eg. -B allows shell-style I along with command arguments -in the I file. Wildcard matching is done via the B -C routine. + sudo -u operator /bin/ls. + +It is also possible to override a C 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 B is now allowed to run F as B, +but F and F as B. + +=head2 NOPASSWD and PASSWD + +By default, B requires that a user authenticate him or herself +before running a command. This behavior can be modified via the +C tag. Like a C, the C tag sets +a default for the commands that follow it in the C. +Conversely, the C tag can be used to reverse things. +For example: + + ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm + +would allow the user B to run F, F, and +F as root on the machine rushmore as B without +authenticating himself. If we only want B to be able to +run F without a password the entry would be: + + ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm + +=head2 Wildcards (aka meta characters): + +B allows shell-style I to be used in pathnames +as well as command line arguments in the I file. Wildcard +matching is done via the B C routine. Note that +these are I regular expressions. =over 8 @@ -137,7 +282,16 @@ escape special characters such as: "*", "?", "[", and "}". =back -=head2 exceptions to wildcard rules: +Note that a forward slash ('/') will B be matched by +wildcards used in the pathname. When matching the command +line arguments, however, as slash B get matched by +wildcards. This is to make a path like: + + /usr/bin/* + +match C but not C. + +=head2 Exceptions to wildcard rules: The following exceptions apply to the above rules: @@ -146,182 +300,215 @@ The following exceptions apply to the above rules: =item C<""> If the empty string C<""> is the only command line argument in the -I entry it means that command may take B arguments. +I entry it means that command is not allowed to be run +with B arguments. =back -=head2 other special characters and reserved words: +=head2 Other special characters and reserved words: -Text after a pound sign (B<#>) is considered a comment. -Words that begin with a percent sign (B<%>) are assumed to -be UN*X groups (%staff refers to users in the group I). -Words that begin with a plus sign (B<+>) are assumed to -be netgroups (B<+cshosts> refers to the netgroup I). -Long lines can be newline escaped with the backslash B<\> character. +The pound sign ('#') is used to indicate a comment (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 uid). Both the +comment character and any text after it, up to the end of the line, +are ignored. -The reserved word B indicates that a user need not -enter a password for the command listed in that entry. The -B modifier is persistent across entries in a I -and can be reversed with the B modifier. +The reserved word B is a a built in I that always causes +a match to succeed. It can be used wherever one might otherwise +use a C, C, C, or C. +You should not try to define your own I called B as the +built in alias will be used in preference to your own. -The reserved alias I can be used for both {Host,User,Cmnd}_Alias. -B define an alias of I, it will B be used. -Note that I implies the entire universe of hosts/users/commands. -You can subtract elements from the universe by using the syntax: +An exclamation point ('!') can be used as a logical I operator +both in an I and in front of a C. This allows one to +exclude certain values. Note, however, that using a C in +conjunction with the built in C alias to allow a user to +run "all but a few" commands rarely works as intended (see SECURITY +NOTES below). - user host=ALL,!ALIAS1,!/sbin/halt... +Long lines can be continued with a backslash ('\\') as the last +character on the line. -Commands may have optional command line arguments. If they do, -then the arguments in the I file must exactly match those -on the command line. It is also possible to have a command's -arguments span multiple lines as long as the line continuance -character "\" is used. The following characters must be escaped -with a "\" if used in command arguments: ",", ":", "=", "\". +Whitespace between elements in a list as well as specicial syntactic +characters in a I ('=', ':', '(', ')') is optional. =head1 EXAMPLES - # Host alias specification - Host_Alias HUB=houdini:\ - REMOTE=merlin,kodiakthorn,spirit - Host_Alias SERVERS=houdini,merlin,kodiakthorn,spirit - Host_Alias CUNETS=128.138.0.0/255.255.0.0 - Host_Alias CSNETS=128.138.243.0,128.138.204.0,\ - 128.138.205.192 +Below are example I entries. Admittedly, some of +these are a bit contrived. First, we define our I: - # User alias specification - User_Alias FULLTIME=millert,dowdy,mikef - User_Alias PARTTIME=juola,mccreary,tor + # User alias specification + User_Alias FULLTIMERS = millert, mikef, dowdy + User_Alias PARTTIMERS = bostley, jwfox, crawl + User_Alias WEBMASTERS = will, wendy, wim - # Runas alias specification - Runas_Alias OP=root,operator + # Runas alias specification + Runas_Alias OP = root, operator + Runas_Alias DB = oracle, sybase - # Command alias specification - Cmnd_Alias LPCS=/usr/sbin/lpc,/usr/bin/lprm - Cmnd_Alias SHELLS=/bin/sh,/bin/csh,/bin/tcsh,/bin/ksh - Cmnd_Alias SU=/usr/bin/su - Cmnd_Alias MISC=/bin/rm,/bin/cat:\ - SHUTDOWN=/sbin/halt,/sbin/shutdown + # Host alias specification + Host_Alias SPARC = bigtime, eclipse, moet, anchor :\ + SGI = grolsch, dandelion, black :\ + ALPHA = widget, thalamus, foobar :\ + HPPA = boa, nag, python + Host_Alias CUNETS = 128.138.0.0/255.255.0.0 + Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0 + Host_Alias SERVERS = master, mail, www, ns + Host_Alias CDROM = orion, perseus, hercules - # User specification - FULLTIME ALL=(ALL) NOPASSWD: ALL - %wheel ALL=ALL - PARTTIME ALL=ALL,!SHELLS,!SU - +interns +openlabs=ALL,!SHELLS,!SU - britt REMOTE=SHUTDOWN:ALL=LPCS - jimbo CUNETS=/usr/bin/su [!-]*,!/usr/bin/su *root* - nieusma SERVERS=SHUTDOWN,/sbin/reboot:\ - HUB=ALL,!SHELLS - jill houdini=/sbin/shutdown -[hr] now,MISC - markm HUB=ALL,!MISC,!/sbin/shutdown,!/sbin/halt - davehieb merlin=(OP) ALL:SERVERS=/sbin/halt:\ - kodiakthorn=NOPASSWD: ALL - steve CSNETS=(operator) /usr/op_commands/ + # Cmnd alias specification + Cmnd_Alias DUMPS = /usr/bin/mt, /usr/sbin/dump, /usr/sbin/rdump,\ + /usr/sbin/restore, /usr/sbin/rrestore + Cmnd_Alias KILL = /usr/bin/kill + Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm + Cmnd_Alias SHUTDOWN = /usr/sbin/shutdown + Cmnd_Alias HALT = /usr/sbin/halt, /usr/sbin/fasthalt + Cmnd_Alias REBOOT = /usr/sbin/reboot, /usr/sbin/fastboot + Cmnd_Alias SHELLS = /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \ + /usr/local/bin/tcsh, /usr/bin/rsh, \ + /usr/local/bin/zsh + Cmnd_Alias SU = /usr/bin/su -=head2 Host Alias specifications: +The I is the part that actually determines who may +run what. -The are four I. The first actually contains -two I. It sets C to be C and C -to the three machines C, C and C. -Similarly, C is set to the machines C, C, -C and C. The C alias will match -any host on the 128.138.243.0, 128.138.204.0, or 128.138.205.192 -nets. The C alias will match any host on the 128.138.0.0 -(class B) network. Note that these are B addresses, not ip -addresses. Unless an explicit netmask is given, the local I -is used to determine whether or not the current host belongs to a network. + root ALL = (ALL) ALL + %wheel ALL = (ALL) ALL -=head2 User Alias specifications: +We let B and any user in group B run any command on any +host as any user. -The two I simply groups the C and -C folks into two separate aliases. + FULLTIMERS ALL = NOPASSWD: ALL -=head2 Command alias specifications: +Full time sysadmins (B, B, and B) may run any +command on any host without authenticating themselves. -Command aliases are lists of commands with or without associated -command line arguments. The entries above should be self-explanatory. + PARTTIMERS ALL = ALL -=head2 User specifications: +Part time sysadmins (B, B, and B) may run any +command on any host but they must authenticate themselves first +(since the entry lacks the C tag). -=over 16 + jack CSNETS = ALL -=item FULLTIME +The user B may run any command on the machines in the I alias +(the networks C<128.138.243.0>, C<128.138.204.0>, and C<128.138.242.0>). +Of those networks, only <128.138.204.0> has an explicit netmask (in +CIDR notation) indicating it is a class C network. For the other +networks in I, the local machine's netmask will be used +during matching. -Full-time sysadmins in the C alias may run any -command on any host as any user without a password. + lisa CUNETS = ALL -=item %wheel +The user B may run any command on any host in the I alias +(the class B network C<128.138.0.0>). -Any user in the UN*X group C may run any -command on any host. + operator ALL = DUMPS, KILL, PRINTING, SHUTDOWN, HALT, REBOOT,\ + /usr/oper/bin/ -=item PARTTIME +The B user may run commands limited to simple maintenance. +Here, those are commands related to backups, killing processes, the +printing system, shutting down the system, and any commands in the +directory F. -Part-time sysadmins in the C alias may run any -command except those in the C and C aliases -on any host. + joe ALL = /usr/bin/su operator -=item +interns +The user B may only su(1) to operator. -Any user in the netgroup C may run any -command except those in the C and C aliases -on any host that is in the C netgroup. + pete HPPA = /usr/bin/passwd [A-z]*, !/usr/bin/passwd root -=item britt +The user B is allowed to change anyone's password except for +root on the I machines. Note that this assumes passwd(1) +does not take multiple usernames on the command line. -The user C may run commands in the C alias -on the C machines and commands in the C alias -on any machine. + bob SPARC = (OP) ALL : SGI = (OP) ALL -=item jimbo +The user B may run anything on the I and I machines +as any user listed in the I C (B and B). -The user C may C to any user save root on the -machines on C (which is explicitly listed as a class -B network). + jim +biglab = ALL -=item nieusma +The user B may run any command on machines in the I netgroup. +B knows that "biglab" is a netgroup due to the '+' prefix. -The user C may run commands in the C alias -as well as F on the C machines and -any command except those in the C alias on the C -machines. + +secretaries ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser -=item jill +Users in the B netgroup need to help manage the printers +as well as add and remove users, so they are allowed to run those +commands on all machines. -The user C may run C or -C as well as the commands in the -C alias on houdini. + fred ALL = (DB) NOPASSWD: ALL -=item markm +The user B can run commands as any user in the I C +(B or B) without giving a password. -The user C may run any command on the C machines -except F, F, and commands listed -in the C alias. + john ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root* -=item davehieb +On the I machines, user B may su to anyone except root +but he is not allowed to give su(1) any flags. -The user C may run any command on C as any -user in the Runas_Alias OP (ie: root or operator). He may -also run F on the C and any command -on C (no password required on C). + jen ALL, !SERVERS = ALL -=item steve +The user B may run any command on any machine except for those +in the I C (master, mail, www and ns). -The user C may run any command in the F -directory as user C on the machines on C. + jill SERVERS = /usr/bin/, !SU, !SHELLS -=back +For any machine in the I C, B may run +any commands in the directory /usr/bin/ except for those commands +belonging to the I and I C. + + steve CSNETS = (operator) /usr/local/op_commands/ + +The user B may run any command in the directory /usr/local/op_commands/ +but only as user operator. + + matt valkyrie = KILL + +On his personal workstation, valkyrie, B needs to be able to +kill hung processes. + + WEBMASTERS www = (www) ALL, (root) /usr/bin/su www + +On the host www, any user in the I C (will, +wendy, and wim), may run any command as user www (which owns the +web pages) or simply su(1) to www. + + ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\ + /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM + +Any user may mount or unmount a CD-ROM on the machines in the CDROM +C (orion, perseus, hercules) without entering a password. +This is a bit tedious for users to type, so it is a prime candiate +for encapsulating in a shell script. + +=head1 SECURITY NOTES + +It is generally not effective to "subtract" commands from C +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 B from running the commands listed in +I or I 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). =head1 CAVEATS The I file should B be edited by the B command which locks the file and does grammatical checking. It is -imperative that the I be free of syntax errors since sudo +imperative that I be free of syntax errors since B will not run with a syntactically incorrect I file. =head1 FILES - /etc/sudoers file of authorized users. - /etc/netgroup list of network groups. + /etc/sudoers List of who can run what + /etc/group Local groups file + /etc/netgroup List of network groups =head1 SEE ALSO