Identity, invitations, and access control
Kener uses one identity and access system for its management area. It supports local accounts and OpenID Connect (OIDC), an external sign-in standard, while invitations, account state, roles, and permissions control what each person can do. See Management console configuration for the product areas protected by these rules.
Account identity
Initial account creation
The first account establishes the workspace identity. It receives the admin role and becomes the workspace owner. After this account exists, the sign-in page accepts existing credentials or configured OIDC sign-in; new local users enter through an invitation.
Email addresses are normalized before account creation and lookup. This lets sign-in and account management treat differences in letter case or surrounding spaces as the same address.
References: src/…/+page.server.ts• L129-170 src/…/userController.ts• L40-65 src/…/userController.ts• L197-216 src/…/users.ts• L60-68 src/…/users.test.ts• L54-90
Sign-in session
Local sign-in checks the account email and password before it creates a signed session token in the kener-user cookie. OIDC sign-in creates the same type of management session after the identity provider confirms the user. In both cases, the account must be active and have at least one active role.
Each management request resolves the account again from the session identity. Deactivation therefore removes access even when an old session cookie remains. Local accounts cannot use the OIDC path, and OIDC accounts cannot use local passwords.
The is_verified flag records email verification. It is not a condition for local sign-in. Users can request a verification message for themselves, while sending one for another user requires user-management access.
References: src/…/+page.server.ts• L25-127 src/…/userController.ts• L280-297 src/…/+server.ts• L147-198 src/…/users.ts• L60-68
OIDC sign-in
OIDC sign-in sends the user to the configured identity provider and returns through a protected callback. The sign-in request uses a state value, a nonce, and PKCE, which is a one-time code check, to bind the callback to the browser session and the original request.
The callback exchanges the provider code for identity data. It reads the subject, email, display name, and groups from the token or the provider's user-information endpoint. The subject is the stable identity key; the email helps detect conflicts and update the profile, but it never merges a local account with an OIDC account.
OIDC can either allow only pre-provisioned users or create a new active and verified account. A newly created account receives roles from matching provider groups, then the configured default role, or finally member. On later sign-ins, mapped OIDC roles are synchronized while manually assigned roles remain. An existing local account with the same email is rejected instead of being linked.
Local sign-in can be hidden when OIDC is enabled and local access is not allowed. The KENER_FORCE_LOCAL_LOGIN setting provides a recovery path when the identity provider is unavailable or misconfigured. OIDC failures return stable messages on the sign-in page rather than provider text or email data in the redirect URL.
When OIDC sign-in processes an account, it follows this sequence:
- The sign-in page starts the provider redirect and stores the one-time checks.
- The callback validates the provider response and extracts identity data.
- The account is found by provider subject or provisioned under the OIDC policy.
- OIDC-managed roles are synchronized with the current provider groups.
- The active account receives the normal management session.
This diagram shows how external identity becomes a local management session.
flowchart LR
A[Sign-in page] --> B[OIDC provider]
B --> C[Callback validates state nonce and PKCE]
C --> D[Find or provision account]
D --> E[Synchronize mapped roles]
E --> F{Active account with an active role?}
F -- No --> G[Show stable sign-in error]
F -- Yes --> H[Create management session]
References: src/…/+server.ts• L5-39 src/…/+server.ts• L12-75 src/…/oidcController.ts• L94-195 src/…/oidcController.ts• L207-315 src/…/+page.server.ts• L14-51 src/…/+page.svelte• L24-100
Sign-out
Sign-out removes the session cookie and returns the user to the sign-in page. An account that an administrator deactivates also fails the session lookup and cannot continue to use the management area.
References: src/…/+page.server.ts• L1-14 src/…/userController.ts• L280-297
Account presentation
The shared account layout provides the common shell for sign-in, invitation, recovery, and verification pages. It applies the site theme, branding, and client capture setup without changing the account rules themselves.
References: src/…/+layout.svelte• L1-59
Account recovery
Password reset
Password recovery has two stages. The user requests a reset link by email, then uses the link to set a new password. The link is signed and time-limited. A successful reset stores the new password and marks the email as verified before the user signs in again.
References: src/…/+page.svelte• L31-59 src/…/+server.ts• L9-58 src/…/+server.ts• L15-61
Email verification
Email verification is a separate link flow. The account page checks the signed link and its validity period, then marks the matching user as verified and sends the user to the user-management view. Administrators can resend this message for users who have not verified their email. OIDC-provisioned accounts are verified by the identity provider flow and do not need this local step.
References: src/…/+page.server.ts• L7-54 src/…/userController.ts• L421-463 src/…/+server.ts• L186-198 src/…/+page.svelte• L430-470
Invitation lifecycle
Invitation issuance
An administrator with user-management access invites a person by email and assigns one or more active roles. The invitation creates an inactive local account with no password. The email link carries the invited email and remains valid for seven days.
Invitation delivery depends on the configured email service. The user-management page disables new invitations and resend actions when that service is not available. OIDC accounts do not use invitation emails; the identity provider policy controls whether they are provisioned at sign-in.
References: src/…/userController.ts• L307-377 src/…/+server.ts• L168-185 src/…/+page.svelte• L131-193 src/…/+page.svelte• L376-390
Invitation acceptance
The recipient opens a valid invitation link and creates a password that meets the account password rule. Acceptance is single-use: the link must be valid, the email must match an invited account, and that account must still have no password. A successful acceptance activates and verifies the account. The recipient then signs in through the normal local account flow.
The invitation path clears any existing management session before it shows the setup form. It treats the link as account activation rather than as a way to change the identity of a signed-in user.
References: src/…/+page.server.ts• L6-76 src/…/+server.ts• L7-68 src/…/+page.svelte• L31-74
The invitation path moves through these states before it produces an active account.
flowchart LR
A[Administrator selects email and roles] --> B[Inactive account with no password]
B --> C[Seven-day invitation link]
C --> D{Link valid and unused?}
D -- No --> E[Reject invitation]
D -- Yes --> F[Recipient sets password]
F --> G[Active and verified account]
G --> H[Sign in and receive management access]
References: src/…/userController.ts• L307-419 src/…/+page.server.ts• L22-76 src/…/+server.ts• L19-68
User ownership and account state
User record state
An account has identity data, active and verified states, an owner marker, an authentication source, and role assignments. OIDC accounts also have a provider subject that links the local record to the external identity. User views expose this access-related state without exposing the stored password hash. The management view uses the presence of a password to show whether an invited local account still needs activation.
The user repository returns only active role assignments when it enriches user records. This keeps role displays and later access decisions aligned when a role is disabled. Email lookup trims surrounding spaces and compares without case sensitivity.
References: src/…/db.ts• L237-273 src/…/users.ts• L25-68 src/…/users.ts• L129-146 src/…/users.ts• L379-386 src/…/userController.ts• L75-90 src/…/users.test.ts• L54-90
Owner protection
The owner is a protected account marker rather than a separate role. The owner must keep the admin role and cannot be deactivated or removed from that role. The marker is assigned to the first account during initial setup.
References: src/…/userController.ts• L197-215 src/…/userController.ts• L239-277 src/…/userController.ts• L661-669 migrations/20260226120000_add_is_owner_to_users.ts• L3-16
Account activation
The active state controls whether an account can enter the management area. Administrators can activate or deactivate other accounts, but cannot deactivate the owner. Deactivation is also an immediate session boundary because later session checks reject inactive accounts.
References: src/…/userController.ts• L239-277 src/…/+page.svelte• L663-710 src/…/userController.ts• L280-297
User administration
The user-management view gives authorized administrators one place to review active or inactive accounts and inspect authentication source, verification, role, and activation state. It supports local invitations, invitation resends for accounts without passwords, role changes, and account activation changes. The view marks the current account and offers self-service email verification without exposing self-edit controls through the administrator actions. OIDC accounts are shown as verified and do not offer local invitation recovery.
References: src/…/+page.svelte• L64-129 src/…/+page.svelte• L394-471 src/…/+page.svelte• L589-710 src/…/user-management.md• L72-138
Roles and permissions
Role assignments
Roles group permissions into reusable access profiles. An account can have multiple roles, and its effective permission set is the union of permissions from all active assigned roles. Inactive roles contribute neither a role ID nor a permission, so disabling a role changes access for every assigned account.
The system provides three protected roles: admin, editor, and member. The administrator role has all permissions. The editor role has all permissions except API-key deletion. The member role has read permissions only. Custom roles can provide a narrower profile. OIDC group mappings and a default role add managed assignments without removing manual roles.
References: src/…/users.ts• L350-375 seeds/roles.ts• L5-29 src/…/userController.ts• L472-502 src/…/oidcController.ts• L287-315 src/…/user-management.md• L8-35
Permission groups
Permissions use a domain-and-action pattern. Read permissions allow a user to view a domain. Write permissions allow a user to change it. Some domains also have a narrow administrative action.
| Permission group | Access boundary |
|---|---|
monitors, incidents, maintenances, pages, triggers, alerts | Operational configuration and history for each domain |
settings, subscribers, email_templates, images | Site administration and supporting content |
api_keys | API-key view, change, and delete operations |
users | User listing, invitations, verification, and account administration |
roles | Role and permission viewing, role changes, permission assignment, and user assignment |
monitors.write also permits custom monitor evaluation code to run on the Kener server. This makes it a server-trust permission rather than only a dashboard editing permission. Signed-in users with monitors.read can also see hidden monitors on the public site.
References: src/…/allPerms.ts• L43-97 src/…/user-management.md• L37-62
Role governance
Role administration is itself permission-controlled. Read access shows roles, permissions, and assignments. Write access creates or changes custom roles. Separate permissions control changes to role permissions and role membership. Built-in roles are read-only. Custom roles can be renamed, disabled, deleted, or used as migration targets when a role is removed.
References: src/…/allPerms.ts• L92-97 src/…/allPerms.ts• L213-224 src/…/userController.ts• L504-634 src/…/+page.svelte• L384-473 src/…/user-management.md• L26-35 src/…/user-management.md• L64-70
Access calculation
The repository calculates access from the account's role links and the active permissions on those roles. It removes duplicates from the resulting permission set, so assigning more than one role broadens access without changing the meaning of a permission.
References: src/…/users.ts• L350-375 src/…/userController.ts• L672-680
Authorization boundaries
Management route checks
The management layout is the first boundary for the authenticated console. It requires completed setup, a valid active session, and a permission assigned to the requested route. A route without a permission mapping is rejected rather than treated as public. Read permissions therefore control whether a user can open a management area before page data is shown.
References: src/…/+layout.server.ts• L20-47 src/…/allPerms.ts• L226-275
Management action checks
The management API is the second boundary for reads and changes initiated by the console. Every action must be known and must meet its mapped permission. Self-service actions such as changing the current password or name do not need a domain permission. Actions for other accounts have separate limits when they can affect another account.
Permission checks are shared across management domains. They do not replace domain validation. The operation still checks the requested role, account state, or resource after access is granted.
References: src/…/+server.ts• L141-198 src/…/allPerms.ts• L99-116 src/…/userController.ts• L127-152
Resource scope
Management authorization is workspace-wide. The authorization gate checks the caller's route or action permission, then the domain operation receives the requested resource identifier. The code does not add a separate per-resource owner check for management resources. A user with the relevant write permission can therefore operate across the workspace domain covered by that permission.
References: src/…/+layout.server.ts• L33-47 src/…/+server.ts• L152-180 src/…/allPerms.ts• L112-126
Change checklist
When these files or sections are changed, remember to consider these:
- Keep email normalization consistent across account creation, local sign-in, OIDC claims, session lookup, invitation links, and duplicate checks. A mismatch can make one account appear to be several accounts.
- Keep the session cookie settings, token validation, and active-account lookup aligned for both local and OIDC sign-in. A change in one can create a session that the management boundary cannot read or revoke.
- Keep the OIDC subject, authentication source, and email-conflict rules aligned. Do not turn an email match into an account merge without defining the ownership and recovery effects.
- Keep OIDC group mappings, the default role, and manual role preservation aligned. A change can silently grant or remove access on the next provider sign-in.
- Keep the route permission map and action permission map aligned with new management routes and actions. A missing map entry is denied by design, while an incorrect entry can expose a whole management area.
- Keep role seeds and permission seeds aligned. The built-in role contract depends on the permission IDs that the seed process creates.
- Preserve the owner invariants when changing role or account administration. The owner must retain
adminand remain active. - Keep invitation and recovery token claims consistent with their expiry checks. Invitation links use
validTill; password reset and verification links use their own validity windows. - Keep email-template availability and email-service setup aligned with invitation, verification, and recovery entry points.
- Keep OIDC callback error codes aligned with the sign-in page's safe message map. Unknown or new provider failures must not expose free text through the redirect.
- Keep the documented permission effects aligned with the permission map. In particular,
monitors.writegrants server-side custom evaluation code andmonitors.readaffects hidden-monitor visibility.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| User has no active role | Password or OIDC authentication succeeds, but no management session is created | Require at least one active role before completing either sign-in path |
| User is inactive | Existing token no longer resolves to a usable session | Re-check is_active during every session lookup |
| OIDC state, nonce, or PKCE data is missing or does not match | The callback cannot prove that the response belongs to the login attempt | Store one-time values in short-lived cookies and validate them during code exchange |
| OIDC user is not provisioned while auto-create is off | Sign-in is rejected without creating an account | Require prior provisioning or enable the intended auto-create policy |
| OIDC email matches a different local account | Sign-in is rejected instead of merging identities | Keep provider subject ownership and email conflict checks separate |
| Invitation is expired, invalid, or already accepted | Account activation is rejected | Verify the signed token, validTill, matching user, and empty password |
Owner loses admin or is deactivated | The protected workspace owner invariant would break | Reject both changes in the user controller |
| Management route or action has no permission mapping | The route returns 403 or the API returns 400 for an unknown action | Add the route or action map entry before exposing the surface |
| Email service is unavailable | New invitations and invitation resends cannot be sent from the user console | Check email readiness before enabling those controls |
| Account lookup uses a case-sensitive email comparison | A valid account may fail to sign in when the entered address differs in case or has extra spaces | Normalize the lookup email and compare without case sensitivity |
A user receives monitors.write without server trust | The user can set custom evaluation code that runs on the Kener server | Restrict this permission to trusted users |
Key files
| File | Why to read it |
|---|---|
| src/…/userController.ts | Central account, invitation, role, permission, session, and owner rules |
| src/…/oidcController.ts | OIDC discovery, callback identity, account provisioning, and group-to-role behavior |
| src/…/+server.ts | OIDC login start and browser-bound callback checks |
| src/…/+server.ts | OIDC response, account state, and management session boundary |
| src/…/+page.server.ts | First-account creation, local sign-in policy, and safe OIDC error messages |
| src/…/+page.svelte | User-facing choice between local sign-in and configured OIDC sign-in |
| src/…/+layout.svelte | Shared account-page shell and site presentation |
| src/…/+server.ts | Invitation validation and account activation boundary |
| src/…/+server.ts | Password recovery token and password update boundary |
| src/…/+layout.server.ts | Authenticated management route boundary |
| src/…/+server.ts | Authenticated management action boundary |
| src/…/allPerms.ts | Permission vocabulary and route/action mappings |
| src/…/+page.svelte | User invitation, authentication source, verification, role, and activation workflows |
| src/…/+page.svelte | Role, permission, and role-membership administration workflows |
| src/…/users.ts | Account lookup, provider identity, and role-permission relationships used to compute access |
| src/…/users.test.ts | Guarantees that account email lookup handles case and surrounding spaces |
| seeds/roles.ts | Built-in role definitions and their default permission profiles |
| src/…/user-management.md | User-facing role, permission, invitation, and server-trust rules |