# Admin accounts and sessions

> Create and switch admin accounts, choose how admins sign in, adjust session durations, and set team mode.

By default, admin accounts sign in with a passkey, or with a password and a code from an authenticator app. Their access tokens expire after 5 minutes. Access tokens for regular accounts expire after 10 minutes. You can choose how admins sign in and adjust session durations. Every session ends no later than 12 hours after sign-in.

## Create and switch admins

A `User` is a regular account by default. Set `spec.accountType: Admin` to make it an admin account.

Only admin account tokens include the `admins` group, which Kubernetes recognizes as `zeabur:admins`. Installing Zeabur Identity binds `zeabur:admins` to `cluster-admin` with the ClusterRoleBinding `zeabur-identity-cluster-admins`. Admins have full cluster permissions immediately after signing in and don't need to sign in again.

Regular accounts have only the permissions you bind to their groups. They have no permission bindings by default.

> Each admin should also have a regular account for daily work. Use admin accounts only to make changes to the cluster. By default, admin accounts can sign in with an upstream account, or link one, only through an OpenID provider that you [mark as enforcing a second factor](https://oss.zeabur.com/docs/identity/users/upstream-sign-in#let-admins-sign-in-through-a-provider). Through any other provider, such as GitHub or Google, the sign-in page displays **Sign in to this account another way**.

### Create the first admin

Run the following command to create the first user. This user is an admin account with no groups. The command prints a one-time passkey setup link.

```sh
zeabur-identityctl setup-link --username admin
```

If an admin can no longer sign in, use the same command with `--reset` to recover the account. See [Sign out, recover, and remove users](https://oss.zeabur.com/docs/identity/users/offboarding).

### Invite an admin or switch account types

Invite a new user as an admin:

```sh
zeabur-identityctl invite --username alice --admin
```

Switch an existing user's account type:

```sh
zeabur-identityctl account-type alice admin     # or: regular
```

You can also use `kubectl` to make an existing user an admin and check account types:

```sh
kubectl -n zeabur-identity patch zbuser alice --type merge -p '{"spec":{"accountType":"Admin"}}'
kubectl -n zeabur-identity get zbuser            # the Type column shows the account type
```

Changes take effect the next time the user signs in or refreshes their token. Previously issued access tokens remain valid until they expire, for up to 5 minutes or 10 minutes. After an account becomes an admin account, its existing sessions that the `admin-sign-in` setting doesn't allow, such as upstream sign-ins, end at the next token refresh.

Directory sync doesn't change an account's admin status. See [Sync users from a directory](https://oss.zeabur.com/docs/identity/users/provisioning).

## Adjust session durations

Each sign-in creates a session. Applications receive a short-lived access token and a refresh token. Until the session ends, they use the refresh token to obtain new access tokens without another sign-in.

A session ends when it reaches its idle timeout or maximum duration. The default limits are:

| Account | Access token lifetime | Session idle timeout | Maximum session duration |
| - | - | - | - |
| Regular account | 10 minutes | 1 hour | 12 hours after sign-in |
| Admin, single team | 5 minutes | 1 hour | 12 hours after sign-in |
| Admin, multiple teams or device-bound passkeys required | 5 minutes | 15 minutes | 12 hours after sign-in |

The 12-hour limit starts at sign-in. Refreshing tokens doesn't reset this limit.

Zeabur Identity doesn't retain a single sign-on session, so every authorization request displays the sign-in page. The `refresh_expires_in` field in the token response indicates how many seconds remain before the refresh token reaches its idle timeout.

Pass the following options to `zeabur-identity` to adjust the limits. When generating installation manifests, pass them with `--serve-arg`.

| Option | Default | Scope |
| - | - | - |
| `--token-lifetime` | `10m` | Access token and ID token lifetime for regular accounts |
| `--admin-token-lifetime` | `5m` | Access token and ID token lifetime for admin accounts |
| `--refresh-idle` | `1h` | Session idle timeout |
| `--admin-refresh-idle` | `15m` | Admin session idle timeout with multiple teams or device-bound passkeys required |
| `--refresh-absolute` | `12h` | Maximum session duration from sign-in |

Token lifetimes must be between 1 minute and 1 hour. Idle timeouts must not exceed `--refresh-absolute`.

## Site-wide settings

The ConfigMap `zeabur-identity-settings` in the Namespace where Zeabur Identity runs stores the following settings:

| Key | Accepted values | Default | Purpose |
| - | - | - | - |
| `teams` | `single`, `multiple` | `single` | When set to `multiple`, admin sessions end after 15 minutes of inactivity by default. |
| `admin-sign-in` | `any`, `two-factor`, `passkey`, `device-bound-passkey` | `two-factor` | How admin accounts sign in. See [Choose how admins sign in](https://oss.zeabur.com/docs/identity/users/admin-sessions#choose-how-admins-sign-in). |

Every installation starts in single-team mode, where admin and regular accounts use the same idle timeout.

When multiple teams share a cluster, create the following configuration:

```sh
kubectl -n zeabur-identity create configmap zeabur-identity-settings --from-literal=teams=multiple
```

To switch back to a single team later, update the configuration:

```sh
kubectl -n zeabur-identity patch configmap zeabur-identity-settings --type merge -p '{"data":{"teams":"single"}}'
```

The **Settings** page in Zeabur OSS also writes to this ConfigMap. Zeabur Identity reads the settings at each sign-in and token refresh. No restart is required.

If the ConfigMap or a setting key doesn't exist, Zeabur Identity uses the default value. If a value isn't one of the accepted values, Zeabur Identity uses the stricter choice: `multiple` for `teams` and `device-bound-passkey` for `admin-sign-in`.

## Choose how admins sign in

The `admin-sign-in` setting decides which sign-in methods admin accounts can use. Regular accounts can always use every method.

| Value | Admin accounts sign in with |
| - | - |
| `any` | Every method regular accounts use: a passkey, a password, or an upstream account |
| `two-factor` (default) | A passkey, a password and a code from an authenticator app, or an upstream account from an OpenID provider [marked `mfa: Enforced`](https://oss.zeabur.com/docs/identity/users/upstream-sign-in#let-admins-sign-in-through-a-provider) |
| `passkey` | A passkey only |
| `device-bound-passkey` | A device-bound passkey only, such as a security key |

To change the setting, update the ConfigMap:

```sh
kubectl -n zeabur-identity patch configmap zeabur-identity-settings --type merge -p '{"data":{"admin-sign-in":"passkey"}}'
```

Zeabur Identity applies the setting at the next sign-in or token refresh. No restart is required. Sessions that the new setting doesn't allow end at their next token refresh.

### Passwords with an authenticator app

With `two-factor`, an admin who sets a password on the setup page also scans a QR code with an authenticator app, such as Google Authenticator, Microsoft Authenticator or 1Password, and enters a code from it. The setup page then shows 10 recovery codes once. Each recovery code works once in place of a code from the app.

When the admin signs in with the password, the sign-in page then asks for a code. Each code works once. Wrong codes count toward the same limit as wrong passwords. See [Passwords](https://oss.zeabur.com/docs/identity/users/manage-users#passwords).

An admin password set with `any` has no authenticator app, so it stops working when you change the setting to `two-factor`. To reset a password or a lost authenticator app, delete the password's `Credential` and send a new setup link. If the admin also has a passkey or a linked account, the setup link needs `--reset`, which deletes those too. The new password comes with a new authenticator and new recovery codes.

## Require device-bound passkeys for admins (AAL3)

When you set `admin-sign-in` to `device-bound-passkey`, admin accounts can use only device-bound passkeys, such as security keys or passkeys that stay on a single device.

Zeabur Identity rejects synced passkeys, such as those in iCloud Keychain or Google Password Manager, during sign-in, passkey registration, and token refresh. Sessions created with synced passkeys, passwords or upstream accounts end at the next token refresh. The rejection message is:

> This passkey syncs to other devices. Admin accounts here need a security key, or a passkey that stays on one device.

With this setting enabled, admin sessions end after 15 minutes of inactivity by default, regardless of the `teams` setting. Regular accounts aren't affected.

### Check that every admin has a device-bound passkey

Before enabling the restriction, check the `BE` values of the passkeys:

```sh
kubectl -n zeabur-identity get zbcred \
  -o custom-columns=NAME:.metadata.name,USER:.spec.user,BE:.spec.passkey.backupEligible
```

Each admin must have at least one passkey with `BE` set to `false`.

Admins without such a passkey won't be able to sign in until you run the following command and they use the new setup link to register a security key:

```sh
zeabur-identityctl setup-link --username <admin> --reset
```

### Change the setting

Update the site-wide settings:

```sh
kubectl -n zeabur-identity patch configmap zeabur-identity-settings --type merge -p '{"data":{"admin-sign-in":"device-bound-passkey"}}'
```

Zeabur Identity applies the restriction at the next sign-in or token refresh. No restart is required.
