Using LDAP for sudoers has several benefits:
Another major difference between LDAP and file-based sudoers is that in LDAP, sudo-specific Aliases are not supported.
For the most part, there is really no need for sudo-specific Aliases. Unix groups or user netgroups can be used in place of User_Aliases and Runas_Aliases. Host netgroups can be used in place of Host_Aliases. Since Unix groups and netgroups can also be stored in LDAP there is no real need for sudo-specific aliases.
Cmnd_Aliases are not really required either since it is possible to have multiple users listed in a sudoRole
. Instead of defining a Cmnd_Alias that is referenced by multiple users, one can create a sudoRole
that contains the commands and assign multiple users to it.
ou=SUDOers
LDAP container.
Sudo first looks for the cn=default
entry in the SUDOers container. If found, the multi-valued sudoOption
attribute is parsed in the same manner as a global Defaults
line in /etc/sudoers. In the following example, the SSH_AUTH_SOCK variable will be preserved in the environment for all users.
dn: cn=defaults,ou=SUDOers,dc=example,dc=com objectClass: top objectClass: sudoRole cn: defaults description: Default sudoOption's go here sudoOption: env_keep+=SSH_AUTH_SOCK
The equivalent of a sudoer in LDAP is a sudoRole
. It consists of the following attributes:
#
’), Unix group (prefixed with ‘%
’), Unix group ID (prefixed with ‘%#
’), or user netgroup (prefixed with ‘+
’).+
’). The special value ALL
will match any host.ALL
will match any command. If a command is prefixed with an exclamation point ‘!
’, the user will be prohibited from running that command.sudoRole
in which it resides.#
’) that commands may be run as or a Unix group (prefixed with a ‘%
’) or user netgroup (prefixed with a ‘+
’) that contains a list of users that commands may be run as. The special value ALL
will match any user.
The sudoRunAsUser
attribute is only available in sudo versions 1.7.0 and higher. Older versions of sudo use the sudoRunAs
attribute instead.
#
’) that commands may be run as. The special value ALL
will match any group.
The sudoRunAsGroup
attribute is only available in sudo versions 1.7.0 and higher.
yyyymmddHHMMSSZ
that can be used to provide a start date/time for when the sudoRole
will be valid. If multiple sudoNotBefore
entries are present, the earliest is used. Note that timestamps must be in Coordinated Universal Time (UTC), not the local timezone. The minute and seconds portions are optional, but some LDAP servers require that they be present (contrary to the RFC).
The sudoNotBefore
attribute is only available in sudo versions 1.7.5 and higher and must be explicitly enabled via the SUDOERS_TIMED option in /etc/ldap.conf.
yyyymmddHHMMSSZ
that indicates an expiration date/time, after which the sudoRole
will no longer be valid. If multiple sudoNotBefore
entries are present, the last one is used. Note that timestamps must be in Coordinated Universal Time (UTC), not the local timezone. The minute and seconds portions are optional, but some LDAP servers require that they be present (contrary to the RFC).
The sudoNotAfter
attribute is only available in sudo versions 1.7.5 and higher and must be explicitly enabled via the SUDOERS_TIMED option in /etc/ldap.conf.
sudoRole
entries retrieved from the LDAP directory have no inherent order. The sudoOrder
attribute is an integer (or floating point value for LDAP servers that support it) that is used to sort the matching entries. This allows LDAP-based sudoers entries to more closely mimic the behaviour of the sudoers file, where the of the entries influences the result. If multiple entries match, the entry with the highest sudoOrder
attribute is chosen. This corresponds to the “last match” behavior of the sudoers file. If the sudoOrder
attribute is not present, a value of 0 is assumed.
The sudoOrder
attribute is only available in sudo versions 1.7.5 and higher.
Each attribute listed above should contain a single value, but there may be multiple instances of each attribute type. A sudoRole
must contain at least one sudoUser
, sudoHost
and sudoCommand
.
The following example allows users in group wheel to run any command on any host via sudo:
dn: cn=%wheel,ou=SUDOers,dc=example,dc=com objectClass: top objectClass: sudoRole cn: %wheel sudoUser: %wheel sudoHost: ALL sudoCommand: ALL
ALL
tag is matched in this query too.) If no match is returned for the user's name and groups, a third query returns all entries containing user netgroups and checks to see if the user belongs to any of them.
If timed entries are enabled with the SUDOERS_TIMED configuration directive, the LDAP queries include a subfilter that limits retrieval to entries that satisfy the time constraints, if any.
The order in which different entries are applied can be controlled using the sudoOrder
attribute, but there is no way to guarantee the order of attributes within a specific entry. If there are conflicting command rules in an entry, the negative takes precedence. This is called paranoid behavior (not necessarily the most specific match).
Here is an example:
johnny ALL=(root) ALL,!/bin/sh puddles ALL=(root) !/bin/sh,ALL dn: cn=role1,ou=Sudoers,dc=my-domain,dc=com objectClass: sudoRole objectClass: top cn: role1 sudoUser: johnny sudoHost: ALL sudoCommand: ALL sudoCommand: !/bin/sh dn: cn=role2,ou=Sudoers,dc=my-domain,dc=com objectClass: sudoRole objectClass: top cn: role2 sudoUser: puddles sudoHost: ALL sudoCommand: !/bin/sh sudoCommand: ALL
Another difference is that negations on the Host, User or Runas are currently ignored. For example, the following attributes do not behave the way one might expect.
sudoUser: !joe sudoUser: ALL sudoUser: !joe sudoHost: ALL sudoHost: !web01
sudoUser
attribute.
Three versions of the schema: one for OpenLDAP servers (schema.OpenLDAP), one for Netscape-derived servers (schema.iPlanet), and one for Microsoft Active Directory (schema.ActiveDirectory) may be found in the sudo distribution.
The schema for sudo in OpenLDAP form is also included in the EXAMPLES section.
Also note that on systems using the OpenLDAP libraries, default values specified in /etc/openldap/ldap.conf or the user's .ldaprc files are not used.
Only those options explicitly listed in /etc/ldap.conf as being supported by sudo are honored. Configuration options are listed below in upper case but are parsed in a case-independent manner.
ldap://
or port 636 for ldaps://
. If no hostname is specified, sudo will connect to localhost. Multiple URI lines are treated identically to a URI line containing multiple entries. Only systems using the OpenSSL libraries support the mixing of ldap://
and ldaps://
URIs. Both the Netscape-derived and Tivoli LDAP libraries used on most commercial versions of Unix are only capable of supporting one or the other.:
’). The HOST parameter is deprecated in favor of the URI specification and is included for backwards compatibility.ou=SUDOers,dc=example,dc=com
for the domain example.com
. Multiple SUDOERS_BASE lines may be specified, in which case they are queried in the order specified.attribute=value
or (&(attribute=value)(attribute2=value2))
.sudoNotBefore
and sudoNotAfter
attributes that implement time-dependent sudoers entries.on
, true
or
yes
, TLS (SSL) encryption is always used when communicating with the LDAP server. Typically, this involves connecting to the server on port 636 (ldaps).start_tls
, the LDAP server connection is initiated normally and TLS encryption is begun before the bind credentials are sent. This has the advantage of not requiring a dedicated port for encrypted communications. This parameter is only supported by LDAP servers that honor the start_tls extension, such as the OpenLDAP and Tivoli Directory servers.tls_cert /etc/ssl/client_cert.pem
tls_cert /var/ldap/cert7.db
When using Netscape-derived libraries, this file may also contain Certificate Authority certificates.
tls_key /etc/ssl/client_key.pem
tls_key /var/ldap/key3.db
tls_cert /usr/ldap/ldapkey.kdb
.sth
file extension instead of .kdb
, e.g. ldapkey.sth
. The default ldapkey.kdb
that ships with Tivoli Directory Server is encrypted with the password ssl_password
. This option is only supported by the Tivoli LDAP libraries.See the ldap.conf entry in the EXAMPLES section.
sudoers
: and uses this to determine the search order. Note that sudo does not stop searching after the first match and later matches take precedence over earlier ones. The following sources are recognized:
In addition, the entry [NOTFOUND=return]
will short-circuit the search if the user was not found in the preceding source.
To consult LDAP first followed by the local sudoers file (if it exists), use:
sudoers: ldap files
The local sudoers file can be ignored completely by using:
sudoers: ldap
If the /etc/nsswitch.conf file is not present or there is no sudoers line, the following default is assumed:
sudoers: files
Note that /etc/nsswitch.conf is supported even when the underlying operating system does not use an nsswitch.conf file, except on AIX (see below).
To consult LDAP first followed by the local sudoers file (if it exists), use:
sudoers = ldap, files
The local sudoers file can be ignored completely by using:
sudoers = ldap
To treat LDAP as authoratative and only use the local sudoers file if the user is not present in LDAP, use:
sudoers = ldap = auth, files
Note that in the above example, the auth
qualfier only affects user lookups; both LDAP and sudoers will be queried for Defaults
entries.
If the /etc/netsvc.conf file is not present or there is no sudoers line, the following default is assumed:
sudoers = files
uri ldap://ldapserver bind_timelimit 30 timelimit 30 sudoers_base ou=SUDOers,dc=example,dc=com
include
line in slapd.conf and restart slapd.
attributetype ( 1.3.6.1.4.1.15953.9.1.1 NAME 'sudoUser' DESC 'User(s) who may run sudo' EQUALITY caseExactIA5Match SUBSTR caseExactIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.2 NAME 'sudoHost' DESC 'Host(s) who may run sudo' EQUALITY caseExactIA5Match SUBSTR caseExactIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.3 NAME 'sudoCommand' DESC 'Command(s) to be executed by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.4 NAME 'sudoRunAs' DESC 'User(s) impersonated by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.5 NAME 'sudoOption' DESC 'Options(s) followed by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.6 NAME 'sudoRunAsUser' DESC 'User(s) impersonated by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.7 NAME 'sudoRunAsGroup' DESC 'Group(s) impersonated by sudo' EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) attributetype ( 1.3.6.1.4.1.15953.9.1.8 NAME 'sudoNotBefore' DESC 'Start of time interval for which the entry is valid' EQUALITY generalizedTimeMatch ORDERING generalizedTimeOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 ) attributetype ( 1.3.6.1.4.1.15953.9.1.9 NAME 'sudoNotAfter' DESC 'End of time interval for which the entry is valid' EQUALITY generalizedTimeMatch ORDERING generalizedTimeOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 ) attributeTypes ( 1.3.6.1.4.1.15953.9.1.10 NAME 'sudoOrder' DESC 'an integer to order the sudoRole entries' EQUALITY integerMatch ORDERING integerOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 ) objectclass ( 1.3.6.1.4.1.15953.9.2.1 NAME 'sudoRole' SUP top STRUCTURAL DESC 'Sudoer Entries' MUST ( cn ) MAY ( sudoUser $ sudoHost $ sudoCommand $ sudoRunAs $ sudoRunAsUser $ sudoRunAsGroup $ sudoOption $ sudoNotBefore $ sudoNotAfter $ sudoOrder $ description ) )