Skip to main content

Project to sync LDAP users / groups to PostgreSQL

Project description

PostgreSQL-LDAP Sync

CI/CD Status Coverage Status Apache license

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

  1. Install the package from PyPi:

    pip install postgresql-ldap-sync
    
  2. 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,
    )
    
  3. Define the actions the synchronizer is allowed to take:

    user_actions = ["CREATE", "KEEP"]
    group_actions = ["CREATE", "KEEP"]
    member_actions = ["GRANT", "REVOKE", "KEEP"]
    
  4. 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:

  1. Bump up the version within the pyproject.toml file.
  2. Add a new section to the CHANGELOG.md.
  3. Commit + push the changes.
  4. 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

postgresql_ldap_sync-0.3.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postgresql_ldap_sync-0.3.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file postgresql_ldap_sync-0.3.2.tar.gz.

File metadata

  • Download URL: postgresql_ldap_sync-0.3.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for postgresql_ldap_sync-0.3.2.tar.gz
Algorithm Hash digest
SHA256 7e5f4af8ee065185657af1b5e4eff277a0441aafe2b372529e95be093891270c
MD5 2ab8a8f5dc49c16e93e31ed2be88ef58
BLAKE2b-256 6295cd6f3f5bec51ac3059ac9bb2a3709db126730e251562f3859bac6f2ae02d

See more details on using hashes here.

Provenance

The following attestation bundles were made for postgresql_ldap_sync-0.3.2.tar.gz:

Publisher: release.yaml on canonical/postgresql-ldap-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postgresql_ldap_sync-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for postgresql_ldap_sync-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ac4ac7afc5e44124ebe55eceda3df0a02516ea47dcbb674fa3f2372c9901beee
MD5 4a0c02fd7c54f828359dfb3be0daff13
BLAKE2b-256 c9fd1c1d90445f3c16976068f4708d53d51af67c3f26e7e30af3a58add237347

See more details on using hashes here.

Provenance

The following attestation bundles were made for postgresql_ldap_sync-0.3.2-py3-none-any.whl:

Publisher: release.yaml on canonical/postgresql-ldap-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page