# Accounts

The first account is an admin called `admin`. Admins add more under *Settings > Accounts*,
each with its own name, password and role:

| Role | Sees the wall | Runs actions (keys, text, power, ports, reboot) | Settings, KVMs, accounts, updates, activity log |
|---|---|---|---|
| Viewer | yes | no | no |
| Operator | yes | yes | no |
| Admin | yes | yes | yes |

- An operator or viewer can be limited to some of the KVMs: to whole groups, to single
  machines, or both. A group counts as whatever is in it on the day, so a machine added to
  the lab next month belongs to whoever has the lab without anybody ticking it. The other
  machines do not exist for that account: not on the wall, not in the status, not by
  guessing their address.
- An account can be **suspended**: it cannot sign in until an admin lifts that, and is
  signed out at once wherever it was. Its password, role, limits and second step are kept.
  For somebody who is away, or whose access is in question; removing the account would lose
  all of that, and changing its password would say something that did not happen.
- With one account, signing in asks for the password only. With several, it asks for the
  user name too.
- Everyone can change their own password (*Settings > Security*), which asks for the
  current one. An admin can set a new one for somebody else, which signs that account out
  everywhere; their own they change like everybody, where the current one is asked for.
- The only admin cannot be removed or demoted, and nobody can change their own role or
  suspend themselves. An admin who is suspended does not count as one to fall back on.
- *Sign out everywhere* (in an account's *Edit*) ends every session of that account at once
  and changes nothing else about it: for a laptop left on a train.
- An admin may take a machine's keyboard and mouse over from whoever holds them in its live
  view, after a question that names them; an operator never takes them from anybody (see
  [Live view and control](https://qkvm.com/docs/live-view-and-control)).
- **Virtual media** (an image in a machine's drive, and the machine started from it) is a right
  of its own, and an admin's, in person: whoever mounts an installer or a rescue system on a
  machine and starts it from that is root on it. Operators run power buttons and type; they
  do not mount images. A token never does, of any role.
- The page hides what an account may not use, but the rule is enforced on the server:
  every request is checked against the role, and anything not explicitly opened to
  viewers or operators takes an admin.
- The activity log records the account behind every sign-in, change and action.

### Two-factor sign-in

Anyone can add a second step to their own account under *Settings > Security*: signing in
then asks for the password and for a 6-digit code from an authenticator app (Google
Authenticator, Microsoft Authenticator, 1Password, Aegis and so on). Setting it up shows a
QR code to scan (and the same key as text); a code works once.

- **It can be required.** *Settings > Accounts > Two-factor sign-in: required of* admins, of
  admins and operators, or of everybody. An account under the rule that has not set it up
  signs in with its password and lands on one page, which sets it up; until that is done it
  sees no screen and can do nothing else. Whoever makes the rule has to have it switched on
  for their own account first.
- **One-time codes for when the phone is not at hand.** Switching the second step on hands
  out ten codes, shown once: each signs you in a single time in place of a code from the
  app (*No phone at hand?* on the sign-in page). *Settings > Security* says how many are left
  and makes ten new ones, which ends the old. qKVM keeps only what it needs to recognise
  them, under the same key as the saved passwords, and a sign-in with one is marked as such
  in the activity log.
- **Wrong codes hold the account, not only the address.** After five of them, from wherever
  they came, the second step of that account is refused for 30 seconds, doubling up to 15
  minutes. Only somebody who has the password ever finds that out.
- If the phone is lost and the codes with it, an admin can take the second step off that
  account under *Accounts*; under a rule that requires it, the next sign-in sets it up anew.
  If it was the only admin's phone, run `qkvm --disable-2fa NAME` on the computer qKVM runs
  on.

### Sign in with an identity provider

A team that signs in to everything in one place (Microsoft Entra ID, Google Workspace,
Authentik, Keycloak, anything that speaks OpenID Connect) signs in to the wall there too, and
the provider's groups say who may do what. It is part of qKVM like everything else, free.

*Settings > Accounts > Identity provider > Set up*:

- **Redirect URI**, shown in the box: this wall's address as you are looking at it, followed by
  `/api/v1/oidc/callback`. Enter it at the provider. Open the settings at the address your
  team uses (`https://kvm.example.org`): sign-ins begin and end there, and the button tells
  whoever presses it at another address where to go.
- **Issuer**: the provider's address, exactly as it says it of itself. qKVM reads
  `<issuer>/.well-known/openid-configuration` and the provider's keys when you save, and says
  so where the provider cannot be asked, or calls itself otherwise (a slash at the end counts).
- **Client ID** and **client secret**: what the provider gave qKVM as an application. The secret
  is stored encrypted with the saved passwords and never shown again. It goes to that issuer and
  that client ID and to no other: change either, and it is asked for again.
- **Scopes**: `openid profile email`, and what else the provider needs to send the groups.
- **Groups claim**: where the provider puts a person's groups, `groups` as it comes (`roles` for
  Entra's app roles; a path such as `realm_access.roles` works too). Empty: none is read.
- **Groups and the role each gives**, written exactly as the provider sends them (a group whose
  name differs in case is another group). Somebody in several gets the highest of them.
- **Who else may sign in**: nobody but those in a group above, as it comes; or anybody else the
  provider signs in, as a viewer, an operator or an admin. That is anybody who can have an
  account there: with a provider that lets people sign up, set the email domain too (the box
  says so). From Google, which signs in any Google account there is, it is refused without one.
  It is for those in none of the groups above: somebody in one of them gets the role of their
  groups, whether it is lower than this one or higher.
- **Email domain**: only people whose address at that domain the provider says is verified
  (`email_verified`), for Google, which sends no groups. Where a provider says the domain of
  the account itself (`hd`, Google's word for a Workspace account), that has to be it too; from
  Google it has to be said.
- **May be a private address**: the provider is on your own network. As for alerts (see
  [What leaves the wall, and what never does](https://qkvm.com/docs/alerts#what-leaves-the-wall-and-what-never-does)), this
  computer, its own addresses and link-local addresses never are, and no proxy is used.

The provider is spoken to over HTTPS only. Its certificate is checked against the list the HTTP
library ships with, or the one `SSL_CERT_FILE` names (for a company's own authority).

How it goes:

- The sign-in page shows *Sign in with* and the name you gave, above the password. The wall's own
  passwords keep working beside it: they are the way in when the provider is down. qKVM keeps
  one such admin: the last admin who signs in here cannot be removed, demoted or suspended,
  not even by an admin of the provider's.
- The first sign-in makes the account, named after the person's verified email (or their user
  name, or name), and known by the provider's own number for them (`sub`) with the issuer. A name
  that is taken is never taken over: an account `olga@example.org` of the wall's own stays
  hers, and the provider's Olga becomes `olga@example.org-1a2b3c`.
- The role is read from the groups at every sign-in, and the activity log says when it
  changed. **A sign-in by the provider lasts 8 hours at the most**, however much it is used (or
  12 hours without use, or until qKVM restarts); then the button signs in again, without a
  question where the person's own sign-in at the provider still holds, and with the role their
  groups give them then. So somebody taken out of a group at the provider loses that role within
  8 hours; *Sign them out*, under *Identity provider*, ends at once every sign-in the provider
  made but that of the admin who presses it, live views included. Suspending the account here keeps that person out, whatever the
  provider says.
- A change here of anything that decides who gets what (the groups and their roles, who else may
  sign in, the email domain, the groups claim, the scopes, the client ID, the issuer, switching
  it off) signs out everybody the provider signed in, at once, live views included: they sign
  in again with the role the new settings give them. (Not the name on the button.)
- Such an account never has a password here, and the recovery key does not give it one. Its role
  is its groups'; which machines it may see is set here (*Edit*), and stays set.
- The provider does its own second step: qKVM's (*Two-factor sign-in*) is not asked of it.
- A sign-in by the provider does not outlast a restart: the button signs in again.
- Started with `--locked-start`, the client secret is locked with the saved passwords: after a
  restart the button works once somebody has signed in with a password.
- In an export the settings go with the part *Identity provider*, the client secret only in an
  encrypted file, and not the redirect URI, which is the address of the wall the file came from.
  Taken in, they come in switched off: an admin switches them on in the box, where the provider
  is asked first.

What is checked, for whoever reviews it: the authorization code flow with PKCE (S256) and
nothing else; a `state` and a `nonce` of each sign-in's own, kept ten minutes and taken once,
from the browser that began it (by a cookie of its own, `SameSite=Lax`, which a browser sends on
the way back from another site; over HTTPS a `__Host-` cookie, which no page on a name beside the
wall's can set); the code exchanged by the wall itself with the client secret;
the ID token's signature against the provider's published keys, RS256 or ES256 only (never
`none`, never HS256, never a key the token carries); a key it names and the set does not have
refused, the set fetched again for that at most every five minutes, and kept an hour in all;
its `iss`, `aud`, `azp`, `exp`, `iat`, `nbf` (with two minutes of leeway) and `nonce`; and
`iss` on the way back where the provider says it sends it (RFC 9207). Every sign-in, every
refusal with its reason, a role changed by groups and every change of the settings are in the
activity log, never a token, a code or the secret.

Entra ID, for somebody in more groups than fit in a token, sends none and says where to fetch
them: qKVM says so in the activity log, and refuses the sign-in. Have Entra send only the groups
given to the application, as below.

**Microsoft Entra ID.** Entra admin center, *App registrations > New registration*; redirect URI
of the platform *Web*: the one qKVM shows. *Certificates & secrets > New client secret*: its
*Value* is the client secret. The client ID is the *Application (client) ID*, and the issuer
`https://login.microsoftonline.com/<Directory (tenant) ID>/v2.0`. *Token configuration > Add
groups claim*: security groups, as *Groups assigned to the application*; then under
*Enterprise applications*, the application's *Users and groups*, assign the groups. Entra sends
each group as its *Object ID*: map those. (Or app roles: define them under *App roles*, assign
them, and set the groups claim to `roles`.)

**Google Workspace.** Google Cloud console, *APIs & Services > Credentials > Create credentials
> OAuth client ID*, of the type *Web application*, with the redirect URI qKVM shows under
*Authorized redirect URIs*; on its consent screen, *Internal*. The issuer is
`https://accounts.google.com`. Google sends no groups: leave the groups claim empty, set *Who
else may sign in* to the role everybody gets, and the email domain to your Workspace's.

**Authentik.** *Applications > Providers > Create*, an *OAuth2/OpenID Provider*: client type
*Confidential*, the redirect URI qKVM shows (strict), and a signing key (a certificate, for
RS256). Then an application with that provider. The issuer is on the provider's page,
*OpenID Configuration Issuer*: `https://auth.example.org/application/o/<slug>/`, with the slash
at its end. Its `profile` scope sends `groups`, by their names.

**Keycloak.** *Clients > Create client*, OpenID Connect, *Client authentication* on, the
*Standard flow* only, and the redirect URI qKVM shows under *Valid redirect URIs*; the secret is
under *Credentials*. Under *Client scopes*, the client's own (dedicated) scope, *Add mapper > By
configuration > Group Membership*: token claim name `groups`, *Full group path* off (the groups
then read `wall-admins`, not `/wall-admins`), added to the ID token. The issuer is
`https://keycloak.example.org/realms/<realm>`.

SAML and SCIM are not offered, nor does the Desktop App sign in to a wall through its provider.

### Signing in through a proxy in front of qKVM

The other way, for a proxy that signs people in itself: where people already sign in in one
place (Authelia, authentik, Keycloak with oauth2-proxy, a company's own gateway), qKVM can take
that place's word for who somebody is. It is the reverse proxy in front of qKVM that signs
people in, and tells qKVM in a header:

```
qkvm --trusted-proxy 172.18.0.5 --sso-header Remote-User
```

```
map $http_upgrade $connection_upgrade {             # the live view is a WebSocket: passed on as one
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    location / {
        auth_basic "qKVM";                          # or auth_request to your identity provider
        auth_basic_user_file /etc/nginx/users;
        proxy_pass http://qkvm:8787;
        proxy_http_version 1.1;                     # a WebSocket needs HTTP/1.1 and these two headers
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;                # on another port than 443: $http_host, which keeps the port
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Remote-User $remote_user;  # set by the proxy: whatever the visitor sent under that name is gone
    }
}
```

- Whoever the proxy names is signed in as **the qKVM account of that name**, with the role
  and the machines that account has. There has to be one: *Settings > Accounts > Add
  account*, with the name the proxy sends (`olga`, `olga@example.org`) and no password.
  Somebody the proxy knows and qKVM does not is told so, and sees nothing.
- **The header is believed of the proxy named with `--trusted-proxy`, and of nobody else:**
  not of the visitor, not of another machine on the network, not of a program on the same
  computer. And only where it arrives once: a proxy has to *set* it, as above, not add its
  line to one the visitor sent. Make sure nothing reaches qKVM's port except through the
  proxy (publish it to the proxy's network only, or use `--allow-from` with its address).
- **The second step is the identity provider's.** Somebody it signed in is not asked for
  qKVM's own code, whatever rule is set under Accounts; that rule is for those who sign in
  here with a password. An account without a password cannot be signed in to by typing
  anything, and a copy of the data folder holds nothing of it to guess at.
- Access is taken away in either place: at the identity provider, or here, by suspending or
  removing the account, which ends its session at once.
- **A live view holds only while the proxy keeps vouching.** The page asks qKVM through the
  proxy every few seconds while it is shown; a live view of somebody the proxy has not named
  on a request for ten minutes (signed out there, or the page hidden that long) ends, and is
  opened again with a click. No live view keeps a sign-in alive by itself, password or proxy:
  only the person's own requests do.
- It cannot be had with `--locked-start`: whoever signs in elsewhere brings no password
  here, and without a key of its own qKVM could not open the saved device passwords (see
  [Keeping it running](https://qkvm.com/docs/keeping-it-running)).
- Accounts with a password still sign in with it, which is the way in when the identity
  provider is down. Keep at least the first admin that way.
