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.
Metadata
Release files for postgresql-ldap-sync 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| postgresql_ldap_sync-0.3.2.tar.gz | 13.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| postgresql_ldap_sync-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.1 kB
Release files / postgresql_ldap_sync-0.3.2.tar.gz
| Download URL | postgresql_ldap_sync-0.3.2.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e5f4af8ee065185657af1b5e4eff277a0441aafe2b372529e95be093891270c
|
|
BLAKE2b-256 checksum How to use checksums |
6295cd6f3f5bec51ac3059ac9bb2a3709db126730e251562f3859bac6f2ae02d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.
Transparency logRelease files / postgresql_ldap_sync-0.3.2-py3-none-any.whl
| Download URL | postgresql_ldap_sync-0.3.2-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac4ac7afc5e44124ebe55eceda3df0a02516ea47dcbb674fa3f2372c9901beee
|
|
BLAKE2b-256 checksum How to use checksums |
c9fd1c1d90445f3c16976068f4708d53d51af67c3f26e7e30af3a58add237347
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.
Transparency logSecurity for postgresql-ldap-sync 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for postgresql_ldap_sync-0.3.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.