Giter Club home page Giter Club logo

ckanext-saml2's Introduction

ckanext-saml2

An extension to enable Single Sign On(SSO) for CKAN data portals via SAML2 Authentication.

datagov/v0.4.0 is the branch currently used in production at data.gov. It is a fork of https://github.com/DataShades/ckanext-saml2 and contains necessary changes for compatibility with the Max.gov idp.

New releases of the default branch of the upstream repository should be evaluated for inclusion via rebase.

Requirements

The following packages are required: memcached, repoze, m2crypto, xmlsec1, xmlsec1-openssl, swig

Installation

  • To install this extension run the following commands (switch to python env first): then pip install -r requirements.txt & python setup.py develop
  • Create custom database table:
paster saml2 create -c config_file
  • Append saml2 to the ckan.plugins list in your ckan configuration file (i.e: /etc/ckan/production.ini)
  • make sure that fields are mapped correctly in production.ini i.e:
# saml2 config
saml2.user_mapping =
    email~mail
    fullname~field_display_name
    id~uid
    name~name

  • There are two ways to map organisational SAML attributes:
# 1. A custom function that take a single argument `saml_info`, dict
# containing the SAML attributes. and returns a dict like the example
# below. This is useful when users may have roles in multiple
# organisations. Default: not set (None)
#
# {
#     'org1': {
#         'capacity': 'member',
#         'data': {
#             'id': 'org1',
#             'description': 'A fun organization',
#             ...
#          },
#     },
#     ...
# }

saml2.organization_mapper = ckanext.myckan.plugin:mapping_function


# 2. Specify a simple mapping from individual SAML attributes to
# organisation schema fields. Note: `saml2.organization_mapping` must
# be defined, with no value if it should not be used

saml2.organization_mapping =
    name~field_unique_id
    title~field_organization
    field_type_of_user~field_role
    extras:organization_type~field_organization_type
  • By default, the SP doesn't create organisations specified in the SAML attributes but this can be configured:
# create organisations specified in SAML attributes that don't exist in CKAN? Default: False
saml2.create_missing_orgs = True
  • By default, when User logins in, SP checks he's Organizations provided and removes from Organizations that haven't been provided through login process. To avoid that, you can add a field saml2.rvm_users_from_orgs and set it to false in your config, so that User won't be removed from Organizations that he's been added to. By default this field is set to true.
saml2.rvm_users_from_orgs = false
  • By default, name_id taken from the id field that set in mapping for User. In order to take name_id from the SAML2 response NameID field, you need to set saml2saml2.name_id_from_saml2_NameID to true. By default its false.
saml2.name_id_from_saml2_NameID = true
  • When User logins, ckanext-saml2 tries to create/update Organization Membership for him. This option allow to avoid Orgnization Membership create/update stage. By default it set to False.
saml2.disable_organization_membership = True
  • When User logins, it redirects him to Dashboard. This option allows to set another URL for redirecting. By default it set to /dashboard.
saml2.redirect_after_login = '/'
  • The SP initiates SLO on CKAN logout by default. In order to make this more prominent you can add the directive saml2.sp_initiates_slo in ckan configuration file. Values true, yes, on, y, t, 1 are treated as true. To disable SP-initiated SLO and only logout from CKAN, set this directive to false, no, off, n, f, or 0.
saml2.sp_initiates_slo = true
  • Modify ckanext/saml2/config/sp_config.py to suit your needs. The BASE variable at the top need reference the domain of the service provider (i.e changed to http://catalog.data.gov or wherever CKAN is currently hosted).
  • Place your identity provider's idp.xml metadata here: ckanext/saml2/config/
  • The certificates need to be placed in this directory: ckanext/saml2/config/pki (they need to be named mycert.pem & mykey.pem)
  • Generate the sp metadata (sp.xml): /usr/lib/ckan/bin/python /usr/lib/ckan/src/pysaml2/tools/make_metadata.py /usr/lib/ckan/src/ckanext-saml2/ckanext/saml2/config/sp_config.py > sp.xml (the paths to python, make_metadata.py sp_config.py might vary depending on where you installed ckan in your virtual env)
  • copy ckanext/saml2/config/who.ini to your ckan's config folder i.e: /etc/ckan/who.ini
  • make sure that your webserver can write to /var/www/sp.log
  • Add saml2.default_org and saml2.default_role - that values will be assigned to newly created users as organization and role in this organization accordingly
  • In order to enable native login and registration as default option, add saml2.enable_native_login = true|false directive to config file.
  • saml2.login_form_sso_text = BUTTON_TEXT allows you to controll label of SSO button at login page(default: 'Login with SSO').

Production deployment

To keep IdP metadata from metadata_url and stored at local_path up-to-date automatically run the following script:

/usr/lib/ckan/default/bin/python ckanext/saml2/admin/fresh_idp_metadata.py -url metadata_url -path local_path

CKAN must be reloaded after the metadata is updated, by, for example, reloading httpd.

Command line

Create custom database table:

paster saml2 create -c config_file

Drop custom database tables::

paster saml2 drop -c config_file

API Changes

Users can also be deleted by Name ID by passing the nameid parameter:

api/3/action/user_delete
Parameters (id or nameid):
    - id (string) – the id, name of the user to delete
    - nameid (string) – SAML NameID of the user to delete

Update user via API. We can pass allow_update as parameter for allow or reject user custom profile data set:

api/3/action/user_update
Parameters (default parametrs and allow_update optional):
    - allow_update (True or False) – checked or unchecked checkbox for SSO user profile page

Known Issues

  • The only binding supported for sending logout reponses for an IdP-initiated global logout is HTTP Redirect. As of v4.4.0 pysaml2's behaviour is to use a Post binding if the SP receives a logout request via either a Post or Redirect binding but it subsequently raises an exception. A workaround is modify the local copy of the IdP metadata by removing the element that declares support for the Post binding for logout, e.g., <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" ... />, which will cause pysaml2 to revert to a Redirect binding.

The included metadata update script performs this configuration update automatically.

ckanext-saml2's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ckanext-saml2's Issues

Add LICENSE

there is no license explicitly specified.

Update to CKAN 2.3+ and pysaml2 4.0 (and other enhancements)

We've been working on some updates and enhancements to this extension in our fork. Top of the list of was updating the extension to run on a standard pysaml2 4.0 release with CKAN 2.3 and 2.4. pysaml2 has the same who.repoze dependency as these versions of CKAN so it fits together more easily. We've also worked on a number of enhancements for different working configurations.

We'd like to contribute this code, starting with the pysaml2 and CKAN updates (we should have done this earlier). Are you happy to receive PRs for these?

If so, the next question is how. We can construct a PR that includes all the upgrades changes only, which may take a little time, OR we could simply make a PR from our master which includes various new features also.

Configuration

Hellou,

I am curious whether this extension is compatible with CKAN 2.2. After my configuration on CKAN 2.2, I get following error when I tried to serve CKAN (paster serve) : ckanext/saml2/plugin.py", line 70, in make_mapping for item in data.split(): AttributeError: 'NoneType' object has no attribute 'split'

Could you help me please? Is it configuration error?

Missing requirement M2Crypto

When I ran through the install I found I needed to do a pip install M2Crypto. Is this a missing requirement or is it pysaml2 that is missing it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.