Created
November 6, 2017 14:38
-
-
Save sochotnicky/2cc19a880412a7319601da12099ad71d to your computer and use it in GitHub Desktop.
/home/w0rm/bin/ssh_keys_for_group.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import ldap | |
| l = ldap.initialize('ldap://ldap.corp.redhat.com') | |
| groups = l.search_s('dc=redhat,dc=com', ldap.SCOPE_SUBTREE, | |
| 'cn=%s' % sys.argv[1]) | |
| no_keys = [] | |
| for group in groups: | |
| query = '(|(uid=%s))' % ')(uid='.join(group[1]['memberUid']) | |
| users = l.search_s('dc=redhat,dc=com', ldap.SCOPE_SUBTREE, | |
| query) | |
| for cn, user in users: | |
| if 'ipaSshPubKey' in user: | |
| for key in user['ipaSshPubKey']: | |
| print key | |
| else: | |
| no_keys.append(user['uid'][0]) | |
| print "Users without ssh keys in ldap: %s" % ", ".join(no_keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment