diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | config.json.example | 1 | ||||
-rw-r--r-- | docs/guides/auth.md | 135 | ||||
-rw-r--r-- | docs/guides/images/auth/onelogin-add-app.png | bin | 0 -> 40519 bytes | |||
-rw-r--r-- | docs/guides/images/auth/onelogin-copy-idp-metadata.png | bin | 0 -> 239493 bytes | |||
-rw-r--r-- | docs/guides/images/auth/onelogin-edit-app-name.png | bin | 0 -> 122369 bytes | |||
-rw-r--r-- | docs/guides/images/auth/onelogin-edit-sp-metadata.png | bin | 0 -> 184470 bytes | |||
-rw-r--r-- | docs/guides/images/auth/onelogin-select-template.png | bin | 0 -> 73244 bytes | |||
-rw-r--r-- | docs/guides/images/auth/onelogin-use-dashboard.png | bin | 0 -> 27216 bytes | |||
-rw-r--r-- | lib/config/default.js | 1 | ||||
-rw-r--r-- | lib/config/environment.js | 1 | ||||
-rw-r--r-- | lib/web/auth/saml/index.js | 1 |
12 files changed, 136 insertions, 6 deletions
@@ -172,7 +172,7 @@ There are some configs you need to change in the files below | HMD_LDAP_SEARCHATTRIBUTES | no example | LDAP attributes to search with | | HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) | | HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider | -| HMD_SAML_IDPSSOURL | `https://idp.example.com/sso` | authentication endpoint of IdP | +| HMD_SAML_IDPSSOURL | `https://idp.example.com/sso` | authentication endpoint of IdP. for details, see [guide](docs/guides/auth.md#saml-onelogin). | | HMD_SAML_IDPCERT | `/path/to/cert.pem` | certificate file path of IdP in PEM format | | HMD_SAML_ISSUER | no example | identity of the service provider (optional, default: serverurl)" | | HMD_SAML_IDENTIFIERFORMAT | no example | name identifier format (optional, default: `urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress`) | @@ -181,7 +181,6 @@ There are some configs you need to change in the files below | HMD_SAML_EXTERNALGROUPS | `Temporary-staff` | group names that not allowed (use vertical bar to separate) (optional) | | HMD_SAML_ATTRIBUTE_ID | `sAMAccountName` | attribute map for `id` (optional, default: NameID of SAML response) | | HMD_SAML_ATTRIBUTE_USERNAME | `mailNickname` | attribute map for `username` (optional, default: NameID of SAML response) | -| HMD_SAML_ATTRIBUTE_DISPLAYNAME | `displayName` | attribute map for `displayname` (optional, default: NameID of SAML response) | | HMD_SAML_ATTRIBUTE_EMAIL | `mail` | attribute map for `email` (optional, default: NameID of SAML response if `HMD_SAML_IDENTIFIERFORMAT` is default) | | HMD_IMGUR_CLIENTID | no example | Imgur API client id | | HMD_EMAIL | `true` or `false` | set to allow email signin | diff --git a/config.json.example b/config.json.example index 00165f51..8d23be8a 100644 --- a/config.json.example +++ b/config.json.example @@ -86,7 +86,6 @@ "attribute": { "id": "change or delete this: attribute map for `id` (default: NameID)", "username": "change or delete this: attribute map for `username` (default: NameID)", - "displayName": "change or delete this: attribute map for `displayName` (default: NameID)", "email": "change or delete this: attribute map for `email` (default: NameID)" } }, diff --git a/docs/guides/auth.md b/docs/guides/auth.md index 37b89004..4f9ce445 100644 --- a/docs/guides/auth.md +++ b/docs/guides/auth.md @@ -75,3 +75,138 @@ To do this Click your profile icon --> Settings and privacy --> Mobile --> Sele HMD_GITHUB_CLIENTID=3747d30eaccXXXXXXXXX HMD_GITHUB_CLIENTSECRET=2a8e682948eee0c580XXXXXXXXXXXXXXXXXXXXXX ```` + +### SAML (OneLogin) +1. Sign-in or sign-up for an OneLogin account. (available free trial for 2 weeks) +2. Go to the administration page. +3. Select the **APPS** menu and click on the **Add Apps**. + +![onelogin-add-app](images/auth/onelogin-add-app.png) + +4. Find "SAML Test Connector (SP)" for template of settings and select it. + +![onelogin-select-template](images/auth/onelogin-select-template.png) + +5. Edit display name and icons for OneLogin dashboard as you want, and click **SAVE**. + +![onelogin-edit-app-name](images/auth/onelogin-edit-app-name.png) + +6. After that other tabs will appear, click the **Configuration**, and fill out the below items, and click **SAVE**. + * RelayState: The base URL of your hackmd, which is issuer. (last slash is not needed) + * ACS (Consumer) URL Validator: The callback URL of your hackmd. (serverurl + /auth/saml/callback) + * ACS (Consumer) URL: same as above. + * Login URL: login URL(SAML requester) of your hackmd. (serverurl + /auth/saml) + +![onelogin-edit-sp-metadata](images/auth/onelogin-edit-sp-metadata.png) + +7. The registration is completed. Next, click **SSO** and copy or download the items below. + * X.509 Certificate: Click **View Details** and **DOWNLOAD** or copy the content of certificate ....(A) + * SAML 2.0 Endpoint (HTTP): Copy the URL ....(B) + +![onelogin-copy-idp-metadata](images/auth/onelogin-copy-idp-metadata.png) + +8. In your hackmd server, create IdP certificate file from (A) +9. Add the IdP URL (B) and the Idp certificate file path to your config.json file or pass them as environment variables. + * config.json: + ````javascript + { + "production": { + "saml": { + "idpSsoUrl": "https://*******.onelogin.com/trust/saml2/http-post/sso/******", + "idpCert": "/path/to/idp_cert.pem" + } + } + } + ```` + * environment variables + ```` + HMD_SAML_IDPSSOURL=https://*******.onelogin.com/trust/saml2/http-post/sso/****** + HMD_SAML_IDPCERT=/path/to/idp_cert.pem + ```` +10. Try sign-in with SAML from your hackmd sign-in button or OneLogin dashboard (like the screenshot below). + +![onelogin-use-dashboard](images/auth/onelogin-use-dashboard.png) + +### SAML (Other cases) +The basic procedure is the same as the case of OneLogin which is mentioned above. If you want to match your IdP, you can use more configurations as below. + +* If your IdP accepts metadata XML of the service provider to ease configuraion, use this url to download metadata XML. + * {{your-serverurl}}/auth/saml/metadata + * _Note: If not accessable from IdP, download to local once and upload to IdP._ +* Change the value of `issuer`, `identifierFormat` to match your IdP. + * `issuer`: A unique id to identify the application to the IdP, which is the base URL of your HackMD as default + * `identifierFormat`: A format of unique id to identify the user of IdP, which is the format based on email address as default. It is recommend that you use as below. + * urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress (default) + * urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified + * config.json: + ````javascript + { + "production": { + "saml": { + /* omitted */ + "issuer": "myhackmd" + "identifierFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" + } + } + } + ```` + * environment variables + ```` + HMD_SAML_ISSUER=myhackmd + HMD_SAML_IDENTIFIERFORMAT=urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified + ```` + +* Change mapping of attribute names to customize the displaying user name and email address to match your IdP. + * `attribute`: A dictionary to map attribute names + * `attribute.id`: A primary key of user table for your HackMD + * `attribute.username`: Attribute name of displaying user name on HackMD + * `attribute.email`: Attribute name of email address, which will be also used for Gravatar + * _Note: Default value of all attributes is NameID of SAML response, which is email address if `idfentifierFormat` is default._ + * config.json: + ````javascript + { + "production": { + "saml": { + /* omitted */ + "attribute": { + "id": "sAMAccountName", + "username": "displayName", + "email": "mail" + } + } + } + } + ```` + * environment variables + ```` + HMD_SAML_ATTRIBUTE_ID=sAMAccountName + HMD_SAML_ATTRIBUTE_USERNAME=nickName + HMD_SAML_ATTRIBUTE_EMAIL=mail + ```` + +* If you want to controll permission by group membership, add group attribute name and required group (allowed) or external group (not allowed). + * `groupAttribute`: An attribute name of group membership + * `requiredGroups`: Group names array for allowed access to HackMD. Use vertical bar to separate for environment variables. + * `externalGroups`: Group names array for not allowed access to HackMD. Use vertical bar to separate for environment variables. + * _Note: Evaluates `externalGroups` first_ + * config.json: + ````javascript + { + "production": { + "saml": { + /* omitted */ + "groupAttribute": "memberOf", + "requiredGroups": [ "hackmd-users", "board-members" ], + "externalGroups": [ "temporary-staff" ] + } + } + } + ```` + * environment variables + ```` + HMD_SAML_GROUPATTRIBUTE=memberOf + HMD_SAML_REQUIREDGROUPS=hackmd-users|board-members + HMD_SAML_EXTERNALGROUPS=temporary-staff + ```` + + diff --git a/docs/guides/images/auth/onelogin-add-app.png b/docs/guides/images/auth/onelogin-add-app.png Binary files differnew file mode 100644 index 00000000..356bb852 --- /dev/null +++ b/docs/guides/images/auth/onelogin-add-app.png diff --git a/docs/guides/images/auth/onelogin-copy-idp-metadata.png b/docs/guides/images/auth/onelogin-copy-idp-metadata.png Binary files differnew file mode 100644 index 00000000..7185f537 --- /dev/null +++ b/docs/guides/images/auth/onelogin-copy-idp-metadata.png diff --git a/docs/guides/images/auth/onelogin-edit-app-name.png b/docs/guides/images/auth/onelogin-edit-app-name.png Binary files differnew file mode 100644 index 00000000..634d1916 --- /dev/null +++ b/docs/guides/images/auth/onelogin-edit-app-name.png diff --git a/docs/guides/images/auth/onelogin-edit-sp-metadata.png b/docs/guides/images/auth/onelogin-edit-sp-metadata.png Binary files differnew file mode 100644 index 00000000..111580b1 --- /dev/null +++ b/docs/guides/images/auth/onelogin-edit-sp-metadata.png diff --git a/docs/guides/images/auth/onelogin-select-template.png b/docs/guides/images/auth/onelogin-select-template.png Binary files differnew file mode 100644 index 00000000..13401816 --- /dev/null +++ b/docs/guides/images/auth/onelogin-select-template.png diff --git a/docs/guides/images/auth/onelogin-use-dashboard.png b/docs/guides/images/auth/onelogin-use-dashboard.png Binary files differnew file mode 100644 index 00000000..ea9038ff --- /dev/null +++ b/docs/guides/images/auth/onelogin-use-dashboard.png diff --git a/lib/config/default.js b/lib/config/default.js index 96bfe79b..d04485ce 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -109,7 +109,6 @@ module.exports = { attribute: { id: undefined, username: undefined, - displayName: undefined, email: undefined } }, diff --git a/lib/config/environment.js b/lib/config/environment.js index 3b2e34a0..b7b0e3f8 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -84,7 +84,6 @@ module.exports = { attribute: { id: process.env.HMD_SAML_ATTRIBUTE_ID, username: process.env.HMD_SAML_ATTRIBUTE_USERNAME, - displayName: process.env.HMD_SAML_ATTRIBUTE_DISPLAYNAME, email: process.env.HMD_SAML_ATTRIBUTE_EMAIL } }, diff --git a/lib/web/auth/saml/index.js b/lib/web/auth/saml/index.js index 063fa1d6..386293ae 100644 --- a/lib/web/auth/saml/index.js +++ b/lib/web/auth/saml/index.js @@ -39,7 +39,6 @@ passport.use(new SamlStrategy({ provider: 'saml', id: 'SAML-' + uuid, username: user[config.saml.attribute.username] || user.nameID, - displayName: user[config.saml.attribute.displayName] || user.nameID, emails: user[config.saml.attribute.email] ? [user[config.saml.attribute.email]] : [] } if (profile.emails.length === 0 && config.saml.identifierFormat === 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress') { |