Zum Hauptinhalt springen

GitLab

Dieser Leitfaden erklärt, wie man die Einmalanmeldung (SSO) zwischen SmartLink und GitLab konfiguriert. GitLab unterstützt sowohl OpenID Connect als auch SAML2 - wir empfehlen OpenID Connect aufgrund seiner Einfachheit.

Voraussetzungen

  • GitLab CE/EE Version 11.4+ (für OpenID Connect)
  • GitLab CE/EE Version 9.0+ (für SAML2)
  • Administratorzugriff auf GitLab
  • Anwendung in SmartLink konfiguriert

Konfiguration mit OpenID Connect (Empfohlen)

1. Anwendung erstellen

  1. Melden Sie sich als Administrator bei SmartLink an
  2. Gehen Sie zu AnwendungenHinzufügen
  3. Erstellen Sie eine neue Anwendung:
    • Name: GitLab
    • URL: https://gitlab.example.com
    • Beschreibung: DevOps-Plattform GitLab
    • Symbol: Wählen Sie das GitLab-Symbol aus

2. OpenID Connect konfigurieren

  1. Im Tab Authentifizierung
  2. Wählen Sie OpenID Connect
  3. Notieren Sie die Informationen:
    • Client-ID: gitlab-xxxxxx
    • Client-Geheimnis: secret-xxxxxx
    • Issuer-URL: https://votre-smartlink.link.vaultys.org/api/oidc/[appid]
    • App-ID: [appid] (eindeutige Kennung der Anwendung in SmartLink)

3. Erlaubte Weiterleitungs-URLs

Fügen Sie hinzu unter Erlaubte Weiterleitungs-URLs:

https://gitlab.example.com/users/auth/openid_connect/callback

4. Erforderliche Berechtigungen (Scopes)

  • openid
  • profile
  • email
  • groups (optional, für die Gruppensynchronisierung)

Konfiguration in GitLab

1. Omnibus-Konfiguration (gitlab.rb)

Bearbeiten Sie /etc/gitlab/gitlab.rb:

### Konfiguration OpenID Connect mit SmartLink ###

gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect']
gitlab_rails['omniauth_sync_email_from_provider'] = 'openid_connect'
gitlab_rails['omniauth_sync_profile_from_provider'] = ['openid_connect']
gitlab_rails['omniauth_sync_profile_attributes'] = ['name', 'email']
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'openid_connect'
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_auto_link_user'] = ['openid_connect']

gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
label: "SmartLink SSO",
icon: "https://votre-smartlink.example.com/logo.png",
args: {
name: "openid_connect",
scope: ["openid", "profile", "email", "groups"],
response_type: "code",
issuer: "https://votre-smartlink.link.vaultys.org",
discovery: true,
discovery_endpoint: "https://votre-smartlink.link.vaultys.org/api/oidc/[appid]/.well-known/openid-configuration",
client_auth_method: "query",
uid_field: "sub",
send_scope_to_token_endpoint: "false",
pkce: true,
client_options: {
identifier: "gitlab-xxxxxx",
secret: "secret-xxxxxx",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]

# Gruppensynchronisierung (optional)
gitlab_rails['omniauth_external_providers'] = ['openid_connect']
gitlab_rails['omniauth_allow_bypass_two_factor'] = ['openid_connect']

2. Docker-Konfiguration

Für GitLab Docker verwenden Sie Umgebungsvariablen:

version: '3.8'
services:
gitlab:
image: gitlab/gitlab-ee:latest
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect']
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'openid_connect'
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
label: "SmartLink SSO",
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "https://votre-smartlink.link.vaultys.org",
discovery: true,
discovery_endpoint: "https://votre-smartlink.link.vaultys.org/api/oidc/[appid]/.well-known/openid-configuration",
uid_field: "sub",
client_options: {
identifier: "${OIDC_CLIENT_ID}",
secret: "${OIDC_CLIENT_SECRET}",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]

3. Konfiguration anwenden

# Für Omnibus
gitlab-ctl reconfigure
gitlab-ctl restart

# Für Docker
docker-compose up -d

Gruppensynchronisierung

Um SmartLink-Gruppen automatisch mit GitLab zu synchronisieren:

# In gitlab.rb
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
# ... vorhandene Konfiguration ...
groups_attribute: "groups",
admin_groups: ["smartlink_admins"],
external_groups: ["smartlink_external"],
required_groups: ["gitlab_users"]
}
}
]

Konfiguration mit SAML2

1. SAML2 konfigurieren

  1. In der GitLab-Anwendung
  2. Tab AuthentifizierungSAML2
  3. Konfigurieren Sie:
    • Entity-ID: https://gitlab.example.com
    • ACS-URL: https://gitlab.example.com/users/auth/saml/callback
    • Format NameID: emailAddress

2. Metadaten herunterladen

Laden Sie herunter oder notieren Sie:

  • IdP-Metadaten: https://votre-smartlink.link.vaultys.org/api/saml2/[appid]/metadata
  • X.509-Zertifikat
  • SSO-URL: https://votre-smartlink.link.vaultys.org/api/saml2/[appid]/sso
  • SLO-URL: https://votre-smartlink.link.vaultys.org/api/saml2/[appid]/slo

Konfiguration in GitLab

# In /etc/gitlab/gitlab.rb

gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml'
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_auto_link_saml_user'] = true

gitlab_rails['omniauth_providers'] = [
{
name: "saml",
label: "SmartLink SSO",
args: {
assertion_consumer_service_url: "https://gitlab.example.com/users/auth/saml/callback",
idp_cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----",
idp_sso_target_url: "https://votre-smartlink.link.vaultys.org/api/saml2/[appid]/sso",
idp_metadata_url: "https://votre-smartlink.link.vaultys.org/api/saml2/[appid]/metadata",
issuer: "https://gitlab.example.com",
name_identifier_format: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
attribute_statements: {
email: ['email'],
name: ['name'],
nickname: ['username'],
groups: ['groups']
}
}
}
]

Berechtigungsverwaltung

Rollenzuordnung

Konfigurieren Sie die automatische Zuordnung von Rollen:

# OpenID Connect
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
# GitLab-Administratorgruppen
admin_groups: ["smartlink-gitlab-admins"],

# Externe Benutzer (beschränkter Zugriff)
external_groups: ["smartlink-contractors"],

# Erforderliche Gruppen für den Zugriff
required_groups: ["smartlink-gitlab-users"],

# Auditorgruppen (nur Lesen)
auditor_groups: ["smartlink-auditors"]
}
}
]

Automatische Bereitstellung von Projekten

Um automatisch Projekte basierend auf Gruppen zu erstellen:

# Benutzerdefiniertes Bereitstellungsskript
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
# ... Konfiguration ...
after_sign_in_path: proc do |user, groups|
groups.each do |group|
# Logik zur Projekt-/Gruppenerstellung
Group.find_or_create_by(path: group) do |g|
g.name = group
g.add_user(user, :developer)
end
end
end
}
}
]

Benutzerkonfiguration

Automatische Lizenzzuweisung (GitLab EE)

# Für GitLab Enterprise Edition
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
# ... Konfiguration ...
license_groups: {
ultimate: ["smartlink-ultimate-users"],
premium: ["smartlink-premium-users"],
starter: ["smartlink-starter-users"]
}
}
}
]

Benutzerprofilkonfiguration

# Vollständige Profilsynchronisierung
gitlab_rails['omniauth_sync_profile_from_provider'] = ['openid_connect']
gitlab_rails['omniauth_sync_profile_attributes'] = [
'name',
'email',
'location',
'bio',
'organization',
'website_url'
]

Konfigurationstest

1. Anmeldetest

  1. Melden Sie sich von GitLab ab
  2. Klicken Sie auf der Anmeldeseite auf SmartLink SSO
  3. Melden Sie sich bei SmartLink an
  4. Überprüfen Sie die Weiterleitung zu GitLab

2. Berechtigungsüberprüfung

# Über die GitLab-API
curl -H "PRIVATE-TOKEN: your_token" \
"https://gitlab.example.com/api/v4/user"

# Über die Rails-Konsole
gitlab-rails console
user = User.find_by_email('user@example.com')
user.identities
user.group_members

3. Test mit Git

# Mit SSO klonen
git clone https://gitlab.example.com/group/project.git

# Falls gefordert, verwenden Sie:
# Benutzername: oauth2
# Passwort: [Ihr persönliches Zugriffstoken]

Fehlerbehebung

Fehler "Could not authenticate you from OpenIDConnect"

Lösung:

  1. Überprüfen Sie die GitLab-Protokolle:
    gitlab-ctl tail gitlab-rails
  2. Testen Sie die OIDC-Entdeckung mit Ihrer App-ID:
    curl https://votre-smartlink.link.vaultys.org/api/oidc/[appid]/.well-known/openid-configuration
  3. Überprüfen Sie die Client-ID und das Geheimnis

Gruppen werden nicht synchronisiert

Lösung:

  1. Überprüfen Sie den Gruppenanspruch in der OIDC-Antwort
  2. Aktivieren Sie detaillierte Protokolle:
    gitlab_rails['omniauth_providers'] = [
    {
    args: {
    client_options: {
    debug: true
    }
    }
    }
    ]

Fehler 422 nach der Authentifizierung

Lösung:

  1. Stellen Sie sicher, dass die E-Mail-Adresse in GitLab eindeutig ist
  2. Aktivieren Sie das automatische Verknüpfen:
    gitlab_rails['omniauth_auto_link_user'] = ['openid_connect']

Benutzer nach der Erstellung blockiert

Lösung:

# Automatische Blockierung deaktivieren
gitlab_rails['omniauth_block_auto_created_users'] = false

# Oder manuell entsperren
gitlab-rails console
User.where(state: 'blocked').update_all(state: 'active')

Sicherheit

Empfehlungen

  1. HTTPS erforderlich für GitLab und SmartLink
  2. Regelmäßige Geheimnisrotation
  3. Beschränkung der Gruppen mit required_groups
  4. Aktivierte Auditprotokolle:
    gitlab_rails['audit_events_enabled'] = true
  5. 2FA-Bypass nur wenn SmartLink MFA verwaltet:
    gitlab_rails['omniauth_allow_bypass_two_factor'] = ['openid_connect']

CSRF-Schutz

# Schutz vor CSRF-Angriffen
gitlab_rails['omniauth_providers'] = [
{
args: {
pkce: true, # Verwendung von PKCE für OpenID Connect
state: true # Überprüfung des State-Parameters
}
}
]

Erweiterte Konfiguration

Multi-Instanz GitLab

Für mehrere GitLab-Instanzen mit demselben SmartLink:

# Produktionsinstanz
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
client_options: {
identifier: "gitlab-prod-xxxxxx",
redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
}
}
}
]

# Staging-Instanz
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
args: {
client_options: {
identifier: "gitlab-staging-xxxxxx",
redirect_uri: "https://gitlab-staging.example.com/users/auth/openid_connect/callback"
}
}
}
]

CI/CD-Integration

Um SSO in den Pipelines zu verwenden:

# .gitlab-ci.yml
variables:
CI_JOB_TOKEN_SCOPE: "openid_connect"

deploy:
script:
- |
TOKEN=$(curl -X POST https://votre-smartlink.link.vaultys.org/api/oidc/[appid]/token \
-d "grant_type=client_credentials" \
-d "client_id=${CI_CLIENT_ID}" \
-d "client_secret=${CI_CLIENT_SECRET}")
- # Verwenden Sie $TOKEN für Bereitstellungen

Ressourcen