ADR-0023: Roles from single sign-on groups¶
- Status: accepted (operator decision
snatcharr-served-identity-role, answer a, 2026-10-21) - Date: 2026-10-21
Context¶
SnatchArr has two roles, admin and viewer (api/internal/domain/user.go, User.role in api/openapi/openapi.yaml), but only part of the API checks for admin today:
- Gated: the instance, download-client, Prowlarr and Seerr writes and their
Test*Inputprobes (requireAdmin,api/internal/httpapi/handlers_instances.go), and four reads:ListLogs,GetConfigarrStatus,GetPolicyFilterOptionsand the log stream (adminOnly,api/internal/httpapi/module.go). - Not gated: the notification channel and rule writes plus
TestNotificationChannel(handlers_notifications.go),CreateAPIKeyandRevokeAPIKey(handlers_apikeys.go), and the probes of stored targetsTestInstance,TestDownloadClient,TestProwlarrLink,TestSeerrLink.
No path creates a viewer:
- First-run setup creates the single admin (
api/internal/auth/service.go,Setup). - An OIDC sign-in whose
subor verifiedemailis onallowed_subjects/allowed_emailsstarts a session as the first admin (api/internal/sso/oidc.go,completeCallback,verifyClaims). - A proxy sign-in whose user is on
proxy_auth.allowed_usersdoes the same (api/internal/httpapi/handlers.go,CreateProxySession).
So every identity SnatchArr lets in is the admin. That blocks least-privilege access for anything that only needs to look: a household member reading History, a dashboard, and the synthetic check that loads the served site after each deploy (order snatcharr-history-layout-ui-check-20261021). A check job never holds admin rights.
Authentik already carries group membership on both sign-in paths:
- OIDC: the default scope mapping for
profilereturns"groups": [group.name for group in request.user.groups.all()](blueprints/system/providers-oauth2.yamlin goauthentik/authentik, read 2026-10-21 onmain). SnatchArr requestsopenid,email,profileby default (api/internal/config/config.go). - Proxy outpost:
X-authentik-groupscarries the user's groups separated by pipes, for examplefoo|bar|baz(docs.goauthentik.io, proxy provider, "Headers sent to upstream applications", read 2026-10-21).
Decision¶
The role of a single sign-on identity comes from its Authentik groups. One group maps to admin, one to viewer; an identity in neither is refused. The per-identity allow-lists stop granting admin.
1. Configuration¶
| Key | Environment | Meaning |
|---|---|---|
snatcharr.oidc.admin_groups |
APP_SNATCHARR_OIDC_ADMIN_GROUPS |
group names in the groups claim that sign in as the admin |
snatcharr.oidc.viewer_groups |
APP_SNATCHARR_OIDC_VIEWER_GROUPS |
group names that sign in as a viewer |
snatcharr.oidc.groups_claim |
APP_SNATCHARR_OIDC_GROUPS_CLAIM |
claim name, default groups |
snatcharr.proxy_auth.groups_header |
APP_SNATCHARR_PROXY_AUTH_GROUPS_HEADER |
header with pipe-separated groups, default X-authentik-groups |
snatcharr.proxy_auth.admin_groups |
APP_SNATCHARR_PROXY_AUTH_ADMIN_GROUPS |
groups that sign in as the admin |
snatcharr.proxy_auth.viewer_groups |
APP_SNATCHARR_PROXY_AUTH_VIEWER_GROUPS |
groups that sign in as a viewer |
- Group names compare exactly (case-sensitive), as Authentik emits them.
- A group on both the admin and the viewer list is refused at config validation.
- With OIDC or proxy auth enabled, an empty
admin_groupsis refused at config validation. The new version then fails to start instead of starting with nobody able to reach admin; on Kubernetes the rolling update stops and the old pod keeps serving. allowed_subjects,allowed_emailsandallowed_usersno longer grant admin. Setting any of them fails config validation with a message that names the group keys, so a stale value cannot quietly keep or lose access.- The new list keys join
CompoundKeys()inapi/internal/config/config.go, otherwise theAPP_SNATCHARR_*variables never reach them. - The proxy groups header is read and stripped by
ProxyHeaderMiddlewareunder the same trusted-CIDR check as the user header (api/internal/sso/sso.go); from an untrusted peer it is dropped.
2. Role resolution¶
One pure function decides, shared by both paths: groups in, admin, viewer or refused out.
- Any admin group present: admin. Admin wins over viewer, so an operator who is also in the viewer group stays admin.
- Else any viewer group present: viewer.
- Else, or with a missing or malformed claim or header: refused,
403application/problem+json, logged with the subject and the group count, never the group names of an unknown identity. - Authentik's default mapping lists direct memberships (
request.user.groups.all()); a group reached only through a parent group does not count. The cluster adds identities to the groups directly.
3. Provisioning¶
- Admin: the session starts as the first admin, as today (
auth.FirstAdmin). There is still one admin row; admin-group membership is what reaches it. - Viewer: the first sign-in of an identity creates a
usersrow with roleviewer.ValidateUsernameallows letters, digits,.,-and_up to 64 characters (api/internal/domain/user.go), so the username isoidc-orproxy-followed by a short hash of the subject or user, and the full identity goes into a newexternal_idcolumn (unique). Creation is an upsert onexternal_id, so two first sign-ins at once yield one row. users.password_hashisNOT NULL(000001_init.up.sql). A viewer row stores a fixed sentinel that is never a valid hash, andauth.Loginrefuses it with401before it callscrypto.VerifyPassword, which would otherwise return an error and answer500.- No viewer row is created while setup is incomplete:
SetupCompletecounts users (api/internal/auth/service.go), so a viewer created first would lock the admin out of/auth/setup. Before setup, a viewer sign-in is refused. - The role is decided at every sign-in. A viewer removed from the viewer group is refused on the next sign-in; the row stays for the audit trail.
- Cookie and bearer authentication load the user by id only (
api/internal/httpapi/security.go) and cannot see groups between sign-ins. A viewer session therefore lives at most the session TTL after a group removal; proxy auth re-reads the header on every session creation. Revocation inside the TTL is thesnatcharr-admin-handlers-hardening-20261021unit. - The session starts through the same
RenewSessionpath as the admin (fresh session id, #268).
4. What a viewer sees¶
- All reads except the four admin-only ones (
ListLogs, the log stream,GetConfigarrStatus,GetPolicyFilterOptions), which return403application/problem+json; the SPA shows its problem note there. - No mutation and no outbound probe:
requireAdminis added to every handler listed as not gated above. - The SPA hides write controls for
viewer, based onisAdminfrom the session (web/src/lib/session.svelte.ts); today it gates only the Logs route, so the other pages gain the same check.
5. Tests¶
- Positive: an admin-group identity gets the first admin's session on both paths; a viewer-group identity gets a viewer session and a second sign-in reuses the row; an identity in both groups is admin.
- Negative: an identity in no mapped group, with no
groupsclaim, with a claim of the wrong type, or with the groups header from an untrusted peer is refused; a viewer gets403on every mutating and probing operation, generated as a table from the OpenAPI operations so a new one cannot be missed, notifications and API keys included, and on the log stream; config with an emptyadmin_groups, a group on both lists, or a legacy allow-list set fails validation; a viewer sign-in before setup is refused and/auth/setupstill works. - Boundary: an empty groups list, a group name differing only in case, a header with empty segments (
a||b), a subject longer than 64 characters or containing:and@(valid username), two concurrent first viewer sign-ins (one row), the password login against a viewer row (401, not500). - Planted cases, each run red once before the green result is trusted: remove the admin-group mapping and the operator-is-admin test fails; map the viewer group to
FirstAdminand the403table fails.
Rollout¶
The change can lock the operator out if the operator's identity is not in the admin group, so it ships behind an operator decision, not with the merge:
- The cluster creates the admin and viewer groups in Authentik, adds the operator to the admin group and the synthetic check identity (
k8s-synthetic-check-identity-20261021) to the viewer group, and sets the group keys alongside removing the allow-lists. - Proof before rollout: a read-only check that the operator's identity is a direct member of the admin group, and that the token or header the deployed provider emits for the check identity carries
groupswith the viewer group. - After deploy: the operator's sign-in lands as admin (session
roleread back), the served layout check runs as the viewer and passes with its screenshots. - Fallback: the previous image with the previous config; the admin password login (
/auth/login) is not affected by this change.
Consequences¶
- Access is managed in Authentik groups, not in SnatchArr config; adding a viewer needs no SnatchArr change.
- The deployed config must change in the same rollout (legacy allow-lists out, group keys in); startup refuses the old shape.
- A migration adds
users.external_id. There is still no role change or user deletion query: an identity moved from the viewer to the admin group signs in as the first admin and leaves its viewer row unused. - Proxy auth trusts the groups header exactly as far as the user header: only from the trusted CIDRs.
Alternatives considered¶
- Per-identity viewer allow-lists (the first draft of this ADR): one config edit per identity, and the allow-lists stay a second place to keep in sync with Authentik. Not chosen by the operator.
- Keep allow-lists as admin next to the groups: rejected, an identity outside every group would still start as admin.
- Check identity as admin: rejected, a check job never holds admin rights.
- Local viewer accounts with passwords: rejected, a second credential store next to Authentik.