Introducing a new way to review your PRs.

Read the announcement

keephq / keep

The open-source AIOps and alert management platform

View on GitHub

22 documents · Updated Nov 23, 2026

docs / authentication-and-authorization

Authentication and authorization

Authentication and authorization protect both the Keep API and its web UI. Authentication proves who made a request and creates a common identity record. Authorization then checks that identity against the required role and scopes before the request can use a protected feature. This page is part of Identity, access, and secrets and relates to Secret management.

Identity request boundary

Request identity pipeline

The API uses an auth verifier as the request boundary. An auth verifier is the provider-specific component that checks request credentials and returns an AuthenticatedEntity, which carries the tenant, user, role, and optional provider data. API routes declare the scopes they need when they create this dependency. The verifier authenticates first and authorizes second.

The main request path is:

flowchart LR
    Request[API request] --> Credential{Credential source}
    Credential -->|Bearer token| Token[Provider token verification]
    Credential -->|API key or Basic/Digest| Key[API key verification]
    Token --> Entity[AuthenticatedEntity]
    Key --> Entity
    Entity --> Scope[Role and scope check]
    Scope -->|Allowed| Route[Protected API route]
    Scope -->|Denied| Error[401 or 403 response]

Bearer tokens have priority when present. Otherwise the verifier can read an API key from X-API-KEY or the query string. It also accepts API keys passed through Basic or Digest authorization forms. Special service-ingestion and CloudWatch paths exist only when their explicit settings allow them.

References: keep/…/authverifierbase.py• L43-69 keep/…/authverifierbase.py• L99-141 keep/…/authverifierbase.py• L143-205 keep/…/authverifierbase.py• L239-332 keep/…/whoami.py• L12-24

Authentication outcomes

Authentication failures stop the request before the route runs. A 401 means that the request has no usable identity or that its credential cannot be verified. A 403 means that an identity was found but it cannot use the requested scope. This split lets clients distinguish a missing or stale login from a valid login with too little access.

The API key path also records the key's tenant and updates its last-used time. If impersonation is enabled, an admin API key can create a request identity from the configured user and role headers. The current boundary does not check whether that key has a separate grant to impersonate the selected user.

References: keep/…/authverifierbase.py• L334-437 keep/…/authverifierbase.py• L207-237 keep/…/authenticatedentity.py• L7-31

Authentication modes

Identity manager selection

An identity manager is the provider-facing service that supplies users and creates the matching auth verifier. IdentityManagerFactory selects it from AUTH_TYPE, while also translating older values such as SINGLE_TENANT, MULTI_TENANT, and NO_AUTH. The same selection controls API verification and user-management behavior, so a frontend provider change must stay aligned with the backend type.

The supported modes have different sources of identity and different management support:

ModeIdentity sourceMain tenant and role behaviorManagement shape
DBKeep username and passwordA signed local JWT carries tenant, email, and roleLocal user creation, update, deletion, and password change
Auth0Auth0-issued JWTToken claims identify the tenant and role. A token can select an allowed active tenantAuth0 user management
KeycloakKeycloak-issued tokenRoles can come from client roles or organization groups. Single-tenant checks can use Keycloak UMAProvider-backed behavior with organization support
Azure ADMicrosoft Entra ID JWTAuthorized Azure group IDs map to Keep rolesToken authentication with local user record provisioning
OktaOkta-issued JWTClaims or groups provide the Keep roleAuthentication and SSO only in this implementation
OneLoginOneLogin-issued JWTConfigured groups map to Keep rolesAuthentication and SSO only in this implementation
OIDCAny OpenID Connect provider's signed JWTConfigured provider groups map to Keep roles. The backend uses a single tenantSSO authentication with just-in-time local user provisioning. User, group, and role management is disabled
OAuth2 ProxyTrusted reverse-proxy headersProxy groups map to a Keep role. The backend uses a single tenantHeader-based authentication and optional local user provisioning
NoAuthSynthetic local identityRequests receive the default tenant and admin role. API keys can still select a test tenantNo real user management

References: keep/…/identitymanagerfactory.py• L16-28 keep/…/identitymanagerfactory.py• L30-83 keep/…/identitymanagerfactory.py• L86-156 keep/…/identitymanager.py• L31-129 keep/…/identitymanager.py• L232-296 keep/…/oidc_identitymanager.py• L13-18

Local credentials

The DB mode provides the local sign-in path. The API checks the submitted username and password, then returns a signed HS256 JWT. The frontend sends those credentials through its server action and stores the returned access token in the NextAuth session. Later API calls use that token as a bearer credential.

This mode is the only mode that supports the self-service password change route. The route checks the current password before it writes the new one. The JWT secret is therefore a shared contract between the sign-in endpoint and the verifier.

References: keep/…/db_identitymanager.py• L25-71 keep/…/db_authverifier.py• L13-51 keep/…/users.py• L110-143 keep-ui/auth.config.ts• L139-184 keep-ui/…/authactions.ts• L7-60

External identity providers

Auth0, Keycloak, Azure AD, Okta, OneLogin, and generic OIDC providers use signed bearer tokens from an external identity service. Their verifiers check the provider's signing keys and token claims before they build the common identity record. The provider-specific claims then supply the Keep tenant and role.

Provider role mapping is part of the trust boundary. Azure AD maps configured group IDs to admin or NOC access. OAuth-style and generic OIDC providers map claims or groups to the small set of Keep roles. The generic OIDC verifier discovers the provider's JWKS endpoint unless a fixed endpoint is configured. It validates RS256 tokens against issuer and audience claims, delays provider discovery until the first token check, and refreshes signing keys when a provider rotates them. It accepts an explicit audience for providers whose access tokens do not use the client ID as audience. OIDC group claims are normalized before role mapping, with admin taking priority over noc and webhook; optional local provisioning creates a user and keeps its role aligned with current provider groups. Keycloak can use Keycloak UMA for single-tenant resource checks, while its multi-organization path uses Keep role checks instead.

References: ee/…/auth0_authverifier.py• L60-130 ee/…/keycloak_authverifier.py• L48-108 ee/…/keycloak_authverifier.py• L194-371 ee/…/azuread_authverifier.py• L137-334 keep/…/okta_authverifier.py• L15-100 keep/…/onelogin_authverifier.py• L14-161 keep/…/oidc_authverifier.py• L21-61 keep/…/oidc_authverifier.py• L64-126 keep/…/oidc_authverifier.py• L128-252

Reverse-proxy and no-auth modes

OAuth2 Proxy delegates the first sign-in step to a trusted proxy. The UI reads the configured forwarded identity, email, access-token, and group headers. The API reads the user and role headers, maps the highest supported role, and can create or update a local user record.

NoAuth is a test or open-access mode rather than an identity check. It returns a synthetic admin identity for bearer tokens that it cannot parse and for unknown API keys. It should not be treated as a production access boundary.

References: keep-ui/…/oauth2proxy-auth.ts• L3-56 keep/…/oauth2proxy_authverifier.py• L19-179 keep/…/noauth_authverifier.py• L14-66 keep/…/noauth_identitymanager.py• L11-42

Web session context

Sign-in provider flow

The web UI uses NextAuth as its session layer. The selected AUTH_TYPE determines whether the sign-in page shows local credentials, redirects to an external provider, reads OAuth2 Proxy headers, or creates a no-auth session. The NextAuth route is the browser-facing entry point for these provider callbacks.

The sign-in page loads the available providers and starts the first matching flow. Local credentials call the backend /signin endpoint through a server action. External providers return through NextAuth with an access token that becomes the API credential.

References: keep-ui/auth.config.ts• L34-46 keep-ui/auth.config.ts• L125-287 keep-ui/…/SignInForm.tsx• L41-127 keep-ui/…/SignInForm.tsx• L129-163 keep-ui/…/route.ts• L1-23

Session and tenant context

The session stores the access token, active tenant, role, and the user's available tenants. The JWT callback builds this state after sign-in. The session callback exposes it to UI code, and NextAuthProvider makes the session available to client components.

Users with access to more than one tenant can use the tenant-switch provider. It first checks that the requested tenant is in the user's tenant list, then prefixes the access token with the selected tenant. Provider verifiers use that context to select the active tenant and reject a tenant that is not present in the verified identity.

References: keep-ui/auth.config.ts• L307-320 keep-ui/auth.config.ts• L320-482 keep-ui/auth.config.ts• L484-500 keep-ui/auth.ts• L10-80 keep-ui/auth.ts• L213-245 ee/…/auth0_authverifier.py• L85-124 ee/…/keycloak_authverifier.py• L194-218

UI route access

The UI middleware checks for a NextAuth session before it allows normal application pages. Unauthenticated users go to /signin, while authenticated users who open /signin go to their requested callback or the incident page. The middleware also sends NOC users to the alert feed.

This browser check is not the API access control. API paths are outside the UI middleware matcher, so each API route must declare its own verifier and scopes. The application layout loads the server session into the shared provider so navigation and page components can use the same identity context.

References: keep-ui/middleware.ts• L15-91 keep-ui/middleware.ts• L93-115 keep-ui/…/layout.tsx• L28-67 keep-ui/auth.config.ts• L311-319

Authorization model

Roles and scopes

Keep uses role-based authorization. A role is a named access profile, and a scope is an action-resource pair such as read:alerts or write:workflows. A route declares the scopes needed for its operation. The role then grants access when it contains each exact scope or an action wildcard such as read:*.

The built-in roles are:

RoleAccess intent
adminAll read, write, delete, update, and execute scopes
nocRead access plus workflow execution
webhookWrite access for alerts and incidents through API keys
workflowrunnerWrite and execute access for workflows through API keys

The role names are the shared contract between token claims, proxy or group mappings, API keys, and route checks. A role that is valid at the identity provider but is not one of these Keep roles cannot pass authorization.

References: keep/…/rbac.py• L21-52 keep/…/rbac.py• L55-92 keep/…/authverifierbase.py• L25-40 keep/…/authverifierbase.py• L207-237

Route authorization

API routes express authorization at the route boundary by requesting a verifier with a required scope. Settings and identity-management routes use settings scopes. Product routes use their own resource scopes, such as workflows, providers, topology, rules, and alerts. The verifier checks the role before the route can read or change data.

Identity-management APIs use the same boundary. User reads need read:settings; user creation and updates need write:settings; user deletion needs delete:settings. Role and permission operations follow the same read or write settings contract.

References: keep/…/users.py• L58-107 keep/…/users.py• L146-167 keep/…/roles.py• L13-66 keep/…/permissions.py• L15-70 keep/…/workflows.py• L84-125 keep/…/providers.py• L265-329

Resource permissions

The settings API also exposes roles, resource permissions, groups, and the list of known scopes. A resource permission links a resource to permission entities that represent users or groups. The identity manager owns the provider-specific storage and behavior for these records.

The default role layer remains the main local decision path. Keycloak single-tenant mode can add a provider-side UMA check for the protected resource. Keycloak API-key requests do not carry a Keycloak token, so they use the common Keep role check instead.

References: keep/…/user.py• L6-49 keep/…/permissions.py• L15-70 keep/…/groups.py• L14-73 ee/…/keycloak_authverifier.py• L343-392 keep/…/identitymanager.py• L131-230

Identity administration

User and group management

The UI-facing auth routes use the selected identity manager for user and group operations. Local DB and Auth0 managers implement meaningful user changes. OAuth2 Proxy can reflect users into the local store. Okta, OneLogin, and generic OIDC provide SSO verification but leave user, group, and role management disabled. Generic OIDC can still provision a local user during token verification and update that user's sign-in time and role from the current provider groups.

This separation matters because successful sign-in does not imply that the settings UI can manage the upstream directory. The management capability belongs to the selected identity manager, while route protection still belongs to the auth verifier.

References: keep/…/users.py• L58-167 keep/…/groups.py• L23-73 keep/…/identitymanager.py• L61-129 keep/…/db_identitymanager.py• L73-143 ee/…/auth0_identitymanager.py• L31-133 ee/…/okta_identitymanager.py• L12-121 ee/…/onelogin_identitymanager.py• L12-123 keep/…/oidc_identitymanager.py• L13-18 keep/…/oidc_identitymanager.py• L50-99 keep/…/oidc_identitymanager.py• L101-138

Role and permission administration

The settings UI can ask the selected identity manager for roles and resource permissions. The base manager exposes the built-in roles and expands wildcard scopes for display. Provider implementations can replace role and permission storage when the external identity system supports it.

The API protects these changes with settings scopes. A role or permission change therefore affects later requests only after the provider's role data and the Keep role names remain consistent.

References: keep/…/identitymanager.py• L232-296 keep/…/roles.py• L13-66 keep/…/permissions.py• L15-70 keep/…/user.py• L25-49

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the AUTH_TYPE values aligned between keep/…/identitymanagerfactory.py and keep-ui/…/authenticationType.ts. Include backward-compatible names when changing an existing mode.
  • Keep the generic oidc mode aligned with its frontend sign-in provider and require the issuer and client ID for both the identity manager and API verifier.
  • Keep OIDC audience, JWKS discovery or override, and provider key-rotation behavior aligned with the token type issued by the identity provider.
  • Keep provider role claims and group mappings aligned with the role names and wildcard rules in keep/…/rbac.py.
  • When changing tenant claims or tenant switching, update the NextAuth JWT and session fields together with the backend verifier's active-tenant checks.
  • When adding or changing an API route scope, review the role that must call it and the scope list shown by the permissions API.
  • When changing API-key impersonation or proxy headers, review both the trust boundary and the identity fields that reach AuthenticatedEntity.
  • When changing a provider's management support, update the expected behavior of the auth settings routes. Sign-in support and directory-management support are separate contracts.

Important failure modes

TriggerConsequenceGuard
Provider issuer, audience, client, or signing-key settings do not match the tokenThe API returns 401 and the user cannot establish an API identityKeep provider claim settings and verifier configuration aligned before enabling the mode
Generic OIDC lacks an issuer or client IDThe OIDC identity manager or API verifier cannot startSet KEEP_OIDC_ISSUER and KEEP_OIDC_CLIENT_ID before selecting AUTH_TYPE=oidc
OIDC discovery or the configured JWKS endpoint has no usable signing keyThe API cannot verify the token and returns 401Keep the discovery document or KEEP_OIDC_JWKS_URL available and publish the active signing keys
A valid token has no recognized Keep role or group mappingAuthentication may complete at the provider, but the API returns 403Map provider groups or claims to admin, noc, webhook, or workflowrunner
The role lacks the scope declared by a routeThe request returns 403 before route work startsAdd the required scope to the role or use a role intended for that operation
The selected active tenant is not in the verified user's tenant listTenant switching or API verification is rejectedBuild tenantIds from the verified identity and validate the selected tenant
OAuth2 Proxy does not send the configured identity or role headersUI sign-in or API authentication returns 401Set the same header names in the proxy and both frontend and backend settings
AUTH_TYPE is set to noauth or its legacy equivalent in a deployed serviceRequests can receive a synthetic admin identity without normal identity proofUse NoAuth only for controlled test or open-access deployments
A read-only instance receives a non-read scope without a bypass keyThe verifier returns 403 even for an otherwise valid identityUse read scopes or configure an intentional read-only bypass key

Key files

FileWhy to read it
keep/…/authverifierbase.pyDefines the common API credential flow, identity result, scope check, API-key behavior, and read-only guard
keep/…/identitymanagerfactory.pyShows how the configured auth mode selects both the identity manager and verifier
keep/…/oidc_identitymanager.py and keep/…/oidc_authverifier.pyShow generic OpenID Connect SSO, token verification, JWKS handling, group-to-role mapping, and local user provisioning
keep/…/authenticatedentity.pyDefines the identity context passed from authentication into route and authorization logic
keep/…/rbac.pyDefines the Keep roles, scope convention, and wildcard matching rule
keep/…/db_identitymanager.py and keep/…/db_authverifier.pyShow the local credential sign-in and JWT verification path
ee/…/auth0_authverifier.py and ee/…/keycloak_authverifier.pyShow external token validation and multi-tenant or provider-side authorization paths
ee/…/azuread_authverifier.pyShows group-to-role mapping and token-based local user provisioning
keep/…/oauth2proxy_authverifier.pyShows the trusted reverse-proxy header path and role selection
keep/…/users.py and keep/…/roles.pyShow how identity administration routes apply settings scopes and delegate to the selected manager
keep-ui/auth.config.tsDefines frontend providers, JWT session fields, token refresh, and route authorization behavior
keep-ui/auth.tsAdds tenant switching and preserves tenant context across the frontend token and session
keep-ui/middleware.ts and keep-ui/…/SignInForm.tsxShow browser route protection and provider-specific sign-in entry behavior
keep-ui/…/auth.d.tsDefines the frontend session and token fields shared by UI code