2009-05-27 08:55:49 -05:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# 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.
|
2009-05-27 08:55:49 -05:00
|
|
|
#
|
|
|
|
# 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
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2016-07-21 06:18:34 -05:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
import logging
|
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
import six
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib import api, errors, util
|
2016-03-02 06:29:27 -06:00
|
|
|
from ipalib import messages
|
2019-07-29 10:00:35 -05:00
|
|
|
from ipalib import Str, StrEnum, Flag
|
2020-11-26 14:42:03 -06:00
|
|
|
from ipalib.parameters import Data, Principal, Certificate
|
2014-06-10 10:27:51 -05:00
|
|
|
from ipalib.plugable import Registry
|
2016-04-20 08:41:34 -05:00
|
|
|
from .baseldap import (LDAPQuery, LDAPObject, LDAPCreate,
|
2014-08-01 05:06:36 -05:00
|
|
|
LDAPDelete, LDAPUpdate, LDAPSearch,
|
|
|
|
LDAPRetrieve, LDAPAddMember,
|
|
|
|
LDAPRemoveMember, host_is_master,
|
2015-06-23 06:42:01 -05:00
|
|
|
pkey_to_value, add_missing_object_class,
|
2016-06-23 12:14:53 -05:00
|
|
|
LDAPAddAttribute, LDAPRemoveAttribute,
|
|
|
|
LDAPAddAttributeViaOption,
|
|
|
|
LDAPRemoveAttributeViaOption)
|
2016-06-23 13:06:42 -05:00
|
|
|
from .service import (
|
2021-03-08 11:15:50 -06:00
|
|
|
validate_realm, validate_auth_indicator, normalize_principal,
|
2013-03-18 06:31:23 -05:00
|
|
|
set_certificate_attrs, ticket_flags_params, update_krbticketflags,
|
2014-10-02 09:57:08 -05:00
|
|
|
set_kerberos_attrs, rename_ipaallowedtoperform_from_ldap,
|
2015-06-23 06:42:01 -05:00
|
|
|
rename_ipaallowedtoperform_to_ldap, revoke_certs)
|
2016-04-20 08:41:34 -05:00
|
|
|
from .dns import (dns_container_exists,
|
2012-02-28 02:05:01 -06:00
|
|
|
add_records_for_host_validation, add_records_for_host,
|
2014-03-20 03:47:20 -05:00
|
|
|
get_reverse_zone)
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib import _, ngettext
|
2014-08-01 05:06:36 -05:00
|
|
|
from ipalib import output
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib.request import context
|
2012-09-03 08:33:30 -05:00
|
|
|
from ipalib.util import (normalize_sshpubkey, validate_sshpubkey_no_options,
|
2016-06-13 13:02:21 -05:00
|
|
|
convert_sshpubkey_post,
|
2016-03-14 11:42:56 -05:00
|
|
|
add_sshpubkey_to_attrs_pre,
|
|
|
|
remove_sshpubkey_from_output_post,
|
2016-06-13 13:02:21 -05:00
|
|
|
remove_sshpubkey_from_output_list_post,
|
|
|
|
normalize_hostname,
|
|
|
|
hostname_validator,
|
2015-09-08 10:43:30 -05:00
|
|
|
set_krbcanonicalname
|
2016-06-13 13:02:21 -05:00
|
|
|
)
|
2016-07-22 09:41:29 -05:00
|
|
|
from ipapython.ipautil import (
|
|
|
|
ipa_generate_password,
|
|
|
|
CheckedIPAddress,
|
2016-12-21 08:07:34 -06:00
|
|
|
TMP_PWD_ENTROPY_BITS
|
2016-07-22 09:41:29 -05:00
|
|
|
)
|
2020-08-28 08:31:10 -05:00
|
|
|
from ipapython.dnsutil import DNSName, zone_for_name
|
2012-09-03 08:33:30 -05:00
|
|
|
from ipapython.ssh import SSHPublicKey
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
from ipapython.dn import DN
|
2016-06-23 11:54:49 -05:00
|
|
|
from ipapython import kerberos
|
2015-07-30 10:49:16 -05:00
|
|
|
from functools import reduce
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Hosts/Machines
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
A host represents a machine. It can be used in a number of contexts:
|
|
|
|
- service entries are associated with a host
|
|
|
|
- a host stores the host/ service principal
|
2011-03-04 10:08:54 -06:00
|
|
|
- a host can be used in Host-based Access Control (HBAC) rules
|
2010-06-02 13:08:50 -05:00
|
|
|
- every enrolled client generates a host entry
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-06-02 13:08:50 -05:00
|
|
|
ENROLLMENT:
|
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
There are three enrollment scenarios when enrolling a new client:
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2010-08-24 22:40:32 -05:00
|
|
|
1. You are enrolling as a full administrator. The host entry may exist
|
2010-12-01 10:23:52 -06:00
|
|
|
or not. A full administrator is a member of the hostadmin role
|
2010-08-24 22:40:32 -05:00
|
|
|
or the admins group.
|
|
|
|
2. You are enrolling as a limited administrator. The host must already
|
2011-03-04 10:08:54 -06:00
|
|
|
exist. A limited administrator is a member a role with the
|
|
|
|
Host Enrollment privilege.
|
2010-06-02 13:08:50 -05:00
|
|
|
3. The host has been created with a one-time password.
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2013-08-02 10:06:29 -05:00
|
|
|
RE-ENROLLMENT:
|
|
|
|
|
|
|
|
Host that has been enrolled at some point, and lost its configuration (e.g. VM
|
|
|
|
destroyed) can be re-enrolled.
|
|
|
|
|
|
|
|
For more information, consult the manual pages for ipa-client-install.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
|
|
|
A host can optionally store information such as where it is located,
|
|
|
|
the OS that it runs, etc.
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-06-02 13:08:50 -05:00
|
|
|
EXAMPLES:
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new host:
|
|
|
|
ipa host-add --location="3rd floor lab" --locality=Dallas test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Delete a host:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa host-del test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Add a new host with a one-time password:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa host-add --os='Fedora 12' --password=Secret123 test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-10-05 21:00:40 -05:00
|
|
|
Add a new host with a random one-time password:
|
|
|
|
ipa host-add --os='Fedora 12' --random test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-08-24 22:40:32 -05:00
|
|
|
Modify information about a host:
|
2010-06-02 13:08:50 -05:00
|
|
|
ipa host-mod --os='Fedora 12' test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2011-12-07 01:50:31 -06:00
|
|
|
Remove SSH public keys of a host and update DNS to reflect this change:
|
|
|
|
ipa host-mod --sshpubkey= --updatedns test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2011-02-16 03:35:49 -06:00
|
|
|
Disable the host Kerberos key, SSL certificate and all of its services:
|
2010-07-12 16:45:06 -05:00
|
|
|
ipa host-disable test.example.com
|
2013-10-09 07:52:04 -05:00
|
|
|
""") + _("""
|
2010-11-10 15:47:29 -06:00
|
|
|
Add a host that can manage this host's keytab and certificate:
|
|
|
|
ipa host-add-managedby --hosts=test2 test
|
2014-10-02 09:57:08 -05:00
|
|
|
""") + _("""
|
|
|
|
Allow user to create a keytab:
|
|
|
|
ipa host-allow-create-keytab test2 --users=tuser1
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
register = Registry()
|
|
|
|
|
2012-06-26 08:23:55 -05:00
|
|
|
|
2016-07-21 06:18:34 -05:00
|
|
|
def remove_ptr_rec(ipaddr, fqdn):
|
2016-03-02 06:29:27 -06:00
|
|
|
"""
|
|
|
|
Remove PTR record of IP address (ipaddr)
|
|
|
|
:return: True if PTR record was removed, False if record was not found
|
|
|
|
"""
|
2017-05-24 08:42:23 -05:00
|
|
|
logger.debug('deleting PTR record of ipaddr %s', ipaddr)
|
2011-01-31 08:30:43 -06:00
|
|
|
try:
|
2011-05-27 13:29:33 -05:00
|
|
|
revzone, revname = get_reverse_zone(ipaddr)
|
2012-08-28 06:43:20 -05:00
|
|
|
|
2016-07-21 06:18:34 -05:00
|
|
|
# assume that target in PTR record is absolute name (otherwise it is
|
|
|
|
# non-standard configuration)
|
|
|
|
delkw = {'ptrrecord': u"%s" % fqdn.make_absolute()}
|
2012-08-28 06:43:20 -05:00
|
|
|
|
2011-01-31 08:30:43 -06:00
|
|
|
api.Command['dnsrecord_del'](revzone, revname, **delkw)
|
2016-07-21 06:18:34 -05:00
|
|
|
except (errors.NotFound, errors.AttrValueNotFound):
|
2017-05-24 08:42:23 -05:00
|
|
|
logger.debug('PTR record of ipaddr %s not found', ipaddr)
|
2016-03-02 06:29:27 -06:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2011-01-31 08:30:43 -06:00
|
|
|
|
2014-08-01 05:08:15 -05:00
|
|
|
|
2011-12-07 01:50:31 -06:00
|
|
|
def update_sshfp_record(zone, record, entry_attrs):
|
|
|
|
if 'ipasshpubkey' not in entry_attrs:
|
|
|
|
return
|
|
|
|
|
|
|
|
pubkeys = entry_attrs['ipasshpubkey'] or ()
|
2014-08-01 05:08:15 -05:00
|
|
|
sshfps = []
|
2011-12-07 01:50:31 -06:00
|
|
|
for pubkey in pubkeys:
|
2012-09-03 08:33:30 -05:00
|
|
|
try:
|
|
|
|
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha1()
|
2014-08-01 05:06:36 -05:00
|
|
|
except (ValueError, UnicodeDecodeError):
|
2012-09-03 08:33:30 -05:00
|
|
|
continue
|
2011-12-07 01:50:31 -06:00
|
|
|
if sshfp is not None:
|
|
|
|
sshfps.append(sshfp)
|
2014-08-01 05:08:15 -05:00
|
|
|
|
2013-01-08 09:13:07 -06:00
|
|
|
try:
|
|
|
|
sshfp = SSHPublicKey(pubkey).fingerprint_dns_sha256()
|
2014-08-01 05:06:36 -05:00
|
|
|
except (ValueError, UnicodeDecodeError):
|
2013-01-08 09:13:07 -06:00
|
|
|
continue
|
|
|
|
if sshfp is not None:
|
|
|
|
sshfps.append(sshfp)
|
2011-12-07 01:50:31 -06:00
|
|
|
|
|
|
|
try:
|
|
|
|
api.Command['dnsrecord_mod'](zone, record, sshfprecord=sshfps)
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
pass
|
|
|
|
|
2014-12-02 08:40:40 -06:00
|
|
|
|
|
|
|
def convert_ipaassignedidview_post(entry_attrs, options):
|
|
|
|
"""
|
|
|
|
Converts the ID View DN to its name for the better looking output.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if 'ipaassignedidview' in entry_attrs and not options.get('raw'):
|
|
|
|
idview_name = entry_attrs.single_value['ipaassignedidview'][0].value
|
|
|
|
entry_attrs.single_value['ipaassignedidview'] = idview_name
|
|
|
|
|
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
host_output_params = (
|
2011-11-10 06:46:16 -06:00
|
|
|
Flag('has_keytab',
|
|
|
|
label=_('Keytab'),
|
|
|
|
),
|
2010-11-10 15:47:29 -06:00
|
|
|
Str('managedby_host',
|
|
|
|
label='Managed by',
|
|
|
|
),
|
2011-06-13 09:23:09 -05:00
|
|
|
Str('managing_host',
|
|
|
|
label='Managing',
|
|
|
|
),
|
2012-08-17 04:00:37 -05:00
|
|
|
Str('managedby',
|
|
|
|
label=_('Failed managedby'),
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_read_keys_user',
|
|
|
|
label=_('Users allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_read_keys_group',
|
|
|
|
label=_('Groups allowed to retrieve keytab'),
|
|
|
|
),
|
2014-12-01 03:15:21 -06:00
|
|
|
Str('ipaallowedtoperform_read_keys_host',
|
|
|
|
label=_('Hosts allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_read_keys_hostgroup',
|
|
|
|
label=_('Host Groups allowed to retrieve keytab'),
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_write_keys_user',
|
|
|
|
label=_('Users allowed to create keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys_group',
|
|
|
|
label=_('Groups allowed to create keytab'),
|
|
|
|
),
|
2014-12-01 03:15:21 -06:00
|
|
|
Str('ipaallowedtoperform_write_keys_host',
|
|
|
|
label=_('Hosts allowed to create keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys_hostgroup',
|
|
|
|
label=_('Host Groups allowed to create keytab'),
|
|
|
|
),
|
2014-10-02 09:57:08 -05:00
|
|
|
Str('ipaallowedtoperform_read_keys',
|
|
|
|
label=_('Failed allowed to retrieve keytab'),
|
|
|
|
),
|
|
|
|
Str('ipaallowedtoperform_write_keys',
|
|
|
|
label=_('Failed allowed to create keytab'),
|
|
|
|
),
|
2010-11-05 14:16:53 -05:00
|
|
|
)
|
|
|
|
|
2014-08-01 05:08:15 -05:00
|
|
|
|
2010-11-23 16:47:29 -06:00
|
|
|
def validate_ipaddr(ugettext, ipaddr):
|
|
|
|
"""
|
|
|
|
Verify that we have either an IPv4 or IPv6 address.
|
|
|
|
"""
|
2011-06-14 09:31:36 -05:00
|
|
|
try:
|
2017-06-14 07:54:43 -05:00
|
|
|
CheckedIPAddress(ipaddr)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-01-20 08:15:11 -06:00
|
|
|
return unicode(e)
|
2010-11-23 16:47:29 -06:00
|
|
|
return None
|
|
|
|
|
2014-08-01 05:08:15 -05:00
|
|
|
|
2021-06-15 05:47:43 -05:00
|
|
|
def resolve_fqdn(name):
|
|
|
|
hostentry = api.Command['host_show'](name)['result']
|
|
|
|
return hostentry['fqdn'][0]
|
|
|
|
|
|
|
|
|
2019-09-17 16:24:12 -05:00
|
|
|
class HostPassword(Str):
|
|
|
|
"""
|
|
|
|
A data type for host passwords to not log password values
|
|
|
|
|
|
|
|
The Password type cannot be used because it disallows
|
|
|
|
setting a password on the command-line which would break
|
|
|
|
backwards compatibility.
|
|
|
|
"""
|
2020-11-26 14:42:03 -06:00
|
|
|
|
|
|
|
kwargs = Data.kwargs + (
|
|
|
|
('pattern', (str,), None),
|
|
|
|
('noextrawhitespace', bool, False),
|
|
|
|
)
|
|
|
|
|
2019-09-17 16:24:12 -05:00
|
|
|
def safe_value(self, value):
|
|
|
|
return u'********'
|
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host(LDAPObject):
|
2009-05-27 08:55:49 -05:00
|
|
|
"""
|
|
|
|
Host object.
|
|
|
|
"""
|
2009-09-15 07:01:58 -05:00
|
|
|
container_dn = api.env.container_host
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('host')
|
|
|
|
object_name_plural = _('hosts')
|
2009-12-16 15:04:53 -06:00
|
|
|
object_class = ['ipaobject', 'nshost', 'ipahost', 'pkiuser', 'ipaservice']
|
2014-10-02 09:57:08 -05:00
|
|
|
possible_objectclasses = ['ipaallowedoperations']
|
2014-01-09 07:43:37 -06:00
|
|
|
permission_filter_objectclasses = ['ipahost']
|
2009-09-15 07:01:58 -05:00
|
|
|
# object_class_config = 'ipahostobjectclasses'
|
2010-07-12 16:45:06 -05:00
|
|
|
search_attributes = [
|
2016-06-29 07:54:54 -05:00
|
|
|
'fqdn', 'description', 'l', 'nshostlocation', 'krbcanonicalname',
|
|
|
|
'krbprincipalname', 'nshardwareplatform', 'nsosversion', 'managedby',
|
2010-07-12 16:45:06 -05:00
|
|
|
]
|
2009-09-15 07:01:58 -05:00
|
|
|
default_attributes = [
|
2016-06-29 07:54:54 -05:00
|
|
|
'fqdn', 'description', 'l', 'nshostlocation', 'krbcanonicalname',
|
|
|
|
'krbprincipalname',
|
2010-02-12 15:34:21 -06:00
|
|
|
'nshardwareplatform', 'nsosversion', 'usercertificate', 'memberof',
|
2015-03-31 03:59:37 -05:00
|
|
|
'managedby', 'memberofindirect', 'macaddress',
|
2016-06-21 13:19:03 -05:00
|
|
|
'userclass', 'ipaallowedtoperform', 'ipaassignedidview', 'krbprincipalauthind'
|
2009-09-15 07:01:58 -05:00
|
|
|
]
|
|
|
|
uuid_attribute = 'ipauniqueid'
|
|
|
|
attribute_members = {
|
|
|
|
'enrolledby': ['user'],
|
2011-05-31 16:52:35 -05:00
|
|
|
'memberof': ['hostgroup', 'netgroup', 'role', 'hbacrule', 'sudorule'],
|
2010-11-10 15:47:29 -06:00
|
|
|
'managedby': ['host'],
|
2011-06-13 09:23:09 -05:00
|
|
|
'managing': ['host'],
|
2011-05-31 16:52:35 -05:00
|
|
|
'memberofindirect': ['hostgroup', 'netgroup', 'role', 'hbacrule',
|
|
|
|
'sudorule'],
|
2014-12-01 03:15:21 -06:00
|
|
|
'ipaallowedtoperform_read_keys': ['user', 'group', 'host', 'hostgroup'],
|
|
|
|
'ipaallowedtoperform_write_keys': ['user', 'group', 'host', 'hostgroup'],
|
2009-09-15 07:01:58 -05:00
|
|
|
}
|
2010-12-02 10:05:54 -06:00
|
|
|
bindable = True
|
2011-01-04 14:15:54 -06:00
|
|
|
relationships = {
|
2011-01-06 16:14:13 -06:00
|
|
|
'memberof': ('Member Of', 'in_', 'not_in_'),
|
2011-01-04 14:15:54 -06:00
|
|
|
'enrolledby': ('Enrolled by', 'enroll_by_', 'not_enroll_by_'),
|
|
|
|
'managedby': ('Managed by', 'man_by_', 'not_man_by_'),
|
2011-06-13 09:23:09 -05:00
|
|
|
'managing': ('Managing', 'man_', 'not_man_'),
|
2014-10-02 09:57:08 -05:00
|
|
|
'ipaallowedtoperform_read_keys': ('Allow to retrieve keytab by', 'retrieve_keytab_by_', 'not_retrieve_keytab_by_'),
|
|
|
|
'ipaallowedtoperform_write_keys': ('Allow to create keytab by', 'write_keytab_by_', 'not_write_keytab_by'),
|
2011-01-04 14:15:54 -06:00
|
|
|
}
|
2011-08-22 15:24:07 -05:00
|
|
|
password_attributes = [('userpassword', 'has_password'),
|
|
|
|
('krbprincipalkey', 'has_keytab')]
|
2014-03-26 09:58:08 -05:00
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Hosts': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'all',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'cn', 'description', 'fqdn', 'ipaclientversion',
|
|
|
|
'ipakrbauthzdata', 'ipasshpubkey', 'ipauniqueid',
|
|
|
|
'krbprincipalname', 'l', 'macaddress', 'nshardwareplatform',
|
|
|
|
'nshostlocation', 'nsosversion', 'objectclass',
|
|
|
|
'serverhostname', 'usercertificate', 'userclass',
|
2014-07-31 05:08:05 -05:00
|
|
|
'enrolledby', 'managedby', 'ipaassignedidview',
|
2014-03-26 09:58:08 -05:00
|
|
|
'krbprincipalname', 'krbcanonicalname', 'krbprincipalaliases',
|
|
|
|
'krbprincipalexpiration', 'krbpasswordexpiration',
|
2016-06-29 08:56:55 -05:00
|
|
|
'krblastpwdchange', 'krbprincipalauthind',
|
2014-03-26 09:58:08 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'System: Read Host Membership': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'all',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'memberof',
|
|
|
|
},
|
|
|
|
},
|
2014-05-30 11:35:31 -05:00
|
|
|
'System: Add Hosts': {
|
|
|
|
'ipapermright': {'add'},
|
|
|
|
'replaces': [
|
|
|
|
'(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Add Hosts";allow (add) groupdn = "ldap:///cn=Add Hosts,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators'},
|
|
|
|
},
|
|
|
|
'System: Add krbPrincipalName to a Host': {
|
|
|
|
# Allow an admin to enroll a host that has a one-time password.
|
|
|
|
# When a host is created with a password no krbPrincipalName is set.
|
|
|
|
# This will let it be added if the client ends up enrolling with
|
|
|
|
# an administrator instead.
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermtargetfilter': [
|
|
|
|
'(objectclass=ipahost)',
|
|
|
|
'(!(krbprincipalname=*))',
|
|
|
|
],
|
|
|
|
'ipapermdefaultattr': {'krbprincipalname'},
|
|
|
|
'replaces': [
|
|
|
|
'(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(targetfilter = "(!(krbprincipalname=*))")(targetattr = "krbprincipalname")(version 3.0;acl "permission:Add krbPrincipalName to a host"; allow (write) groupdn = "ldap:///cn=Add krbPrincipalName to a host,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
|
|
|
'System: Enroll a Host': {
|
|
|
|
'ipapermright': {'write'},
|
2020-06-15 16:51:44 -05:00
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'enrolledby', 'nshardwareplatform', 'nsosversion'
|
|
|
|
},
|
2014-05-30 11:35:31 -05:00
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "objectclass")(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Enroll a host";allow (write) groupdn = "ldap:///cn=Enroll a host,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
'(targetattr = "enrolledby || objectclass")(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Enroll a host";allow (write) groupdn = "ldap:///cn=Enroll a host,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
|
|
|
'System: Manage Host SSH Public Keys': {
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'ipasshpubkey'},
|
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "ipasshpubkey")(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Manage Host SSH Public Keys";allow (write) groupdn = "ldap:///cn=Manage Host SSH Public Keys,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators'},
|
|
|
|
},
|
|
|
|
'System: Manage Host Keytab': {
|
|
|
|
'ipapermright': {'write'},
|
2015-12-01 03:42:38 -06:00
|
|
|
'ipapermtargetfilter': [
|
|
|
|
'(objectclass=ipahost)',
|
|
|
|
'(!(memberOf=%s))' % DN('cn=ipaservers',
|
|
|
|
api.env.container_hostgroup,
|
|
|
|
api.env.basedn),
|
|
|
|
],
|
2014-05-30 11:35:31 -05:00
|
|
|
'ipapermdefaultattr': {'krblastpwdchange', 'krbprincipalkey'},
|
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "krbprincipalkey || krblastpwdchange")(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Manage host keytab";allow (write) groupdn = "ldap:///cn=Manage host keytab,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
2014-10-02 09:57:08 -05:00
|
|
|
'System: Manage Host Keytab Permissions': {
|
|
|
|
'ipapermright': {'read', 'search', 'compare', 'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'ipaallowedtoperform;write_keys',
|
|
|
|
'ipaallowedtoperform;read_keys', 'objectclass'
|
|
|
|
},
|
|
|
|
'default_privileges': {'Host Administrators'},
|
|
|
|
},
|
2014-05-30 11:35:31 -05:00
|
|
|
'System: Modify Hosts': {
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'description', 'l', 'nshardwareplatform', 'nshostlocation',
|
2014-07-31 05:08:05 -05:00
|
|
|
'nsosversion', 'macaddress', 'userclass', 'ipaassignedidview',
|
2016-06-29 08:56:55 -05:00
|
|
|
'krbprincipalauthind',
|
2014-05-30 11:35:31 -05:00
|
|
|
},
|
|
|
|
'replaces': [
|
|
|
|
'(targetattr = "description || l || nshostlocation || nshardwareplatform || nsosversion")(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Modify Hosts";allow (write) groupdn = "ldap:///cn=Modify Hosts,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators'},
|
|
|
|
},
|
|
|
|
'System: Remove Hosts': {
|
|
|
|
'ipapermright': {'delete'},
|
|
|
|
'replaces': [
|
|
|
|
'(target = "ldap:///fqdn=*,cn=computers,cn=accounts,$SUFFIX")(version 3.0;acl "permission:Remove Hosts";allow (delete) groupdn = "ldap:///cn=Remove Hosts,cn=permissions,cn=pbac,$SUFFIX";)',
|
|
|
|
],
|
|
|
|
'default_privileges': {'Host Administrators'},
|
|
|
|
},
|
2014-06-04 06:54:54 -05:00
|
|
|
'System: Manage Host Certificates': {
|
|
|
|
'ipapermbindruletype': 'permission',
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'usercertificate'},
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
2016-06-23 13:06:42 -05:00
|
|
|
'System: Manage Host Principals': {
|
|
|
|
'ipapermbindruletype': 'permission',
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'krbprincipalname', 'krbcanonicalname'},
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
2014-06-04 06:54:54 -05:00
|
|
|
'System: Manage Host Enrollment Password': {
|
|
|
|
'ipapermbindruletype': 'permission',
|
|
|
|
'ipapermright': {'write'},
|
|
|
|
'ipapermdefaultattr': {'userpassword'},
|
|
|
|
'default_privileges': {'Host Administrators', 'Host Enrollment'},
|
|
|
|
},
|
2014-09-03 03:54:50 -05:00
|
|
|
'System: Read Host Compat Tree': {
|
|
|
|
'non_object': True,
|
2014-09-05 08:25:29 -05:00
|
|
|
'ipapermbindruletype': 'anonymous',
|
2014-09-03 03:54:50 -05:00
|
|
|
'ipapermlocation': api.env.basedn,
|
|
|
|
'ipapermtarget': DN('cn=computers', 'cn=compat', api.env.basedn),
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'objectclass', 'cn', 'macaddress',
|
|
|
|
},
|
|
|
|
},
|
2014-03-26 09:58:08 -05:00
|
|
|
}
|
2009-09-15 07:01:58 -05:00
|
|
|
|
2010-02-08 06:03:28 -06:00
|
|
|
label = _('Hosts')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('Host')
|
2010-02-08 06:03:28 -06:00
|
|
|
|
2009-05-27 08:55:49 -05:00
|
|
|
takes_params = (
|
2016-06-13 13:02:21 -05:00
|
|
|
Str('fqdn', hostname_validator,
|
2009-05-27 08:55:49 -05:00
|
|
|
cli_name='hostname',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Host name'),
|
2009-05-27 08:55:49 -05:00
|
|
|
primary_key=True,
|
2012-02-28 02:13:13 -06:00
|
|
|
normalizer=normalize_hostname,
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
|
|
|
Str('description?',
|
2009-09-15 07:01:58 -05:00
|
|
|
cli_name='desc',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Description'),
|
|
|
|
doc=_('A description of this host'),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
2010-02-12 15:34:21 -06:00
|
|
|
Str('l?',
|
2009-05-27 08:55:49 -05:00
|
|
|
cli_name='locality',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Locality'),
|
|
|
|
doc=_('Host locality (e.g. "Baltimore, MD")'),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
|
|
|
Str('nshostlocation?',
|
|
|
|
cli_name='location',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Location'),
|
|
|
|
doc=_('Host location (e.g. "Lab 2")'),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
|
|
|
Str('nshardwareplatform?',
|
|
|
|
cli_name='platform',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Platform'),
|
|
|
|
doc=_('Host hardware platform (e.g. "Lenovo T61")'),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
|
|
|
Str('nsosversion?',
|
|
|
|
cli_name='os',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Operating system'),
|
|
|
|
doc=_('Host operating system and version (e.g. "Fedora 9")'),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
2019-09-17 16:24:12 -05:00
|
|
|
HostPassword('userpassword?',
|
|
|
|
cli_name='password',
|
|
|
|
label=_('User password'),
|
|
|
|
doc=_('Password used in bulk enrollment'),
|
|
|
|
flags=('no_search',),
|
2009-05-27 08:55:49 -05:00
|
|
|
),
|
2010-10-05 21:00:40 -05:00
|
|
|
Flag('random?',
|
|
|
|
doc=_('Generate a random password to be used in bulk enrollment'),
|
2011-11-14 10:03:44 -06:00
|
|
|
flags=('no_search', 'virtual_attribute'),
|
2010-10-05 21:00:40 -05:00
|
|
|
default=False,
|
|
|
|
),
|
|
|
|
Str('randompassword?',
|
|
|
|
label=_('Random password'),
|
2011-11-14 10:03:44 -06:00
|
|
|
flags=('no_create', 'no_update', 'no_search', 'virtual_attribute'),
|
2010-10-05 21:00:40 -05:00
|
|
|
),
|
2017-07-03 10:10:34 -05:00
|
|
|
Certificate('usercertificate*',
|
2009-12-16 15:04:53 -06:00
|
|
|
cli_name='certificate',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Certificate'),
|
2016-03-04 05:45:39 -06:00
|
|
|
doc=_('Base-64 encoded host certificate'),
|
2009-12-16 15:04:53 -06:00
|
|
|
),
|
2016-06-29 23:37:16 -05:00
|
|
|
Str('subject',
|
|
|
|
label=_('Subject'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('serial_number',
|
|
|
|
label=_('Serial Number'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('serial_number_hex',
|
|
|
|
label=_('Serial Number (hex)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('issuer',
|
|
|
|
label=_('Issuer'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('valid_not_before',
|
|
|
|
label=_('Not Before'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('valid_not_after',
|
|
|
|
label=_('Not After'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Str('sha1_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA1)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2017-02-23 10:03:01 -06:00
|
|
|
Str('sha256_fingerprint',
|
|
|
|
label=_('Fingerprint (SHA256)'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2016-06-29 23:37:16 -05:00
|
|
|
Str('revocation_reason?',
|
|
|
|
label=_('Revocation reason'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2016-06-23 11:54:49 -05:00
|
|
|
Principal(
|
2016-06-23 13:06:42 -05:00
|
|
|
'krbcanonicalname?',
|
2016-06-23 11:54:49 -05:00
|
|
|
validate_realm,
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Principal name'),
|
2016-06-23 11:54:49 -05:00
|
|
|
normalizer=normalize_principal,
|
2016-06-23 13:06:42 -05:00
|
|
|
flags={'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
|
|
|
Principal(
|
|
|
|
'krbprincipalname*',
|
|
|
|
validate_realm,
|
|
|
|
label=_('Principal alias'),
|
|
|
|
normalizer=normalize_principal,
|
|
|
|
flags=['no_create', 'no_search'],
|
2010-02-12 15:34:21 -06:00
|
|
|
),
|
2012-01-20 14:10:44 -06:00
|
|
|
Str('macaddress*',
|
|
|
|
normalizer=lambda value: value.upper(),
|
2019-09-23 16:30:22 -05:00
|
|
|
pattern=r'^([a-fA-F0-9]{2}[:|\-]?){5}[a-fA-F0-9]{2}$',
|
2014-08-01 05:08:15 -05:00
|
|
|
pattern_errmsg=('Must be of the form HH:HH:HH:HH:HH:HH, where '
|
|
|
|
'each H is a hexadecimal character.'),
|
2012-01-20 14:10:44 -06:00
|
|
|
label=_('MAC address'),
|
|
|
|
doc=_('Hardware MAC address(es) on this host'),
|
|
|
|
),
|
2012-09-03 08:33:30 -05:00
|
|
|
Str('ipasshpubkey*', validate_sshpubkey_no_options,
|
2011-12-07 01:50:31 -06:00
|
|
|
cli_name='sshpubkey',
|
2012-09-03 08:33:30 -05:00
|
|
|
label=_('SSH public key'),
|
|
|
|
normalizer=normalize_sshpubkey,
|
2011-12-07 01:50:31 -06:00
|
|
|
flags=['no_search'],
|
|
|
|
),
|
2016-06-29 23:37:16 -05:00
|
|
|
Str('sshpubkeyfp*',
|
|
|
|
label=_('SSH public key fingerprint'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'},
|
|
|
|
),
|
2013-04-23 02:59:24 -05:00
|
|
|
Str('userclass*',
|
|
|
|
cli_name='class',
|
|
|
|
label=_('Class'),
|
|
|
|
doc=_('Host category (semantics placed on this attribute are for '
|
|
|
|
'local interpretation)'),
|
|
|
|
),
|
2014-12-02 08:40:40 -06:00
|
|
|
Str('ipaassignedidview?',
|
|
|
|
label=_('Assigned ID View'),
|
2014-07-31 05:08:05 -05:00
|
|
|
flags=['no_option'],
|
|
|
|
),
|
2019-07-29 10:00:35 -05:00
|
|
|
StrEnum(
|
|
|
|
'krbprincipalauthind*',
|
2016-06-21 13:19:03 -05:00
|
|
|
cli_name='auth_ind',
|
|
|
|
label=_('Authentication Indicators'),
|
2020-06-11 07:28:31 -05:00
|
|
|
doc=_("Defines an allow list for Authentication Indicators."
|
2016-06-21 13:19:03 -05:00
|
|
|
" Use 'otp' to allow OTP-based 2FA authentications."
|
|
|
|
" Use 'radius' to allow RADIUS-based 2FA authentications."
|
2019-07-29 10:00:35 -05:00
|
|
|
" Use 'pkinit' to allow PKINIT-based 2FA authentications."
|
|
|
|
" Use 'hardened' to allow brute-force hardened password"
|
|
|
|
" authentication by SPAKE or FAST."
|
2022-05-03 03:40:24 -05:00
|
|
|
" Use 'idp' to allow External Identity Provider"
|
|
|
|
" authentications."
|
2019-07-29 10:00:35 -05:00
|
|
|
" With no indicator specified,"
|
|
|
|
" all authentication mechanisms are allowed."),
|
2022-05-03 03:40:24 -05:00
|
|
|
values=(u'radius', u'otp', u'pkinit', u'hardened', u'idp'),
|
2016-06-21 13:19:03 -05:00
|
|
|
),
|
2013-03-18 06:31:23 -05:00
|
|
|
) + ticket_flags_params
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
def get_dn(self, *keys, **options):
|
2011-01-18 12:28:37 -06:00
|
|
|
hostname = keys[-1]
|
|
|
|
dn = super(host, self).get_dn(hostname, **options)
|
2009-09-15 07:01:58 -05:00
|
|
|
try:
|
|
|
|
self.backend.get_entry(dn, [''])
|
|
|
|
except errors.NotFound:
|
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = self.backend.find_entry_by_attr(
|
2011-01-18 12:28:37 -06:00
|
|
|
'serverhostname', hostname, self.object_class, [''],
|
2013-02-04 02:47:00 -06:00
|
|
|
DN(self.container_dn, api.env.basedn))
|
2013-10-31 11:54:21 -05:00
|
|
|
dn = entry_attrs.dn
|
2009-09-15 07:01:58 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
return dn
|
|
|
|
|
2011-06-13 09:23:09 -05:00
|
|
|
def get_managed_hosts(self, dn):
|
|
|
|
host_filter = 'managedBy=%s' % dn
|
|
|
|
host_attrs = ['fqdn']
|
|
|
|
ldap = self.api.Backend.ldap2
|
|
|
|
managed_hosts = []
|
|
|
|
|
|
|
|
try:
|
2016-09-26 07:08:17 -05:00
|
|
|
(hosts, _truncated) = ldap.find_entries(
|
2013-02-04 02:47:00 -06:00
|
|
|
base_dn=DN(self.container_dn, api.env.basedn),
|
|
|
|
filter=host_filter, attrs_list=host_attrs)
|
2011-06-13 09:23:09 -05:00
|
|
|
|
|
|
|
for host in hosts:
|
2013-10-31 11:54:21 -05:00
|
|
|
managed_hosts.append(host.dn)
|
2011-06-13 09:23:09 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
return []
|
|
|
|
|
|
|
|
return managed_hosts
|
|
|
|
|
2013-06-25 08:08:18 -05:00
|
|
|
def suppress_netgroup_memberof(self, ldap, entry_attrs):
|
2011-09-14 15:33:33 -05:00
|
|
|
"""
|
|
|
|
We don't want to show managed netgroups so remove them from the
|
|
|
|
memberofindirect list.
|
|
|
|
"""
|
|
|
|
ng_container = DN(api.env.container_netgroup, api.env.basedn)
|
2013-06-25 08:08:18 -05:00
|
|
|
for member in list(entry_attrs.get('memberofindirect', [])):
|
|
|
|
memberdn = DN(member)
|
|
|
|
if not memberdn.endswith(ng_container):
|
|
|
|
continue
|
|
|
|
|
|
|
|
filter = ldap.make_filter({'objectclass': 'mepmanagedentry'})
|
|
|
|
try:
|
|
|
|
ldap.get_entries(memberdn, ldap.SCOPE_BASE, filter, [''])
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
entry_attrs['memberofindirect'].remove(member)
|
2011-09-14 15:33:33 -05:00
|
|
|
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host_add(LDAPCreate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add a new host.')
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
has_output_params = LDAPCreate.has_output_params + host_output_params
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = _('Added host "%(value)s"')
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
2012-08-03 02:04:58 -05:00
|
|
|
takes_options = LDAPCreate.takes_options + (
|
2010-07-22 13:16:22 -05:00
|
|
|
Flag('force',
|
2011-02-18 00:02:51 -06:00
|
|
|
label=_('Force'),
|
2010-07-22 13:16:22 -05:00
|
|
|
doc=_('force host name even if not in DNS'),
|
|
|
|
),
|
2010-12-14 12:02:18 -06:00
|
|
|
Flag('no_reverse',
|
|
|
|
doc=_('skip reverse DNS detection'),
|
|
|
|
),
|
2011-01-05 14:37:53 -06:00
|
|
|
Str('ip_address?', validate_ipaddr,
|
2010-11-23 16:47:29 -06:00
|
|
|
doc=_('Add the host to DNS with this IP address'),
|
2011-06-20 11:04:02 -05:00
|
|
|
label=_('IP Address'),
|
2010-11-23 16:47:29 -06:00
|
|
|
),
|
2010-07-22 13:16:22 -05:00
|
|
|
)
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2009-12-10 09:39:24 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2019-05-01 09:15:37 -05:00
|
|
|
config = ldap.get_ipa_config()
|
|
|
|
if 'ipamaxhostnamelength' in config:
|
|
|
|
maxlen = int(config.get('ipamaxhostnamelength')[0])
|
|
|
|
if len(keys[-1]) > maxlen:
|
|
|
|
raise errors.ValidationError(
|
|
|
|
name=self.obj.primary_key.cli_name,
|
|
|
|
error=_('can be at most %(len)d characters' %
|
|
|
|
dict(len=maxlen))
|
|
|
|
)
|
2012-02-24 07:15:24 -06:00
|
|
|
if options.get('ip_address') and dns_container_exists(ldap):
|
2010-11-23 16:47:29 -06:00
|
|
|
parts = keys[-1].split('.')
|
2012-02-24 07:15:24 -06:00
|
|
|
host = parts[0]
|
2010-11-23 16:47:29 -06:00
|
|
|
domain = unicode('.'.join(parts[1:]))
|
2012-02-24 07:15:24 -06:00
|
|
|
check_reverse = not options.get('no_reverse', False)
|
2014-05-16 05:21:04 -05:00
|
|
|
add_records_for_host_validation('ip_address',
|
|
|
|
DNSName(host),
|
2014-06-10 08:57:30 -05:00
|
|
|
DNSName(domain).make_absolute(),
|
2012-02-24 07:15:24 -06:00
|
|
|
options['ip_address'],
|
|
|
|
check_forward=True,
|
|
|
|
check_reverse=check_reverse)
|
2016-06-03 03:05:34 -05:00
|
|
|
if not options.get('force', False) and 'ip_address' not in options:
|
2016-05-17 10:20:25 -05:00
|
|
|
util.verify_host_resolvable(keys[-1])
|
2010-01-12 13:09:17 -06:00
|
|
|
if 'locality' in entry_attrs:
|
|
|
|
entry_attrs['l'] = entry_attrs['locality']
|
2009-09-15 07:01:58 -05:00
|
|
|
entry_attrs['cn'] = keys[-1]
|
|
|
|
entry_attrs['serverhostname'] = keys[-1].split('.', 1)[0]
|
2014-01-14 13:23:47 -06:00
|
|
|
if not entry_attrs.get('userpassword', False) and not options.get('random', False):
|
2009-05-27 08:55:49 -05:00
|
|
|
entry_attrs['krbprincipalname'] = 'host/%s@%s' % (
|
2009-09-15 07:01:58 -05:00
|
|
|
keys[-1], self.api.env.realm
|
2009-05-27 08:55:49 -05:00
|
|
|
)
|
2011-02-02 12:47:21 -06:00
|
|
|
if 'krbprincipalaux' not in entry_attrs['objectclass']:
|
2011-01-24 09:46:44 -06:00
|
|
|
entry_attrs['objectclass'].append('krbprincipalaux')
|
2011-02-02 12:47:21 -06:00
|
|
|
if 'krbprincipal' not in entry_attrs['objectclass']:
|
2009-05-27 08:55:49 -05:00
|
|
|
entry_attrs['objectclass'].append('krbprincipal')
|
2015-09-08 10:43:30 -05:00
|
|
|
set_krbcanonicalname(entry_attrs)
|
2011-01-18 14:43:07 -06:00
|
|
|
else:
|
|
|
|
if 'krbprincipalaux' in entry_attrs['objectclass']:
|
|
|
|
entry_attrs['objectclass'].remove('krbprincipalaux')
|
2011-01-24 09:46:44 -06:00
|
|
|
if 'krbprincipal' in entry_attrs['objectclass']:
|
|
|
|
entry_attrs['objectclass'].remove('krbprincipal')
|
2011-11-14 10:03:44 -06:00
|
|
|
if options.get('random'):
|
2016-07-22 09:41:29 -05:00
|
|
|
entry_attrs['userpassword'] = ipa_generate_password(
|
2018-01-30 10:23:45 -06:00
|
|
|
entropy_bits=TMP_PWD_ENTROPY_BITS, special=None)
|
2011-11-14 10:03:44 -06:00
|
|
|
# save the password so it can be displayed in post_callback
|
|
|
|
setattr(context, 'randompassword', entry_attrs['userpassword'])
|
2017-07-03 10:10:34 -05:00
|
|
|
|
2009-12-16 15:04:53 -06:00
|
|
|
entry_attrs['managedby'] = dn
|
2012-01-20 14:10:44 -06:00
|
|
|
entry_attrs['objectclass'].append('ieee802device')
|
2011-12-07 01:50:31 -06:00
|
|
|
entry_attrs['objectclass'].append('ipasshhost')
|
2013-03-18 06:31:23 -05:00
|
|
|
update_krbticketflags(ldap, entry_attrs, attrs_list, options, False)
|
|
|
|
if 'krbticketflags' in entry_attrs:
|
|
|
|
entry_attrs['objectclass'].append('krbticketpolicyaux')
|
2021-03-08 11:15:50 -06:00
|
|
|
validate_auth_indicator(entry_attrs)
|
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
return dn
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2010-10-05 21:00:40 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2011-12-07 01:50:31 -06:00
|
|
|
if dns_container_exists(ldap):
|
|
|
|
try:
|
2010-11-23 16:47:29 -06:00
|
|
|
parts = keys[-1].split('.')
|
2012-02-24 07:15:24 -06:00
|
|
|
host = parts[0]
|
2010-11-23 16:47:29 -06:00
|
|
|
domain = unicode('.'.join(parts[1:]))
|
2011-01-31 08:30:43 -06:00
|
|
|
|
2012-02-24 07:15:24 -06:00
|
|
|
if options.get('ip_address'):
|
|
|
|
add_reverse = not options.get('no_reverse', False)
|
2011-01-28 07:25:47 -06:00
|
|
|
|
2014-06-10 08:57:30 -05:00
|
|
|
add_records_for_host(DNSName(host),
|
|
|
|
DNSName(domain).make_absolute(),
|
2014-05-16 05:21:04 -05:00
|
|
|
options['ip_address'],
|
2012-02-24 07:15:24 -06:00
|
|
|
add_forward=True,
|
|
|
|
add_reverse=add_reverse)
|
2011-12-07 01:50:31 -06:00
|
|
|
del options['ip_address']
|
|
|
|
|
|
|
|
update_sshfp_record(domain, unicode(parts[0]), entry_attrs)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2018-01-30 05:49:35 -06:00
|
|
|
self.add_message(messages.FailedToAddHostDNSRecords(reason=e))
|
2010-10-05 21:00:40 -05:00
|
|
|
if options.get('random', False):
|
|
|
|
try:
|
2018-01-30 05:49:35 -06:00
|
|
|
entry_attrs['randompassword'] = unicode(
|
|
|
|
getattr(context, 'randompassword'))
|
2010-10-05 21:00:40 -05:00
|
|
|
except AttributeError:
|
|
|
|
# On the off-chance some other extension deletes this from the
|
|
|
|
# context, don't crash.
|
|
|
|
pass
|
2010-11-05 14:16:53 -05:00
|
|
|
set_certificate_attrs(entry_attrs)
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2011-06-13 09:23:09 -05:00
|
|
|
|
|
|
|
if options.get('all', False):
|
2011-12-07 01:50:31 -06:00
|
|
|
entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
|
2011-08-22 15:24:07 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
|
|
|
if entry_attrs['has_password']:
|
|
|
|
# If an OTP is set there is no keytab, at least not one
|
|
|
|
# fetched anywhere.
|
|
|
|
entry_attrs['has_keytab'] = False
|
2011-06-13 09:23:09 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
convert_sshpubkey_post(entry_attrs)
|
2011-12-07 01:50:31 -06:00
|
|
|
|
2010-10-05 21:00:40 -05:00
|
|
|
return dn
|
|
|
|
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host_del(LDAPDelete):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Delete a host.')
|
2009-12-09 10:09:53 -06:00
|
|
|
|
|
|
|
msg_summary = _('Deleted host "%(value)s"')
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2014-08-05 02:12:24 -05:00
|
|
|
takes_options = LDAPDelete.takes_options + (
|
2010-11-23 16:47:29 -06:00
|
|
|
Flag('updatedns?',
|
2016-04-01 05:02:11 -05:00
|
|
|
doc=_('Remove A, AAAA, SSHFP and PTR records of the host(s) '
|
|
|
|
'managed by IPA DNS'),
|
2010-11-23 16:47:29 -06:00
|
|
|
default=False,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
def pre_callback(self, ldap, dn, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2021-06-15 05:47:43 -05:00
|
|
|
fqdn = resolve_fqdn(keys[-1])
|
2012-02-22 16:42:38 -06:00
|
|
|
host_is_master(ldap, fqdn)
|
2009-05-27 08:55:49 -05:00
|
|
|
# Remove all service records for this host
|
2009-09-15 07:01:58 -05:00
|
|
|
truncated = True
|
|
|
|
while truncated:
|
|
|
|
try:
|
2021-03-17 12:48:10 -05:00
|
|
|
ret = api.Command['service_find'](fqdn, pkey_only=True)
|
2009-12-09 10:09:53 -06:00
|
|
|
truncated = ret['truncated']
|
|
|
|
services = ret['result']
|
2009-09-15 07:01:58 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
break
|
|
|
|
else:
|
2009-12-09 10:09:53 -06:00
|
|
|
for entry_attrs in services:
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = kerberos.Principal(
|
|
|
|
entry_attrs['krbprincipalname'][0])
|
|
|
|
hostname = principal.hostname
|
2010-03-29 10:31:10 -05:00
|
|
|
if hostname.lower() == fqdn:
|
2009-09-15 07:01:58 -05:00
|
|
|
api.Command['service_del'](principal)
|
2010-11-23 16:47:29 -06:00
|
|
|
updatedns = options.get('updatedns', False)
|
|
|
|
if updatedns:
|
|
|
|
try:
|
|
|
|
updatedns = dns_container_exists(ldap)
|
|
|
|
except errors.NotFound:
|
|
|
|
updatedns = False
|
|
|
|
|
|
|
|
if updatedns:
|
2016-04-01 05:45:57 -05:00
|
|
|
# Remove A, AAAA, SSHFP and PTR records of the host
|
2016-07-21 06:18:34 -05:00
|
|
|
fqdn_dnsname = DNSName(fqdn).make_absolute()
|
2020-08-28 08:31:10 -05:00
|
|
|
zone = DNSName(zone_for_name(fqdn_dnsname))
|
2016-07-21 06:18:34 -05:00
|
|
|
relative_hostname = fqdn_dnsname.relativize(zone)
|
|
|
|
|
2016-04-01 05:45:57 -05:00
|
|
|
# Get all resources for this host
|
2016-03-02 06:29:27 -06:00
|
|
|
rec_removed = False
|
2012-02-28 02:13:13 -06:00
|
|
|
try:
|
2016-03-03 04:26:15 -06:00
|
|
|
record = api.Command['dnsrecord_show'](
|
2016-07-21 06:18:34 -05:00
|
|
|
zone, relative_hostname)['result']
|
2012-02-28 02:13:13 -06:00
|
|
|
except errors.NotFound:
|
2016-03-02 06:29:27 -06:00
|
|
|
pass
|
2016-03-02 08:53:27 -06:00
|
|
|
else:
|
2016-04-01 05:45:57 -05:00
|
|
|
# remove PTR records first
|
|
|
|
for attr in ('arecord', 'aaaarecord'):
|
2016-03-03 04:26:15 -06:00
|
|
|
for val in record.get(attr, []):
|
2016-03-02 06:29:27 -06:00
|
|
|
rec_removed = (
|
2016-07-21 06:18:34 -05:00
|
|
|
remove_ptr_rec(val, fqdn_dnsname) or
|
2016-03-02 06:29:27 -06:00
|
|
|
rec_removed
|
|
|
|
)
|
2016-04-01 05:45:57 -05:00
|
|
|
try:
|
|
|
|
# remove all A, AAAA, SSHFP records of the host
|
|
|
|
api.Command['dnsrecord_mod'](
|
2016-07-21 06:18:34 -05:00
|
|
|
zone,
|
2016-04-01 05:45:57 -05:00
|
|
|
record['idnsname'][0],
|
|
|
|
arecord=[],
|
|
|
|
aaaarecord=[],
|
|
|
|
sshfprecord=[]
|
|
|
|
)
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
pass
|
2016-03-02 06:29:27 -06:00
|
|
|
else:
|
|
|
|
rec_removed = True
|
|
|
|
|
|
|
|
if not rec_removed:
|
|
|
|
self.add_message(
|
|
|
|
messages.FailedToRemoveHostDNSRecords(
|
|
|
|
host=fqdn,
|
|
|
|
reason=_("No A, AAAA, SSHFP or PTR records found.")
|
|
|
|
)
|
|
|
|
)
|
2010-11-23 16:47:29 -06:00
|
|
|
|
2014-10-13 07:30:15 -05:00
|
|
|
if self.api.Command.ca_is_enabled()['result']:
|
2021-05-20 10:22:41 -05:00
|
|
|
certs = self.api.Command.cert_find(host=keys)['result']
|
2016-08-26 00:31:13 -05:00
|
|
|
revoke_certs(certs)
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
return dn
|
2009-05-27 08:55:49 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host_mod(LDAPUpdate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify information about a host.')
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
has_output_params = LDAPUpdate.has_output_params + host_output_params
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = _('Modified host "%(value)s"')
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
takes_options = LDAPUpdate.takes_options + (
|
2011-12-07 01:50:31 -06:00
|
|
|
Flag('updatedns?',
|
|
|
|
doc=_('Update DNS entries'),
|
|
|
|
default=False,
|
|
|
|
),
|
2009-09-14 16:04:08 -05:00
|
|
|
)
|
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2021-06-15 05:47:43 -05:00
|
|
|
fqdn = resolve_fqdn(keys[-1])
|
2011-09-08 12:47:37 -05:00
|
|
|
# Allow an existing OTP to be reset but don't allow a OTP to be
|
|
|
|
# added to an enrolled host.
|
2012-06-26 08:23:55 -05:00
|
|
|
if options.get('userpassword') or options.get('random'):
|
2011-09-08 12:47:37 -05:00
|
|
|
entry = {}
|
|
|
|
self.obj.get_password_attributes(ldap, dn, entry)
|
|
|
|
if not entry['has_password'] and entry['has_keytab']:
|
2014-08-01 05:08:15 -05:00
|
|
|
raise errors.ValidationError(
|
|
|
|
name='password',
|
|
|
|
error=_('Password cannot be set on enrolled host.'))
|
2011-09-08 12:47:37 -05:00
|
|
|
|
2009-09-14 16:04:08 -05:00
|
|
|
# Once a principal name is set it cannot be changed
|
2011-02-15 14:04:40 -06:00
|
|
|
if 'cn' in entry_attrs:
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.ACIError(info=_('cn is immutable'))
|
2010-01-12 13:09:17 -06:00
|
|
|
if 'locality' in entry_attrs:
|
|
|
|
entry_attrs['l'] = entry_attrs['locality']
|
2009-09-14 16:04:08 -05:00
|
|
|
if 'krbprincipalname' in entry_attrs:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs_old = ldap.get_entry(
|
2009-09-15 07:01:58 -05:00
|
|
|
dn, ['objectclass', 'krbprincipalname']
|
|
|
|
)
|
|
|
|
if 'krbprincipalname' in entry_attrs_old:
|
|
|
|
msg = 'Principal name already set, it is unchangeable.'
|
|
|
|
raise errors.ACIError(info=msg)
|
|
|
|
obj_classes = entry_attrs_old['objectclass']
|
2017-05-11 08:26:03 -05:00
|
|
|
if 'krbprincipalaux' not in (item.lower() for item in
|
|
|
|
obj_classes):
|
2009-09-15 07:01:58 -05:00
|
|
|
obj_classes.append('krbprincipalaux')
|
|
|
|
entry_attrs['objectclass'] = obj_classes
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2015-05-27 07:02:08 -05:00
|
|
|
# verify certificates
|
|
|
|
certs = entry_attrs.get('usercertificate') or []
|
|
|
|
|
|
|
|
# revoke removed certificates
|
2016-09-07 04:00:18 -05:00
|
|
|
ca_is_enabled = self.api.Command.ca_is_enabled()['result']
|
|
|
|
if 'usercertificate' in options and ca_is_enabled:
|
2015-06-03 06:11:58 -05:00
|
|
|
try:
|
|
|
|
entry_attrs_old = ldap.get_entry(dn, ['usercertificate'])
|
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(*keys)
|
2015-05-27 07:02:08 -05:00
|
|
|
old_certs = entry_attrs_old.get('usercertificate', [])
|
2017-08-23 08:23:43 -05:00
|
|
|
removed_certs = set(old_certs) - set(certs)
|
|
|
|
for cert in removed_certs:
|
2019-01-25 09:18:59 -06:00
|
|
|
rm_certs = api.Command.cert_find(
|
|
|
|
certificate=cert,
|
|
|
|
host=keys)['result']
|
2016-08-26 00:31:13 -05:00
|
|
|
revoke_certs(rm_certs)
|
2015-06-23 06:40:30 -05:00
|
|
|
|
2015-06-03 06:11:58 -05:00
|
|
|
if certs:
|
2017-07-03 10:10:34 -05:00
|
|
|
entry_attrs['usercertificate'] = certs
|
2011-12-07 01:50:31 -06:00
|
|
|
|
2011-11-14 10:03:44 -06:00
|
|
|
if options.get('random'):
|
2016-12-21 08:07:34 -06:00
|
|
|
entry_attrs['userpassword'] = ipa_generate_password(
|
|
|
|
entropy_bits=TMP_PWD_ENTROPY_BITS)
|
2011-11-14 10:03:44 -06:00
|
|
|
setattr(context, 'randompassword', entry_attrs['userpassword'])
|
2013-03-18 06:31:23 -05:00
|
|
|
|
2012-01-20 14:10:44 -06:00
|
|
|
if 'macaddress' in entry_attrs:
|
|
|
|
if 'objectclass' in entry_attrs:
|
|
|
|
obj_classes = entry_attrs['objectclass']
|
|
|
|
else:
|
2013-10-31 11:54:21 -05:00
|
|
|
_entry_attrs = ldap.get_entry(dn, ['objectclass'])
|
2012-01-20 14:10:44 -06:00
|
|
|
obj_classes = _entry_attrs['objectclass']
|
2017-05-11 08:26:03 -05:00
|
|
|
if 'ieee802device' not in (item.lower() for item in obj_classes):
|
2012-01-20 14:10:44 -06:00
|
|
|
obj_classes.append('ieee802device')
|
|
|
|
entry_attrs['objectclass'] = obj_classes
|
2010-10-05 21:00:40 -05:00
|
|
|
|
2011-12-07 01:50:31 -06:00
|
|
|
if options.get('updatedns', False) and dns_container_exists(ldap):
|
2021-06-15 05:47:43 -05:00
|
|
|
parts = fqdn.split('.')
|
2011-12-07 01:50:31 -06:00
|
|
|
domain = unicode('.'.join(parts[1:]))
|
2012-02-28 02:13:13 -06:00
|
|
|
try:
|
|
|
|
result = api.Command['dnszone_show'](domain)['result']
|
|
|
|
domain = result['idnsname'][0]
|
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(*keys)
|
2011-12-07 01:50:31 -06:00
|
|
|
update_sshfp_record(domain, unicode(parts[0]), entry_attrs)
|
|
|
|
|
|
|
|
if 'ipasshpubkey' in entry_attrs:
|
|
|
|
if 'objectclass' in entry_attrs:
|
|
|
|
obj_classes = entry_attrs['objectclass']
|
|
|
|
else:
|
2013-10-31 11:54:21 -05:00
|
|
|
_entry_attrs = ldap.get_entry(dn, ['objectclass'])
|
2011-12-07 01:50:31 -06:00
|
|
|
obj_classes = entry_attrs['objectclass'] = _entry_attrs['objectclass']
|
2017-05-11 08:26:03 -05:00
|
|
|
if 'ipasshhost' not in (item.lower() for item in obj_classes):
|
2011-12-07 01:50:31 -06:00
|
|
|
obj_classes.append('ipasshhost')
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
update_krbticketflags(ldap, entry_attrs, attrs_list, options, True)
|
|
|
|
|
|
|
|
if 'krbticketflags' in entry_attrs:
|
|
|
|
if 'objectclass' not in entry_attrs:
|
|
|
|
entry_attrs_old = ldap.get_entry(dn, ['objectclass'])
|
|
|
|
entry_attrs['objectclass'] = entry_attrs_old['objectclass']
|
2017-05-11 08:26:03 -05:00
|
|
|
if 'krbticketpolicyaux' not in (item.lower() for item in
|
|
|
|
entry_attrs['objectclass']):
|
2013-03-18 06:31:23 -05:00
|
|
|
entry_attrs['objectclass'].append('krbticketpolicyaux')
|
|
|
|
|
2016-06-21 13:19:03 -05:00
|
|
|
if 'krbprincipalauthind' in entry_attrs:
|
|
|
|
if 'objectclass' not in entry_attrs:
|
|
|
|
entry_attrs_old = ldap.get_entry(dn, ['objectclass'])
|
|
|
|
entry_attrs['objectclass'] = entry_attrs_old['objectclass']
|
2017-05-11 08:26:03 -05:00
|
|
|
if 'krbprincipalaux' not in (item.lower() for item in
|
|
|
|
entry_attrs['objectclass']):
|
2016-06-21 13:19:03 -05:00
|
|
|
entry_attrs['objectclass'].append('krbprincipalaux')
|
2021-03-08 11:15:50 -06:00
|
|
|
validate_auth_indicator(entry_attrs)
|
2016-06-21 13:19:03 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
add_sshpubkey_to_attrs_pre(self.context, attrs_list)
|
|
|
|
|
2010-10-05 21:00:40 -05:00
|
|
|
return dn
|
2009-12-16 15:04:53 -06:00
|
|
|
|
2010-10-05 21:00:40 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-10-05 21:00:40 -05:00
|
|
|
if options.get('random', False):
|
|
|
|
entry_attrs['randompassword'] = unicode(getattr(context, 'randompassword'))
|
2010-11-05 14:16:53 -05:00
|
|
|
set_certificate_attrs(entry_attrs)
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2011-08-25 08:24:47 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
|
|
|
if entry_attrs['has_password']:
|
|
|
|
# If an OTP is set there is no keytab, at least not one
|
|
|
|
# fetched anywhere.
|
|
|
|
entry_attrs['has_keytab'] = False
|
2011-06-13 09:23:09 -05:00
|
|
|
|
|
|
|
if options.get('all', False):
|
|
|
|
entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
|
|
|
|
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2011-09-14 15:33:33 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
convert_sshpubkey_post(entry_attrs)
|
|
|
|
remove_sshpubkey_from_output_post(self.context, entry_attrs)
|
2014-12-02 08:40:40 -06:00
|
|
|
convert_ipaassignedidview_post(entry_attrs, options)
|
2011-12-07 01:50:31 -06:00
|
|
|
|
2009-09-15 07:01:58 -05:00
|
|
|
return dn
|
2009-05-27 08:55:49 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host_find(LDAPSearch):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Search for hosts.')
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
has_output_params = LDAPSearch.has_output_params + host_output_params
|
2009-12-09 10:09:53 -06:00
|
|
|
msg_summary = ngettext(
|
2011-02-23 15:47:49 -06:00
|
|
|
'%(count)d host matched', '%(count)d hosts matched', 0
|
2009-12-09 10:09:53 -06:00
|
|
|
)
|
2011-01-04 14:15:54 -06:00
|
|
|
member_attributes = ['memberof', 'enrolledby', 'managedby']
|
2009-12-09 10:09:53 -06:00
|
|
|
|
2012-01-26 06:41:39 -06:00
|
|
|
def get_options(self):
|
|
|
|
for option in super(host_find, self).get_options():
|
|
|
|
yield option
|
|
|
|
# "managing" membership has to be added and processed separately
|
|
|
|
for option in self.get_member_options('managing'):
|
|
|
|
yield option
|
|
|
|
|
2010-11-23 08:02:54 -06:00
|
|
|
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(base_dn, DN)
|
2010-01-12 13:09:17 -06:00
|
|
|
if 'locality' in attrs_list:
|
|
|
|
attrs_list.remove('locality')
|
|
|
|
attrs_list.append('l')
|
2012-01-26 06:41:39 -06:00
|
|
|
if 'man_host' in options or 'not_man_host' in options:
|
|
|
|
hosts = []
|
|
|
|
if options.get('man_host') is not None:
|
|
|
|
for pkey in options.get('man_host', []):
|
|
|
|
dn = self.obj.get_dn(pkey)
|
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = ldap.get_entry(dn, ['managedby'])
|
2012-01-26 06:41:39 -06:00
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(pkey)
|
2012-01-26 06:41:39 -06:00
|
|
|
hosts.append(set(entry_attrs.get('managedby', '')))
|
|
|
|
hosts = list(reduce(lambda s1, s2: s1 & s2, hosts))
|
|
|
|
|
|
|
|
if not hosts:
|
|
|
|
# There is no host managing _all_ hosts in --man-hosts
|
|
|
|
filter = ldap.combine_filters(
|
|
|
|
(filter, '(objectclass=disabled)'), ldap.MATCH_ALL
|
|
|
|
)
|
|
|
|
|
|
|
|
not_hosts = []
|
|
|
|
if options.get('not_man_host') is not None:
|
|
|
|
for pkey in options.get('not_man_host', []):
|
|
|
|
dn = self.obj.get_dn(pkey)
|
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = ldap.get_entry(dn, ['managedby'])
|
2012-01-26 06:41:39 -06:00
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(pkey)
|
2012-01-26 06:41:39 -06:00
|
|
|
not_hosts += entry_attrs.get('managedby', [])
|
|
|
|
not_hosts = list(set(not_hosts))
|
|
|
|
|
|
|
|
for target_hosts, filter_op in ((hosts, ldap.MATCH_ANY),
|
|
|
|
(not_hosts, ldap.MATCH_NONE)):
|
|
|
|
hosts_avas = [DN(host)[0][0] for host in target_hosts]
|
2014-08-01 05:08:15 -05:00
|
|
|
hosts_filters = [ldap.make_filter_from_attr(ava.attr, ava.value)
|
|
|
|
for ava in hosts_avas]
|
2012-01-26 06:41:39 -06:00
|
|
|
hosts_filter = ldap.combine_filters(hosts_filters, filter_op)
|
|
|
|
|
|
|
|
filter = ldap.combine_filters(
|
|
|
|
(filter, hosts_filter), ldap.MATCH_ALL
|
|
|
|
)
|
|
|
|
|
2019-08-01 12:53:44 -05:00
|
|
|
if not options.get('pkey_only', False):
|
|
|
|
add_sshpubkey_to_attrs_pre(self.context, attrs_list)
|
2016-03-14 11:42:56 -05:00
|
|
|
|
2010-11-23 08:02:54 -06:00
|
|
|
return (filter.replace('locality', 'l'), base_dn, scope)
|
2010-01-12 13:09:17 -06:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
def post_callback(self, ldap, entries, truncated, *args, **options):
|
2011-10-26 04:12:38 -05:00
|
|
|
if options.get('pkey_only', False):
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2013-10-31 11:54:21 -05:00
|
|
|
for entry_attrs in entries:
|
2016-06-09 06:13:24 -05:00
|
|
|
hostname = entry_attrs['fqdn']
|
|
|
|
if isinstance(hostname, (tuple, list)):
|
|
|
|
hostname = hostname[0]
|
|
|
|
try:
|
|
|
|
set_certificate_attrs(entry_attrs)
|
|
|
|
except errors.CertificateFormatError as e:
|
|
|
|
self.add_message(
|
|
|
|
messages.CertificateInvalid(
|
|
|
|
subject=hostname,
|
|
|
|
reason=e,
|
|
|
|
)
|
|
|
|
)
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.error("Invalid certificate: %s", e)
|
2016-06-09 06:13:24 -05:00
|
|
|
del(entry_attrs['usercertificate'])
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2011-06-13 09:23:09 -05:00
|
|
|
if options.get('all', False):
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs['managing'] = self.obj.get_managed_hosts(entry_attrs.dn)
|
2011-06-13 09:23:09 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
convert_sshpubkey_post(entry_attrs)
|
2014-12-02 08:40:40 -06:00
|
|
|
convert_ipaassignedidview_post(entry_attrs, options)
|
2011-12-07 01:50:31 -06:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
remove_sshpubkey_from_output_list_post(self.context, entries)
|
|
|
|
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
|
|
|
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-09-15 07:01:58 -05:00
|
|
|
class host_show(LDAPRetrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Display information about a host.')
|
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
has_output_params = LDAPRetrieve.has_output_params + host_output_params
|
2010-12-10 09:53:20 -06:00
|
|
|
takes_options = LDAPRetrieve.takes_options + (
|
|
|
|
Str('out?',
|
|
|
|
doc=_('file to store certificate in'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
add_sshpubkey_to_attrs_pre(self.context, attrs_list)
|
|
|
|
return dn
|
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2011-08-22 15:24:07 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
|
|
|
if entry_attrs['has_password']:
|
|
|
|
# If an OTP is set there is no keytab, at least not one
|
|
|
|
# fetched anywhere.
|
2010-07-12 16:45:06 -05:00
|
|
|
entry_attrs['has_keytab'] = False
|
|
|
|
|
2016-06-09 06:13:24 -05:00
|
|
|
hostname = entry_attrs['fqdn']
|
|
|
|
if isinstance(hostname, (tuple, list)):
|
|
|
|
hostname = hostname[0]
|
|
|
|
try:
|
|
|
|
set_certificate_attrs(entry_attrs)
|
|
|
|
except errors.CertificateFormatError as e:
|
|
|
|
self.add_message(
|
|
|
|
messages.CertificateInvalid(
|
|
|
|
subject=hostname,
|
|
|
|
reason=e,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
del(entry_attrs['usercertificate'])
|
|
|
|
|
2013-03-18 06:31:23 -05:00
|
|
|
set_kerberos_attrs(entry_attrs, options)
|
2014-10-02 09:57:08 -05:00
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
2010-10-15 23:40:38 -05:00
|
|
|
|
2011-06-13 09:23:09 -05:00
|
|
|
if options.get('all', False):
|
|
|
|
entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
|
|
|
|
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2011-09-14 15:33:33 -05:00
|
|
|
|
2016-03-14 11:42:56 -05:00
|
|
|
convert_sshpubkey_post(entry_attrs)
|
|
|
|
remove_sshpubkey_from_output_post(self.context, entry_attrs)
|
2014-12-02 08:40:40 -06:00
|
|
|
convert_ipaassignedidview_post(entry_attrs, options)
|
2011-12-07 01:50:31 -06:00
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
return dn
|
2009-05-27 08:55:49 -05:00
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2010-07-12 16:45:06 -05:00
|
|
|
class host_disable(LDAPQuery):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Disable the Kerberos key, SSL certificate and all services of a host.')
|
|
|
|
|
2010-07-12 16:45:06 -05:00
|
|
|
has_output = output.standard_value
|
2011-02-16 03:35:49 -06:00
|
|
|
msg_summary = _('Disabled host "%(value)s"')
|
2010-07-12 16:45:06 -05:00
|
|
|
|
|
|
|
def execute(self, *keys, **options):
|
|
|
|
ldap = self.obj.backend
|
|
|
|
|
2021-06-15 05:47:43 -05:00
|
|
|
fqdn = resolve_fqdn(keys[-1])
|
2012-03-19 09:16:49 -05:00
|
|
|
host_is_master(ldap, fqdn)
|
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
# See if we actually do anthing here, and if not raise an exception
|
|
|
|
done_work = False
|
|
|
|
|
|
|
|
truncated = True
|
|
|
|
while truncated:
|
|
|
|
try:
|
2021-03-17 12:48:10 -05:00
|
|
|
ret = api.Command['service_find'](fqdn, pkey_only=True)
|
2010-11-05 14:16:53 -05:00
|
|
|
truncated = ret['truncated']
|
|
|
|
services = ret['result']
|
|
|
|
except errors.NotFound:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
for entry_attrs in services:
|
2016-06-23 11:54:49 -05:00
|
|
|
principal = kerberos.Principal(
|
|
|
|
entry_attrs['krbprincipalname'][0])
|
|
|
|
hostname = principal.hostname
|
2010-11-05 14:16:53 -05:00
|
|
|
if hostname.lower() == fqdn:
|
|
|
|
try:
|
|
|
|
api.Command['service_disable'](principal)
|
|
|
|
done_work = True
|
|
|
|
except errors.AlreadyInactive:
|
|
|
|
pass
|
2013-03-28 08:48:28 -05:00
|
|
|
|
|
|
|
dn = self.obj.get_dn(*keys, **options)
|
|
|
|
try:
|
2013-10-31 11:54:21 -05:00
|
|
|
entry_attrs = ldap.get_entry(dn, ['usercertificate'])
|
2013-03-28 08:48:28 -05:00
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.obj.handle_not_found(*keys)
|
2015-05-27 07:02:08 -05:00
|
|
|
if self.api.Command.ca_is_enabled()['result']:
|
2016-08-26 00:31:13 -05:00
|
|
|
certs = self.api.Command.cert_find(host=keys)['result']
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2015-05-27 07:02:08 -05:00
|
|
|
if certs:
|
2016-08-26 00:31:13 -05:00
|
|
|
revoke_certs(certs)
|
2015-05-27 07:02:08 -05:00
|
|
|
# Remove the usercertificate altogether
|
|
|
|
entry_attrs['usercertificate'] = None
|
|
|
|
ldap.update_entry(entry_attrs)
|
|
|
|
done_work = True
|
2010-11-05 14:16:53 -05:00
|
|
|
|
2011-08-22 15:24:07 -05:00
|
|
|
self.obj.get_password_attributes(ldap, dn, entry_attrs)
|
|
|
|
if entry_attrs['has_keytab']:
|
2010-11-05 14:16:53 -05:00
|
|
|
ldap.remove_principal_key(dn)
|
|
|
|
done_work = True
|
2010-07-12 16:45:06 -05:00
|
|
|
|
2010-11-05 14:16:53 -05:00
|
|
|
if not done_work:
|
|
|
|
raise errors.AlreadyInactive()
|
2010-07-12 16:45:06 -05:00
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=True,
|
2014-03-27 08:04:00 -05:00
|
|
|
value=pkey_to_value(keys[0], options),
|
2010-07-12 16:45:06 -05:00
|
|
|
)
|
|
|
|
|
2011-09-14 15:33:33 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2011-09-14 15:33:33 -05:00
|
|
|
return dn
|
|
|
|
|
2010-11-10 15:47:29 -06:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2010-11-10 15:47:29 -06:00
|
|
|
class host_add_managedby(LDAPAddMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Add hosts that can manage this host.')
|
|
|
|
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
|
|
|
has_output_params = LDAPAddMember.has_output_params + host_output_params
|
2011-01-10 13:21:45 -06:00
|
|
|
allow_same = True
|
2010-11-10 15:47:29 -06:00
|
|
|
|
2011-09-14 15:33:33 -05:00
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2011-09-14 15:33:33 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
2010-11-10 15:47:29 -06:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2010-11-10 15:47:29 -06:00
|
|
|
class host_remove_managedby(LDAPRemoveMember):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Remove hosts that can manage this host.')
|
|
|
|
|
2010-11-10 15:47:29 -06:00
|
|
|
member_attributes = ['managedby']
|
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + host_output_params
|
|
|
|
|
2011-09-14 15:33:33 -05:00
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2013-06-25 08:08:18 -05:00
|
|
|
self.obj.suppress_netgroup_memberof(ldap, entry_attrs)
|
2011-09-14 15:33:33 -05:00
|
|
|
return (completed, dn)
|
|
|
|
|
2014-10-02 09:57:08 -05:00
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_allow_retrieve_keytab(LDAPAddMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Allow users, groups, hosts or host groups to retrieve a keytab'
|
|
|
|
' of this host.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_read_keys']
|
|
|
|
has_output_params = LDAPAddMember.has_output_params + host_output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
add_missing_object_class(ldap, u'ipaallowedoperations', dn)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_disallow_retrieve_keytab(LDAPRemoveMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Disallow users, groups, hosts or host groups to retrieve a '
|
|
|
|
'keytab of this host.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_read_keys']
|
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + host_output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_allow_create_keytab(LDAPAddMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Allow users, groups, hosts or host groups to create a keytab '
|
|
|
|
'of this host.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_write_keys']
|
|
|
|
has_output_params = LDAPAddMember.has_output_params + host_output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
add_missing_object_class(ldap, u'ipaallowedoperations', dn)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
|
|
|
return (completed, dn)
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_disallow_create_keytab(LDAPRemoveMember):
|
2014-12-01 03:15:21 -06:00
|
|
|
__doc__ = _('Disallow users, groups, hosts or host groups to create a '
|
|
|
|
'keytab of this host.')
|
2014-10-02 09:57:08 -05:00
|
|
|
member_attributes = ['ipaallowedtoperform_write_keys']
|
|
|
|
has_output_params = LDAPRemoveMember.has_output_params + host_output_params
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_to_ldap(found)
|
|
|
|
rename_ipaallowedtoperform_to_ldap(not_found)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
|
|
|
|
rename_ipaallowedtoperform_from_ldap(entry_attrs, options)
|
|
|
|
rename_ipaallowedtoperform_from_ldap(failed, options)
|
|
|
|
return (completed, dn)
|
2015-06-23 06:42:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2016-06-23 12:14:53 -05:00
|
|
|
class host_add_cert(LDAPAddAttributeViaOption):
|
2015-06-23 06:42:01 -05:00
|
|
|
__doc__ = _('Add certificates to host entry')
|
|
|
|
msg_summary = _('Added certificates to host "%(value)s"')
|
|
|
|
attribute = 'usercertificate'
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
2016-06-23 12:14:53 -05:00
|
|
|
class host_remove_cert(LDAPRemoveAttributeViaOption):
|
2015-06-23 06:42:01 -05:00
|
|
|
__doc__ = _('Remove certificates from host entry')
|
|
|
|
msg_summary = _('Removed certificates from host "%(value)s"')
|
|
|
|
attribute = 'usercertificate'
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
|
|
|
assert isinstance(dn, DN)
|
|
|
|
|
2016-08-26 00:31:13 -05:00
|
|
|
for cert in options.get('usercertificate', []):
|
2019-01-25 09:18:59 -06:00
|
|
|
revoke_certs(api.Command.cert_find(
|
|
|
|
certificate=cert,
|
|
|
|
host=keys)['result'])
|
2015-06-23 06:42:01 -05:00
|
|
|
|
|
|
|
return dn
|
2016-06-23 13:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_add_principal(LDAPAddAttribute):
|
|
|
|
__doc__ = _('Add new principal alias to host entry')
|
|
|
|
msg_summary = _('Added new aliases to host "%(value)s"')
|
|
|
|
attribute = 'krbprincipalname'
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
|
|
|
util.check_principal_realm_in_trust_namespace(self.api, *keys)
|
|
|
|
util.ensure_krbcanonicalname_set(ldap, entry_attrs)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
class host_remove_principal(LDAPRemoveAttribute):
|
|
|
|
__doc__ = _('Remove principal alias from a host entry')
|
|
|
|
msg_summary = _('Removed aliases from host "%(value)s"')
|
|
|
|
attribute = 'krbprincipalname'
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
|
|
|
util.ensure_last_krbprincipalname(ldap, entry_attrs, *keys)
|
|
|
|
return dn
|