This page discusses a specific implementation using LDAP backed NIS Netgroups and detail what exactly makes them so powerful.
An understanding of PAM and the PAM module stack Howto:PAM!! How does it work?
netgroup entries are stored as an objectClass of type nisNetgroup in the directory server. The relative distinguished name attribute is typically cn (common name). There are two important attributes in creating the netgroup. Note that they are not mutually exclusive. Also, neither are required (sometimes having an empty netgroup is as valuable as one populated with values).
You also want to attach a description attribute and value to your object. You were planning on describing that netgroup, weren't you?
Let's look at an Example LDIF:
dn: cn=QAUsers,ou=Netgroup,dc=example,dc=com objectClass: nisNetgroup objectClass: top cn: QAUsers nisNetgroupTriple: (,bobby,example.com) nisNetgroupTriple: (,joey,example.com) description: All QA users in my organization
We can see here that the users 'bobby' and 'joey' belong to the QAUsers netgroup. Now, any tool that will query for the QAUsers netgroup will get back these values and can act upon them. With nss_ldap appropriately configured and /etc/nsswitch.conf conveniently pointing netgroup queries to ldap, we can test this entry on the command line like so:
# getent netgroup QAUsers QAUsers (,bobby,example.com) (,joey,example.com)
The getent command is part of the glibc-common package on Fedora. It can be used to query any of the available NSS databases.
Now, let's look at an LDIF defining which machines are QA systems on our network:
dn: cn=QASystems,ou=Netgroup,dc=example,dc=com objectClass: nisNetgroup objectClass: top cn: QASystems nisNetgroupTriple: (qa01,,example.com) nisNetgroupTriple: (qa02,,example.com) description: All QA systems on our network
OK, so we have our users and systems in place, now how do we give QAUsers login access to QASystems? Enter PAM's access.conf.
PAM's access control module is invoked with pam_access.so. Fedora includes a reference to pam_access.so in /etc/pam.d/crond, which in turn references /etc/security/access.conf. To prevent issues with crond, it is best to create separate access control file for netgroups with this line in /etc/pam.d/system-auth:
account required pam_access.so accessfile=/etc/security/access.netgroup.conf
We can give our users remote login access from our 10.x.x.x network with by modifying /etc/security/access.conf and adding this line:
+ : @QAUsers@@QASystems : 10.
NOTE: PAM operates on a first match basis for granting access. This implies you want to end your ACL list by denying all unmatched entries, but before you do that make sure root and/or your admin users have been matched!
For example, adding root for console only, users in the Admins netgroup remote access and denying all other unmatched entries:
+ : root : LOCAL + : @Admins : 10. - : ALL : ALL
An advantage to using machine groups in the access.conf is the ability to push out this access.conf configuration file to all systems in your network, regardless if they are related to QA. This gives an admin the ability to maintain a central access control list of general user and group pairs, which can be deployed via tools like CFEngine. If a QA user attempts to login to a non-QA system, PAM will first check for the user's name in the users portion of the ACL. If a match is found, it will then check if the current machine's hostname exists in the netgroup or machine name section. If the current machine does not belong to the netgroup, the ACL fails and the next one will be tried.
Since we have created our own framework of system and user group ACLs inside the LDAP server, we have decoupled access control from the actual posixAccount and posixGroup entries. This means that the user no longer requires an account in the LDAP server itself. A simple entry in /etc/passwd is good enough to apply access control in this manner. With this infrastructure in place, we can now start up Fedora's Admin Console or our favorite LDAP editor and quickly add or remove login access to users and machines!