.\" .\" Copyright (c) 2003-2012 Todd C. Miller .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd $Mdocdate: August 17 2012 $ .Dt SUDOERS.LDAP @mansectsu@ .Os .Sh NAME .Nm sudoers.ldap .Nd sudo LDAP configuration .Sh DESCRIPTION In addition to the standard .Em sudoers file, .Nm sudo may be configured via LDAP. This can be especially useful for synchronizing .Em sudoers in a large, distributed environment. .Pp Using LDAP for .Em sudoers has several benefits: .Bl -bullet .It .Nm sudo no longer needs to read .Em sudoers in its entirety. When LDAP is used, there are only two or three LDAP queries per invocation. This makes it especially fast and particularly usable in LDAP environments. .It .Nm sudo no longer exits if there is a typo in .Em sudoers . It is not possible to load LDAP data into the server that does not conform to the sudoers schema, so proper syntax is guaranteed. It is still possible to have typos in a user or host name, but this will not prevent .Nm sudo from running. .It It is possible to specify per-entry options that override the global default options. .Pa @sysconfdir@/sudoers only supports default options and limited options associated with user/host/commands/aliases. The syntax is complicated and can be difficult for users to understand. Placing the options directly in the entry is more natural. .It The .Nm visudo program is no longer needed. .Nm visudo provides locking and syntax checking of the .Pa @sysconfdir@/sudoers file. Since LDAP updates are atomic, locking is no longer necessary. Because syntax is checked when the data is inserted into LDAP, there is no need for a specialized tool to check syntax. .El .Pp Another major difference between LDAP and file-based .Em sudoers is that in LDAP, .Nm sudo Ns No -specific Aliases are not supported. .Pp For the most part, there is really no need for .Nm sudo Ns No -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 .Nm sudo Ns No -specific aliases. .Pp Cmnd_Aliases are not really required either since it is possible to have multiple users listed in a .Li sudoRole . Instead of defining a Cmnd_Alias that is referenced by multiple users, one can create a .Li sudoRole that contains the commands and assign multiple users to it. .Ss SUDOers LDAP container The .Em sudoers configuration is contained in the .Li ou=SUDOers LDAP container. .Pp Sudo first looks for the .Li cn=default entry in the SUDOers container. If found, the multi-valued .Li sudoOption attribute is parsed in the same manner as a global .Li Defaults line in .Pa @sysconfdir@/sudoers . In the following example, the .Ev SSH_AUTH_SOCK variable will be preserved in the environment for all users. .Bd -literal -offset 4n 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 .Ed .Pp The equivalent of a sudoer in LDAP is a .Li sudoRole . It consists of the following attributes: .Bl -tag -width 4n .It Sy sudoUser A user name, user ID (prefixed with .Ql # ) , Unix group (prefixed with .Ql % ) , Unix group ID (prefixed with .Ql %# ) , or user netgroup (prefixed with .Ql + ) . .It Sy sudoHost A host name, IP address, IP network, or host netgroup (prefixed with a .Ql + ) . The special value .Li ALL will match any host. .It Sy sudoCommand A Unix command with optional command line arguments, potentially including globbing characters (aka wild cards). The special value .Li ALL will match any command. If a command is prefixed with an exclamation point .Ql \&! , the user will be prohibited from running that command. .It Sy sudoOption Identical in function to the global options described above, but specific to the .Li sudoRole in which it resides. .It Sy sudoRunAsUser A user name or uid (prefixed with .Ql # ) that commands may be run as or a Unix group (prefixed with a .Ql % ) or user netgroup (prefixed with a .Ql + ) that contains a list of users that commands may be run as. The special value .Li ALL will match any user. .Pp The .Li sudoRunAsUser attribute is only available in .Nm sudo versions 1.7.0 and higher. Older versions of .Nm sudo use the .Li sudoRunAs attribute instead. .It Sy sudoRunAsGroup A Unix group or gid (prefixed with .Ql # ) that commands may be run as. The special value .Li ALL will match any group. .Pp The .Li sudoRunAsGroup attribute is only available in .Nm sudo versions 1.7.0 and higher. .It Sy URI Ar ldap[s]://[hostname[:port]] ... Specifies a whitespace-delimited list of one or more URIs describing the LDAP server(s) to connect to. The .Em protocol may be either .Em ldap .Em ldaps , the latter being for servers that support TLS (SSL) encryption. If no .Em port is specified, the default is port 389 for .Li ldap:// or port 636 for .Li ldaps:// . If no .Em hostname is specified, .Nm sudo will connect to .Em localhost . Multiple .Sy URI lines are treated identically to a .Sy URI line containing multiple entries. Only systems using the OpenSSL libraries support the mixing of .Li ldap:// and .Li 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. .It Sy HOST Ar name[:port] ... If no .Sy URI is specified, the .Sy HOST parameter specifies a whitespace-delimited list of LDAP servers to connect to. Each host may include an optional .Em port separated by a colon .Pq Ql :\& . The .Sy HOST parameter is deprecated in favor of the .Sy URI specification and is included for backwards compatibility. .It Sy PORT Ar port_number If no .Sy URI is specified, the .Sy PORT parameter specifies the default port to connect to on the LDAP server if a .Sy HOST parameter does not specify the port itself. If no .Sy PORT parameter is used, the default is port 389 for LDAP and port 636 for LDAP over TLS (SSL). The .Sy PORT parameter is deprecated in favor of the .Sy URI specification and is included for backwards compatibility. .It Sy BIND_TIMELIMIT Ar seconds The .Sy BIND_TIMELIMIT parameter specifies the amount of time, in seconds, to wait while trying to connect to an LDAP server. If multiple .Sy URI Ns No s or .Sy HOST Ns No s are specified, this is the amount of time to wait before trying the next one in the list. .It Sy TIMELIMIT Ar seconds The .Sy TIMELIMIT parameter specifies the amount of time, in seconds, to wait for a response to an LDAP query. .It Sy SUDOERS_BASE Ar base The base DN to use when performing .Nm sudo LDAP queries. Typically this is of the form .Li ou=SUDOers,dc=example,dc=com for the domain .Li example.com . Multiple .Sy SUDOERS_BASE lines may be specified, in which case they are queried in the order specified. .It Sy SUDOERS_DEBUG Ar debug_level This sets the debug level for .Nm sudo LDAP queries. Debugging information is printed to the standard error. A value of 1 results in a moderate amount of debugging information. A value of 2 shows the results of the matches themselves. This parameter should not be set in a production environment as the extra information is likely to confuse users. .It Sy BINDDN Ar DN The .Sy BINDDN parameter specifies the identity, in the form of a Distinguished Name (DN), to use when performing LDAP operations. If not specified, LDAP operations are performed with an anonymous identity. By default, most LDAP servers will allow anonymous access. .It Sy BINDPW Ar secret The .Sy BINDPW parameter specifies the password to use when performing LDAP operations. This is typically used in conjunction with the .Sy BINDDN parameter. .It Sy ROOTBINDDN Ar DN The .Sy ROOTBINDDN parameter specifies the identity, in the form of a Distinguished Name (DN), to use when performing privileged LDAP operations, such as .Em sudoers queries. The password corresponding to the identity should be stored in .Pa @ldap_secret@ . If not specified, the .Sy BINDDN identity is used (if any). .It Sy LDAP_VERSION Ar number The version of the LDAP protocol to use when connecting to the server. The default value is protocol version 3. .It Sy SSL Ar on/true/yes/off/false/no If the .Sy SSL parameter is set to .Li on , .Li true .Li or .Li yes , TLS (SSL) encryption is always used when communicating with the LDAP server. Typically, this involves connecting to the server on port 636 (ldaps). .It Sy SSL Ar start_tls If the .Sy SSL parameter is set to .Li 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 .Em start_tls extension, such as the OpenLDAP and Tivoli Directory servers. .It Sy TLS_CHECKPEER Ar on/true/yes/off/false/no If enabled, .Sy TLS_CHECKPEER will cause the LDAP server's TLS certificated to be verified. If the server's TLS certificate cannot be verified (usually because it is signed by an unknown certificate authority), .Nm sudo will be unable to connect to it. If .Sy TLS_CHECKPEER is disabled, no check is made. Note that disabling the check creates an opportunity for man-in-the-middle attacks since the server's identity will not be authenticated. If possible, the CA's certificate should be installed locally so it can be verified. This option is not supported by the Tivoli Directory Server LDAP libraries. .It Sy TLS_CACERTFILE Ar file name The path to a certificate authority bundle which contains the certificates for all the Certificate Authorities the client knows to be valid, e.g.\& .Pa /etc/ssl/ca-bundle.pem . This option is only supported by the OpenLDAP libraries. Netscape-derived LDAP libraries use the same certificate database for CA and client certificates (see .Sy TLS_CERT ) . .It Sy TLS_CACERTDIR Ar directory Similar to .Sy TLS_CACERTFILE but instead of a file, it is a directory containing individual Certificate Authority certificates, e.g.\& .Pa /etc/ssl/certs . The directory specified by .Sy TLS_CACERTDIR is checked after .Sy TLS_CACERTFILE . This option is only supported by the OpenLDAP libraries. .It Sy TLS_CERT Ar file name The path to a file containing the client certificate which can be used to authenticate the client to the LDAP server. The certificate type depends on the LDAP libraries used. .Bl -tag -width 4n .It OpenLDAP: .Li tls_cert /etc/ssl/client_cert.pem .It Netscape-derived: .Li tls_cert /var/ldap/cert7.db .It Tivoli Directory Server: Unused, the key database specified by .Sy TLS_KEY contains both keys and certificates. .Pp When using Netscape-derived libraries, this file may also contain Certificate Authority certificates. .El .It Sy TLS_KEY Ar file name The path to a file containing the private key which matches the certificate specified by .Sy TLS_CERT . The private key must not be password-protected. The key type depends on the LDAP libraries used. .Bl -tag -width 4n .It OpenLDAP: .Li tls_key /etc/ssl/client_key.pem .It Netscape-derived: .Li tls_key /var/ldap/key3.db .It Tivoli Directory Server: .Li tls_cert /usr/ldap/ldapkey.kdb .El When using Tivoli LDAP libraries, this file may also contain Certificate Authority and client certificates and may be encrypted. .It Sy TLS_KEYPW Ar secret The .Sy TLS_KEYPW contains the password used to decrypt the key database on clients using the Tivoli Directory Server LDAP library. If no .Sy TLS_KEYPW is specified, a .Em stash file will be used if it exists. The .Em stash file must have the same path as the file specified by .Sy TLS_KEY , but use a .Li .sth file extension instead of .Li .kdb , e.g.\& .Li ldapkey.sth . The default .Li ldapkey.kdb that ships with Tivoli Directory Server is encrypted with the password .Li ssl_password . This option is only supported by the Tivoli LDAP libraries. .It Sy TLS_RANDFILE Ar file name The .Sy TLS_RANDFILE parameter specifies the path to an entropy source for systems that lack a random device. It is generally used in conjunction with .Em prngd or .Em egd . This option is only supported by the OpenLDAP libraries. .It Sy TLS_CIPHERS Ar cipher list The .Sy TLS_CIPHERS parameter allows the administer to restrict which encryption algorithms may be used for TLS (SSL) connections. See the OpenLDAP or Tivoli Directory Server manual for a list of valid ciphers. This option is not supported by Netscape-derived libraries. .It Sy USE_SASL Ar on/true/yes/off/false/no Enable .Sy USE_SASL for LDAP servers that support SASL authentication. .It Sy SASL_AUTH_ID Ar identity The SASL user name to use when connecting to the LDAP server. By default, .Nm sudo will use an anonymous connection. .It Sy ROOTUSE_SASL Ar on/true/yes/off/false/no Enable .Sy ROOTUSE_SASL to enable SASL authentication when connecting to an LDAP server from a privileged process, such as .Nm sudo . .It Sy ROOTSASL_AUTH_ID Ar identity The SASL user name to use when .Sy ROOTUSE_SASL is enabled. .It Sy SASL_SECPROPS Ar none/properties SASL security properties or .Em none for no properties. See the SASL programmer's manual for details. .It Sy KRB5_CCNAME Ar file name The path to the Kerberos 5 credential cache to use when authenticating with the remote server. .El .Pp See the .Pa ldap.conf entry in the .Sx EXAMPLES section. .Ss Configuring nsswitch.conf Unless it is disabled at build time, .Nm sudo consults the Name Service Switch file, .Pa @nsswitch_conf@ , to specify the .Em sudoers search order. Sudo looks for a line beginning with .Li sudoers : and uses this to determine the search order. Note that .Nm sudo does not stop searching after the first match and later matches take precedence over earlier ones. The following sources are recognized: .Pp .Bl -tag -width 8n -offset 4n -compact .It files read sudoers from .Pa @sysconfdir@/sudoers .It ldap read sudoers from LDAP .El .Pp In addition, the entry .Li [NOTFOUND=return] will short-circuit the search if the user was not found in the preceding source. .Pp To consult LDAP first followed by the local sudoers file (if it exists), use: .Bd -literal -offset 4n sudoers: ldap files .Ed .Pp The local .Em sudoers file can be ignored completely by using: .Bd -literal -offset 4n sudoers: ldap .Ed .Pp If the .Pa @nsswitch_conf@ file is not present or there is no sudoers line, the following default is assumed: .Bd -literal -offset 4n sudoers: files .Ed .Pp Note that .Pa @nsswitch_conf@ is supported even when the underlying operating system does not use an nsswitch.conf file, except on AIX (see below). .Ss Configuring netsvc.conf On AIX systems, the .Pa @netsvc_conf@ file is consulted instead of .Pa @nsswitch_conf@ . .Nm sudo simply treats .Pa netsvc.conf as a variant of .Pa nsswitch.conf ; information in the previous section unrelated to the file format itself still applies. .Pp To consult LDAP first followed by the local sudoers file (if it exists), use: .Bd -literal -offset 4n sudoers = ldap, files .Ed .Pp The local .Em sudoers file can be ignored completely by using: .Bd -literal -offset 4n sudoers = ldap .Ed .Pp To treat LDAP as authoratative and only use the local sudoers file if the user is not present in LDAP, use: .Bd -literal -offset 4n sudoers = ldap = auth, files .Ed .Pp Note that in the above example, the .Li auth qualfier only affects user lookups; both LDAP and .Em sudoers will be queried for .Li Defaults entries. .Pp If the .Pa @netsvc_conf@ file is not present or there is no sudoers line, the following default is assumed: .Bd -literal -offset 4n sudoers = files .Ed .Sh FILES .Bl -tag -width 24n .It Pa @ldap_conf@ LDAP configuration file .It Pa @nsswitch_conf@ determines sudoers source order .It Pa @netsvc_conf@ determines sudoers source order on AIX .El .Sh EXAMPLES .Ss Example ldap.conf .Bd -literal -offset 2n # Either specify one or more URIs or one or more host:port pairs. # If neither is specified sudo will default to localhost, port 389. # #host ldapserver #host ldapserver1 ldapserver2:390 # # Default port if host is specified without one, defaults to 389. #port 389 # # URI will override the host and port settings. uri ldap://ldapserver #uri ldaps://secureldapserver #uri ldaps://secureldapserver ldap://ldapserver # # The amount of time, in seconds, to wait while trying to connect to # an LDAP server. bind_timelimit 30 # # The amount of time, in seconds, to wait while performing an LDAP query. timelimit 30 # # Must be set or sudo will ignore LDAP; may be specified multiple times. sudoers_base ou=SUDOers,dc=example,dc=com # # verbose sudoers matching from ldap #sudoers_debug 2 # # optional proxy credentials #binddn #bindpw #rootbinddn # # LDAP protocol version, defaults to 3 #ldap_version 3 # # Define if you want to use an encrypted LDAP connection. # Typically, you must also set the port to 636 (ldaps). #ssl on # # Define if you want to use port 389 and switch to # encryption before the bind credentials are sent. # Only supported by LDAP servers that support the start_tls # extension such as OpenLDAP. #ssl start_tls # # Additional TLS options follow that allow tweaking of the # SSL/TLS connection. # #tls_checkpeer yes # verify server SSL certificate #tls_checkpeer no # ignore server SSL certificate # # If you enable tls_checkpeer, specify either tls_cacertfile # or tls_cacertdir. Only supported when using OpenLDAP. # #tls_cacertfile /etc/certs/trusted_signers.pem #tls_cacertdir /etc/certs # # For systems that don't have /dev/random # use this along with PRNGD or EGD.pl to seed the # random number pool to generate cryptographic session keys. # Only supported when using OpenLDAP. # #tls_randfile /etc/egd-pool # # You may restrict which ciphers are used. Consult your SSL # documentation for which options go here. # Only supported when using OpenLDAP. # #tls_ciphers # # Sudo can provide a client certificate when communicating to # the LDAP server. # Tips: # * Enable both lines at the same time. # * Do not password protect the key file. # * Ensure the keyfile is only readable by root. # # For OpenLDAP: #tls_cert /etc/certs/client_cert.pem #tls_key /etc/certs/client_key.pem # # For SunONE or iPlanet LDAP, tls_cert and tls_key may specify either # a directory, in which case the files in the directory must have the # default names (e.g. cert8.db and key4.db), or the path to the cert # and key files themselves. However, a bug in version 5.0 of the LDAP # SDK will prevent specific file names from working. For this reason # it is suggested that tls_cert and tls_key be set to a directory, # not a file name. # # The certificate database specified by tls_cert may contain CA certs # and/or the client's cert. If the client's cert is included, tls_key # should be specified as well. # For backward compatibility, "sslpath" may be used in place of tls_cert. #tls_cert /var/ldap #tls_key /var/ldap # # If using SASL authentication for LDAP (OpenSSL) # use_sasl yes # sasl_auth_id # rootuse_sasl yes # rootsasl_auth_id # sasl_secprops none # krb5_ccname /etc/.ldapcache .Ed .Ss Sudo schema for OpenLDAP The following schema, in OpenLDAP format, is included with .Nm sudo source and binary distributions as .Pa schema.OpenLDAP . Simply copy it to the schema directory (e.g.\& .Pa /etc/openldap/schema ) , add the proper .Li include line in .Pa slapd.conf and restart .Nm slapd . .Bd -literal -offset 2n 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 ) 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 $ description ) ) .Ed .Sh SEE ALSO .Xr ldap.conf @mansectsu@ , .Xr sudoers @mansectsu@ .Sh CAVEATS Note that there are differences in the way that LDAP-based .Em sudoers is parsed compared to file-based .Em sudoers . See the .Sx Differences between LDAP and non-LDAP sudoers section for more information. .Sh BUGS If you feel you have found a bug in .Nm sudo , please submit a bug report at http://www.sudo.ws/sudo/bugs/ .Sh SUPPORT Limited free support is available via the sudo-users mailing list, see http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search the archives. .Sh DISCLAIMER .Nm sudo is provided .Dq 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. See the LICENSE file distributed with .Nm sudo or http://www.sudo.ws/sudo/license.html for complete details.