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: # Jr Aquino <jr.aquino@citrixonline.com> # # Copyright (C) 2010 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/>.
Sudo Rules
Sudo (su "do") allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments.
FreeIPA provides a means to configure the various aspects of Sudo: Users: The user(s)/group(s) allowed to envoke Sudo. Hosts: The host(s)/hostgroup(s) which the user is allowed to to invoke Sudo. Allow Command: The specific command(s) permited to be run via Sudo. Deny Command: The specific command(s) prohibited to be run via Sudo. RunAsUser: The user(s) or group(s) of users whose rights Sudo will be invoked with. RunAsGroup: The group(s) whose gid rights Sudo will be invoked with. Options: The various Sudoers Options that can modify Sudo's behavior.
FreeIPA provides a designated binddn to use with Sudo located at: uid=sudo,cn=sysaccounts,cn=etc,dc=example,dc=com
To enable the binddn run the following command to set the password: LDAPTLS_CACERT=/etc/ipa/ca.crt /usr/bin/ldappasswd -S -W \ -h ipa.example.com -ZZ -D "cn=Directory Manager" \ uid=sudo,cn=sysaccounts,cn=etc,dc=example,dc=com
For more information, see the FreeIPA Documentation to Sudo. """)
raise errors.ValidationError(name=attribute, error=_('this option has been deprecated.'))
deprecated('externaluser')
deprecated('runasexternaluser')
deprecated('runasexternalgroup')
""" Sudo Rule object. """ 'cn', 'ipaenabledflag', 'externaluser', 'description', 'usercategory', 'hostcategory', 'cmdcategory', 'memberuser', 'memberhost', 'memberallowcmd', 'memberdenycmd', 'ipasudoopt', 'ipasudorunas', 'ipasudorunasgroup', 'ipasudorunasusercategory', 'ipasudorunasgroupcategory', ] 'memberuser': ['user', 'group'], 'memberhost': ['host', 'hostgroup'], 'memberallowcmd': ['sudocmd', 'sudocmdgroup'], 'memberdenycmd': ['sudocmd', 'sudocmdgroup'], 'ipasudorunas': ['user', 'group'], 'ipasudorunasgroup': ['group'], }
Str('cn', cli_name='sudorule_name', label=_('Rule name'), primary_key=True, ), Str('description?', cli_name='desc', label=_('Description'), ), Flag('ipaenabledflag?', label=_('Enabled'), flags=['no_create', 'no_update', 'no_search'], ), StrEnum('usercategory?', cli_name='usercat', label=_('User category'), doc=_('User category the rule applies to'), values=(u'all', ), ), StrEnum('hostcategory?', cli_name='hostcat', label=_('Host category'), doc=_('Host category the rule applies to'), values=(u'all', ), ), StrEnum('cmdcategory?', cli_name='cmdcat', label=_('Command category'), doc=_('Command category the rule applies to'), values=(u'all', ), ), StrEnum('ipasudorunasusercategory?', cli_name='runasusercat', label=_('RunAs User category'), doc=_('RunAs User category the rule applies to'), values=(u'all', ), ), StrEnum('ipasudorunasgroupcategory?', cli_name='runasgroupcat', label=_('RunAs Group category'), doc=_('RunAs Group category the rule applies to'), values=(u'all', ), ), Str('memberuser_user?', label=_('Users'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberuser_group?', label=_('User Groups'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberhost_host?', label=_('Hosts'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberhost_hostgroup?', label=_('Host Groups'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberallowcmd_sudocmd?', label=_('Sudo Allow Commands'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberdenycmd_sudocmd?', label=_('Sudo Deny Commands'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberallowcmd_sudocmdgroup?', label=_('Sudo Allow Command Groups'), flags=['no_create', 'no_update', 'no_search'], ), Str('memberdenycmd_sudocmdgroup?', label=_('Sudo Deny Command Groups'), flags=['no_create', 'no_update', 'no_search'], ), Str('ipasudorunas_user?', label=_('RunAs Users'), doc=_('Run as a user'), flags=['no_create', 'no_update', 'no_search'], ), Str('ipasudorunas_group?', label=_('Groups of RunAs Users'), doc=_('Run as any user within a specified group'), flags=['no_create', 'no_update', 'no_search'], ), Str('externaluser?', validate_externaluser, cli_name='externaluser', label=_('External User'), doc=_('External User the rule applies to (sudorule-find only)'), ), Str('ipasudorunasextuser?', validate_runasextuser, cli_name='runasexternaluser', label=_('RunAs External User'), doc=_('External User the commands can run as (sudorule-find only)'), ), Str('ipasudorunasextgroup?', validate_runasextgroup, cli_name='runasexternalgroup', label=_('RunAs External Group'), doc=_('External Group the commands can run as (sudorule-find only)'), ), Str('ipasudoopt?', label=_('Sudo Option'), flags=['no_create', 'no_update', 'no_search'], ), Str('ipasudorunasgroup_group?', label=_('RunAs Groups'), doc=_('Run with the gid of a specified POSIX group'), flags=['no_create', 'no_update', 'no_search'], ), )
# Sudo Rules are enabled by default
except errors.NotFound: self.obj.handle_not_found(*keys)
raise errors.MutuallyExclusiveError(reason=_("user category cannot be set to 'all' while there are users")) raise errors.MutuallyExclusiveError(reason=_("host category cannot be set to 'all' while there are hosts")) 'memberdenywcmd') in _entry_attrs: raise errors.MutuallyExclusiveError(reason=_("command category cannot be set to 'all' while there are allow or deny commands")) raise errors.MutuallyExclusiveError(reason=_("group runAs category cannot be set to 'all' while there are groups"))
'%(count)d Sudo Rule matched', '%(count)d Sudo Rules matched', 0 )
ldap = self.obj.backend
dn = self.obj.get_dn(cn) entry_attrs = {'ipaenabledflag': 'TRUE'}
try: ldap.update_entry(dn, entry_attrs) except errors.EmptyModlist: pass except errors.NotFound: self.obj.handle_not_found(cn)
return dict(result=True)
textui.print_dashed(_('Enabled Sudo Rule "%s"') % cn)
ldap = self.obj.backend
dn = self.obj.get_dn(cn) entry_attrs = {'ipaenabledflag': 'FALSE'}
try: ldap.update_entry(dn, entry_attrs) except errors.EmptyModlist: pass except errors.NotFound: self.obj.handle_not_found(cn)
return dict(result=True)
textui.print_dashed(_('Disabled Sudo Rule "%s"') % cn)
except errors.NotFound: self.obj.handle_not_found(*keys)
except errors.NotFound: self.obj.handle_not_found(*keys) raise errors.MutuallyExclusiveError(reason=_("commands cannot be added when command category='all'"))
except errors.NotFound: self.obj.handle_not_found(*keys)
except errors.NotFound: self.obj.handle_not_found(*keys)
return False
except errors.NotFound: self.obj.handle_not_found(*keys) is_all(_entry_attrs, 'ipasudorunasgroupcategory'):
raise errors.ValidationError(name='runas-user', error=unicode(_("RunAsUser does not accept '%(name)s' as a user name")) % dict(name=name)) for name in options['group']: if not check_validity(name): raise errors.ValidationError(name='runas-user', error=unicode(_("RunAsUser does not accept '%(name)s' as a group name")) % dict(name=name))
return False
except errors.NotFound: self.obj.handle_not_found(*keys) is_all(_entry_attrs, 'ipasudorunasgroupcategory'): raise errors.MutuallyExclusiveError(reason=_("users cannot be added when runAs user or runAs group category='all'"))
raise errors.ValidationError(name='runas-group', error=unicode(_("RunAsGroup does not accept '%(name)s' as a group name")) % dict(name=name))
Str('ipasudoopt', cli_name='sudooption', label=_('Sudo Option'), ), )
raise errors.EmptyModlist()
entry_attrs.setdefault('ipasudoopt', []).append( options['ipasudoopt']) else: raise errors.DuplicateEntry options['ipasudoopt']) except errors.EmptyModlist: pass except errors.NotFound: self.obj.handle_not_found(cn)
dn, attrs_list, normalize=self.obj.normalize_dn )
textui.print_dashed(_('Added option "%(option)s" to Sudo Rule "%(rule)s"') % \ dict(option=options['ipasudoopt'], rule=cn)) super(sudorule_add_option, self).output_for_cli(textui, result, cn, options)
Str('ipasudoopt', cli_name='sudooption', label=_('Sudo Option'), ), )
raise errors.EmptyModlist() options['ipasudoopt']) else: raise errors.AttrValueNotFound( attr='ipasudoopt', value=options['ipasudoopt'] ) except ValueError, e: pass except KeyError: raise errors.AttrValueNotFound( attr='ipasudoopt', value=options['ipasudoopt'] ) except errors.NotFound: self.obj.handle_not_found(cn)
dn, attrs_list, normalize=self.obj.normalize_dn )
textui.print_dashed(_('Removed option "%(option)s" from Sudo Rule "%(rule)s"') % \ dict(option=options['ipasudoopt'], rule=cn)) super(sudorule_remove_option, self).output_for_cli(textui, result, cn, options)
|