Zum Inhalt springen

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).

ProductVersionModesWhat was verified
GitLab CE (Omnibus Docker image), omniauth-saml 2.2.5 / ruby-saml 1.18.119.5.3-ce.0password + MFASign-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
  • 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_groups and auditor_groups are GitLab EE only.
  • IdP-initiated sign-in works, but GitLab ignores the RelayState and opens its start page.
  • GitLab must be served over HTTPS. OkYouIn posts the SAML Response only to an https ACS 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:

    SettingValue
    SP Entity IDhttps://gitlab.example.com (GitLab’s external_url, the issuer in the snippet)
    ACS endpointshttps://gitlab.example.com/users/auth/saml/callback
    SP single logout URLhttps://gitlab.example.com/users/auth/saml/slo (HTTP-Redirect)
    NameID formatPersistent, NameID value: Opaque per-application ID
    Attribute mappingemail, first_name, last_name, username, groups (multi-valued)
    Signing certificateGlobal certificate
  • The application gets a SAML slug — gitlab in 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.

  1. 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
  2. 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'] = false
    gitlab_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"
    }
    }
    ]
  3. Apply it: sudo gitlab-ctl reconfigure. An OkYouIn button appears on the GitLab sign-in page.

  4. Set the after-sign-out path (see Sign-out) and allow the application in the policy.

  • 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 username attribute, name and e-mail from the others. With omniauth_block_auto_created_users false it 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_attribute reads the groups attribute at every sign-in. Members of the OkYouIn groups listed in external_groups become GitLab external users. Use Groups filter to limit which groups are sent.

The snippet trusts every /etc/gitlab/okyouin-saml-*.pem file (idp_cert_multi), which allows a rotation without downtime:

  1. In OkYouIn, prepare the next certificate (state Next). It is published in the metadata at once; the Active one keeps signing.
  2. Save it as /etc/gitlab/okyouin-saml-2.pem from https://mfa.example.com/saml/gitlab/certificate.pem?which=next and run sudo gitlab-ctl reconfigure.
  3. Click Activate next in OkYouIn — GitLab needs no change.
  4. Delete the old file afterwards.

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/spslo

GitLab 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.

  1. In a private window, click OkYouIn on the GitLab sign-in page, sign in with password and code. The account is created and active.
  2. Logging ▸ SSO sign-in log shows the sign-in with protocol SAML, the MFA round and the allow.
  3. Sign out of GitLab: OkYouIn asks “Sign out?”, then GitLab’s sign-in page returns. The next sign-in asks for the password again.
SymptomCause
”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 rotationGitLab 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 inThe after-sign-out path is not set to …/users/auth/saml/spslo.