Auth
What is this
Who is making a request, and what they’re allowed to see and do. It’s split in three, and only the first part is a plugin:
| Layer | Owned by | Answers |
|---|---|---|
| Authentication | an AuthProvider plugin — swappable |
How does a person prove who they are? |
| API tokens | core | How does a training script prove who it is? (the same way under every provider) |
| Authorization | core, always on | What may this user see or change? |
Built-in providers:
anonymous(LOCAL_AUTH, whatdlboard serve localuses) — nobody signs in. A request is attributed to a best-effort name (the client’sX-Dlboard-Userheader,DLBOARD_USER, or the OS login), which nothing proves, so access control stays off: everyone can see and edit everything, liketensorboard.password(PASSWORD_AUTH) — username/password accounts, for hosting dlboard for other people without an identity provider.trusted_header(TRUSTED_HEADER_AUTH) — a reverse proxy that already signed the caller in (oauth2-proxy, Pomerium, Authelia, …) says who they are in headers.oidc(OIDC_AUTH) — an OpenID Connect identity provider (Okta, Entra ID, Google, Keycloak, …) signs people in, with dlboard as its client and no proxy in front.
When you’d need this
- You’re hosting dlboard for more than yourself, and people should only see their own (or their team’s) projects: deploy with
PASSWORD_AUTH(below). - Your organization already has an identity provider (Okta, Entra ID, Google, Keycloak, …): deploy with
OIDC_AUTH(below). If a proxy in front already signs people in against it, deploy withTRUSTED_HEADER_AUTHinstead.
How it works
Every request goes through one gate.
install_request_gate (dlboard/serve/_backend/_auth.py) puts a before_request hook in front of every route: pages, Dash callbacks, REST, and /artifact/<id>.
In order, it tries:
- an API token,
Authorization: Bearer dlb_.... A token that doesn’t check out is a 401. It never falls back to another way of identifying the caller. - a signed-in session cookie (only under a provider that verifies identity),
- the provider’s own
authenticate().
Whoever that resolves to is bound to the request, and get_current_user() reads it back.
Someone it can’t resolve is redirected to the provider’s login_url() if they’re a browser asking for a page.
Anything else gets a 401.
Only routes registered with add_public_route skip the gate.
Every store access is authorized.
get_data_store()/get_artifact_store() return wrappers bound to the request’s user (dlboard/serve/_backend/_authorization.py), so no page, callback or REST handler can forget to check, and no storage backend has to know about users.
Background work with no user behind it uses get_system_data_store() explicitly.
Access is per project. Experiments, runs, metrics, artifacts, views and notes inherit it from their project:
| Role | Can |
|---|---|
viewer |
read everything, post notes, save personal views |
editor |
+ log runs/metrics/artifacts, create experiments, edit the shared layout, soft-delete within the project, keep a run, hold an experiment to a stricter retention rule |
owner |
+ manage members and sharing, rename or delete the project, set its retention rule, release or delete a kept run |
A role comes from a grant to a user, a grant to an IdP group, or the project’s everyone_role (“everyone signed in can view/edit”).
Whoever creates a project owns it.
Something you can’t see reads as missing, exactly like something that doesn’t exist.
Site-wide powers are Scopes on the user: restore, purge, the audit log, and user:manage.
An admin (Scope.ALL) is an owner everywhere.
Under anonymous, grants aren’t enforced: everyone is an editor everywhere, and deleting still takes the scope it always has.
The first user anonymous ever sees becomes the admin.
A provider that verifies identity never does that; its admins come from configuration instead.
Hosting dlboard for other people (PASSWORD_AUTH)
# mydeployment.py
from dlboard.plugins import BUILTIN_BACKEND, BUILTIN_CHARTS, PASSWORD_AUTH, POSTGRES_S3_STORAGE, themes
PLUGINS = [*POSTGRES_S3_STORAGE, *PASSWORD_AUTH, *BUILTIN_BACKEND, *BUILTIN_CHARTS, themes.default]
export DLBOARD_SECRET_KEY=$(openssl rand -hex 32) # signs sessions; the same for every worker
dlboard serve custom --plugins mydeployment:PLUGINS --host 0.0.0.0 --workers 4
dlboard users set-password alice --admin --plugins mydeployment:PLUGINS # your first admin
Serve it over HTTPS (session cookies are Secure by default), behind a reverse proxy that rate-limits /login.
The provider’s own throttle is per username, per worker process.
Without a shell, set DLBOARD_PASSWORD_FIRST_ADMIN_SETUP=true for the first start instead.
Then open /setup, which logs a setup token derived from DLBOARD_SECRET_KEY so every worker agrees on it, and enter that token to create the admin.
Turn the setting back off afterwards.
If it’s still on once the database has users, the server refuses to start until you turn it off.
The setting is off by default, and even when it’s on, /setup only works while the database has no users at all.
Once any user exists, /setup returns 404 for good.
Demoting every admin doesn’t reopen it, and neither does relying on DLBOARD_ADMIN_USERS.
Anyone who can read the server log during that first window could create the admin first, so do it before sharing the address.
Letting people sign up
There is a sign-up page, /signup, but it is off by default: on a server anyone can reach, strangers should not be able to make themselves an account unless you say so.
With the default, DLBOARD_PASSWORD_SIGNUP=admin_creates, /signup answers 404, the login page offers no way to make an account, and an admin creates each one from Admin → Users (or dlboard users set-password NAME).
Set it to open the page; the login page then links to it (“No account yet?
Create one”):
approval: anyone can sign up, but the account stays disabled until an admin enables it from Admin → Users. Sign-up says so, and the person can sign in once that’s done.open: anyone who can reach the server can sign up and use it straight away. Only for a server on a network you trust.
Either way, a new account sees only the projects that let it: one shared with it from the project’s Sharing tab, or one that gives everyone a role (which DLBOARD_NEW_PROJECT_ACCESS, below, does for each new project).
| Setting | Default | |
|---|---|---|
DLBOARD_SECRET_KEY |
— (required) | Signs session cookies. Startup fails without it. |
DLBOARD_ADMIN_USERS |
none | Comma-separated usernames made admin whenever they sign in. |
DLBOARD_ADMIN_GROUPS |
none | Comma-separated IdP groups whose members are made admin, and stop being one when they leave the group. |
DLBOARD_TOKEN_IDLE_DAYS |
unset (never) | An API token nothing has used for this many days stops working; using it starts that over. |
DLBOARD_NEW_PROJECT_ACCESS |
unset (private) | viewer/editor: what everyone signed in gets on a new project. |
DLBOARD_SESSION_LIFETIME_HOURS |
336 | How long a browser stays signed in. |
DLBOARD_SECURE_COOKIES |
true |
Turn off only for plain-HTTP testing. |
DLBOARD_PASSWORD_SIGNUP |
admin_creates |
Who may make an account at /signup: approval (sign up, then an admin enables you) or open. See Letting people sign up. |
DLBOARD_PASSWORD_MIN_LENGTH |
12 | |
DLBOARD_PASSWORD_FIRST_ADMIN_SETUP |
false |
Serve /setup for the first admin (above). Startup fails if it’s on and the database already has users. |
The rest happens in the app:
- Admins add users and reset passwords from Admin → Users. They can also disable users and grant admin there.
- Project owners share a project from its page’s Sharing tab, with someone who has an account, or with a group.
With
OIDC_AUTH, an email address invites someone who hasn’t signed in yet; password accounts have no email, so the Sharing tab offers no invites here. - Everyone creates API tokens for their training scripts (the home page offers a newcomer their first in one click, and the Account page makes more), then sets
DLBOARD_API_KEYwhereverDLBoardLoggerruns (see client.md).
Signing in with your identity provider (OIDC_AUTH)
dlboard can be the OpenID Connect client itself, so Okta, Entra ID, Google, Keycloak or any other OIDC provider signs people in with no proxy in front:
# mydeployment.py
from dlboard.plugins import BUILTIN_BACKEND, BUILTIN_CHARTS, OIDC_AUTH, POSTGRES_STORAGE, themes
PLUGINS = [*POSTGRES_STORAGE, *OIDC_AUTH, *BUILTIN_BACKEND, *BUILTIN_CHARTS, themes.default]
export DLBOARD_SECRET_KEY=$(openssl rand -hex 32) # signs sessions; the same for every worker
export DLBOARD_OIDC_ISSUER=https://example.okta.com/oauth2/default
export DLBOARD_OIDC_CLIENT_ID=0oa1example
export DLBOARD_OIDC_CLIENT_SECRET=...
export DLBOARD_ADMIN_GROUPS=dlboard-admins # optional: who is an admin
dlboard serve custom --plugins mydeployment:PLUGINS --host 0.0.0.0 --workers 4
A signed-out browser is sent to /login, which sends it on to the provider, and comes back to /oidc/callback; register that as the redirect URI, under your server’s public address (and DLBOARD_URL_PREFIX, if you set one).
The other settings (scopes, which claims name someone and list their groups, timeouts) are in Configuration.
Setting it up in Okta
- In the Admin Console, go to Applications → Create App Integration, and choose OIDC - OpenID Connect and Web Application.
- Set the sign-in redirect URI to
https://dlboard.example.com/oidc/callbackand the sign-out redirect URI tohttps://dlboard.example.com/, and keep the Authorization Code grant. Also tick the Refresh Token grant, so that dlboard can ask Okta about each person once a day (below). - Assign it the people or groups who may use dlboard. Okta refuses anyone else, and dlboard shows them why.
- Copy the client ID and secret into
DLBOARD_OIDC_CLIENT_IDandDLBOARD_OIDC_CLIENT_SECRET. - For groups, go to Security → API → Authorization Servers, open the server (
default), and add a claim on its Claims tab: namegroups, included in the ID token always, value type Groups, with a filter such as “Starts with”dlboard-. - Set
DLBOARD_OIDC_ISSUERto that server’s Issuer URI,https://example.okta.com/oauth2/default.
Other providers differ in where the issuer and groups come from:
- Entra ID: the issuer is
https://login.microsoftonline.com/<tenant-id>/v2.0. A groups claim (Token configuration → Add groups claim) lists group ids, not names, soDLBOARD_ADMIN_GROUPSand group grants name the ids. Past 200 groups the token lists none, so emit only the groups assigned to the application. Or name groups by app role instead: assign roles in the app registration and setDLBOARD_OIDC_GROUPS_CLAIM=roles. - Keycloak: the issuer is
https://keycloak.example.com/realms/<realm>, and a Group Membership mapper (with “Full group path” off) addsgroups. - Google: the issuer is
https://accounts.google.com, and it sends no groups, so share by person or with everyone.
What it does
- An ID token is believed only once it checks out.
Its signature must be by one of the keys the provider publishes (fetched again when it rotates them), with a public-key algorithm: never
none, or one made with the client secret. Its issuer must be the one the provider calls itself, which must beDLBOARD_OIDC_ISSUER; it must be addressed toDLBOARD_OIDC_CLIENT_ID, unexpired, and carry thenonceof the sign-in it ends. The callback must carry its sign-in’sstate, which is used once, from the browser that started it, and the code is redeemed with PKCE. - An account is made the first time the provider signs someone in.
It is known by the issuer and their
sub, and named by the username claim (preferred_username, which in Okta is their Okta username), else their email, else theirsub. The name is set once: renaming someone in the provider doesn’t rename them here, and a new identity under a name another account already has is refused, saying so. A new account can see only what is shared with everyone (DLBOARD_NEW_PROJECT_ACCESS, a project’s sharing) or with one of its groups. Admins come fromDLBOARD_ADMIN_GROUPSorDLBOARD_ADMIN_USERS; nobody is made admin for signing in first. - The provider is asked about everyone once a day, whether they sign in or not.
At sign-in dlboard asks for
offline_access, when the provider offers it (Okta, Entra ID and Keycloak do; Google doesn’t), and keeps the refresh token it gives, encrypted withDLBOARD_SECRET_KEY. EveryDLBOARD_OIDC_RECHECK_HOURS(24) it asks the provider to renew each person’s sign-in with it, from the custodian, so it learns what changed even for someone who only ever uses a token.0turns this off. - Someone the provider removes is disabled within a day.
When the provider refuses to renew their sign-in (it deactivated them, or took them off the app), dlboard disables them: their API and run tokens stop, and so do their browser’s sessions.
Admin → Users says they were removed by the identity provider.
If the provider lets them in again, their next sign-in enables them again, with the tokens they had; one an admin disabled stays disabled.
A provider that can’t be reached changes nothing: it is asked again on the next run.
With a provider that gives no refresh tokens, disable them in Admin → Users instead, and
DLBOARD_TOKEN_IDLE_DAYSstops the tokens they left behind. - Change
DLBOARD_SECRET_KEYwith the old one inDLBOARD_SECRET_KEY_FALLBACKS. Changed alone, it signs every browser out (with OIDC, most are signed straight back in by the provider) and drops every refresh token, so someone who only uses a token is no longer asked about until they sign in again. With the old key as a fallback, sessions go on and each refresh token is sealed with the new key at its next renewal; after a session lifetime and a day, remove the fallback. API and run tokens never depend on the key. - Groups are as the provider last said, at sign-in or at its last renewal.
A group someone leaves, and admin they had from
DLBOARD_ADMIN_GROUPSalone, are gone by the next renewal, so within a day. - A project can be shared with someone before they ever sign in, by their email.
An owner types the address on the Sharing tab, where a username goes, and it waits there as an invite until the first sign-in whose provider says it checked that address (
email_verified): that person is granted its role, and the invite is gone. An invite lastsDLBOARD_INVITE_DAYS(30), so that an address someone left with is not taken up by whoever it passes to, and an owner can withdraw it until then; one to someone who already has a role on the project leaves that role as it is. Okta, Google and Keycloak say they checked an address; Entra ID never does, so with Entra ID share with a group instead, which also works for people who haven’t signed in yet. - Signing out of dlboard signs the browser out of the provider too.
dlboard ends its session, then sends the browser to the provider’s
end_session_endpoint(OpenID Connect RP-initiated logout), naming the sign-in and the client, and the provider sends it back to the app’s front page, which asks it to sign in again. Register that page (DLBOARD_OIDC_POST_SIGN_OUT_URL, elsehttps://<your server>/) as a sign-out redirect URI with the provider. A provider with no such endpoint (Google), orDLBOARD_OIDC_SIGN_OUT_AT_PROVIDER=false, signs out of dlboard alone, and while the provider still has the person signed in, their next visit signs them straight back in. - Behind a proxy that terminates TLS, set
DLBOARD_TRUSTED_PROXIES. The redirect URI is the request’s own scheme and host, so without it the provider is asked to send people back tohttp://, which it refuses; or setDLBOARD_OIDC_REDIRECT_URL. - A training script signs in with an API token, as under every provider.
Behind an authenticating proxy (TRUSTED_HEADER_AUTH)
When a reverse proxy in front already signs people in against your identity provider, dlboard can believe the headers it forwards:
# mydeployment.py
from dlboard.plugins import BUILTIN_BACKEND, BUILTIN_CHARTS, POSTGRES_STORAGE, TRUSTED_HEADER_AUTH, themes
PLUGINS = [*POSTGRES_STORAGE, *TRUSTED_HEADER_AUTH, *BUILTIN_BACKEND, *BUILTIN_CHARTS, themes.default]
It needs DLBOARD_TRUSTED_HEADER_ISSUER, a stable name for the identity source, and DLBOARD_TRUSTED_HEADER_PROXIES, the proxy’s addresses; the headers it reads are settings too (see Configuration).
Their defaults are what oauth2-proxy sends with --pass-user-headers.
Authelia sends Remote-User, Remote-Email and Remote-Groups; Pomerium sends what its jwt_claims_headers names.
DLBOARD_SECRET_KEY is needed as for any provider that verifies identity.
- The headers are believed from the proxy alone.
DLBOARD_TRUSTED_HEADER_PROXIESis checked against the connection’s own address, never againstX-Forwarded-For, which a client can write. A request from anywhere else that carries one of the headers gets a 403, so a network that lets someone reach dlboard around the proxy shows up at once. The proxy must also overwrite these headers on every request it forwards, never pass along ones the client sent (oauth2-proxy and Pomerium do). - An account is made the first time the proxy names someone.
There is nothing to create beforehand, and Admin → Users lists people once they have visited.
A new account can see only what is shared with everyone (
DLBOARD_NEW_PROJECT_ACCESS, a project’s sharing) or with one of its groups, and can make projects of its own. Admins come fromDLBOARD_ADMIN_GROUPSorDLBOARD_ADMIN_USERS; nobody is made admin for signing in first. - It is known by its user header, and named by its username header.
The user header must carry the identity provider’s stable id (an OIDC
sub): an account is found by it on every request, so a value that changes (an email, a renamed user) makes a new, empty account. The username header (X-Forwarded-Preferred-Username, which oauth2-proxy sends) is the readable name the account is made with, and what sharing andDLBOARD_ADMIN_USERSname it by; without it, the account is named by its user header. The name is set once: renaming someone in the identity provider doesn’t rename them here, and a new identity under a name another account already has is refused, saying so. If people can choose their own username in the identity provider, grant admin by group (DLBOARD_ADMIN_GROUPS), not by name: anyone could otherwise take a name inDLBOARD_ADMIN_USERSthat hasn’t signed in yet. - A project can be shared with someone once they have visited. Before that, the Sharing tab doesn’t know the name; share with one of their groups instead, which works for people who haven’t visited yet. The Sharing tab offers no invites by email here: a proxy’s headers are only its word for an address, and an invite needs the identity provider’s.
- When someone leaves, disable them in Admin → Users.
Removing them from the identity provider stops the proxy signing them in, but a token never goes through the proxy, so their tokens keep working.
Disabling them stops everything at once: a disabled user can’t use the app or any token.
DLBOARD_TOKEN_IDLE_DAYSstops a token nothing has used for that many days, so the keys they left behind end on their own, but never one a job is still using: a run that trains for months must not lose what it logs to it. Their groups stay as the proxy last sent them until they sign in again (#822). - Admin from a group lasts as long as the group does.
Someone made admin by
DLBOARD_ADMIN_GROUPSalone stops being one the first time the proxy signs them in without the group. An admin made any other way (byDLBOARD_ADMIN_USERS, or from Admin → Users) is kept until it’s taken away there. - A training script signs in with an API token, not the proxy. A token works from anywhere, so a script can talk to dlboard directly or through the proxy, if the proxy lets bearer tokens through.
- Signing out is the proxy’s to do: the headers sign a browser in again on its next request.
- An AWS ALB’s or Cloudflare Access’s signed assertion (
x-amzn-oidc-data,Cf-Access-Jwt-Assertion) is not checked: put oauth2-proxy (or another proxy that forwards plain headers) behind them, or useOIDC_AUTHinstead.
How do I build a provider
Implement AuthProvider (dlboard/models/_auth.py) and register it from plug(app).
For example, behind a proxy that has already authenticated the caller:
from typing import ClassVar
from flask import request
from dlboard.models import Principal
from dlboard.serve import set_auth_provider
class ProxyHeaderProvider:
display_name: ClassVar[str] = "Company SSO"
verifies_identity: ClassVar[bool] = True
verifies_email: ClassVar[bool] = False # True only if it checks their email (`email_verified`)
manage_url: ClassVar[str | None] = None # where a user manages their own sign-in
admin_url: ClassVar[str | None] = None # where an admin adds users; None = users come from the IdP
def authenticate(self) -> Principal | None:
email = request.headers.get("X-Forwarded-Email")
if email is None:
return None
groups = frozenset(filter(None, request.headers.get("X-Forwarded-Groups", "").split(",")))
return Principal(
issuer="https://sso.example.com",
subject=email,
username=email.split("@")[0],
email=email,
groups=groups,
)
def login_url(self, next_path: str) -> str | None:
return None # the proxy handles sign-in before a request ever gets here
def sign_out_url(self) -> str | None:
return None # signing out is the proxy's too; an OIDC provider returns its end-session URL
@classmethod
def get_or_create(cls) -> "ProxyHeaderProvider":
return cls()
def plug(app) -> None:
set_auth_provider(app, ProxyHeaderProvider.get_or_create())
- A
Principalis keyed by(issuer, subject), not by username.subjectmust be the identity provider’s stable id (an OIDCsub). A user who is renamed keeps their projects, and two identity providers presenting the same username can’t take over each other’s accounts. authenticate()is called on every request that has no API token and no session. ReturnNoneif your provider signs people in through a form or redirect instead. In that case, register those routes withadd_public_route. Once the person proves who they are, callsign_in(store, principal, get_auth_settings()), thenstart_session(user). Seepassword.py, oroidc.pyfor a redirect to an identity provider.- Check configuration that needs the data store with
add_startup_check(app, check). Plugin order isn’t guaranteed, so the store may not be set yet during yourplug(). A registered check runs once every plugin has plugged in, and startup fails if it raises. - Only set
verifies_identity = Trueif the provider really proves identity. It turns on access control, and that’s only as strong as the provider’s proof.trusted_header-style providers must only be reachable through the proxy. - Only one provider per app.
set_auth_providerrefuses a second one.