Your next coffee is on us. → Tell us how Traceway is working for you. Share your experience →
Self Host
SSO

Single Sign-On (SSO)

On a self-hosted Traceway your team can sign in with Google, GitHub, or your own identity provider (Authentik, Keycloak, Okta, Dex, or anything else that speaks OpenID Connect), next to email and password or in place of it. Every provider you configure adds a Continue with ... button to the login and register pages. A provider you do not configure simply has no button.

SSO is configured with environment variables on the backend. There is nothing to switch on in the dashboard. Setting it up takes three steps:

What you doWhereHow often
1Register Traceway with the providerThe provider's admin consoleOnce per provider
2Set the environment variables and restartThe Traceway backendOnce per provider
3Let your team inTraceway Settings, or one more variableOnce, or once per person

The examples use https://traceway.mycompany.com as the address of your instance. Use your own everywhere you see it.

Step 1: Register Traceway with the provider

A provider only sends users back to applications it knows. You register Traceway there and get a client ID and a client secret in return.

The one value the provider needs from you is the callback URL. It is the address of your instance followed by /api/auth/callback/ and google, github or oidc. It must match exactly, with no trailing slash.

GitHub calls these OAuth Apps. A GitHub App is a different thing.

  1. On GitHub, open Settings → Developer settings → OAuth Apps → New OAuth App. For an app owned by an organization, start from the organization's Settings instead.
  2. Fill in the form:
    • Application name: what users see on the consent screen, for example Traceway.
    • Homepage URL: https://traceway.mycompany.com
    • Authorization callback URL: https://traceway.mycompany.com/api/auth/callback/github
  3. Click Register application.
  4. On the app page, click Generate a new client secret. Copy the Client ID and the secret now. GitHub shows the secret only once.

Traceway asks GitHub for the user:email scope. Each person needs a verified primary email address on their GitHub account, or their sign-in fails.

Google and GitHub can be on at the same time as one OIDC provider. Repeat this step for each one you want.

To try SSO on a local instance, register a second application whose callback uses the local address, and use that address as APP_BASE_URL in step 2. With the dashboard dev server that is http://localhost:5173, so the GitHub callback is http://localhost:5173/api/auth/callback/github.

Step 2: Set the environment variables and restart

Give the backend the values from step 1, plus APP_BASE_URL, the public address of your instance. Traceway builds the callback URL from it, so it has to be the same address you registered.

APP_BASE_URL=https://traceway.mycompany.com
GITHUB_CLIENT_ID=Ov23li...
GITHUB_CLIENT_SECRET=...

Set them where the rest of your backend configuration lives, for example the environment: block of your Compose file or the -e flags of docker run. Then restart the backend. Providers are read once, at startup.

With Docker, a container keeps the environment it was created with. Recreate it (docker compose up -d) so it sees the new variables. docker restart is not enough.

Step 3: Let your team in

A self-hosted instance is invite-only once it has an organization, and SSO does not change that. You can sign in with SSO right away if your provider account has the same email address as your Traceway account. A colleague who has no Traceway account yet is sent back to the login page with:

This server is invite-only. Ask an admin to invite you.

There are two ways to let people in.

Invite each person

Works with every provider.

  1. Open Settings at the bottom of the sidebar and go to Team Members.
  2. Click New Invitation, enter the person's email address and pick a role.
  3. The person accepts the invitation from the email.

From then on they can use the Continue with ... button, as long as their provider account has the email address you invited.

Auto-creating OIDC users

Works with the OIDC provider only, not with Google or GitHub. Use it when your identity provider already decides who belongs to your team.

OIDC_AUTO_CREATE_USERS=true

After a restart, everyone who signs in through your OIDC provider:

  • gets a Traceway account, if they do not have one yet, and
  • joins your organization with the user role, or with the role that role mapping gives them.

An account that already exists but belongs to no organization joins on its next sign-in.

Only turn this on for a provider where you control who has an account. With a provider that is open to the public, anyone who can sign in there gets into your Traceway.

Starting from an empty instance

On a new instance without an organization, the first person who signs in with SSO lands on a setup page, creates the organization and the first project there, and becomes the owner. Everyone after that needs an invitation or auto-creation.

Check that it works

Ask the backend which providers it loaded:

curl https://traceway.mycompany.com/api/auth/providers

The answer, formatted here for reading:

{
  "providers": ["google", "github", "oidc"],
  "providerLabels": { "oidc": "Authentik" },
  "passwordLoginEnabled": true
}

Every provider you configured should be in providers. Then open https://traceway.mycompany.com/login in a private browser window. The Continue with ... buttons are above the email and password form. Click one, approve at the provider, and you should land in the dashboard as yourself.

If a provider is missing from the list or the sign-in ends on the login page with a message, see When sign-in fails.

Role mapping

Works with the OIDC provider. By default a person keeps the role they were invited with, and an auto-created user gets user. With role mapping, a claim your identity provider sends decides the role. That is useful when group or role membership is already managed centrally, for example in Keycloak.

Two variables turn it on, and both are needed:

OIDC_ROLE_CLAIM=realm_access.roles
OIDC_ROLE_MAP={"traceway-admin":"admin","traceway-ro":"readonly"}
  • OIDC_ROLE_CLAIM is the path to the claim that holds the role or roles. Dots step into nested objects. The value can be one string or a list of strings. Traceway reads it from the ID token and from the provider's UserInfo response.
  • OIDC_ROLE_MAP is a JSON object that maps claim values to the Traceway roles admin, user and readonly.

How it behaves:

  • It runs on every sign-in, not only the first. Change someone's group at the identity provider and their Traceway role follows the next time they sign in.
  • The highest role wins. If several of a person's claim values are in the map, they get the highest one: admin, then user, then readonly.
  • No match changes nothing. If none of a person's claim values is in the map, their role stays as it is.
  • Owners are left alone. The owner role is never given by mapping and never taken away by it.

Keycloak example: realm roles

Keycloak puts realm-level roles in the token under realm_access.roles:

{
  "realm_access": {
    "roles": ["traceway-admin", "offline_access", "uma_authorization"]
  }
}

To make holders of traceway-admin admins and holders of traceway-ro read-only:

OIDC_ROLE_CLAIM=realm_access.roles
OIDC_ROLE_MAP={"traceway-admin":"admin","traceway-ro":"readonly"}

Create the matching realm roles in Keycloak (Realm Settings → Roles → Create role) and assign them to users or groups.

Generic example: groups claim

Many providers send group membership as a top-level groups claim:

{
  "groups": ["/admins", "/users"]
}
OIDC_ROLE_CLAIM=groups
OIDC_ROLE_MAP={"/admins":"admin","/users":"user"}

Adding the claim in Authentik

Authentik does not send role or group claims by default. Add them with a scope mapping:

  1. Go to Customization → Property Mappings → Create → Scope Mapping.
  2. Set the Scope name to a scope of your own, for example traceway.
  3. Set the Expression so that it returns the claim:
    return {"groups": [g.name for g in request.user.ak_groups.all()]}
  4. Add traceway to the scopes of your Authentik provider, and tell Traceway to ask for it with OIDC_EXTRA_SCOPES:
    OIDC_EXTRA_SCOPES=traceway
    OIDC_ROLE_CLAIM=groups
    OIDC_ROLE_MAP={"traceway-admins":"admin","traceway-users":"user"}

Routing users to organizations

A self-hosted instance normally has one organization, and auto-created users join it. Skip this section unless your instance holds several organizations.

With several organizations, auto-created users join the oldest one. To send each person to a specific organization, let your identity provider name it in a claim:

  1. Set OIDC_ORG_CLAIM to the name of the claim that carries the organization name:
    OIDC_ORG_CLAIM=traceway_org
  2. Set OIDC_EXTRA_SCOPES to the scope that makes your provider send that claim. It is a comma-separated list:
    OIDC_EXTRA_SCOPES=traceway
  3. Configure your provider to send the claim. The Authentik steps are below.

When someone without an organization signs in, Traceway reads traceway_org and looks the organization up by name. The name has to match exactly, including upper and lower case. If the claim is missing or no organization has that name, the person joins the oldest organization.

The claim has to be at the top level of the token and hold one name as text. A path with dots is not supported here.

Adding the organization claim in Authentik

  1. Go to Customization → Property Mappings → Create → Scope Mapping.
  2. Set the Scope name to traceway. It must match OIDC_EXTRA_SCOPES.
  3. Set the Expression so that it returns the claim:
    return {"traceway_org": "My Organization Name"}
    You can compute the name per user with Authentik's expression variables, for example from request.user.ak_groups.all().
  4. Open your Traceway provider in Authentik, go to Advanced protocol settings → Scopes and add traceway next to openid, email and profile.

Keycloak, Okta, Dex and other providers send custom claims too, each through its own claim or attribute mapping.

Providers without OIDC discovery

Most OIDC providers publish a discovery document at /.well-known/openid-configuration. For one that does not, give Traceway the three endpoints in place of OIDC_DISCOVERY_URL:

OIDC_CLIENT_ID=traceway
OIDC_CLIENT_SECRET=...
OIDC_AUTH_URL=https://provider.example.com/oauth/authorize
OIDC_TOKEN_URL=https://provider.example.com/oauth/token
OIDC_USER_INFO_URL=https://provider.example.com/oauth/userinfo

All three have to be set. If OIDC_DISCOVERY_URL is set as well, it wins and the three URLs are ignored.

Forcing SSO-only login

To make everyone sign in through a provider, turn password login off:

DISABLE_PASSWORD_LOGIN=true

Set it only after you have signed in with SSO yourself. With password login off and no working provider, nobody can sign in until you remove the variable again.

With it set:

  • The email and password form and the "or" divider are gone from the login page. The register and forgot-password pages send visitors to the login page.
  • POST /api/login, POST /api/register and the password reset endpoints answer 403 with Password login is disabled. Please use SSO to sign in. Scripts that log in with a password fail with that message, and so does traceway login --password. The CLI's default browser login keeps working.
  • passwordLoginEnabled in /api/auth/providers is false.

People still need an account to get in. On a new instance without an organization, the first person signs in with SSO and creates the organization, because the register page is off. Combine SSO-only login with auto-creating OIDC users so that nobody has to be invited. If you invite people instead, the invitation page still asks a new person to choose a password. That password is not usable while password login is off.

How it works

Browser ──► /api/auth/start/github
            └─► redirect to GitHub
                └─► user approves
                    └─► GitHub redirects to /api/auth/callback/github
                        └─► backend issues a JWT, redirects to
                            /auth/callback#token=<jwt>&needsSetup=<bool>
                            └─► frontend stores the token,
                                navigates to / (or /finish-setup
                                for brand-new users)

When the provider sends someone back, Traceway finds their account in this order:

  1. By provider identity. Someone who signed in with this provider before is recognized by the provider's user ID and logged in.
  2. By email address. If an account with the same email exists, for example one that was created with a password, the provider identity is linked to it. Both ways of signing in work from then on.
  3. New user. Otherwise an account is created, if the instance allows it. A self-hosted instance that already has an organization does not, unless auto-creating OIDC users is on. The person is sent back to the login page with invite_required.

A person who ends up with an account but no organization is sent to /finish-setup to create one. On a self-hosted instance that is the very first user. In cloud mode (CLOUD_MODE=true) it happens to every new email, because sign-up is open there.

Environment variables

Set these on the backend. Each provider is independent: configure one, several or none.

All providers

VariableDescription
APP_BASE_URLRequired. Public address of your instance, for example https://traceway.mycompany.com. Used to build the callback URL and to send the browser back after sign-in.
OAUTH_SESSION_SECRETOptional. Signs the cookie used during the sign-in round trip. Falls back to JWT_SECRET. Set it to rotate cookie signing separately from sessions.
DISABLE_PASSWORD_LOGINOptional. true turns email and password login off. See Forcing SSO-only login.

Google and GitHub

VariableDescription
GOOGLE_CLIENT_IDOAuth client ID from the Google Cloud Console.
GOOGLE_CLIENT_SECRETOAuth client secret. Both Google variables are needed for the button to appear.
GITHUB_CLIENT_IDClient ID of the GitHub OAuth App.
GITHUB_CLIENT_SECRETClient secret of the GitHub OAuth App. Both GitHub variables are needed.

OIDC

VariableDescription
OIDC_CLIENT_IDRequired. Client ID from your provider.
OIDC_CLIENT_SECRETRequired. Client secret from your provider.
OIDC_DISCOVERY_URLFull URL of the discovery document, usually ending in /.well-known/openid-configuration. Required unless you set the three endpoint URLs below.
OIDC_AUTH_URLAuthorization endpoint, for a provider without discovery. Needs the next two as well. See Providers without OIDC discovery.
OIDC_TOKEN_URLToken endpoint.
OIDC_USER_INFO_URLUserInfo endpoint.
OIDC_DISPLAY_NAMEOptional. Name on the button, after "Continue with". Defaults to SSO.
OIDC_EXTRA_SCOPESOptional. Comma-separated scopes to request on top of openid, email and profile. Needed when a custom scope carries your role or organization claim.
OIDC_AUTO_CREATE_USERSOptional. true creates accounts and organization membership for unknown emails. See Auto-creating OIDC users.
OIDC_ROLE_CLAIMOptional. Path to the claim with the user's roles, for example realm_access.roles or groups. See Role mapping.
OIDC_ROLE_MAPOptional. JSON object from claim values to admin, user or readonly. See Role mapping.
OIDC_ORG_CLAIMOptional. Name of a claim that holds the organization to join. See Routing users to organizations.

When sign-in fails

A failed sign-in ends on the login page with one of these messages. The backend sends the browser there as /login?error=<code>, and the table names the code with each cause.

Message on the login pageCauseFix
This server is invite-only. Ask an admin to invite you.invite_required: the email has no Traceway account and the instance already has an organizationInvite the person, or turn on auto-creation
We couldn't read an email address from that account. Please make sure it has a verified email and try again.oauth_no_email: the provider sent no email addressGive the user an email at the provider, and allow the email scope for the client
Sign-in failed. Please try again.oauth_failed: the provider refused, the person cancelled, the callback URL or client secret is wrong, more than 10 minutes passed at the provider, or a GitHub account has no verified primary emailCompare the callback URL and the secret with step 1, then try again

When a button is missing or a setting has no effect, start with /api/auth/providers:

What you seeCauseFix
providers is emptyThe backend did not get your variablesCheck that they are set on the backend container and that it was recreated, not only restarted. Without Docker, set them in the shell that starts the backend
One provider is missingIts client ID or client secret is emptySet both variables of that provider
oidc is missingOIDC_DISCOVERY_URL is not set and the three endpoint URLs are not all set, or the discovery URL could not be fetchedOpen the discovery URL from the machine the backend runs on, fix it, and restart
Roles are not appliedOIDC_ROLE_MAP is not valid JSON, or the claim is not in the tokenCheck the JSON, and request the scope that carries the claim with OIDC_EXTRA_SCOPES

Traceway fetches the discovery document once, when it starts. If that fails, OIDC stays off until the next restart, and nothing is printed to the backend's output. With self-monitoring on, the failure shows up as an issue whose message contains OIDC provider init failed.

Security notes

  • The callback hands the session token back in the URL fragment (#token=...), so it never reaches the backend logs or a TLS-terminating proxy as a query string.
  • The cookie used during the round trip is HttpOnly and SameSite=Lax, lives for 10 minutes, and is marked Secure when APP_BASE_URL starts with https://. It holds a signed session ID only. The provider session itself is stored in the main database.
  • OAUTH_SESSION_SECRET is the signing key of that cookie. Changing it breaks sign-ins that are in progress at that moment and nothing else. Sessions that were already issued are signed with JWT_SECRET.
  • Accounts are matched by the email address the provider reports. For the OIDC provider Traceway does not check an email_verified claim, so connect only a provider whose email addresses you trust.
  • A user created through SSO has no password. Password login for that account fails until the person sets one with Forgot password? on the login page.
  • Role mapping never makes anyone an owner.