Skip to main content
Sourcegraph supports multiple authentication providers. Users need an account to access your instance, and the auth provider determines how accounts are created and verified. You can configure more than one provider — for example, SAML for SSO sign-in plus GitHub OAuth to prove code host identity for permission syncing. Authentication providers are configured in the auth.providers array in your site configuration. Go to Site admin > Configuration to edit this.
If you enable repository permissions, auth providers are also used to verify who a user is on the code host. For example, to see private GitHub repositories, a user must authenticate with the GitHub OAuth provider so Sourcegraph can map their Sourcegraph account to their GitHub account.

Choosing an auth provider

If you are unsure which provider to use:
  • No SSO / quick start: use builtin password auth. You can migrate later; email addresses link accounts automatically.
  • Behind an auth proxy (like oauth2_proxy or Google IAP): use http-header.
  • Indexing GitHub or GitLab: use the OAuth provider for that code host, even if the code host itself uses SAML externally.
  • Identity provider with SAML support: use saml.
  • Identity provider with OIDC support (Okta, Azure AD, Google Workspace, Auth0, Ping Identity): use openidconnect.

Auth provider configuration

The builtin provider manages usernames and passwords inside Sourcegraph. It is the default on a fresh install and the simplest option for teams without a corporate SSO system.
{
  "auth.providers": [
    {
      "type": "builtin",
      "allowSignup": false
    }
  ]
}
allowSignup
  • true — any user who can reach your instance can create an account.
  • false (recommended) — new users must be created by a site admin, or they can submit an access request that admins approve.
Account lockoutAccounts are locked for 30 minutes after 5 failed sign-in attempts within one hour. You can tune this:
{
  "auth.lockout": {
    "consecutivePeriod": 3600,
    "failedAttemptThreshold": 5,
    "lockoutPeriod": 1800
  }
}
To allow self-serve account unlock via email, add:
{
  "auth.unlockAccountLinkExpiry": 30,
  "auth.unlockAccountLinkSigningKey": "base64-encoded-signing-key"
}
Generate the signing key with ssh-keygen -t ed25519 -a 128 -f auth.unlockAccountLinkSigningKey && base64 auth.unlockAccountLinkSigningKey | tr -d '\n'.Password policyEnforce minimum length and complexity:
{
  "auth.minPasswordLength": 12,
  "auth.passwordPolicy": {
    "enabled": true,
    "numberOfSpecialCharacters": 1,
    "requireAtLeastOneNumber": true,
    "requireUpperandLowerCase": true
  }
}

How account linking works

Sourcegraph links accounts across providers by matching verified email addresses. When a user signs in with a new provider, if their email matches an existing Sourcegraph account, the accounts are linked. If there is no match and allowSignup is enabled, a new account is created. Usernames from external providers are normalized: characters outside [a-zA-Z0-9-._] are replaced with -, and email-style usernames are truncated at @. For example, [email protected] becomes alice-smith.

Managing user accounts

Site admins can manage users at Site admin > Users:
  • Create users: Go to /site-admin/users/new to create accounts manually.
  • Deactivate users: Deactivated users cannot sign in but their data is retained.
  • Delete users: Permanently removes the account and all associated data.
  • Reset passwords: For builtin auth, admins can send password reset emails.

SCIM provisioning (beta)

SCIM (System for Cross-domain Identity Management) lets your identity provider automatically provision and deprovision Sourcegraph user accounts. To enable SCIM, set a shared secret token in site configuration:
{
  "scim.authToken": "your-scim-token",
  "scim.identityProvider": "STANDARD"
}
Use "scim.identityProvider": "Azure AD" if your IdP is Microsoft Entra ID (Azure AD). The SCIM endpoint is https://sourcegraph.example.com/.api/scim/v2. Configure this in your IdP’s enterprise application settings along with the auth token.

Session settings

Control how long user sessions remain valid:
{
  "auth.sessionExpiry": "2160h",
  "auth.maxSessionIdleDuration": "0"
}
  • auth.sessionExpiry: Maximum session duration (default: 90 days / 2160h). Must be at least 1 hour.
  • auth.maxSessionIdleDuration: If set, sessions expire after this period of inactivity. Defaults to no idle expiry.

Access tokens

Users can create personal access tokens for API and CLI access. Control this with:
{
  "auth.accessTokens": {
    "allow": "all-users-create",
    "allowNoExpiration": false,
    "defaultExpirationDays": 90
  }
}
Set "allow": "site-admin-create" to restrict token creation to site admins, or "allow": "none" to disable access tokens entirely.

Build docs developers (and LLMs) love