LDAP

All posts tagged LDAP

Previously had docs on how to get this working in SLES11/CentOS 5.x   .  Been struggling getting this working on CentOS 6, I mean come on people how the hell is this any easier.. LDAP is already hard to configure and it definitely did NOT get any easier..

I plan on writing my own docs, but for now, this site saved me another broken keyboard…

 

Copied from http://meinit.nl/user-authentication-centos-6-active-directory-based-hosts-and-groups

User authentication on CentOS 6 with Active Directory based on hosts and groups

Follow this article when you would like users to be able to login to a CentOS 6 host, authenticating to Active directory based on:

  1. Group membership of a user (a group like “Linux Administrators”) (or)
  2. A “host” attribute set per user to allow fine grained host-based permissions

This has a major benefit. You can add users to an administrative group and besides that you can assign permissions to login to a user per host. Once you have set this up, you can manage permissions fully through Active Directory.

Install required pacakges

You need to install one single package:

yum install nss-pam-ldapd

 

Configuration

There are quite few files to configure, I know that system-config-auth exists, but don’t know if it gives the right results. So here are the files one-by-one:

/etc/nslcd.conf

 

# This program runs under this user and group, these are local/system (/etc/passwd) users.
uid nslcd
gid ldap
# The base is where to start looking for users. Your Windows colleagues will know this value.
base dc=nl,dc=example,dc=com
# This is the URI that describes how to connect to the LDAP server/active directory server. You may use a DNS round-robin name here to point to multiple Domain Controllers.
uri ldaps://ldap.nl.example.com:636/
# This is a user that can authenticate to Active Directory. It's used to connect to AD and query stuff.
binddn somegenericuser@nl.example.com
bindpw SoMePaSsWoRd
# Don't exactly know where I got these settings from, man-page has more information.
scope  group  sub
scope  hosts  sub
# If there are many results, paging is used.
pagesize 1000
# LDAP servers can refer you to another location, in my experience this slow down authentication dramatically.
referrals off
# This is the trick to match users from a certain group and users that have a host-attribute filled in.
# Note that the value of the variable "host" should be set to the hostname where this file in installed.
filter passwd (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*)(|(host=mylinuxhost.nl.example.com)(memberOf=CN=Linux Administrators,OU=Groups,DC=nl,DC=example,DC=com)))
# Active Directory may store some values in attributes that need to be mapped.
map    passwd homeDirectory    unixHomeDirectory
filter shadow (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*))
map    shadow shadowLastChange pwdLastSet
# This filters out groups that have a "gidNumber" set. This typically only happens for groups that need to be available on Linux.
filter group  (&(objectClass=group)(gidNumber=*))
map    group  uniqueMember     member
# Some time limits.
bind_timelimit 3
timelimit 3
scope sub
# Secure Socket Layer, yes we do!
ssl on
tls_reqcert never

 

/etc/pam_ldap.conf

This file looks very much like /etc/nslcd.conf, don’t know why there are two actually. It confuses people.

bind_timelimit 3
timelimit 3
network_timeout 3
bind_policy hard
scope sub
nss_base_passwd dc=nl,dc=example,dc=com
nss_base_shadow dc=nl,dc=example,dc=com
nss_base_group dc=nl,dc=example,dc=com
nss_map_objectclass posixAccount user
nss_map_objectclass shadowAccount user
nss_map_objectclass posixGroup Group
nss_map_attribute homeDirectory unixHomeDirectory
nss_map_attribute uniqueMember member
nss_map_attribute shadowLastChange pwdLastSet
pam_login_attribute uid
pam_filter objectClass=user
pam_password ad
pam_member_attribute member
pam_min_uid 10000
pam_groupdn CN=Linux Administrators,OU=Groups,DC=nl,DC=example,DC=com
base dc=nl,dc=example,dc=com
uri ldaps://ldap.nl.example.com:636/
binddn somegenericuser@nl.example.com
bindpw SoMePaSsWoRd
bind_timelimit 3
timelimit 3
scope sub
ssl on
tls_reqcert never

 

/etc/pam.d/system-auth-ac and /etc/pam.d/password-auth-ac

These two files contain the same.

auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        sufficient    pam_krb5.so
auth        required      pam_deny.so

account     [default=bad user_unknown=ignore success=ok authinfo_unavail=ignore] pam_krb5.so
account     required      pam_unix.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3
password    sufficient    pam_unix.so md5 shadow nullok try_first_pass use_autht ok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
session     required      pam_mkhomedir.so skel=/etc/skel umask=0077

 

/etc/nsswitch.conf

This determines to send certain resolving queries to what facility. Make sure these lines are in:

passwd:     files ldap [NOTFOUND=return UNAVAIL=return] db
shadow:     files ldap [NOTFOUND=return UNAVAIL=return] db
group:      files ldap [NOTFOUND=return UNAVAIL=return] db
sudoers:    files ldap [NOTFOUND=return UNAVAIL=return] db

 

Starting of daemons

When all configuration changes are done, make sure to startup nslcd:

service nslcd start
chkconfig nslcd on

 

Troubleshooting

There is a caching mechanism in nslcd. I don’t know how to flush that cache, but it caches negative hits too. (So when a user is not found, it will keep on saying that the user is not found) Waiting (a night) clears that cache, but this does not help you to solve the problem today.

You may stop nslcd and run in in debug mode:

service nslcd stop
nslcd -d

4
down vote
This is going to be rather long, but let’s do it anyway. First of all, yes this can be done. I can’t supply much in the way of configuring CVS, but I can provide all you need to make a linux server authenticate users against Active Directory.
It all starts with /etc/nsswitch.conf. Here is the relevant section:
passwd: files ldap compat
shadow: files ldap compat
group: files ldap compat

Now, depending on what distro you are using, you will need to install some ldap packages. Under Redhat/Fedora/CentOS this would be nss_ldap, under Debian/Ubuntu and the likes, you will need libnss-ldap and libpam-ldap. I would also recommend some ldap-utils for debugging.

With the above your name services will attempt to use LDAP, so now you need to configure the various LDAP packages to use your AD server. The search base should be base cn=Users,dc=aminocom,dc=com and the bind DN should be binddn cn=LDAPsearch,cn=Users,dc=aminocom,dc=com. You will need to define a specific User to allow browsing of the AD. We have created a user named LDAPSearch, and put its credentials into a separate file named .secret. Read the documentation of these packages for more detail. Furthermore I would recommend a soft bind policy and the following attribute mappings:

# Services for UNIX 3.5 mappings
nss_base_passwd cn=Users,dc=aminocom,dc=com?sub
nss_base_shadow cn=Users,dc=aminocom,dc=com?sub
nss_base_group cn=Users,dc=aminocom,dc=com?sub
nss_map_objectclass posixAccount user
nss_map_objectclass shadowAccount user
nss_map_attribute uid sAMAccountName
nss_map_attribute uidNumber msSFU30UidNumber
nss_map_attribute gidNumber msSFU30GidNumber
nss_map_attribute loginShell msSFU30LoginShell
nss_map_attribute gecos name
nss_map_attribute userPassword msSFU30Password
nss_map_attribute homeDirectory msSFU30HomeDirectory
nss_map_objectclass posixGroup Group
nss_map_attribute uniqueMember msSFU30PosixMember
nss_map_attribute cn cn
pam_login_attribute sAMAccountName
pam_filter objectclass=user
pam_member_attribute msSFU30PosixMember
pam_groupdn cn=nixUsers,cn=Users,dc=aminocom,dc=com
pam_password ad
All of this assumes that you have the Windows Services for Unix installed on your domain controller. In AD you will need to configure a primary Unix group (in our case called nixUsers) and add every CVS user into that group.
You should probably be able to use AD directly (i.e. without the Windows Services for Unix), but that will require different attribute mappings. You might have to experiment a bit there.

Now we get to the PAM configuration. Under Debian there are basically 4 files that need modifications:

1.) common-account:

account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid

2.) common-auth:

auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >=500 quiet
auth sufficient pam_ldap.so use_first_pass
auth required pam_deny.so

3.) common-session:

session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_ldap.so

4.) common-password

password sufficient pam_unix.so md5 shadow nullok try_first_pass
password sufficient pam_ldap.so
password required pam_deny.so
Under Redhat (and derivatives) all the necessary changes should go into the relevant sections in /etc/pam.d/system-auth and /etc/pam.d/system-auth-ac.

The above will allow users to log in with AD credentials. However, this does NOT automatically create a home directory for them (unless you do some more scripting around that) and it does not allow them to change their passwords through linux. This can be done, too, but it requires modification of their workstations (if they use Linux). Any more questions re the above, just ask.

We use this on many of our servers, works like a charm.

link|improve this answer

2.9.4.1 Setting up the server for password authentication

First of all, you probably want to tighten the permissions on the $CVSROOT and $CVSROOT/CVSROOT directories. See Password authentication security, for more details.

On the server side, the file /etc/inetd.conf needs to be edited so inetd knows to run the command cvs pserver when it receives a connection on the right port. By default, the port number is 2401; it would be different if your client were compiled with CVS_AUTH_PORT defined to something else, though. This can also be specified in the CVSROOT variable (see Remote repositories) or overridden with the CVS_CLIENT_PORT environment variable (see Environment variables).

If your inetd allows raw port numbers in /etc/inetd.conf, then the following (all on a single line in inetd.conf) should be sufficient:

2401 stream tcp nowait root /usr/local/bin/cvs
cvs -f –allow-root=/usr/cvsroot pserver
(You could also use the -T' option to specify a temporary directory.)

The –allow-root’ option specifies the allowable cvsroot directory. Clients which attempt to use a different cvsroot directory will not be allowed to connect. If there is more than one cvsroot directory which you want to allow, repeat the option. (Unfortunately, many versions of inetd have very small limits on the number of arguments and/or the total length of the command. The usual solution to this problem is to have inetd run a shell script which then invokes cvs with the necessary arguments.)

If your inetd wants a symbolic service name instead of a raw port number, then put this in /etc/services:

cvspserver 2401/tcp
and put cvspserver instead of 2401 in inetd.conf.

If your system uses xinetd instead of inetd, the procedure is slightly different. Create a file called /etc/xinetd.d/cvspserver containing the following:

service cvspserver
{
port = 2401
socket_type = stream
protocol = tcp
wait = no
user = root
passenv = PATH
server = /usr/local/bin/cvs
server_args = -f –allow-root=/usr/cvsroot pserver
}
(If cvspserver is defined in /etc/services, you can omit the port line.)

Once the above is taken care of, restart your inetd, or do whatever is necessary to force it to reread its initialization files.

If you are having trouble setting this up, see Connection.

Because the client stores and transmits passwords in cleartext (almost—see Password authentication security, for details), a separate cvs password file is generally used, so people don’t compromise their regular passwords when they access the repository. This file is $CVSROOT/CVSROOT/passwd (see Intro administrative files). It uses a colon-separated format, similar to /etc/passwd on Unix systems, except that it has fewer fields: cvs username, optional password, and an optional system username for cvs to run as if authentication succeeds. Here is an example passwd file with five entries:

anonymous:
bach:ULtgRLXo7NRxs
spwang:1sOp854gDF3DY
melissa:tGX1fS8sun6rY:pubcvs
qproj:XR4EZcEs0szik:pubcvs
(The passwords are encrypted according to the standard Unix crypt() function, so it is possible to paste in passwords directly from regular Unix /etc/passwd files.)

The first line in the example will grant access to any cvs client attempting to authenticate as user anonymous, no matter what password they use, including an empty password. (This is typical for sites granting anonymous read-only access; for information on how to do the “read-only” part, see Read-only access.)

The second and third lines will grant access to bach and spwang if they supply their respective plaintext passwords.

The fourth line will grant access to melissa, if she supplies the correct password, but her cvs operations will actually run on the server side under the system user pubcvs. Thus, there need not be any system user named melissa, but there must be one named pubcvs.

The fifth line shows that system user identities can be shared: any client who successfully authenticates as qproj will actually run as pubcvs, just as melissa does. That way you could create a single, shared system user for each project in your repository, and give each developer their own line in the $CVSROOT/CVSROOT/passwd file. The cvs username on each line would be different, but the system username would be the same. The reason to have different cvs usernames is that cvs will log their actions under those names: when melissa commits a change to a project, the checkin is recorded in the project’s history under the name melissa, not pubcvs. And the reason to have them share a system username is so that you can arrange permissions in the relevant area of the repository such that only that account has write-permission there.

If the system-user field is present, all password-authenticated cvs commands run as that user; if no system user is specified, cvs simply takes the cvs username as the system username and runs commands as that user. In either case, if there is no such user on the system, then the cvs operation will fail (regardless of whether the client supplied a valid password).

The password and system-user fields can both be omitted (and if the system-user field is omitted, then also omit the colon that would have separated it from the encrypted password). For example, this would be a valid $CVSROOT/CVSROOT/passwd file:

anonymous::pubcvs
fish:rKa5jzULzmhOo:kfogel
sussman:1sOp854gDF3DY
When the password field is omitted or empty, then the client’s authentication attempt will succeed with any password, including the empty string. However, the colon after the cvs username is always necessary, even if the password is empty.

cvs can also fall back to use system authentication. When authenticating a password, the server first checks for the user in the $CVSROOT/CVSROOT/passwd file. If it finds the user, it will use that entry for authentication as described above. But if it does not find the user, or if the cvs passwd file does not exist, then the server can try to authenticate the username and password using the operating system’s user-lookup routines (this “fallback” behavior can be disabled by setting SystemAuth=no in the cvs config file, see config).

The default fallback behavior is to look in /etc/passwd for this system user unless your system has PAM (Pluggable Authentication Modules) and your cvs server executable was configured to use it at compile time (using ./configure –enable-pam – see the INSTALL file for more). In this case, PAM will be consulted instead. This means that cvs can be configured to use any password authentication source PAM can be configured to use (possibilities include a simple UNIX password, NIS, LDAP, and others) in its global configuration file (usually /etc/pam.conf or possibly /etc/pam.d/cvs). See your PAM documentation for more details on PAM configuration.

Note that PAM is an experimental feature in cvs and feedback is encouraged. Please send a mail to one of the cvs mailing lists (info-cvs@gnu.org or bug-cvs@gnu.org) if you use the cvs PAM support.

WARNING: Using PAM gives the system administrator much more flexibility about how cvs users are authenticated but no more security than other methods. See below for more.

CVS needs an “auth”, “account” and “session” module in the PAM configuration file. A typical PAM configuration would therefore have the following lines in /etc/pam.conf to emulate the standard cvs system /etc/passwd authentication:

cvs auth required pam_unix.so
cvs account required pam_unix.so
cvs session required pam_unix.so
The the equivalent /etc/pam.d/cvs would contain

auth required pam_unix.so
account required pam_unix.so
session required pam_unix.so
Some systems require a full path to the module so that pam_unix.so (Linux) would become something like /usr/lib/security/$ISA/pam_unix.so.1 (Sun Solaris). See the contrib/pam subdirectory of the cvs source distribution for further example configurations.

The PAM service name given above as “cvs” is just the service name in the default configuration and can be set using ./configure –with-hardcoded-pam-service-name= before compiling. cvs can also be configured to use whatever name it is invoked as as its PAM service name using ./configure –without-hardcoded-pam-service-name, but this feature should not be used if you may not have control of the name cvs will be invoked as.

Be aware, also, that falling back to system authentication might be a security risk: cvs operations would then be authenticated with that user’s regular login password, and the password flies across the network in plaintext. See Password authentication security for more on this. This may be more of a problem with PAM authentication because it is likely that the source of the system password is some central authentication service like LDAP which is also used to authenticate other services.

On the other hand, PAM makes it very easy to change your password regularly. If they are given the option of a one-password system for all of their activities, users are often more willing to change their password on a regular basis.

In the non-PAM configuration where the password is stored in the CVSROOT/passwd file, it is difficult to change passwords on a regular basis since only administrative users (or in some cases processes that act as an administrative user) are typically given access to modify this file. Either there needs to be some hand-crafted web page or set-uid program to update the file, or the update needs to be done by submitting a request to an administrator to perform the duty by hand. In the first case, having to remember to update a separate password on a periodic basis can be difficult. In the second case, the manual nature of the change will typically mean that the password will not be changed unless it is absolutely necessary.

Note that PAM administrators should probably avoid configuring one-time-passwords (OTP) for cvs authentication/authorization. If OTPs are desired, the administrator may wish to encourage the use of one of the other Client/Server access methods. See the section on see Remote repositories for a list of other methods.

Right now, the only way to put a password in the cvs passwd file is to paste it there from somewhere else. Someday, there may be a cvs passwd command.

Unlike many of the files in $CVSROOT/CVSROOT, it is normal to edit the passwd file in-place, rather than via cvs. This is because of the possible security risks of having the passwd file checked out to people’s working copies. If you do want to include the passwd file in checkouts of $CVSROOT/CVSROOT, see checkoutlist.

So this method wasn’t our first attempt to get our Linux farm authenticating against Windows AD. Our first attempt was to use the Microsoft Identity Management for UNIX component which is a role based component for Windows 2008 R2. We attempted to just do a one-way sync from AD to the Linux farm. This did work, but we latter found out that it’s just very insecure. Perhaps, I set it up wrong, but I tried to follow the instructions given or what I could find online the best I could.

There method was to have a Linux agent (ssod binary) that will need to run on every Linux box. That agent by default (and can be changed via /etc/sso.conf) is set to run on port 6677. It seemed the only purpose of this agent was to encrypt and decrypt the pass words so there were not being sent over the wire in plain text. Why I even thought that was a good idea without just enforcing LDAP over SSL or TLS from the get go, I have no idea. Anyhow, we choose to use that method. Well things were fine right up to the point of noticing that our network engineering accidentally started blocking port 6677 to the AD hosts. Had they not done that, we might still be using that insecure method. Anyhow with that port being blocked, low and behold I started noticing plain text being sent over the wire. Turns out if that ssod binary isn’t running or is getting blocked on the network, plain text pass words start getting sent. Well that definitely isn’t good, wouldn’t take very much effort to kill that ssod binary on any host, and fire up a sniffer. Shit snowball in full effect.

At that point, I needed to figure out how the hell to get either LDAPS (LDAP over SSL port 636) or TLS (port 389) working in AD, as of course, that being the secure method and well it being Microsoft that isn’t the default choice.

Long story short…here’s how.

First you need to install the CA manager in AD and/or a 3rd party CA. We have a CA at work, so I used this form. You of course will need to replace with your info.

Save this into a file like notepad, name it like ‘fqdn.example.com.cnf’. I’ll write up more on this if someone requests this, but there are a billion howto’s on how to create these self signed certs and to get Windows setup on that.

Make sure you save yourself a copy of the CA-cert, as you will need this on every Linux host you plan on authenticating from.

Continue to Page 2