Project to sync LDAP users / groups to PostgreSQL
Project description
PostgreSQL-LDAP Sync
LDAP is often used for a centralized user and role management in an enterprise environment. PostgreSQL offers LDAP as one of its authentication methods, but the users must already exist in the database, before the authentication can be used. There is currently no direct authorization of database users on LDAP, so roles and memberships have to be administered twice.
This program helps to solve the issue by synchronizing users, groups and their memberships from LDAP to PostgreSQL, where access to LDAP is read-only.
It is meant to run as a cron job.
🧑💻 Usage
-
Install the package from PyPi:
pip install postgresql-ldap-sync
-
Import and build the Synchronizer object:
from postgresql_ldap_sync.clients import DefaultPostgresClient from postgresql_ldap_sync.clients import GLAuthClient from postgresql_ldap_sync.matcher import DefaultMatcher from postgresql_ldap_sync.syncher import Synchronizer ldap_client = GLAuthClient(...) psql_client = DefaultPostgresClient(...) matcher = DefaultMatcher(...) syncher = Synchronizer( ldap_client=ldap_client, psql_client=psql_client, entity_matcher=matcher, )
-
Define the actions the synchronizer is allowed to take:
user_actions = ["CREATE", "KEEP"] group_actions = ["CREATE", "KEEP"] member_actions = ["GRANT", "REVOKE", "KEEP"]
-
Run the synchronizer, as a cron-job:
import time while True: syncher.sync_users(user_actions) syncher.sync_groups(group_actions) syncher.sync_group_memberships(member_actions) time.sleep(30)
🔧 Development
Dependencies
In order to install all the development packages:
poetry install --all-extras
Linting
All Python files are linted using Ruff, to run it:
tox -e lint
Testing
Project testing is performed using Pytest, to run them:
tox -e unit
export GLAUTH_USERNAME="..."
export GLAUTH_PASSWORD="..."
export POSTGRES_DATABASE="..."
export POSTGRES_USERNAME="..."
export POSTGRES_PASSWORD="..."
podman-compose -f compose.yaml up --detach && tox -e integration
podman-compose -f compose.yaml down
Release
Commits can be tagged to create releases of the package, in order to do so:
- Bump up the version within the
pyproject.tomlfile. - Add a new section to the
CHANGELOG.md. - Commit + push the changes.
- Trigger the release workflow.
🧡 Acknowledges
This project is a Python port of the popular pg-ldap-sync Ruby project.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postgresql_ldap_sync-0.3.1.tar.gz.
File metadata
- Download URL: postgresql_ldap_sync-0.3.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b82e9b19ff42ac11b37b7e607939448fa1b3887807579f3cd3d765c13d58066e
|
|
| MD5 |
028362ce0eaef33b4f7172e2cc10aa1c
|
|
| BLAKE2b-256 |
44288293acfc5386ef41c93d5f09ead354264a3da327bda777eb6367c4510a62
|
Provenance
The following attestation bundles were made for postgresql_ldap_sync-0.3.1.tar.gz:
Publisher:
release.yaml on canonical/postgresql-ldap-sync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postgresql_ldap_sync-0.3.1.tar.gz -
Subject digest:
b82e9b19ff42ac11b37b7e607939448fa1b3887807579f3cd3d765c13d58066e - Sigstore transparency entry: 187770773
- Sigstore integration time:
-
Permalink:
canonical/postgresql-ldap-sync@62ff2c2aadfc246d8f695d61f9f3857875d29767 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@62ff2c2aadfc246d8f695d61f9f3857875d29767 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file postgresql_ldap_sync-0.3.1-py3-none-any.whl.
File metadata
- Download URL: postgresql_ldap_sync-0.3.1-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c413bc7ed0af3b50f0d5a2cde66b93517d540f8097779d8c72b1f3266938603
|
|
| MD5 |
1479254fb0878d0c91d12038b4d16488
|
|
| BLAKE2b-256 |
6261d1f6a23e386b56d257e2500167f94f11d1efffb4e2592c8e1dbcdedacaa2
|
Provenance
The following attestation bundles were made for postgresql_ldap_sync-0.3.1-py3-none-any.whl:
Publisher:
release.yaml on canonical/postgresql-ldap-sync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
postgresql_ldap_sync-0.3.1-py3-none-any.whl -
Subject digest:
9c413bc7ed0af3b50f0d5a2cde66b93517d540f8097779d8c72b1f3266938603 - Sigstore transparency entry: 187770774
- Sigstore integration time:
-
Permalink:
canonical/postgresql-ldap-sync@62ff2c2aadfc246d8f695d61f9f3857875d29767 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@62ff2c2aadfc246d8f695d61f9f3857875d29767 -
Trigger Event:
workflow_dispatch
-
Statement type: