ckanext-ldap

A CKAN extension that provides LDAP authentication.

https://github.com/naturalhistorymuseum/ckanext-ldap

Science Score: 62.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    3 of 18 committers (16.7%) from academic institutions
  • Institutional organization owner
    Organization naturalhistorymuseum has institutional domain (www.nhm.ac.uk)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.3%) to scientific vocabulary

Keywords

ckan ckan-extension

Keywords from Contributors

sketchfab gbif
Last synced: 6 months ago · JSON representation ·

Repository

A CKAN extension that provides LDAP authentication.

Basic Info
  • Host: GitHub
  • Owner: NaturalHistoryMuseum
  • License: gpl-3.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 307 KB
Statistics
  • Stars: 34
  • Watchers: 10
  • Forks: 39
  • Open Issues: 9
  • Releases: 31
Topics
ckan ckan-extension
Created over 11 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Support

README.md

The Natural History Museum logo.

ckanext-ldap

Tests Coveralls CKAN Python Docs

A CKAN extension that provides LDAP authentication.

Overview

This plugin provides LDAP authentication for CKAN.

Features include:

  • Imports username, full name, email and description;
  • Can match against several LDAP fields (eg. username or full name);
  • Allows to have LDAP only authentication, or combine LDAP and basic CKAN authentication;
  • Can add LDAP users to a given organization automatically;
  • Works with Active Directory.

Installation

Path variables used below:

  • $INSTALL_FOLDER (i.e. where CKAN is installed), e.g. /usr/lib/ckan/default
  • $CONFIG_FILE, e.g. /etc/ckan/default/development.ini

Installing from PyPI

shell pip install ckanext-ldap

Installing from source

  1. Clone the repository into the src folder: shell cd $INSTALL_FOLDER/src git clone https://github.com/NaturalHistoryMuseum/ckanext-ldap.git

  2. Activate the virtual env: shell . $INSTALL_FOLDER/bin/activate

  3. Install via pip: shell pip install $INSTALL_FOLDER/src/ckanext-ldap

Installing in editable mode

Installing from a pyproject.toml in editable mode (i.e. pip install -e) requires setuptools>=64; however, CKAN 2.9 requires setuptools==44.1.0. See our CKAN fork for a version of v2.9 that uses an updated setuptools if this functionality is something you need.

Post-install setup

  1. Add 'ldap' to the list of plugins in your $CONFIG_FILE: ini ckan.plugins = ... ldap

  2. Upgrade the database to create the tables: shell ckan -c $CONFIG_FILE db upgrade -p ldap

Configuration

These are the options that can be specified in your .ini config file.

LDAP configuration [REQUIRED]

| Name | Description | Options | |------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------| | ckanext.ldap.uri | The URI of the LDAP server, of the form ldap://example.com. You can use the URI to specify TLS (use 'ldaps' protocol), and the port number (suffix ':port'). | True/False | | ckanext.ldap.base_dn | The base dn in which to perform the search. Example: 'ou=USERS,dc=example,dc=com'. | | | ckanext.ldap.search.filter | This is the search string that is sent to the LDAP server, in which '{login}' is replaced by the user name provided by the user. Example: 'sAMAccountName={login}'. The search performed here must return exactly 0 or 1 entry. | | | ckanext.ldap.username | The LDAP attribute that will be used as the CKAN username. This must be unique. | | | ckanext.ldap.email | The LDAP attribute to map to the user's email address. This must be unique. | |

Other options

| Name | Description | Options | Default | |-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|----------| | ckanext.ldap.ckan_fallback | If true this will attempt to log in against the CKAN user database when no LDAP user exists. | True/False | False | | ckanext.ldap.prevent_edits | If true, this will prevent LDAP users from editing their profile. Note that there is no problem in allowing users to change their details - even their user name can be changed. But you may prefer to keep things centralized in your LDAP server. Important: while this prevents the operation from happening, it won't actually remove the 'edit settings' button from the dashboard. You need to do this in your own template. | True/False | False | | ckanext.ldap.auth.dn | DN to use if LDAP server requires authentication. | | | | ckanext.ldap.auth.password | Password to use if LDAP server requires authentication. | | | | ckanext.ldap.auth.method | Authentication method | SIMPLE, SASL | | | ckanext.ldap.auth.mechanism | SASL mechanism to use, if auth.method is set to SASL. | | | | ckanext.ldap.fullname | The LDAP attribute to map to the user's full name. | | | | ckanext.ldap.about | The LDAP attribute to map to the user's description. | | | | ckanext.ldap.organization.id | If this is set, users that log in using LDAP will automatically get added to the given organization. Warning: Changing this parameter will only affect users that have not yet logged on. It will not modify the organization of users who have already logged on. Warning: The organization to which to add LDAP users must already exist; the first user logging in will not automatically create it and instead you will see a "500 Server Error" returned. | | | | ckanext.ldap.organization.role | The role given to users added in the given organization ('admin', 'editor' or 'member'). Warning: Changing this parameter will only affect users that have not yet logged on. It will not modify the role of users who have already logged on. This is only used if ckanext.ldap.organization.id is set. There is currently no functionality for mapping LDAP groups to CKAN roles, so this just assigns the same role to every new LDAP user. | member, editor, admin | 'member' | | ckanext.ldap.search.alt | An alternative search string for the LDAP filter. If this is present and the search using ckanext.ldap.search.filter returns exactly 0 results, then a search using this filter will be performed. If this search returns exactly one result, then it will be accepted. You can use this for example in Active Directory to match against both username and fullname by setting ckanext.ldap.search.filter to 'sAMAccountName={login}' and ckanext.ldap.search.alt to 'name={login}'. The approach of using two separate filter strings (rather than one with an or statement) ensures that priority will always be given to the unique id match. ckanext.ldap.search.alt however can be used to match against more than one field. For example you could match against either the full name or the email address by setting ckanext.ldap.search.alt to '(\ | (name={login})(mail={login}))'. | | | ckanext.ldap.search.alt_msg | A message that is output to the user when the search on ckanext.ldap.search.filter returns 0 results, and the search on ckanext.ldap.search.alt returns more than one result. Example: 'Please use your short account name instead'. | | | | ckanext.ldap.migrate | If true this will change an existing CKAN user with the same username to an LDAP user. Otherwise, an exception UserConflictErroris raised if LDAP-login with an already existing local CKAN username is attempted. This option provides a migration path from local CKAN authentication to LDAP authentication: Rename all users to their LDAP usernames and instruct them to login with their LDAP credentials. Migration then happens transparently. | True/False | False | | ckanext.ldap.debug_level | python-ldap debug level. Security warning: it is strongly recommended to keep this parameter set to 0 (zero) on production systems, otherwise plaintext passwords will be logged by python-ldap | 0-9 | 0 | | ckanext.ldap.trace_level | python-ldap trace level. Security warning: it is strongly recommended to keep this parameter set to 0 (zero) on production systems, otherwise plaintext passwords will be logged by python-ldap | 0-9 | 0 | | ckanext.ldap.allow_password_reset | If true, allows LDAP users to reset their passwords, if false, disallows this functionality. Note that if this is true, the password that is reset is the CKAN user password, not the LDAP one. If set to false, the request to reset will be denied only if the user is an LDAP user, if not they will be allowed to reset regardless of the value of this option. | True/False | true | | ckanext.ldap.ignore_referrals | If true, The plugin will ignore referral query results sent by the LDAP server. This might be necessary if your base_dn is at the domain level, but the LDAP server searches in multiple paths for the user, resulting in queries containing more than one result. | True/False | false |

Usage

Example Test Configuration

To test that the extension is working correctly without having to set up an LDAP service yourself, you can try this config snippet:

ini ckanext.ldap.uri = ldap://ldap.forumsys.com:389 ckanext.ldap.base_dn = dc=example,dc=com ckanext.ldap.search.filter = cn=*{login}* ckanext.ldap.username = cn ckanext.ldap.auth.dn = cn=read-only-admin,dc=example,dc=com ckanext.ldap.email = mail ckanext.ldap.auth.password = password ckanext.ldap.auth.method = SIMPLE

See here for more information. Then just login with tesla or gauss for example with password as the password.

Commands

ldap

  1. setup-org: create the organisation specified in ckanext.ldap.organization.id. bash ckan -c $CONFIG_FILE ldap setup-org

Templates

This extension overrides templates/user/login.html and sets the form action to the LDAP login handler.

To use it elsewhere:

html+jinja {% set ldap_action = h.get_login_action() %} {% snippet "user/snippets/login_form.html", action=ldap_action, error_summary=error_summary %}

The helper function h.is_ldap_user() is also provided for templates.

Testing

There is a Docker compose configuration available in this repository to make it easier to run tests. The ckan image uses the Dockerfile in the docker/ folder.

To run the tests can be run against ckan 2.9.x and 2.10.x on Python3:

  1. Build the required images: shell docker compose build

  2. Then run the tests. The root of the repository is mounted into the ckan container as a volume by the Docker compose configuration, so you should only need to rebuild the ckan image if you change the extension's dependencies. ```shell

    run tests against ckan 2.9.x

    docker compose run latest

# run tests against ckan 2.10.x docker compose run next ```

Owner

  • Name: Natural History Museum
  • Login: NaturalHistoryMuseum
  • Kind: organization
  • Location: London

Citation (CITATION.cff)

cff-version: 1.2.0
title: CKAN Ldap extension
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - name: Natural History Museum
    city: London
    country: GB
    alias: NHM
    email: data@nhm.ac.uk
repository-code: 'https://github.com/NaturalHistoryMuseum/ckanext-ldap'
abstract: A CKAN extension that provides LDAP authentication.
keywords:
  - ckan
  - ckanext
  - ldap
license: GPL-3.0-or-later
version: 4.1.2

GitHub Events

Total
  • Create event: 11
  • Issues event: 5
  • Release event: 3
  • Delete event: 6
  • Member event: 1
  • Issue comment event: 6
  • Push event: 29
  • Pull request event: 23
Last Year
  • Create event: 11
  • Issues event: 5
  • Release event: 3
  • Delete event: 6
  • Member event: 1
  • Issue comment event: 6
  • Push event: 29
  • Pull request event: 23

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 157
  • Total Committers: 18
  • Avg Commits per committer: 8.722
  • Development Distribution Score (DDS): 0.522
Top Committers
Name Email Commits
Ginger Butcher a****i@g****m 75
Josh Humphries j****s@n****k 31
github-actions[bot] g****]@u****m 11
benscott b****n@b****k 11
Harald von Waldow h****w@e****h 7
amercader a****o@g****m 7
Wes Hinsley w****y@i****k 3
Alice Heaton a****n@n****k 2
Ashley Sommer a****r@g****m 1
Alice Heaton a****5@g****m 1
Jarett DeAngelis s****r@g****m 1
Mark Gregson m****n@l****u 1
I. P. (he / him) 3****k@u****m 1
kartik k****a@u****m 1
rahcor 3****r@u****m 1
dependabot[bot] 4****]@u****m 1
Tim Anderegg t****g@c****v 1
Alice Heaton a****5@u****m 1
Committer Domains (Top 20 + Academic)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 213 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 0
  • Total versions: 21
  • Total maintainers: 1
pypi.org: ckanext-ldap

A CKAN extension that provides LDAP authentication.

  • Versions: 21
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Downloads: 213 Last month
Rankings
Dependent packages count: 2.9%
Forks count: 6.7%
Downloads: 9.2%
Stargazers count: 11.4%
Average: 12.2%
Dependent repos count: 30.6%
Maintainers (1)
Last synced: 7 months ago

Dependencies

setup.py pypi
  • python-ldap ==3.4.0
.github/workflows/bump.yml actions
  • actions/checkout v3 composite
  • commitizen-tools/commitizen-action master composite
  • softprops/action-gh-release v1 composite
.github/workflows/main.yml actions
  • actions/checkout v3 composite
.github/workflows/pypi-publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
docker/Dockerfile docker
  • naturalhistorymuseum/ckantest 0.2 build
docker-compose.yml docker
  • ckan/ckan-solr 2.9
  • redis latest
docs/requirements.txt pypi
  • mkdocs *
  • mkdocs-gen-files *
  • mkdocs-include-markdown-plugin *
  • mkdocs-material *
  • mkdocs-section-index *
  • mkdocstrings *
pyproject.toml pypi
  • ckantools >=0.3.0
  • python-ldap ==3.4.3