This package provides a standalone LDAP syncer. For more information
on how to execute it, run python -m ldap_sync --help
.
The process is separated into the following steps:
Fetch the users/groups/properties we want to sync from the database
(ldap_sync.sources.db
)
Fetch the current users/groups/properties from the ldap (ldap_sync.sources.ldap
)
Create a diff (ldap_sync.diff_records
)
Execute the actions (ldap_sync.execution
)
Actions (Add/Delete/Modify/Nothing)
Base class for the different actions the exporter can execute on an individual entity.
An action in the sense of the LDAP export is something which
refers to a record (i.e. something with a DN)
can be executed (provided an LDAP connection).
Add an LDAP record
Modify an LDAP record by changing its attributes.
a dict with entries of the form 'attribute_name': new_value
,
where the value is a list if the corresponding attribute is not single-valued.
Delete an LDAP record.
Do nothing.
Create a new record with a dn and certain attributes.
A record represents an entry which is to be synced to the LDAP, and consists of a dn and relevant attributes. Constructors are provided for SQLAlchemy ORM objects as well as entries of an ldap search response.
Create a new user record with a dn and certain attributes.
Create a new groupOfMembers record with a dn and certain attributes. Used to represent groups and properties.
A Class representing the state (current, desired) of a record.
This class is essentially a duple consisting of a current and desired record to represent the difference.
Type aliases, NewTypes
, etc.
This module is responsible for fetching the list of desired records from the DB. Most prominently:
Fetch all groups together with all members
session¶ – The SQLAlchemy session to use
An iterable of (Group, members) ResultProxies.
Fetch the groups who should be synced.
Explicitly, this returns everything in EXPORTED_PROPERTIES
together with
the current users having the respective property as members.
session¶ – The SQLAlchemy session to use
An iterable of (property_name, members) ResultProxies.
Fetch users to be synced, plus whether ldap_login_enabled
is set.
If the ldap_login_enabled
flag is not present,
we interpret this as should_be_blocked
.
Fetch the groups to be synced (in the form of GroupRecords
).
Fetch the properties to be synced (in the form of GroupRecords
).
Fetch the users to be synced (in the form of UserRecords
).
The properties of a user we export to LDAP.
SyncConfig(db_uri, host, port, use_ssl, ca_certs_file, ca_certs_data, bind_dn, bind_pw, base_dn, required_property)
db_uri (str
) – Alias for field number 0
host (str
) – Alias for field number 1
port (int
) – Alias for field number 2
use_ssl (bool
) – Alias for field number 3
ca_certs_file (Optional
[str
]) – Alias for field number 4
ca_certs_data (Optional
[str
]) – Alias for field number 5
bind_pw (str
) – Alias for field number 7
required_property (str
) – Alias for field number 9
Fetch the config from the environments, filling in defaults as specified.
Values are converted in accordance to the types hints of SyncConfig
.
The environment variables need to be of the format is PYCROFT_LDAP_$VAR
, e.g.
PYCROFT_LDAP_PORT
.
See get_config()
Converts DB information to concepts.record.Record
instances.
Execution strategies for an Action
.
Concretely, the real one and the dry-run.
Communicate whether the last operation on connection has been successful.
Determine which attributes need to be updated.
This function doesn’t check whether both dicts have equal
keys, meaning keys not given in desired_attrs
won’t end up in the modification dict. Removing attributes
has to be done by explicitly setting them to an empty string.
Like diff_attributes()
, but aware of the
ppolicy overlay.
Determines an action to take, given a desired and a current record.