Sign-in and access
People sign in to Karta's admin interface through an OpenID Connect provider (Karta is tested with Authentik), or, when it is turned on, with local login: a password and a code from an authenticator app. What a signed-in user may do depends on their role in each organisation.
The admin pages are described in Managing organisations, servers and keys.
Signing in through an identity provider
Karta uses the authorization code flow with PKCE (S256), state and
nonce (through the oidcc library). The ID token's signature, issuer,
audience, expiry and nonce are checked, and the provider's userinfo is
added to its claims. A user is signed in only when the provider says their
e-mail address is verified (email_verified is true).
At the provider, create a confidential OpenID Connect client (in Authentik: an OAuth2/OpenID provider with an application) with:
- the redirect URI
https://<PHX_HOST>/auth/oidc/callback; - the scopes
openid,emailandprofile, and ID tokens signed with an asymmetric key (RS256, for example); - a groups claim if you want roles from groups (Authentik's
profilescope includesgroups).
Then set:
| Variable | Meaning |
|---|---|
KARTA_OIDC_ISSUER | The provider's issuer URL (its discovery document is at <issuer>/.well-known/openid-configuration). Turns sign-in through the provider on. |
KARTA_OIDC_CLIENT_ID, KARTA_OIDC_CLIENT_SECRET | Karta's client at the provider. Required with the issuer. |
KARTA_OIDC_NAME | The name on the sign-in button (default "single sign-on"). |
KARTA_OIDC_ADMIN_GROUPS | Groups whose members are instance administrators, comma-separated. When set, the provider decides who is an administrator at every sign-in. |
KARTA_OIDC_GROUP_ROLES | Organisation roles from groups: group:organisation-slug:role entries separated by commas; roles owner, admin, member, read_only. |
KARTA_OIDC_GROUPS_CLAIM | The claim with the groups (default groups). |
KARTA_OIDC_AUTO_CREATE | false lets only users Karta already knows sign in (default true: users are created at their first sign-in). |
KARTA_OIDC_LINK_BY_EMAIL | true links a Karta user who has never signed in through the provider to the provider's account with the same verified address (default false; see below). |
KARTA_OIDC_CACERTFILE | A CA bundle for the provider's certificate, when a CA the system trusts did not sign it. The certificate and its host name are always checked. |
At each sign-in:
- The user is found by the provider's subject (
sub); their address and name follow the provider's. A user linked to another subject is never taken over. - A Karta user who has never signed in through the provider (a local
account, or one made with
make_admin) is not linked to a provider account just because the addresses match: many providers, Authentik among them, let users change their own address, and a verified-looking address would then be enough to take over the account, an administrator's included. The sign-in is refused, and the log names the provider's subject; an operator links the two withbin/karta eval 'Karta.Release.link_oidc("ann@example.com", "<subject>")'. SetKARTA_OIDC_LINK_BY_EMAIL=trueonly if users cannot change their address at the provider. - For every organisation named in
KARTA_OIDC_GROUP_ROLES, the user's membership is set to the highest role their groups give, or removed when they are in none of its groups. Memberships of other organisations are managed in Karta and left as they are. An organisation slug that does not exist is skipped and logged.
While the provider cannot be reached Karta keeps running and retries; the sign-in page then says the provider is unavailable.
Local login
Local login is off unless KARTA_LOCAL_LOGIN=true (it is on in
development). It asks for an e-mail address and a password, then for a
six-digit TOTP code (RFC 6238). The first time, the user adds Karta to an
authenticator app with the key shown, and confirms with a code.
- Passwords are Argon2id hashes; TOTP secrets are encrypted with the vault key. A code is accepted once, and one step early or late.
- Every failed password step gets the same answer after the same work, whether or not the account exists.
- At most 10 password attempts per address in 15 minutes (whether or not the account exists), 30 per client (an IPv4 address or an IPv6 /64), and 5 codes per user in 5 minutes. These counts are kept in the database and shared by every node, so more nodes do not give an attacker more attempts; a count that cannot be read refuses the attempt. An address's attempts are counted under a hash of the address, never the address itself.
Accounts are set up from the command line, which prints a new password to hand over:
bin/karta eval 'Karta.Release.local_user("ann@example.com")'
bin/karta eval 'Karta.Release.local_user("ann@example.com", admin: true)'
Running it again for the same address resets the password and the authenticator (there are no recovery codes) and ends the user's sessions.
The first administrator
- With an identity provider: put yourself in a group listed in
KARTA_OIDC_ADMIN_GROUPS; or sign in once (which creates your user), then runbin/karta eval 'Karta.Release.make_admin("ann@example.com")'. - With local login:
Karta.Release.local_user/2withadmin: true.
Roles
Each membership of a user in an organisation has a role:
| Action | owner | admin | member | read-only |
|---|---|---|---|---|
| See the organisation, its servers, domains, credentials and webhooks (never their secrets), messages and deliveries | ✓ | ✓ | ✓ | ✓ |
| Manage messages and credentials | ✓ | ✓ | ✓ | |
| Manage servers, webhooks, domains and members below owner | ✓ | ✓ | ||
| Manage owners; rename the organisation | ✓ |
Instance administrators may do everything in every organisation, and they
alone create organisations, verify domains and suspend servers. The rules
are in Karta.Accounts.Scope; the pages check them on the server for
every page and every action, with the user's roles as they are in the
database at that moment, so a role taken away counts at the next click.
- An organisation that has an owner keeps at least one.
- Members are added by address, once they have signed in to Karta (users are created at their first sign-in).
- The members of an organisation named in
KARTA_OIDC_GROUP_ROLESare managed in the identity provider; its members page only shows them.
Sessions
- A session lasts 12 hours from sign-in (
config :karta, Karta.Accounts, session_hours:) and is not extended; with an identity provider, signing in again is usually a redirect and back. - The session cookie holds a random token; the database stores only its SHA-256. Signing out ends the session and disconnects its open pages; a disabled user's sessions end at once. Open pages check their session every minute.
- The cookie is encrypted and signed,
HttpOnlyandSameSite=Lax; in production it isSecureand named with the__Host-prefix. Signing in replaces it, so a session id is never carried across sign-in. - Forms need Phoenix's CSRF token; signing out is a
DELETEwith it. - The account page lists your sessions and signs you out everywhere else. A local account changes its password there (at least 12 characters; your other sessions end) and moves to a new authenticator app; both need the current password, which can be tried 10 times in 15 minutes.
Behind a reverse proxy
Set KARTA_TRUSTED_PROXIES to the exact ranges of your proxies (see
Installation). Karta then takes the
client's address from X-Forwarded-For and the scheme from
X-Forwarded-Proto of those proxies only, for the redirect to HTTPS, the
login limits per client, the API key verification limit and the networks
recorded for opens and clicks.