Requirements

To use ADFS to log in to your Seafile, you need the following components:

  1. A Winodws Server with ADFS installed. For configuring and installing ADFS you can see this article.

  2. A valid SSL certificate for ADFS server, and here we use adfs-server.adfs.com as the domain name example.

  3. A valid SSL certificate for Seafile server, and here we use demo.seafile.com as the domain name example.

Prepare Certs File

  1. x.509 certs for SP (Service Provider)

    You can generate them by:

    1. openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout sp.key -out sp.crt

    These x.509 certs are used to sign and encrypt elements like NameID and Metadata for SAML.

    Then copy these two files to /seahub-data/certs. (if the certs folder not exists, create it.)

  2. x.509 cert from IdP (Identity Provider)

    1. Log into the ADFS server and open the ADFS management.

    2. Double click Service and choose Certificates.

    3. Export the Token-Signing certificate:

      1. Right-click the certificate and select View Certificate.
      2. Select the Details tab.
      3. Click Copy to File (select DER encoded binary X.509).
    4. Convert this certificate to PEM format, rename it to idp.crt

    5. Then copy it to /seahub-data/certs.

Prepare IdP Metadata File

  1. Open https://adfs-server.adfs.com/federationmetadata/2007-06/federationmetadata.xml

  2. Save this xml file, rename it to idp_federation_metadata.xml

  3. Copy it to /seahub-data/certs.

Install Requirements on Seafile Server

  • For Ubuntu 16.04
    1. sudo apt install xmlsec1
    2. sudo pip install cryptography djangosaml2==0.15.0

Config Seafile

Add the following lines to seahub_settings.py

  1. from os import path
  2. import saml2
  3. import saml2.saml
  4. # update following lines according to your situation
  5. CERTS_DIR = '<seafile-install-path>/seahub-data/certs'
  6. SP_SERVICE_URL = 'https://demo.seafile.com'
  7. XMLSEC_BINARY = '/usr/local/bin/xmlsec1'
  8. ATTRIBUTE_MAP_DIR = '<seafile-install-path>/seafile-server-latest/seahub-extra/seahub_extra/adfs_auth/attribute-maps'
  9. SAML_ATTRIBUTE_MAPPING = {
  10. 'DisplayName': ('display_name', ),
  11. 'ContactEmail': ('contact_email', ),
  12. 'Deparment': ('department', ),
  13. 'Telephone': ('telephone', ),
  14. }
  15. # update the 'idp' section in SAMPL_CONFIG according to your situation, and leave others as default
  16. ENABLE_ADFS_LOGIN = True
  17. EXTRA_AUTHENTICATION_BACKENDS = (
  18. 'seahub_extra.adfs_auth.backends.Saml2Backend',
  19. )
  20. SAML_USE_NAME_ID_AS_USERNAME = True
  21. LOGIN_REDIRECT_URL = '/saml2/complete/'
  22. SAML_CONFIG = {
  23. # full path to the xmlsec1 binary programm
  24. 'xmlsec_binary': XMLSEC_BINARY,
  25. 'allow_unknown_attributes': True,
  26. # your entity id, usually your subdomain plus the url to the metadata view
  27. 'entityid': SP_SERVICE_URL + '/saml2/metadata/',
  28. # directory with attribute mapping
  29. 'attribute_map_dir': ATTRIBUTE_MAP_DIR,
  30. # this block states what services we provide
  31. 'service': {
  32. # we are just a lonely SP
  33. 'sp' : {
  34. "allow_unsolicited": True,
  35. 'name': 'Federated Seafile Service',
  36. 'name_id_format': saml2.saml.NAMEID_FORMAT_EMAILADDRESS,
  37. 'endpoints': {
  38. # url and binding to the assetion consumer service view
  39. # do not change the binding or service name
  40. 'assertion_consumer_service': [
  41. (SP_SERVICE_URL + '/saml2/acs/',
  42. saml2.BINDING_HTTP_POST),
  43. ],
  44. # url and binding to the single logout service view
  45. # do not change the binding or service name
  46. 'single_logout_service': [
  47. (SP_SERVICE_URL + '/saml2/ls/',
  48. saml2.BINDING_HTTP_REDIRECT),
  49. (SP_SERVICE_URL + '/saml2/ls/post',
  50. saml2.BINDING_HTTP_POST),
  51. ],
  52. },
  53. # attributes that this project need to identify a user
  54. 'required_attributes': ["uid"],
  55. # attributes that may be useful to have but not required
  56. 'optional_attributes': ['eduPersonAffiliation', ],
  57. # in this section the list of IdPs we talk to are defined
  58. 'idp': {
  59. # we do not need a WAYF service since there is
  60. # only an IdP defined here. This IdP should be
  61. # present in our metadata
  62. # the keys of this dictionary are entity ids
  63. 'https://adfs-server.adfs.com/federationmetadata/2007-06/federationmetadata.xml': {
  64. 'single_sign_on_service': {
  65. saml2.BINDING_HTTP_REDIRECT: 'https://adfs-server.adfs.com/adfs/ls/idpinitiatedsignon.aspx',
  66. },
  67. 'single_logout_service': {
  68. saml2.BINDING_HTTP_REDIRECT: 'https://adfs-server.adfs.com/adfs/ls/?wa=wsignout1.0',
  69. },
  70. },
  71. },
  72. },
  73. },
  74. # where the remote metadata is stored
  75. 'metadata': {
  76. 'local': [path.join(CERTS_DIR, 'idp_federation_metadata.xml')],
  77. },
  78. # set to 1 to output debugging information
  79. 'debug': 1,
  80. # Signing
  81. 'key_file': '',
  82. 'cert_file': path.join(CERTS_DIR, 'idp.crt'), # from IdP
  83. # Encryption
  84. 'encryption_keypairs': [{
  85. 'key_file': path.join(CERTS_DIR, 'sp.key'), # private part
  86. 'cert_file': path.join(CERTS_DIR, 'sp.crt'), # public part
  87. }],
  88. 'valid_for': 24, # how long is our metadata valid
  89. }

Config ADFS Server

  1. Add Relying Party Trust

    Relying Party Trust is the connection between Seafile and ADFS.

    1. Log into the ADFS server and open the ADFS management.

    2. Double click Trust Relationships, then right click Relying Party Trusts, select Add Relying Party Trust….

    3. Select Import data about the relying party published online or one a local network, input https://demo.seafile.com/saml2/metadata/ in the Federation metadata address.

    4. Then Next until Finish.

  2. Add Relying Party Claim Rules

    Relying Party Claim Rules is used for attribute communication between Seafile and users in Windows Domain.

    Important: Users in Windows domain must have the E-mail value setted.

    1. Right-click on the relying party trust and select Edit Claim Rules…

    2. On the Issuance Transform Rules tab select Add Rules…

    3. Select Send LDAP Attribute as Claims as the claim rule template to use.

    4. Give the claim a name such as LDAP Attributes.

    5. Set the Attribute Store to Active Directory, the LDAP Attribute to E-Mail-Addresses, and the Outgoing Claim Type to E-mail Address.

    6. Select Finish.

    7. Click Add Rule… again.

    8. Select Transform an Incoming Claim.

    9. Give it a name such as Email to Name ID.

    10. Incoming claim type should be E-mail Address (it must match the Outgoing Claim Type in rule #1).

    11. The Outgoing claim type is Name ID (this is requested in Seafile settings policy 'name_id_format': saml2.saml.NAMEID_FORMAT_EMAILADDRESS).

    12. the Outgoing name ID format is Email.

    13. Pass through all claim values and click Finish.