Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Authors: # Rob Crittenden <rcritten@redhat.com> # Pavel Zuna <pzuna@redhat.com> # # Copyright (C) 2009 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. Directory Server Access Control Instructions (ACIs)
ACIs are used to allow or deny access to information. This module is currently designed to allow, not deny, access.
The aci commands are designed to grant permissions that allow updating existing entries or adding or deleting new ones. The goal of the ACIs that ship with IPA is to provide a set of low-level permissions that grant access to special groups called taskgroups. These low-level permissions can be combined into roles that grant broader access. These roles are another type of group, roles.
For example, if you have taskgroups that allow adding and modifying users you could create a role, useradmin. You would assign users to the useradmin role to allow them to do the operations defined by the taskgroups.
You can create ACIs that delegate permission so users in group A can write attributes on group B.
The type option is a map that applies to all entries in the users, groups or host location. It is primarily designed to be used when granting add permissions (to write new entries).
An ACI consists of three parts: 1. target 2. permissions 3. bind rules
The target is a set of rules that define which LDAP objects are being targeted. This can include a list of attributes, an area of that LDAP tree or an LDAP filter.
The targets include: - attrs: list of attributes affected - type: an object type (user, group, host, service, etc) - memberof: members of a group - targetgroup: grant access to modify a specific group. This is primarily designed to enable users to add or remove members of a specific group. - filter: A legal LDAP filter used to narrow the scope of the target. - subtree: Used to apply a rule across an entire set of objects. For example, to allow adding users you need to grant "add" permission to the subtree ldap://uid=*,cn=users,cn=accounts,dc=example,dc=com. The subtree option is a fail-safe for objects that may not be covered by the type option.
The permissions define what the ACI is allowed to do, and are one or more of: 1. write - write one or more attributes 2. read - read one or more attributes 3. add - add a new entry to the tree 4. delete - delete an existing entry 5. all - all permissions are granted
Note the distinction between attributes and entries. The permissions are independent, so being able to add a user does not mean that the user will be editable.
The bind rule defines who this ACI grants permissions to. The LDAP server allows this to be any valid LDAP entry but we encourage the use of taskgroups so that the rights can be easily shared through roles.
For a more thorough description of access controls see http://www.redhat.com/docs/manuals/dir-server/ag/8.0/Managing_Access_Control.html
EXAMPLES:
NOTE: ACIs are now added via the permission plugin. These examples are to demonstrate how the various options work but this is done via the permission command-line now (see last example).
Add an ACI so that the group "secretaries" can update the address on any user: ipa group-add --desc="Office secretaries" secretaries ipa aci-add --attrs=streetAddress --memberof=ipausers --group=secretaries --permissions=write --prefix=none "Secretaries write addresses"
Show the new ACI: ipa aci-show --prefix=none "Secretaries write addresses"
Add an ACI that allows members of the "addusers" permission to add new users: ipa aci-add --type=user --permission=addusers --permissions=add --prefix=none "Add new users"
Add an ACI that allows members of the editors manage members of the admins group: ipa aci-add --permissions=write --attrs=member --targetgroup=admins --group=editors --prefix=none "Editors manage admins"
Add an ACI that allows members of the admins group to manage the street and zip code of those in the editors group: ipa aci-add --permissions=write --memberof=editors --group=admins --attrs=street,postalcode --prefix=none "admins edit the address of editors"
Add an ACI that allows the admins group manage the street and zipcode of those who work for the boss: ipa aci-add --permissions=write --group=admins --attrs=street,postalcode --filter="(manager=uid=boss,cn=users,cn=accounts,dc=example,dc=com)" --prefix=none "Edit the address of those who work for the boss"
Add an entirely new kind of record to IPA that isn't covered by any of the --type options, creating a permission: ipa permission-add --permissions=add --subtree="cn=*,cn=orange,cn=accounts,dc=example,dc=com" --desc="Add Orange Entries" add_orange
The show command shows the raw 389-ds ACI.
IMPORTANT: When modifying the target attributes of an existing ACI you must include all existing attributes as well. When doing an aci-mod the targetattr REPLACES the current attributes, it does not add to them.
"""
'user': 'ldap:///uid=*,%s,%s' % (api.env.container_user, api.env.basedn), 'group': 'ldap:///cn=*,%s,%s' % (api.env.container_group, api.env.basedn), 'host': 'ldap:///fqdn=*,%s,%s' % (api.env.container_host, api.env.basedn), 'hostgroup': 'ldap:///cn=*,%s,%s' % (api.env.container_hostgroup, api.env.basedn), 'service': 'ldap:///krbprincipalname=*,%s,%s' % (api.env.container_service, api.env.basedn), 'netgroup': 'ldap:///ipauniqueid=*,%s,%s' % (api.env.container_netgroup, api.env.basedn), 'dnsrecord': 'ldap:///idnsname=*,%s,%s' % (api.env.container_dns, api.env.basedn), }
u'read', u'write', u'add', u'delete', u'all' ]
u'permission', u'delegation', u'selfservice', u'none' )
assert isinstance(entries, self.type) for (i, entry) in enumerate(entries): if not isinstance(entry, unicode): raise TypeError(output.emsg % (cmd.name, self.__class__.__name__, self.name, i, unicode, type(entry), entry) )
output.Output('result', unicode, 'A string representing the ACI'), output.value, output.summary, )
""" Given a name and a prefix construct an ACI name. """
""" Parse the raw ACI name and return a tuple containing the ACI prefix and the actual ACI name. """
""" Pull the group name out of a memberOf filter """ # We have a raw group name, use that en = memberof.find(')', st) return memberof[st+9:en]
""" Given a name and a set of keywords construct an ACI. """ # Do some quick and dirty validation. else:
raise errors.ValidationError(name='target', error=_('type, filter, subtree and targetgroup are mutually exclusive'))
raise errors.ValidationError(name='aciprefix', error=_('ACI prefix is required'))
raise errors.ValidationError(name='target', error=_('at least one of: type, filter, subtree, targetgroup, attrs or memberof are required'))
raise errors.ValidationError(name='target', error=_('filter and memberof are mutually exclusive'))
raise errors.ValidationError(name='target', error=_('group, permission and self are mutually exclusive')) raise errors.ValidationError(name='target', error=_('One of group, permission or self is required'))
# Grab the dn of the group we're granting access to. This group may be a # permission or a user group. # This will raise NotFound if the permission doesn't exist raise e else: # Not so friendly with groups. This will raise except errors.NotFound: raise errors.NotFound(reason=_("Group '%s' does not exist") % kw['group'])
else: # Test the filter by performing a simple search on it. The # filter is considered valid if either it returns some entries # or it returns no entries, otherwise we let whatever exception # happened be raised. if kw['filter'] in ('', None, u''): raise errors.BadSearchFilter(info=_('empty filter')) try: entries = ldap.find_entries(filter=kw['filter']) except errors.NotFound: pass a.set_target_filter(kw['filter']) # Purposely no try here so we'll raise a NotFound # See if the subtree is a full URI target = 'ldap:///%s' % target raise errors.ValidationError(name='target', error=_('Syntax Error: %(error)s') % dict(error=str(e)))
"""Convert an ACI into its equivalent keywords.
This is used for the modify operation so we can merge the incoming kw and existing ACI and pass the result to _make_aci(). """ else: kw['filter'] = unicode(target) kw['filter'] = unicode(target) else: # See if the target is a group. If so we set the # targetgroup attr, otherwise we consider it a subtree else:
pass else: # FIXME, use real name here else:
except SyntaxError, e: root_logger.warning("Failed to parse: %s" % a)
return '"%s" is not a valid permission' % p
cli_name='prefix', label=_('ACI prefix'), doc=_('Prefix used to distinguish ACI types ' \ '(permission, delegation, selfservice, none)'), values=_valid_prefix_values, )
""" ACI object. """
Str('aciname', cli_name='name', label=_('ACI name'), primary_key=True, flags=('virtual_attribute',), ), Str('permission?', cli_name='permission', label=_('Permission'), doc=_('Permission ACI grants access to'), flags=('virtual_attribute',), ), Str('group?', cli_name='group', label=_('User group'), doc=_('User group ACI grants access to'), flags=('virtual_attribute',), ), Str('permissions+', validate_permissions, cli_name='permissions', label=_('Permissions'), doc=_('comma-separated list of permissions to grant' \ '(read, write, add, delete, all)'), csv=True, normalizer=_normalize_permissions, flags=('virtual_attribute',), ), Str('attrs*', cli_name='attrs', label=_('Attributes'), doc=_('Comma-separated list of attributes'), csv=True, flags=('virtual_attribute',), ), StrEnum('type?', cli_name='type', label=_('Type'), doc=_('type of IPA object (user, group, host, hostgroup, service, netgroup)'), values=(u'user', u'group', u'host', u'service', u'hostgroup', u'netgroup', u'dnsrecord'), flags=('virtual_attribute',), ), Str('memberof?', cli_name='memberof', label=_('Member of'), # FIXME: Does this label make sense? doc=_('Member of a group'), flags=('virtual_attribute',), ), Str('filter?', cli_name='filter', label=_('Filter'), doc=_('Legal LDAP filter (e.g. ou=Engineering)'), flags=('virtual_attribute',), ), Str('subtree?', cli_name='subtree', label=_('Subtree'), doc=_('Subtree to apply ACI to'), flags=('virtual_attribute',), ), Str('targetgroup?', cli_name='targetgroup', label=_('Target group'), doc=_('Group to apply ACI to'), flags=('virtual_attribute',), ), Flag('selfaci?', cli_name='self', label=_('Target your own entry (self)'), doc=_('Apply ACI to your own entry (self)'), flags=('virtual_attribute',), ), )
""" Create new ACI. """
_prefix_option, Flag('test?', doc=_('Test the ACI syntax but don\'t write anything'), default=False, ), )
""" Execute the aci-create operation.
Returns the entry as it will be created in LDAP.
:param aciname: The name of the ACI being added. :param kw: Keyword arguments for the other LDAP attributes. """
# FIXME: add check for permission_group = permission_group
result = dict(aci=unicode(newaci_str)) else: result=result, value=aciname, )
""" Delete ACI. """
""" Execute the aci-delete operation.
:param aciname: The name of the ACI being deleted. :param aciprefix: The ACI prefix. """
result=True, value=aciname, )
""" Modify ACI. """ Str('aci', label=_('ACI'), ), )
# The strategy here is to convert the ACI we're updating back into # a series of keywords. Then we replace any keywords that have been # updated and convert that back into an ACI and write it out. # selfaci is set in aci_to_kw to True only if the target is self
# _make_aci is what is run in aci_add and validates the input. # Do this before we delete the existing ACI. raise errors.EmptyModlist()
except Exception, e: # ACI could not be added, try to restore the old deleted ACI and # report the ADD error back to user try: self.api.Command['aci_add'](aciname, **oldkw) except Exception: pass raise e
result = dict(aci=unicode(newaci)) else: result=result, value=aciname, )
""" Search for ACIs.
Returns a list of ACIs
EXAMPLES:
To find all ACIs that apply directly to members of the group ipausers: ipa aci-find --memberof=ipausers
To find all ACIs that grant add access: ipa aci-find --permissions=add
Note that the find command only looks for the given text in the set of ACIs, it does not evaluate the ACIs to see if something would apply. For example, searching on memberof=ipausers will find all ACIs that have ipausers as a memberof. There may be other ACIs that apply to members of that group indirectly. """
gen_pkey_only_option("name"),)
else:
for a in acis: if not 'targetattr' in a.target: results.remove(a) continue alist1 = sorted( [t.lower() for t in a.target['targetattr']['expression']] ) alist2 = sorted([t.lower() for t in kw['attrs']]) if len(set(alist1) & set(alist2)) != len(alist2): results.remove(a) acis = list(results)
try: self.api.Command['permission_show']( kw['permission'] ) except errors.NotFound: pass else: for a in acis: if a.bindrule['expression'] != ('ldap:///%s' % dn): results.remove(a) acis = list(results)
for a in acis: alist1 = sorted(a.permissions) alist2 = sorted(kw['permissions']) if len(set(alist1) & set(alist2)) != len(alist2): results.remove(a) acis = list(results)
try: dn = _group_from_memberof(kw['memberof']) except errors.NotFound: pass else: memberof_filter = '(memberOf=%s)' % dn for a in acis: if 'targetfilter' in a.target: targetfilter = a.target['targetfilter']['expression'] if targetfilter != memberof_filter: results.remove(a) else: results.remove(a)
for a in acis: if 'target' in a.target: target = a.target['target']['expression'] else: results.remove(a) continue found = False for k in _type_map.keys(): if _type_map[k] == target and kw['type'] == k: found = True break; if not found: try: results.remove(a) except ValueError: pass
try: results.remove(a) except ValueError: pass
for a in acis: groupdn = a.bindrule['expression'] groupdn = groupdn.replace('ldap:///','') cn = None if groupdn.startswith('cn='): cn = explode_dn(groupdn)[0] cn = cn.replace('cn=','') if cn is None or cn != kw['group']: try: results.remove(a) except ValueError: pass
for a in acis: found = False if 'target' in a.target: target = a.target['target']['expression'] if api.env.container_group in target: targetdn = unicode(target.replace('ldap:///','')) cn = explode_dn(targetdn)[0] cn = cn.replace('cn=','') if cn == kw['targetgroup']: found = True if not found: try: results.remove(a) except ValueError: pass
if not kw['filter'].startswith('('): kw['filter'] = unicode('('+kw['filter']+')') for a in acis: if 'targetfilter' not in a.target or\ not a.target['targetfilter']['expression'] or\ a.target['targetfilter']['expression'] != kw['filter']: results.remove(a)
else: results.remove(a) continue except ValueError: pass
else: pkey_only=kw.get('pkey_only', False))
result=acis, count=len(acis), truncated=False, )
""" Display a single ACI given an ACI name. """
Str('aci', label=_('ACI'), ), )
""" Execute the aci-show operation.
Returns the entry
:param uid: The login name of the user to retrieve. :param kw: unused """
else: result=result, value=aciname, )
""" Rename an ACI. """ Str('aci', label=_('ACI'), ), )
_prefix_option, Str('newname', doc=_('New ACI name'), ), )
raise errors.DuplicateEntry()
# The strategy here is to convert the ACI we're updating back into # a series of keywords. Then we replace any keywords that have been # updated and convert that back into an ACI and write it out. # selfaci is set in aci_to_kw to True only if the target is self kw['selfaci'] = True
# _make_aci is what is run in aci_add and validates the input. # Do this before we delete the existing ACI.
result = dict(aci=unicode(newaci)) else: result=result, value=kw['newname'], )
|