GitLab (SAML)
Self-managed GitLab can use OkYouIn as its SAML 2.0 identity provider through the SAML OmniAuth provider. An OkYouIn button appears on the GitLab sign-in page; users sign in on OkYouIn’s page with their password and second factor. For OkYouIn’s SAML IdP in general, see SAML 2.0. The OpenID Connect alternative is GitLab (OIDC).
Verified on
Section titled “Verified on”| Product | Version | Modes | What was verified |
|---|---|---|---|
| GitLab CE (Omnibus Docker image), omniauth-saml 2.2.5 / ruby-saml 1.18.1 | 19.5.3-ce.0 | password + MFA | Sign-in with TOTP creates the account; single sign-on from Nextcloud without a prompt; MFA asked again after the session lifetime; policy deny; IdP-initiated sign-in; sign-out through spslo (OkYouIn confirmation); external_groups from the groups attribute; signing Response and assertion / Assertion only / Response only; certificate rotation without downtime with idp_cert_multi |
What works
Section titled “What works”- Second factor: TOTP was verified. Push and e-mail MFA were not tested with GitLab.
- Groups:
external_groups(GitLab external users) works in GitLab CE.admin_groups,required_groupsandauditor_groupsare GitLab EE only. - IdP-initiated sign-in works, but GitLab ignores the RelayState and opens its start page.
Before you start
Section titled “Before you start”-
GitLab must be served over HTTPS. OkYouIn posts the SAML Response only to an
httpsACS URL. -
OkYouIn’s public URL (Settings ▸ General) must be an
https://address. -
Create the application in Access ▸ Applications ▸ Add application ▸ GitLab (SAML). The template fills in the service-provider values from GitLab’s
external_url:Setting Value SP Entity ID https://gitlab.example.com(GitLab’sexternal_url, theissuerin the snippet)ACS endpoints https://gitlab.example.com/users/auth/saml/callbackSP single logout URL https://gitlab.example.com/users/auth/saml/slo(HTTP-Redirect)NameID format Persistent, NameID value: Opaque per-application ID Attribute mapping email,first_name,last_name,username,groups(multi-valued)Signing certificate Global certificate -
The application gets a SAML slug —
gitlabin the examples below — that appears in every IdP URL and cannot be changed later. The Connect tab shows the snippet with your real slug and host.
Configure
Section titled “Configure”-
Save the signing certificate on the GitLab server as
/etc/gitlab/okyouin-saml-1.pem. It is at the application’s certificate URL:Terminal window curl -fsS https://mfa.example.com/saml/gitlab/certificate.pem -o /etc/gitlab/okyouin-saml-1.pem -
Add the OmniAuth provider to
/etc/gitlab/gitlab.rb:/etc/gitlab/gitlab.rb gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']gitlab_rails['omniauth_block_auto_created_users'] = falsegitlab_rails['omniauth_providers'] = [{name: "saml",label: "OkYouIn",groups_attribute: "groups",# external_groups: ["contractors"],args: {assertion_consumer_service_url: "https://gitlab.example.com/users/auth/saml/callback",issuer: "https://gitlab.example.com",idp_sso_service_url: "https://mfa.example.com/saml/gitlab/sso",idp_slo_service_url: "https://mfa.example.com/saml/gitlab/slo",idp_cert_multi: { signing: Dir["/etc/gitlab/okyouin-saml-*.pem"].sort.map { |f| File.read(f) } },name_identifier_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",attribute_statements: { nickname: ["username"] },slo_default_relay_state: "https://gitlab.example.com/users/sign_in"}}] -
Apply it:
sudo gitlab-ctl reconfigure. An OkYouIn button appears on the GitLab sign-in page. -
Set the after-sign-out path (see Sign-out) and allow the application in the policy.
Accounts, attributes and groups
Section titled “Accounts, attributes and groups”- Account creation. The first SSO sign-in creates the GitLab account. The persistent NameID —
an opaque ID per user and application — links it; the username comes from the
usernameattribute, name and e-mail from the others. Withomniauth_block_auto_created_usersfalseit is active at once. - Re-created application. The opaque NameID is derived from this application’s own secret. If you delete and re-create the application, it sends new NameIDs, and GitLab refuses existing users (“An account already exists with the email address…”) until their SAML identities are re-linked. Preview for a user on the application shows the NameID a user would get.
- Users without an e-mail get
temp-email-for-oauth-<username>@gitlab.localhost. That is refused (“Email has already been taken”) when another provider — for example the OIDC template — already created a GitLab account with the same username. - Groups.
groups_attributereads thegroupsattribute at every sign-in. Members of the OkYouIn groups listed inexternal_groupsbecome GitLab external users. Use Groups filter to limit which groups are sent.
Certificate rotation
Section titled “Certificate rotation”The snippet trusts every /etc/gitlab/okyouin-saml-*.pem file (idp_cert_multi), which allows a
rotation without downtime:
- In OkYouIn, prepare the next certificate (state Next). It is published in the metadata at once; the Active one keeps signing.
- Save it as
/etc/gitlab/okyouin-saml-2.pemfromhttps://mfa.example.com/saml/gitlab/certificate.pem?which=nextand runsudo gitlab-ctl reconfigure. - Click Activate next in OkYouIn — GitLab needs no change.
- Delete the old file afterwards.
Sign-out
Section titled “Sign-out”GitLab’s Sign out sends no SAML LogoutRequest by itself. Set Admin ▸ Settings ▸ General ▸ Sign-in restrictions ▸ After sign-out path to:
https://gitlab.example.com/users/auth/saml/spsloGitLab then sends a LogoutRequest; OkYouIn asks “Sign out?” (the request is unsigned), ends
its session and returns to GitLab’s sign-in page (slo_default_relay_state). GitLab has one
after-sign-out path — it serves either this or the OIDC template’s end-session URL.
Other applications in the same OkYouIn session are not signed out: SAML single logout ends the OkYouIn session only. Likewise, revoking a session in Logging ▸ SSO sessions makes the next sign-in ask for the password but does not end a GitLab session that is already open.
Verify
Section titled “Verify”- In a private window, click OkYouIn on the GitLab sign-in page, sign in with password and code. The account is created and active.
- Logging ▸ SSO sign-in log shows the sign-in with protocol SAML, the MFA round and the allow.
- Sign out of GitLab: OkYouIn asks “Sign out?”, then GitLab’s sign-in page returns. The next sign-in asks for the password again.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause |
|---|---|
| ”Could not authenticate you from SAML because … authnfailed” | OkYouIn’s policy denied the user (the SSO sign-in log names the rule). |
| ”Fingerprint mismatch” after a rotation | GitLab pins one fingerprint. Use idp_cert_multi as in the snippet, or Revert in OkYouIn. |
| ”An account already exists with the email address…” | The application was re-created and sends new NameIDs; re-link the users’ SAML identities. |
| ”Email has already been taken” | A user without an e-mail collides with an account created by another provider. Give the user an e-mail in OkYouIn. |
| Signing out of GitLab leaves OkYouIn signed in | The after-sign-out path is not set to …/users/auth/saml/spslo. |