> For the complete documentation index, see [llms.txt](https://www.health-samurai.io/docs/interbox/llms.txt).
> Use it to discover all available pages before guessing URLs.

---
# Securing dashboard access

The Interbox dashboard and its API reach message content (PHI), the error queue,
a read-only SQL console and an assistant with file and shell tools. Three things
protect them, and only the first ships with Interbox:

1. **A login.** Built in and on by default. This page starts there.
2. **Private.** The dashboard is never on the public internet. You reach it over
   a VPN or VNet through an *internal* ingress.
3. **Encrypted.** TLS sits in front.

The login does not replace the other two. It authenticates whoever reaches the
port. It does not decide who can reach it.

> There is no built-in RBAC. Everyone who signs in gets everything the dashboard
> is configured to allow, including editing the workspace if you have turned
> that on. That setting is `INTERBOX_WORKSPACE_ACCESS`, and it defaults to
> read-only. See [The workspace](../deploy/workspace.md).

## Signing in

You can enable either of two ways in, or both.

**An administrator password.** One shared account, no username. With single
sign-on also enabled, the password is not the front door: the sign-in screen
offers the provider, and the password sits behind a **Use the administrator
password** link that replaces it. With single sign-on off, the password box is
the screen. Set `INTERBOX_AUTH_ADMIN_PASSWORD`. It must be at least 20
characters, and Interbox never invents one for you. An unset password makes the
dashboard refuse to serve, and no generated secret is printed in a log where it
would live forever. Generate one with:

```sh
openssl rand -base64 24
```

That recipe produces no `$`, which matters because `--env-file` expands `$` as
a variable reference and would mangle the password without any error.

**Single sign-on.** Point Interbox at any OpenID Connect provider:

```sh
INTERBOX_AUTH_ISSUER=https://idp.example.com
INTERBOX_AUTH_CLIENT_ID=<the client you registered>
INTERBOX_AUTH_CLIENT_SECRET=<optional; PKCE carries a public client alone>
```

Register `https://<your host>/api/auth/callback` as the redirect URI.

The password account stays on unless you set `INTERBOX_AUTH_ADMIN_ENABLED=false`,
and while it is on `INTERBOX_AUTH_ADMIN_PASSWORD` is required. See
[Turning the password account off](#turning-the-password-account-off).

### The sign-in button names your provider

With single sign-on enabled, the button reads **Sign in with Google**, **Sign in
with Okta**, and so on. Interbox derives that name from `INTERBOX_AUTH_ISSUER`
alone and fetches nothing to work it out. For a provider you run yourself the
derived name is wrong, and you can set the name yourself, as described below.

Interbox knows the major hosted providers by their issuer host, and only by that
host. The host is what proves the name, so nothing else about an issuer can
borrow a brand the host does not own. Every other provider, self-hosted ones
included, is named by the issuer's host. An issuer at
`https://sso.internal.example` gives you **Sign in with sso.internal.example**,
and a non-default port stays in the name (`sso.internal.example:8443`).

That default is deliberately conservative, and it is the wrong answer for a
provider you run yourself. Aidbox, Keycloak and Dex all issue from *your*
hostname, which says nothing about the product, and inspecting the issuer cannot
fix that: the same host publishes everything an issuer publishes. Set the name
yourself:

```sh
INTERBOX_AUTH_PROVIDER_LABEL=Aidbox
```

This gives **Sign in with Aidbox**. The label wins over the host and over the
built-in names. Use it too if you want the button to read `Corporate SSO`
instead of `acme.okta.com`, or if you do not want your identity provider's
hostname on a page anyone can load. The label is at most 64 characters, and
Interbox refuses control characters because the page renders it.

The sign-in screen is public, so anyone who can reach the page sees that host,
signed in or not. A hostname is not a credential, and the redirect that
`/api/auth/start` sends an anonymous visitor to already shows the same host. If
you do not want to name your identity provider to strangers, keep the page off
the open internet. See [Additional layers](#additional-layers).

### What the issuer is, and how to find it

`INTERBOX_AUTH_ISSUER` is the provider's **identity**. You do not call it as an
endpoint. It is the value the provider puts in the `iss` claim of every token it
signs, and Interbox builds everything else from it. Interbox uses it three
times, and all three comparisons are exact:

1. It fetches `<issuer>/.well-known/openid-configuration`.
2. It requires that document's own `issuer` field to equal what you configured.
3. It requires every id_token's `iss` claim to equal it too.

Do not paste the discovery URL into this variable. Interbox appends
`/.well-known/openid-configuration` itself, so a value that already ends in that
path makes it look for the path twice.

To get the right value, ask the provider and read the answer back:

```sh
curl -s https://<your provider>/.well-known/openid-configuration | jq -r .issuer
```

Paste that output verbatim. A trailing slash, a difference in case, or `http`
where the provider says `https` makes it a different issuer, and the sign-in
fails.

Where to point that `curl`, by provider:

| provider | issuer |
|---|---|
| Aidbox | the Aidbox base URL, e.g. `https://aidbox.example.com` |
| Google | `https://accounts.google.com` |
| Microsoft Entra ID | `https://login.microsoftonline.com/<tenant id>/v2.0`, with a tenant id and never `common` |
| Auth0 | `https://<tenant>.<region>.auth0.com/`, where the trailing slash is part of it |
| Keycloak | `https://<host>/realms/<realm>` |

Interbox fetches that document **server-side**, so the issuer must be an address
the Interbox process can reach. An address that resolves only in your browser is
not enough. The issuer must be `https` unless it is a loopback address, which is
what lets a local Dex or Aidbox rig work over plain HTTP.

If any of this is wrong, `/api/auth/start` answers `503` with "the identity
provider could not be reached", and the server log says which check failed:
unreachable, a redirect where a document was expected, or a document naming a
different issuer.

### Who may sign in

An OIDC issuer on its own admits **every account that provider will
authenticate**. For a multi-tenant provider, that is most of the internet. So
Interbox parks the dashboard until you say who may in:

```sh
INTERBOX_AUTH_ALLOWED_EMAILS=alice@example.com,bob@example.com
INTERBOX_AUTH_ALLOWED_DOMAINS=example.com
INTERBOX_AUTH_ALLOWED_GROUPS=interbox-operators
INTERBOX_AUTH_ALLOWED_SUBJECTS=00000000-0000-0000-0000-000000000000
```

Any one of them is enough. A domain rule matches the label after the last `@`
exactly, so `example.com` does not admit `notexample.com` or
`mail.example.com`. An email rule also requires the provider to have marked the
address verified.

The group example above is a *name*, which is what some providers put in the
token. Others put an opaque id, and a name never matches there. Entra ID is one
of those, so read [its worked example](sign-in-providers.md#worked-example-microsoft-entra-id)
before you write a group rule against it.

`INTERBOX_AUTH_REQUIRED_CLAIMS` is a JSON object that every identity must match:

```sh
INTERBOX_AUTH_REQUIRED_CLAIMS={"tid":"<your tenant id>"}
```

It **narrows** who gets in and cannot admit anyone by itself. That is
deliberate. The claims an operator reaches for first are `aud` ("only my
application") and `iss` ("only my provider"). Both are already true of every
token the verifier accepts, so pinning one and nothing else would admit the
whole provider while looking like a restriction.

> `INTERBOX_AUTH_ALLOWED_GROUPS` is only safe on a **single-tenant** issuer. A
> group name is a string the identity provider controls, and on a multi-tenant
> or self-service-group provider the person signing in may be able to choose it.
> Pair it with `INTERBOX_AUTH_REQUIRED_CLAIMS` pinning the tenant, or match on
> subjects instead. Providers that emit group **IDs** instead of names are not
> affected.

#### Will my provider give me an email rule?

`INTERBOX_AUTH_ALLOWED_EMAILS` and `_DOMAINS` need the provider to send
`email_verified` as the boolean `true`, in addition to `email`. Interbox does
not trust an address the provider has not vouched for, because the account
holder may have typed an unverified address themselves.

OpenID Connect defines both claims as part of the `email` scope. A conforming
provider that supports that scope returns them, and email and domain rules work.
Google is the common case. Two providers covered in
[Sign-in provider examples](sign-in-providers.md) do not:

- **Aidbox** sends `email` and no `email_verified`.
- **Microsoft Entra ID** does not send `email_verified` either, and its `email`
  may come from an unverified `otherMails` entry.

For both, match on `INTERBOX_AUTH_ALLOWED_SUBJECTS` instead.

To check the provider you actually have, complete one sign-in, take the
`id_token` from the token response and look at its claims. The middle segment of
the JWT is base64url-encoded JSON:

```sh
echo '<the id_token>' | cut -d. -f2 | base64 -d 2>/dev/null | jq .
```

If `email_verified` is `true`, email and domain rules work. If it is absent or a
string, they do not, and Interbox refuses every sign-in with `403`. That looks
like a rejected account and not a configuration mistake, so check before you
deploy the rule.

### What a session is

A session is a 256-bit random token in a `__Host-` cookie: HttpOnly, Secure,
SameSite=Lax, no `Domain`. Interbox stores only its hash, so a leaked database
row is not a usable credential. Sessions last **12 hours absolutely**, with no
idle extension and no renewal.

Signing out ends one session. Ending *every* session is a separate capability,
and the dashboard has no button for it. A button beside **Sign out** would do
something far larger: it signs out every operator, including whoever pressed it.
You make this request yourself, with the cookie your browser already holds:

```sh
curl -X POST https://interbox.internal.example/api/auth/sessions/revoke-all \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://interbox.internal.example' \
  -b '__Host-interbox_session=<your session cookie>' \
  -d '{}'
```

Both headers are required. A state-changing request that carries the session
cookie must declare `application/json` and must name this deployment as its
`Origin`, or Interbox refuses it with `403`. These are the same two rules that
stop another site's page from using your logged-in browser. A browser sends
`Origin` on every request that is not a `GET`, so nothing in the dashboard has to
handle it, but a command-line client must send it. The cookie is `HttpOnly`, so
you cannot read it with `document.cookie`. Take it from your browser's storage
inspector.

The request ends every session, every assistant conversation, and every
conversation's credential. Yours is among them, so it signs you out too.

Administrator sessions survive restarts and failovers. Starting a replica with a
new `INTERBOX_AUTH_ADMIN_PASSWORD` revokes previous administrator sessions and
assistant grants, and replicas with the old password cannot sign users in.
Disabling the account also revokes access. OIDC sessions are unaffected.

PostgreSQL stores salted credential fingerprints and their retired history,
never plaintext passwords. A replaced password never comes back: a replica
started with one parks its API instead of restoring it. Rotate to a new
password, including when you roll back. Disabling the account works at any time.

Trusted-device cookies survive restarts and failovers. They select the reserved
password verification lane, and users still need a password and a valid session.

Ending an assistant session does the following. Interbox stops the agent
process, drops the conversation from memory, and forgets the identifier it would
have used to resume it, so nobody can continue the conversation without starting
a new one. It does **not** delete what the agent itself wrote under its own home
directory. Those files are inside the workspace service's container, where the
assistant runs, and share its lifetime. A container that is replaced on each
deploy discards them, and one with a persistent volume mounted over that path
keeps them. If you have a retention obligation that reaches transcripts, treat
it as a filesystem question. Signing out does not handle it.

### Browser support

Interbox decides whether a request came from its own pages using the `Origin`
header. Browsers send it on a **same-origin** write from **Chrome 51+, Firefox
70+, Safari 12+**. That floor is years below the Fetch Metadata one that follows,
and below anything still receiving security updates.

Where the browser also sends [Fetch Metadata](https://www.w3.org/TR/fetch-metadata/)
(the `Sec-Fetch-*` headers, **Chrome 76+, Firefox 90+, Safari 16.4+**), Interbox
applies a second, stricter set of rules on top. A cookie-carrying request must
say it is same-origin, and a cross-origin link may not navigate to an API route.
Browsers send those headers only to a *potentially trustworthy* origin, meaning
`https` or loopback. A deployment served over plain `http` on a private address
gets none of them and relies on `Origin` alone. See
[When there is no TLS anywhere](#when-there-is-no-tls-anywhere).

### Turning the password account off

```sh
INTERBOX_AUTH_ADMIN_ENABLED=false
```

This leaves single sign-on as the only way in. Unlike the switch that turns the
whole login off, an unrecognised value here is refused and not assumed.

**Do this in any deployment that serves a workspace UI.** Workspace-authored
pages are served from Interbox's own origin at `/workspace-ui/*`. A page in that
workspace can render a convincing copy of the sign-in form on the address
operators trust, and collect the password. Interbox cannot stop that while a
password exists to be typed. With OIDC only, there is nothing to phish on this
origin, because the credential is entered at the identity provider.

### Attribution

The password account is one shared identity called `admin`. The log says that an
authenticated operator did something and not **which** operator. Only single
sign-on tells you who.

The dashboard shows who is signed in beside the sign-out control, and
`/api/auth/status` returns the same information: a display name, the subject,
the issuer that vouched for it, and when the session began.

The display name is whatever the provider is willing to say. Interbox takes the
first of `name`, `preferred_username` and `email` that the verified ID token
carries. If the token carries none of them and the provider publishes a
`userinfo_endpoint`, Interbox asks that endpoint once during the sign-in, while
it still holds the access token, and keeps the name from the answer. It refuses
an answer about a different subject. Providers differ here: some put a name in
the token and others hold it back until asked, so a deployment may see a name,
an email address, or neither.

The display name is a label and nothing else. Identity is issuer plus subject.
The allow-rules judge it, the session is keyed by it, and the log records it.
Where nothing named the account, as with the built-in `admin`, the control falls
back to the subject. It shortens a long subject and shows the full value in a
tooltip.

## How signing in works

Every failure below maps onto a step of this flow, so read it once.

**Discovery, on the first sign-in.** Interbox fetches
`<issuer>/.well-known/openid-configuration`, refusing redirects, and requires the
document's own `issuer` to equal the one you configured. It keeps the result for
the life of the process, so a provider that is later compromised cannot swap the
token endpoint underneath a running instance. Changing a provider's endpoints
means restarting Interbox.

**`GET /api/auth/start`.** Interbox mints four values: a `state`, a `nonce`, a
PKCE verifier, and a random cookie value. The first three go into a row in its
own database, keyed by the *hash* of that cookie, and the row lives ten minutes.
The cookie goes to the browser. Interbox then redirects to the provider with
`code_challenge_method=S256`. It always uses S256 and never reads the method
back from discovery, because a provider that omits the field would otherwise
downgrade the exchange to `plain` without any sign.

**At the provider.** The person authenticates however that provider works:
password, MFA, a corporate session they already have. Interbox is not involved
and never sees the credential.

**`GET /api/auth/callback`.** The provider sends the browser back with a code.
Interbox then does the following, in order:

1. It reads the login cookie and **deletes the matching row in the same
   statement**, so a code can never be used twice.
2. It checks `state` against that row, and the `iss` response parameter too when
   the provider advertises support for it.
3. It exchanges the code, sending the stored PKCE verifier and the one
   configured `redirect_uri`.
4. It verifies the id_token against the provider's published keys with a pinned
   algorithm list, requiring `exp`, `iat` and `sub`.
5. It checks `nonce`, `aud`, and `azp` when the token names several audiences.
6. It applies your allow-rules.
7. It mints a session and sends the browser to wherever the sign-in started.

The most important step is requiring **the cookie in addition to `state`**.
Without it, an attacker could start a login with their own identity and drive
your browser to the callback, putting you inside *their* session on a dashboard
that reaches PHI and a shell agent.

**What is never stored.** Interbox discards the provider's access and refresh
tokens. It makes exactly one call with the access token: the userinfo request
described above, during the sign-in that issued the token, and only when the ID
token named nobody. It never keeps the token afterwards, because the SQL console
and the assistant can reach a stored token.

**What identifies you** is issuer plus subject. The allow-rules judge it, the
session row is keyed by it, and the audit log records it. The email address never
identifies anyone, because addresses get reassigned to new people. Interbox
records a display name alongside the identity. It may well be an email, but
nothing decides anything on it. It exists to put a person's name in a header
instead of an opaque identifier.

```text
browser → /api/auth/start → provider login → /api/auth/callback → dashboard
             ↑ sets a 10-minute cookie          ↑ that cookie, plus state,
               and stores state/nonce/verifier    plus a verified token
```

### Licence activation

Activation cookies expire after ten minutes. Their signing key is stored in
PostgreSQL, so an unexpired callback stays valid across API process replacement
and another API process that uses the same database can verify it.

### When a sign-in fails

| what you see | what it usually is |
|---|---|
| Dashboard parked; `/api/auth/status` names `INTERBOX_AUTH_ALLOWED_EMAILS` | an issuer is set with no allow-rule. Add one |
| `503` "the identity provider could not be reached" | the issuer does not match what the provider publishes, the Interbox process cannot reach it, or that URL answered with a redirect |
| The provider rejects the request before showing a login | its registered redirect URI is not exactly `<INTERBOX_PUBLIC_URL>/api/auth/callback` |
| `400` "this sign-in did not start here" | the login cookie is missing, older than ten minutes, or already used. Start again from the sign-in page |
| `403` on `/api/auth/start` from a bookmark or a link on another site | that address is not an entry point. Reach it from this deployment's own sign-in page, which makes the request same-origin |
| `403` "a cookie this deployment sets arrived more than once" | another host on your parent domain has set a cookie of the same name. The response clears it, so reload once. This happens only without TLS, where the `__Host-` prefix is unavailable |
| `400` "this sign-in could not be completed" | `state`, the code exchange, or token verification failed. The server log names which |
| `403` "this account may not use this instance" | authentication worked, and no allow-rule matches that identity. The log records the subject that tried |
| Sign-in succeeds, then every panel shows errors | the dashboard is served from a different origin than the API, so its requests carry a foreign `Origin`. See [Writes are same-origin only](#writes-are-same-origin-only) |

The server log records every one of these with a reason. The browser is told less
than the log on purpose: a sign-in page that explains exactly which check failed
helps an attacker.

## Required in every deployment

`INTERBOX_PUBLIC_URL` is the browser-facing origin: scheme, host and port, no
path.

```sh
INTERBOX_PUBLIC_URL=https://interbox.internal.example
```

It is required **whether or not the login is on**, because it does more than
configure authentication. It is the origin Interbox answers for. Interbox
refuses a request that arrives with any other `Host`, which stops a DNS-rebinding
page in someone's browser from talking to a port-forwarded dashboard. The URL
must be `https` unless it is loopback, since a `Secure` cookie cannot travel over
plain HTTP.

### When there is no TLS anywhere

```sh
INTERBOX_AUTH_ALLOW_INSECURE_HTTP=true
```

This permits plain `http` on a non-loopback host for two addresses and no
others: `INTERBOX_PUBLIC_URL` and `INTERBOX_AUTH_ISSUER`. It is off unless set to
`true` or `1`, and Interbox refuses an unrecognised value instead of reading it
as off.

It does **not** permit a plain `http` endpoint inside a discovery document. That
follows the issuer, not this flag. A cleartext issuer may name `http` endpoints
**on its own origin**, because an on-path attacker can already rewrite the
document it served, and nothing beyond that origin was ever conceded. An `https`
issuer may name none, however this flag is set. A loopback issuer may not either:
`http://localhost` is a trustworthy origin and not a cleartext one, so it
vouches for its own endpoints and for nobody else's. A deployment that turns this
flag on for its own origin does not downgrade its provider.

Use this flag for a private network with no TLS anywhere, and not for
convenience. It gives up the following:

- The session cookie and every exchange with the identity provider cross the
  network in cleartext, so anyone on the path can read one and replay it.
- **If the issuer itself is `http`**, its discovery document arrives
  unauthenticated. A substituted `jwks_uri` then points token verification at an
  attacker's keys, and the attacker can mint `id_token`s the login accepts. **A
  cleartext issuer means the login holds only as far as the network does.** An
  `https` issuer is unaffected: Interbox still requires its endpoints to be
  `https` and refuses a document that names an `http` one.
- The session, sign-in and licence cookies lose `Secure` and their `__Host-`
  prefix, because a browser stores neither over `http`. Without `__Host-`, a
  sibling host on the same parent domain can set a cookie that the browser sends
  here. Interbox refuses a cookie header that names one of its cookies twice, so
  a shadowing attempt ends in a refusal and no swap happens. The refusal carries
  `Set-Cookie` headers that delete the stray copy from the host and from each
  parent domain it could have been set on, so one reload recovers. Those headers
  clear `Path=/`, which is where a cookie must be set to reach every route.
  Interbox refuses a copy planted on a narrower path just the same, but you have
  to clear it from the browser by hand. Nothing can make the `__Host-` prefix
  available over cleartext, and that prefix is what would have stopped the cookie
  from being set in the first place.
- The browser sends no [Fetch Metadata](https://www.w3.org/TR/fetch-metadata/) to
  a cleartext origin on a private address, so the stricter same-origin rules
  described under [Browser support](#browser-support) never run. Four independent
  layers remain: `SameSite=Lax` cookies, the CORS preflight, the
  `application/json` requirement, and the `Origin` check. The scheme does not
  touch the first three. The fourth has a blind spot: a cross-origin `<img>`
  sends no `Origin`, and such a request is indistinguishable from one of the
  dashboard's own reads. Two `GET`s do change something, and neither is worth a
  cross-site link. The licence return must present both a cookie Interbox
  minted and the matching value it was sent away with. Starting a single sign-on
  writes a short-lived login row that expires on its own. Every other `GET` only
  reads.
- A cross-origin link can open a `GET` API route in the operator's tab and render
  JSON there. The other site cannot read what it rendered, because it is a
  cross-origin document, so this is untidy and discloses nothing.

Boot logs a warning that names each variable in cleartext. Loopback is
unaffected either way: browsers already treat `http://localhost` as a secure
origin and send it the metadata that a private address does not get.

## When it is misconfigured, the engine keeps running

A missing password or a malformed variable does **not** stop the process. The
dashboard and its API answer `503` and say which variable is at fault, and the
engine keeps consuming and delivering messages throughout. This matters because
the container runs both: exiting on a dashboard variable would take the MLLP
listener with it and refuse a hospital's feed at the TCP level.

`/api/health` keeps answering so the container is not killed, and
`/api/auth/status` names the variables so an operator can see what to fix.
`/api/ready` answers `503` while parked or while the local engine is not ready.

> With `/api/ready` as the readiness probe ([Readiness](../deploy/deployment.md#readiness)), a
> parked replica leaves the Services and receives no feeds, while its engine
> keeps processing if it holds the active lease. A rolling update stops at a
> parked new pod while the old pods keep serving, so check the variables before
> a rollout.

## Turning it off

```sh
INTERBOX_AUTH_ENABLED=false
```

This turns off **the session requirement and nothing else**. The Host allowlist
and the cross-site rules stay on, because the threats they cover do not need a
cookie to work. Those threats are DNS rebinding against a port-forward, and a
cross-site write from a page the operator happens to be visiting.

Only `false` and `0` disable the login. Anything unrecognised leaves it **on**,
because a typo in this variable must not unlock a dashboard.

## What reaches the API without a browser

Two things reach the API without a browser: a signed-in session, and a **service
grant**, which is the credential the dashboard mints for one assistant
conversation. There is no deployment-wide bearer token to configure, and no
setting creates one. Every credential this deployment accepts therefore expires,
and every one can be revoked. See [What a session is](#what-a-session-is).

### The assistant carries a grant

The assistant is an agent with a shell, and it reads message content. A message
crafted by whoever sends you clinical data can therefore try to instruct it. When
a conversation starts, the assistant receives a credential of its own. Interbox
mints it for that conversation, ties it to the dashboard session that opened the
conversation, and keeps it valid for **one hour**.

You can take the grant away, which is the point. Signing out revokes the grants
of the conversations that session started, and
[revoking every session](#what-a-session-is) revokes every grant. Both take
effect at once, and neither needs a restart or a configuration change.

A grant reaches real data. It reads message content, which is PHI: each
pipeline's units, their attributes and error messages, each unit's stored value,
and the payload of each of its items that is waiting to be sent or was rejected.
It also writes. It can update the workspace checkout, rewrite clinical code
translation, and Retry and Defer units.

A grant reaches eleven route shapes, matched by method and path, and nothing
outside them. Seven read:

- `GET /api/unmapped-codes` and `GET /api/terminology/loinc`
- `GET /api/repository`
- `GET /api/pipelines` and `GET /api/pipelines/:name/units`
- `GET /api/units/:id` (the unit with its stored value) and
  `GET /api/units/:id/items/:itemId` (the item, with its payload while it waits
  and, once it has finished, only if it was rejected)

Four write:

- `POST /api/repository/pull`: updates the workspace service's checkout and
  publishes it to the replicas
- `POST /api/concept-maps/:map/entries`: rewrites clinical code translation
- `POST /api/pipelines/:name/units/retry` and
  `POST /api/pipelines/:name/units/defer`: Retry or Defer units, up to 1000
  per request; a Retry re-queues a unit already sent, too

Nothing else is reachable: no SQL console, no workspace actions, no repository
file writes, no deleting a 2.0 unit's items, and no assistant route.

The grant does not stop a crafted message from reaching the agent, and it does
not stop the agent from acting within the routes it can already reach. It bounds
what a stolen credential is worth and how long it stays worth it. If you suspect
a message drove the assistant somewhere it should not have gone,
[revoke every session](#what-a-session-is). That ends every conversation's
credential at once.

### The command-line tool

`interbox` is not a browser, so a grant is the only thing that gets it in. It
therefore works from inside the dashboard assistant, where that credential is
already in the environment under `INTERBOX_SERVICE_TOKEN`. Setting that variable
by hand to a value of your own does not work: the API knows no such credential
and answers `401`. The tool also refuses to send its credential to a plain-`http`
`INTERBOX_API_URL` whose host is not a loopback address. Loopback means
`localhost`, an IPv4 address in `127.0.0.0/8` or `[::1]`, and no other name,
however it resolves. Sending it anyway would put a live credential on the network
in cleartext.

Interbox writes every request made with a grant to the log, with the method, the
path, and the session the grant belongs to, so you can tell afterwards what was
read.

## The database role Interbox connects as

The SQL console is read-only: every query runs inside a read-only transaction, so
nothing it does can write to your tables. That covers less than it sounds like.
Read-only stops writes, and reading a file off the database *host* is a read. If
`DATABASE_URL` names a superuser, or any role belonging to
`pg_read_server_files`, then `pg_read_file('/etc/passwd')` answers inside that
read-only transaction, and the console reaches the machine and not only the data.

Only signed-in operators can ask, and the assistant's credential is refused this
route, so an anonymous caller cannot walk through this hole. It is still a
reason to give Interbox a role that cannot do it in the first place.

**Interbox needs ownership of its own database, and nothing above that.** It
creates its schemas, tables, partitions and indexes on boot, and it installs two
extensions, `pg_trgm` and `btree_gist`. Both are *trusted* extensions, so the
database owner can install them without being a superuser:

```sql
CREATE ROLE interbox LOGIN PASSWORD 'a-strong-password';
CREATE DATABASE interbox OWNER interbox;
```

Point `DATABASE_URL` at that role and not at the cluster's administrative one.

On a managed service, the "admin" account you are given is often more than an
owner. Check two things:

```sql
SELECT current_setting('is_superuser');            -- expect: off
SELECT pg_read_file('/etc/hostname');              -- expect: permission denied
```

If the second one answers, revoke the membership that allows it:

```sql
REVOKE pg_read_server_files FROM interbox;
REVOKE pg_execute_server_program FROM interbox;
```

Some managed services also require extensions to be allowlisted before the owner
can create them. See [PostgreSQL extensions](../deploy/requirements.md#postgresql-extensions).

## Additional layers

A login on the application does not make the application public-facing. For a
real deployment, put it behind an internal ingress with TLS. If your organisation
already runs a login gate, put that in front as well.
[Private ingress and TLS](private-ingress.md) describes that setup.
[Sign-in provider examples](sign-in-providers.md) walks through Google, Aidbox
and Microsoft Entra ID.

## Writes are same-origin only

Interbox checks every `/api/…` request before it reaches a route. It refuses
with `403` an `Origin` header that names anything but this deployment's own host,
whatever the method. On a non-GET it also refuses a declared content type other
than `application/json`. These checks stop a page on another site from using a
logged-in operator's browser to commit to your workspace, switch its branch, or
run a workspace action. A `localhost` origin gets no special treatment on a
remote deployment. Interbox accepts it only when the deployment itself is served
from `localhost`, so a page running on an operator's own machine cannot write to
a remote instance through their browser.

A request that carries the session cookie is held to more than that. A non-GET
must send an `Origin`, and it must be this deployment's own. Interbox refuses an
absent `Origin`, because a browser always sends one. A `GET` may omit it, since
browsers send no `Origin` on a same-origin read, but a `GET` that names another
origin is refused. That refusal stops another site from opening a stream against
a logged-in browser. Interbox judges a client that holds a service credential on
that credential instead, so command-line use is unaffected.

`INTERBOX_ALLOWED_ORIGINS`, a comma-separated list, adds origins that the guard
treats as this deployment's own, which satisfies the `Origin` check for them.

It does **not** make a dashboard on a different host work. The session cookie is
`SameSite=Lax`, so it travels on top-level navigations and nothing else. A
cross-site `fetch` carries no cookie, and every gated route answers `401`
however you list the origin. Interbox refuses a cross-site state-changing request
separately, on `Origin`. So with the login on, listing an origin gives a browser
exactly the routes that need no session: `/api/health`, `/api/ready`, and
`/api/auth/status`.

Serve the dashboard from the origin that serves the API, which is what the image
does, or put both behind one hostname on a reverse proxy. The variable is for a
second front end that calls those public routes. Do not use it to split the
dashboard off.

Reading is narrower than writing. Interbox grants a cross-origin **read** only to
`INTERBOX_PUBLIC_URL` and to anything named in `INTERBOX_ALLOWED_ORIGINS`. A page
on another port of the same machine is refused even when Interbox is served from
`localhost`. Development does not need that grant, because the dashboard's dev
server proxies `/api` and does not call it across origins. Reflecting every local
port would widen what any other program on the machine can read, for no benefit.

The origin check does not replace the login gate. A request that carries no
`Origin` at all is not from a browser and passes the check, so a script that can
reach the port can still call the API. A scripted client may send
`Content-Type: application/json` or no content type at all, and only a different
declared type is refused.

Interbox caps request bodies at 8 MB, and at 4 MB on the `/api/repository/…`
routes.

## See also

- [Sign-in provider examples](sign-in-providers.md): Google, Aidbox and Microsoft
  Entra ID, each configured end to end.
- [Private ingress and TLS](private-ingress.md): the internal ingress, TLS
  certificate and login gate in front of the dashboard.
- [Testing locally with k3d](../deploy/local-k3d.md): rehearse this whole path (ingress
  and TLS and SSO) on a laptop before touching a real cloud.
- [Deployment](../deploy/deployment.md): the chart, install, and the engine-specific rollout
  facts, including [TLS to PostgreSQL](../deploy/deployment.md#tls-to-postgresql).
- [System requirements](../deploy/requirements.md): sizing the pod, Postgres, and Aidbox, including
  [PostgreSQL extensions](../deploy/requirements.md#postgresql-extensions).
