Skip to main content

elabFTW LDAP Sync Script

This Script reads groupnames and user-IDs from a CSV file, queries an Identity Provider (LDAP) for all users of a given group and adds the users to the team LDAP, creating them if they don't exist yet:

alt text

It does not create the team in LDAP. This is a design decision to be in manual control of the process and could easily be implemented as the elabFTW API supports this.

The Script will archive users (and put them in a team called userarchiv) in elabFTW that were in a team in elabFTW once but are not members of the team in LDAP anymore. It is also capable of un-archiving users when they are added back again in LDAP.

Setup

Build Prerequisites for LDAP: https://www.python-ldap.org/en/python-ldap-3.3.0/installing.html#alpine

apk add build-base openldap-dev python3-dev

Run the script locally

  1. Get API Key in elabFTW: https://your-elab-instance.com/ucp.php?tab=4
  2. Copy the .env.example file to .env and fill in your data (or use any other means to provide the needed environment variables)
  3. Provide a CSV List of groups in the folder you are running the script from (see group_whitelist.csv for an example)
  4. Set up a virtual Environment and install dependencies with pipen:
    pipenv install --dev
    pipenv shell
    
  5. Create a team called userarchiv in the elabFTW instance
  6. Create the team(s) defined in the group_whitelist.csv in elabFTW where elabFTW orgid needs to match the name you defined in the CSV file.
  7. run the script: elabftw

Adapt the script to use any Identity Provider other than LDAP

In the for loop that goes over each group read from the CSV whitelist in the main.py/start_sync() function, LDAP is queried to return all members of the group:

ldap_users, leader_mail = process_ldap(
   ld,
   LDAP_BASE_DN,
   LDAP_SEARCH_GROUP.format(groupname=group["groupname"]),
   LDAP_SEARCH_USER_ATTRS.split(","),
   group["leader"],
)

replace this with custom code to output something like:

[
   {
      "email": "max.mustermann@uni-muenster.de",
      "firstname": "Max",
      "lastname": "Mustermann",
      "uni_id": "m_muster01",
   },
   {
      "email": "eva.beispiel@uni-muenster.de",
      "firstname": "Eva",
      "lastname": "Beispiel",
      "uni_id": "e_beisp02",
   },
]

for ldap_users and a string for leader_mail.

CLI option to define a custom CSV Whitelist

If not called with elabus --whitelist /path/to/csv the script will look for the environment variable WHITELIST_FILENAME to determine the path of the CSV to read or default to group_whitelist.csv in the folder the script is run from.

Metadata

Release files for elabftw-usersync 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elabftw-usersync 1.0.1
File Size Uploaded Provenance Actions
elabftw_usersync-1.0.1.tar.gz 18.3 kB Without provenance Details for elabftw_usersync-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elabftw-usersync 1.0.1
File Interpreter ABI Platform Actions
elabftw_usersync-1.0.1-py3-none-any.whl Python 3 none any Details for elabftw_usersync-1.0.1-py3-none-any.whl

Total release size: 40.0 kB

Release files / elabftw_usersync-1.0.1.tar.gz

Download URL elabftw_usersync-1.0.1.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6b2a7b6a58958c0e9c8fe19c915b2102e38e139b236221b67cb1c51007d14653
BLAKE2b-256 checksum
How to use checksums
b32e27328af6f059b5a798d1a270cb82f4189e5f12bb34c654606fa1058074dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.12

Release files / elabftw_usersync-1.0.1-py3-none-any.whl

Download URL elabftw_usersync-1.0.1-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d075a538ac234f0c1bce20ce7264f9f182649b65cef92856315d547a7f5dcd7
BLAKE2b-256 checksum
How to use checksums
41cbdba35c5929b20ee015ebc4ac0098e35d881a307965b001c1a68d056833d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.12

Security for elabftw-usersync 1.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page