> For AI agents: the complete documentation index is available at https://docs.hod.sh/llms.txt, the full documentation bundle is available at https://docs.hod.sh/llms-full.txt.

# Users and roles

People get org roles (`owner`, `member`, `viewer`) and project roles (`manage`, `run`, `read`); the admin token may do anything.

## Signing in

People sign in through an OIDC identity provider (Okta, Entra ID, Google, Keycloak, Dex, and GitLab or Forgejo as OIDC providers) or with GitHub, through Hod's GitHub App. There are no passwords. Each provider is a `[[auth.providers]]` table in the config file; its redirect URI at the provider is `<HOD_PUBLIC_URL>/login/<name>/callback`:

```toml
[auth]
# Server admins, by provider and their stable ID there: never by login or
# email. Also HOD_AUTH_SERVER_ADMINS (comma-separated). Taking one out
# of the list takes the role away when the server restarts.
server_admins = ["github:12345", "okta:00u1ab2c"]

[[auth.providers]]
name = "okta"                            # /login/okta, and the login page's button
issuer = "https://example.okta.com"      # exactly as its discovery document says
client_id = "..."
client_secret_file = "/run/credentials/hod/okta"    # or client_secret
scopes = ["openid", "profile", "email", "groups"]   # default: openid profile email
```

## Adding people

Someone who signs in for the first time gets an account with no access: "You're not a member of any org yet". To add people, an owner makes an **invite link** in the web UI (the org's Settings, Members): it gives a role, works for as many people and days as the owner says (1 person and 7 days unless changed, 30 days at most), and can be revoked. Whoever opens it and signs in joins with its role; someone already in the org keeps a higher role they had. The link's secret is after `#` in its URL, so it doesn't reach server or proxy logs; send it the way you'd send a password. Hod keeps no directory of the server's users for owners to search, so an org's owners never see who else has an account.

## Role rules

An org can also give roles at every sign-in with a **role rule**, CEL over the sign-in's claims (the ID token's and userinfo's; for GitHub, `id`, `login`, `name`, `email`, `orgs` (orgs they're an active member of, not an outside collaborator, among those where the App is installed), `org_roles` (`{"acme": "admin"}`), and `teams` as `org/slug`, read only when the rule names `teams`):

```sh
API=localhost:8080/api/v1; AUTH="Authorization: Bearer $HOD_ADMIN_TOKEN"
curl -H "$AUTH" -X PATCH $API/orgs/default -H 'content-type: application/json' \
  -d '{"role_rule": "\"platform\" in claims.groups ? \"owner\" : \"eng\" in claims.groups ? \"member\" : \"\""}'
```

The rule's role replaces the one it gave before; `""` takes it away. A role granted by hand stays, and the person gets the higher of the two. A rule that fails (a missing claim, say) changes nothing and is logged. Before saving a rule, an owner can try it in the web UI ("Try with my sign-in", or `POST /orgs/{org}/role-rule/try`): it runs on the claims of their own latest sign-in, which Hod keeps with their session and nowhere else, and shows those claims and the role they'd get.

## With the admin token

Users can also be created and given roles with the admin token (`API` and `AUTH` set as in [Role rules](#role-rules)):

```sh
curl -H "$AUTH" -X POST $API/users -d '{"name": "alice"}' -H 'content-type: application/json'
curl -H "$AUTH" -X PUT $API/orgs/default/members/<user id> -d '{"role": "member"}' -H 'content-type: application/json'
```

## Project roles and public projects

Members get the org's default project role, `run` unless changed (`PATCH /orgs/default` with `{"default_project_role": "read"}`). A project can be made **public**: anyone, signed in or not, may then read its runs, logs and files, but not trigger, cancel or see its settings and secrets:

```sh
curl -H "$AUTH" -X PATCH $API/orgs/default/projects/app -d '{"public": true}' -H 'content-type: application/json'
```

## Audit log

Changes are recorded in the org's audit log (`GET /orgs/default/audit`, or the org's Settings, Audit log), filtered by who, what kind of change, what it touched and when. Each entry records the client's IP address: the connection's, or behind a reverse proxy listed in `HOD_TRUSTED_PROXIES`, the one it reports ([Configuration](https://docs.hod.sh/self-hosting/configuration.md)). An IP address is personal data under the GDPR; entries are kept until deleted from the database.

## Disabling a user

A server admin can disable someone in the web UI (Users, in the account menu) or with `PATCH /users/<id>` and `{"disabled": true}`: they are signed out everywhere, their personal tokens stop working, their open pages close, and they can't sign in again until enabled. Their memberships stay. A server admin named in `[auth] server_admins` is changed in the config, not here, and nobody can disable themselves.

## What each role sees

In the web UI, each person sees what their role allows: a viewer sees Rerun and Run pipeline greyed out, with the role they need; the org's Settings show only to its owners and a project's Settings only to those who manage it. Your own personal tokens, in every org, are on your account page (`/account`).

## Personal tokens and `hod login`

People use the CLI with **personal tokens** (`hod_pat_…`). A token works in one org, does what its user may there but no more than its role (`read`, `run`, `manage` or `owner`), and always expires: in 30 days unless asked otherwise, and never later than the org allows (365 days unless an owner changes it with `PATCH /orgs/default` and `{"token_max_days": 90}`). It stops working when it's revoked, when its user leaves the org, and when the user is disabled.

```sh
hod login https://ci.example.com               # approve a token in the browser; saved in ~/.config/hod/hosts.yaml
hod login https://ci.example.com --org beta    # a token for another org on the same server
hod token create --role run --days 7           # print a token for a script, once
hod token list                                 # yours; --all: everyone's (owners)
hod token revoke <id>
hod logout                                     # forgets the server and revokes its tokens
```

`hod login` listens on `127.0.0.1` and opens the server's `/cli-login` page, where you approve the token; the browser then hands the CLI a one-time code it trades for the token (the RFC 8252 loopback flow, with PKCE). There's no device-code flow: it lets an attacker get a victim to approve the attacker's session. On a machine without a browser, make a token elsewhere and pipe it in with `hod login <url> --with-token`.

## Re-authentication

Writing secrets, creating runner registration tokens, changing members or org settings, and minting a token need a sign-in less than 10 minutes old when done from the web UI: the UI sends you back through your identity provider first. OIDC providers are asked to sign you in again (`prompt=login`, `max_age=0`), and Hod checks the ID token's `auth_time`. GitHub can't be asked that: it shows its account picker, so a person has to click, but a browser signed in to GitHub isn't asked for a password. Tokens, and the admin token, aren't asked to re-authenticate: as with GitHub's sudo mode, they're credentials made on purpose, and only a browser session can mint one.

## Token formats

Every token Hod makes has the same shape, so secret scanners can find a leaked one:

| Prefix                   | What it is                                  |
| ------------------------ | ------------------------------------------- |
| `hod_pat_`               | A personal token, for the API and the CLI   |
| `hod_reg_`               | A runner registration token                 |
| `hod_runner_`            | A runner's access token (one hour)          |
| `hod_job_`               | One job's token, for its RPCs and its clone |
| `hod_push_`              | One step's push grant                       |
| `hod_sess_`              | A web UI session, in its cookie             |
| `hod_login_`, `hod_cli_` | One-time sign-in codes (one minute)         |
| `hod_inv_`               | An invite link's secret, after `/invite#`   |

After the prefix come 43 random characters and a 6-character checksum, all letters and digits. To scan for Hod tokens with gitleaks, trufflehog or GitHub's custom patterns, use:

```
hod_(reg|runner|job|push|sess|login|cli|pat|inv)_[0-9A-Za-z]{43}[0-4][0-9A-Za-z]{5}
```

The last 6 characters are the CRC-32 of the 43 before them, in base62 (`0-9A-Za-z`), so a scanner can drop look-alikes without asking the server. The format follows GitHub's and the [ASF draft standard for scannable secret tokens](https://tooling.apache.org/draft-asf-token-standard). If a token leaks, revoke it: `hod token revoke` for a personal token, `hod runner tokens revoke` for a registration token.
