Skip to content

Access and sign-in

Who may do what is three questions, each a Guatiao provider kind from the shared coqui-access crates:

Question Kind Providers
Are these credentials good? Authenticator coqui_access_password (passwords), coqui_access_key (bearer keys), coqui_access_ldap, coqui_access_proxy (a trusted reverse proxy), coqui_access_mtls (client certificates: Station certificates, or a CA's)
Who is this? Directory coqui_access_password, coqui_access_key, coqui_access_ldap, coqui_access_mtls
May they do this here? Authorizer coqui_roles, or the access record Universal Exports reads itself

password, key and mtls can also manage their own accounts (the Accounts kind). The providers are libraries: point --plugin-path at the directory that holds them.

Providers

Each provider takes a JSON object; every key is optional.

Provider Config
coqui_access_password source, max_accounts, argon2 (memory_kib, iterations, parallelism), max_password_bytes, record_limits
coqui_access_key source, prefix (default ck_), key_hash ({ "algorithm": "sha256" }, or "argon2id" with its costs beside it), max_keys, record_limits
coqui_access_mtls source, waiting, max_records, waiting_per_source, waiting_total, waiting_rerecord_secs, trust (pinned, ca, pinned-or-ca), ca_file, subject, san, ip_in_dns, account, max_chain, record_limits
coqui_access_ldap url, start_tls, ca_file, base, bind, bind_password, user_filter, name_attribute, group_attribute, group_filter, group_base, nested_groups, timeout_seconds, cache
coqui_access_proxy trusted, user_header, certificate_header, certificate_encoding (pem-url, der-base64, xfcc), subject_header, account, max_certificate_bytes
coqui_access_totp built into the gateway, over the Registry; issuer, algorithm, digits, period, skew, recovery_codes, enrol_seconds, max_records, lockout_after, lockout_seconds, lockout_longest_seconds (a second step)
coqui_roles scope_kinds, roles, rules, limits

In a provider's configuration a bound such as max_chain or one of record_limits is a count or none (no bound); null is a key that was not given and reads the default. A duration is 30, 30s or 250ms.

source says where records live: { "file": { "path": "accounts.toml", "format": "toml" } }, format being toml or json. With no source they live in memory and are gone at exit.

Universal Exports keeps what its Directory and Authorizer answer for a few seconds, to absorb bursts: a person found or an action granted 5 s, "no such person" or a denial 1 s, at most 10 000 of each (the unex record's access_cache_ttl, access_cache_negative_ttl and access_cache_entries, Configuration; 0 turns one off). A removed account or a withdrawn grant can pass for up to the first; passwords and keys are always checked at the provider (a personal key's scopes and its person's grants, at every use). A longer lifetime is reported at start.

Credentials in a provider's configuration

A field that holds a credential, such as the LDAP provider's bind_password, takes a secret reference instead of the value, so the shared configuration holds none:

directory = "coqui_access_ldap"
secret_fields = ["bind_password"]        # fields besides those a provider's schema marks sensitive
directory_config = { url = "ldaps://dc.example", bind = "cn=svc", bind_password = { provider = "file", key = "/run/secrets/ldap-bind" } }

The reference is { provider = "file", key = "..." } (also env, and any loaded secret provider) or { secret = "name" } for a [secret.<name>]. The gateway reads it when it builds the provider and holds the value in memory only, wiped as it is handed over; it never writes it back. A secret kept in the Registry is sealed to Stations and the gateway is none, so name another provider. Which fields are credentials is the provider's own schema (a field it marks x-sensitive) and the unex record's secret_fields; no name is assumed, so a field neither names is read as written. A literal in such a field still works and is reported as a weakening that names the reference as the fix.

Wherever the unex record is shown (GET /v1/user/roster/unex, so ai6ctl and Outer Office) a credential literal in secret_fields reads <redacted> and a reference is shown as it is. A record read and written back keeps the stored literal where it sends <redacted>.

Several sign-in providers

The unex record's authenticators is an ordered list; each entry is a provider and its configuration, which is checked against that provider's own schema when the gateway starts:

authenticators = [
  { provider = "coqui_access_system" },
  { provider = "coqui_access_key", config = { source = { file = { path = "keys.toml", format = "toml" } } } },
]

Each credential goes to the provider that claims it, not to all of them:

  • A bearer key, sent as Authorization: Bearer ck_..., goes to the key provider (the one that takes keys). A key is never accepted on the sign-in page, and the page does not offer it.
  • A name and a password go to the other providers in list order. A provider answers Unknown for a credential that is not its to judge, and the next is asked; Invalid means it is its own and refused, and no later provider is asked.
  • A proxy assertion (proxy_user_header) is read by the gateway and resolved in the directory, as before.

A principal keeps its provider's namespace: person: and group: rules bind what the people's directory says, account: what the key provider's accounts say, so a rule names each explicitly. The directory and the authorizer stay one each. Several providers are ordinary configuration, not a loosening: each answers only for its own credentials and grants nothing, since the access policy decides what a principal may do. Adding one is stored without a confirmation. Take the key provider away and keys stop working at the next start, while people go on signing in.

accounts, when unset, is the first listed provider that offers accounts, so the account routes work on the key provider when the people's provider (coqui_access_system) keeps none.

API keys

A key lets automation act without a password and without the hour a sign-in lasts. Two kinds share the key provider:

  • A service account is an account of the key provider (ai6ctl accounts create NAME, which needs account.manage at config:accounts) with a key of its own. It is the account:NAME principal and has the grants rules give that name or its groups. Use it for work that should not be tied to a person.
  • A personal key acts as the person who made it, narrowed to the scopes named at creation. A person makes, lists and revokes their own, signed in with a token, not with another key.
ai6ctl keys create --scope config.manage@config:plugin --expires 30d --name deploy > ~/.ai6-key
ai6ctl keys create --scope mission.read@operation:G --output key.txt   # a new file, mode 600
ai6ctl keys list            # name, scopes, created, expires, last used; never a value
ai6ctl keys revoke KEY_ID

The routes are POST, GET and DELETE /v1/user/keys. A key's value is shown once, in the answer that creates it (printed alone on standard output, or written to a file only its owner can read), and is in no log, audit record or error.

What a personal key may do is the person's own grants and its scopes, each ACTION@SCOPE (config.manage@config:plugin; an Operation scope covers the Operations under it). A scope the person does not hold now is refused when the key is made, a key needs at least one scope, and the check is made again at every use: a grant the person loses the key loses too, and a person removed from the directory takes their keys with them. A key never changes the access policy or acts as a chief, and it cannot make keys or drive Moneypenny: a key that tries answers 403, "an API key cannot do this; sign in with a password or a sign-in token". A compartment adds nothing to it.

A key lasts key_ttl seconds unless its maker says otherwise (--expires): the default is 90 days, never (or key_ttl = 0, reported as a weakening) lasts until revoked. The listing shows when each key was last used, to the precision of the access cache's lifetime. Revoking removes the key at once: the next request with it is refused. An administrator holding account.manage at config:accounts lists everyone's keys (ai6ctl keys list --all) and revokes any; another person cannot see or revoke yours. Every use that changes something is audited under the person and the key (ID via key KEYID).

Outer Office shows the person's keys in the API keys tab of their account page (#/profile), with the same make, list and revoke.

People by name

An audit record, an access rule and a page name a person by the ID their directory gave them (a user ID, a directory SID), which is no way to tell who it is. The gateway keeps what the directory said of each person who signs in (the account name, the name to show and the groups) in the Registry, under principals, and names them where it shows an ID:

  • GET /v1/user/audit carries actor_name beside actor for a person it has seen sign in. ?action=PREFIX keeps only the records whose action starts with it (run.context for what was read of a Run's transcript, internal.read for what was read through a Station's API), before the page is cut; it searches the newest records the log keeps for one page. ai6ctl audit list [--operation ID | --station ID] [--action PREFIX] [--limit N] prints it. The reads it shows are the gateway's, by person (run.context.read, assistant.log.read, assistant.context.read, and a Run's attach and detach), and a Station API's, by the API (internal.read): the API's bearer token is shared, so the actor of an internal.read is station-api, not a person, and the person-level trail is the gateway's.
  • POST /v1/user/principals with {"ids": [...]} answers the people among the IDs it has seen. A person is always named to themself; to name others it needs access.read, or audit.read on an Operation.
  • GET /v1/user/principals?q= finds people and groups whose name, account name or ID holds every word of q, for the rule picker; it needs access.read.
  • A page's classification bar says "for you" to its owner and names the owner to anyone it is shared with.

The name is for display only and decides nothing. A person never seen has no record: their ID is shown as it is. A record is written when the person is first seen, when their name or groups change, and otherwise at most once in [registry.limits.principals] refresh (300 s by default); the other limits of that table bound the people kept, a record and a name.

The access policy

The access record of the configuration provider binds people to roles at a scope (Outer Office's Access page edits it; access.toml is its import and export form). A scope is * or station:<id>, operation:<id>, theater:<id>, config:roster (the roster every Station reads), config:assistant (Moneypenny's repositories), config:memory (the global memory), config:access (the global policy) or config:accounts (the accounts) or config:<family> (a configuration family such as config:charge); the first rule that matches decides, and no match denies. The actions Universal Exports checks are access.manage, access.read, account.manage, agent.configure, agent.read, approval.class, approval.decide, assistant.memory.admin, assistant.own_agent, audit.read, cable.read, cable.send, charge.converse, issue.comment, issue.create, issue.link, issue.update, memory.write, mission.control, mission.create, mission.delete, mission.read, mission.control, mission.create, mission.read, mission.review, mission.verify, config.manage, config.read, plugin.manage, pool.manage, pool.read, roster.manage, roster.read, run.context, run.delete, run.input, run.read, station.configure, station.enroll and station.read. run.context reads what an agent was given and did in a Run (Run context): on an Operation its Missions' Runs, and with audit.read on config:assistant another person's conversations with Moneypenny (her conversation log); seeing a Run (run.read, mission.read) does not grant it. roster.read and roster.manage at config:roster list and edit the roster's Operations, Agents, roles and covers (Changing the configuration of running Stations); audit.read there shows those edits and the refused ones. pool.read shows the account pools an Operation may draw from, never a credential; pool.manage lifts an account's limit and changes which Stations hold a login or forgets it (Logins kept in the Registry). mission.control (cancel, retry, resume and interrupt a Mission) is separate from run.input: typing into a Run does not grant stopping it. approval.decide signs or refuses an Agent's request for green ink and approval.class manages class authorisations; neither comes with mission.create or mission.control. mission.review decides over a Mission's review panel, with a reason, and lets a brief name a review policy, which may weaken one. charge.converse attaches a person to a charge's live Run, at operation:<id>, station:<id> or config:charge (M's), to read it, type into it and answer it; it is in no seeded role. mission.verify gives a verdict on a Mission's outcome, which counts on its Agent's scorecard and settles a held Mission; it does not come with mission.control. mission.delete and run.delete delete a settled Mission or Run with everything kept by it (Deleting Missions and Runs); each is audited, comes with mission.control in no role, and is seeded only on controller (and held by the chief). cable.send and cable.read on operation:<id> are what Moneypenny may do with Cables there for the person: send and reply, and read what is sent to her. The Station's cables record still has to let her Agent do it. A person reads and changes Moneypenny's memory of them with no action at all, and nobody else's; plugin.manage on config:plugin approves a provider library a Station found and did not load (it decides what code that Station runs, so it is held by the chief until a role is given it); assistant.memory.admin on config:assistant lets an administrator read anyone's, each read audited memory.read, and change none. assistant.own_agent on config:assistant lets a person link their own agent, and every seeded role holds it; each connect of a relay asks again, so a person who loses it is refused on the next one, and a deployment that removes it from every role turns the feature off. memory.write on operation:<id> changes that Operation's memory and decides its Agents' proposals, and on config:memory the global one; reading an Operation's memory takes mission.read there.

A rule on an Operation reaches the Operations under it: Universal Exports names a request's ancestors (the Operation's parent, then its parent's, nearest first, from the Stations' check-ins), and a rule whose scope is one of them matches as well, unless it sets propagate = false. The first match still decides, so a child is narrowed by a rule placed before its parent's. An Operation no Station has reported has no ancestors, so only rules on it and on * apply. A person sees an ancestor Operation only with mission.read on it; one they cannot read is never named, and its subordinates stand at the top of their board. [limits] ancestors (a number or "none", default 64) bounds the ancestry a request may carry; more is an error, not a denial.

[role.viewer]
actions = ["mission.read", "run.read"]

[role.memory-admin]
actions = ["assistant.memory.admin"]

[[rule]]
subject = "group:field"
scope = "operation:G"
role = "viewer"

[[rule]]
subject = "group:security"
scope = "config:assistant"
role = "memory-admin"

Subject names

A group name matches without regard to case, and may hold inner spaces: group:Domain Users matches the group a directory lists as Domain Users and the one an operating-system account service such as SSSD reports as domain users. A group that differs in anything but case does not match. account: and person: names match exactly. A subject with leading or trailing whitespace (group: staff) is refused, not trimmed: a rule in an Operation's record is skipped and listed as an orphan naming the subject and its rule, and a rule in the global policy or a chief entry (chief, [unex.access] chief) fails to load naming the field and the entry.

Everyone who is signed in

The subject any:signed-in matches every person a sign-in, a key or a certificate resolved, whatever groups they are in, and nobody else: a caller with no sign-in reaches the policy with an empty person ID, which it never matches (a route that needs a sign-in answers such a caller 401 before it asks the policy anything). Nothing binds it by default; a deployment that wants every signed-in person to read a scope names it:

[[rule]]
subject = "any:signed-in"
scope = "operation:G"
role = "viewer"

An Active Directory sign-in token carries Everyone and Authenticated Users as SIDs, not as groups, so no group: rule can name them; any:signed-in covers them for every way in. The directory provider (coqui_access_ldap) does list a person's primary group, read from primaryGroupID and found by SID under group_base, so group:Domain Users matches an AD person without a memberOf entry for it. The system provider (coqui_access_system) lists the groups the host reports, which SSSD gives in lowercase; the same rule matches those too. A primary group that cannot be found adds nothing, and the person keeps the groups they have. The first match still decides, so place a rule for any:signed-in after narrower ones it should not override.

The sign-in policy

Which methods a sign-in may use, from where it is made, and what it still needs, is decided by a coqui_sign_in_policy provider, the sign-in policy of coqui-access. The unex record's sign_in_policy names it: a provider (default coqui_signin_rules, ordered rules) and its config, checked against the provider's own schema when the gateway starts, and again whenever the record changes.

# unex.toml. From the office network a password or a proxy-asserted identity; from anywhere else, and when the
# address is not known, the proxy-asserted identity alone.

[[sign_in_policy.config.rule]]
networks = ["10.0.0.0/8"]
allow = [["password"], ["proxy"]]

[[sign_in_policy.config.rule]]
allow = [["proxy"]]

The methods this gateway meets are password (a name and a secret in the login body) and proxy (the identity the reverse proxy asserts). A rule may name networks, clients, services and subjects, and list the providers that may be asked for a method, by the ID each is listed under in authenticators. Order is the operator's tool: the strictest rule goes last, where an address that is not known falls.

With no sign_in_policy nothing changes: each configured method alone is enough, from anywhere (password while a sign-in provider that takes a name and a password is listed, proxy with proxy_user_header).

What is decided, and where:

  • GET /v1/auth/methods answers the policy's offer for its own request: its address (see Behind a reverse proxy), and its client, a browser when the request names an origin or carries the Sec-Fetch-Mode or Sec-Fetch-Site a browser adds (a browser sends no origin on a same-origin GET) and an api client otherwise. Outer Office's desktop builds reach the gateway the same way an API client does, so a rule for the app client never matches here. A clients condition is advice about what to offer, never a barrier: the caller says which kind it is, and a caller holding a credential can present either, so a rule must not rely on clients alone to refuse a method.
  • POST /v1/auth/login decides the method it was given before anything else: a method the policy does not offer from here is answered 403, no sign-in provider is asked and no try is counted against the address or the name. Only the providers the offer lists are asked, in its order. A valid factor is decided again with the person it named. A complete sign-in is issued; one the policy offers more steps to waits for them (202, a second step); anything else is answered as a wrong password is. A login refused by a check of the request itself is journaled, one line naming the check (the origin is missing or is not the public origin, the forwarded protocol is not https, the proxy secret does not match, the proxy identity header is unusable, the directory has no such person), and never the secret or any header's value; the caller is told only request is not authorized or authentication is required.
  • A sign-in keeps the steps it passed. POST /v1/auth/resume and POST /v1/auth/renew decide again, with the person as the directory has them now, the policy now in force and the address of this request, and a sign-in the policy no longer completes ends: 401. A token a Station issued for a person is marked as that, is not decided here and gets no page cookie from a renewal. A sign-in record that holds no steps and is not a Station's is not complete: after an upgrade each existing sign-in signs in once more.
  • A page's viewer, named from the request by the page authenticator, is decided as the method certificate (a certificate the gateway's own TLS proved) or proxy, for the service pages. A viewer the policy refuses may still hold a page cookie, which is decided for pages the same way by the steps its sign-in passed, so a rule for services = ["pages"] holds for cookies minted by a login, a renewal or a page hand-off too.
  • The built-in proxy identity has no provider ID, so a providers condition never matches its step; list providers only on rules for the methods a named provider answers. A policy listing a provider no sign-in provider is configured under is refused.

Bearer API keys are outside the policy. A key is scoped and revocable, is never a page sign-in, and is checked at the provider at every use. A policy never offers key, and none refuses one.

A policy is edited in the unex record, or through a route:

Route Needs
GET /v1/user/access/sign-in access.read at config:access
PUT, DELETE /v1/user/access/sign-in access.manage at config:access, the revision read, in If-Match

PUT takes { "provider"?, "config"? }. A policy that does not build is refused (400) before it is stored, and one that builds is stored in the unex record and put in force on this gateway at once; other gateways on the same database take it at their next poll. Every change, and every refusal, is audited (access.sign_in.update, .remove, .refused).

A policy that offers no sign-in is accepted. An empty rule list offers nothing to anyone: the gateway starts, says so plainly (no sign-in is offered; API keys still work), and everyone who is not already signed in is refused. That is stricter, not weaker, so it is not reported as a weakening. The way back is a key: ai6ctl access sign-in with a key whose person holds access.manage at config:access reads and changes the policy, since keys are outside it (--revision sends the one show printed, so a change since is refused). With no key provider configured nothing is left but an edit to the database's unex record, and the start notice and the route say so.

A policy the gateway cannot build (its provider library missing, a bad configuration, a listed provider that is not configured), whether at start or when the stored record changes, fails closed: at start the gateway refuses to run, and when the record changes under a running gateway it offers nothing, keys still work, the reason is logged and GET /v1/user/access/sign-in shows it as invalid; the older policy is never kept. Every gateway reads the stored record again under the lock a route's change holds, so a poll cannot put an older policy over a newer one. A route change is audited before it is stored.

Which ways in, from where

A deployment says in one policy which ways in it allows, from which networks, and where a second step is asked. This one lets people in from the office with a password or the identity the reverse proxy asserts, asks administrators for a one-time code after the password, and from anywhere else accepts the proxy's identity alone:

# unex.toml. `proxy` is what the gateway calls a certificate its reverse proxy has checked.
authenticators = [
  { provider = "coqui_access_system" },
  { provider = "coqui_access_totp", config = { issuer = "Example" } },
]

[[sign_in_policy.config.rule]]
networks = ["10.0.0.0/8"]
subjects = ["group:admins"]
allow = [["password", "totp"], ["password", "recovery_code"], ["proxy"]]

[[sign_in_policy.config.rule]]
networks = ["10.0.0.0/8"]
allow = [["password"], ["proxy"]]

[[sign_in_policy.config.rule]]
allow = [["proxy"]]

# A signed-in person may set up or replace their own code app.
[[sign_in_policy.config.rule]]
purposes = ["enrol"]
allow = [["password"], ["proxy"]]

# A sign-in waiting for a code the person has none of yet may set one up, from the office only.
[[sign_in_policy.config.rule]]
purposes = ["enrol_first"]
networks = ["10.0.0.0/8"]
allow = [["password"]]

To grow it, add a rule above the others: a subjects condition narrows it to a group, networks and clients to where it is made, providers to who may be asked, and each chain in allow lists the methods that must all succeed for one person. Rules are walked in order and the strictest goes last, where an address that is not known falls. A rule for enrol or enrol_first is written out, since purposes defaults to sign_in and resume; with none, nobody sets up a factor for themselves.

A second step

coqui_access_totp is listed under authenticators like any provider, and is never asked for a first factor: it checks a one-time code (totp) or a recovery code (recovery_code) for a person an earlier step named. It is built into the gateway, not loaded as a library, and keeps its accounts and enrolments in the Registry, so every gateway and Station sharing the database sees the same factors, spent codes and used recovery codes. Its configuration is every key the provider takes except where it keeps its records: issuer, algorithm, digits, period, skew, recovery_codes, enrol_seconds, max_records, lockout_after, lockout_seconds and lockout_longest_seconds. A code needs the secret, so it is kept, but sealed: AES-256-GCM under a key derived from [unex] factor_key in ai6.cfg (a secret reference, as proxy_secret is), with a fresh nonce per write and the account and kind of factor as associated data. Every gateway sharing the Registry names the same key. A key shorter than [unex] factor_key_min_bytes (default 32, a lower floor is reported at start as a weakening) is not used, so with that or no factor_key nobody can set up a factor (409, naming the key) and nothing can be checked. A record that the key does not open (sealed under another key, or damaged) is logged and stands as a disabled account: it fails its own person's sign-in, never skips the step and is never written back, and everybody else signs in as before. The provider reads the whole table at each check, so that is a cost of the table's size, not of one person's record. Changing the key invalidates every enrolled factor: there is no rotation, so reset them and enrol again. Recovery codes are kept as digests.

When the policy offers a second step after the first, POST /v1/auth/login answers 202:

{ "pending": "…", "methods": ["totp", "recovery_code"], "expires_in": 300 }

The sign-in waits in the Registry, kept by a digest of pending. pending is a bearer secret: whoever holds it holds the sign-in's place, so it is long and random, lasts pending_seconds, and only the kind of client that began the sign-in (a browser, or not) continues it; it is no binding to one machine. The next step is POST /v1/auth/login with { "pending", "method", "secret" } (totp, recovery_code, or proxy with the proxy's headers); it answers 201 with the token, 202 when a further step is offered, 403 when the method is not offered after the steps already passed, and 401 for a wrong code, the wrong person, or a sign-in that has ended. GET /v1/auth/methods with the header X-AI6-Pending says what is offered next ({"step": "next", "methods": [...]}). A sign-in completed this way records every step it passed, and is decided again by all of them when it renews or resumes. Only a browser continues what a browser began.

Every try at a next step is counted three ways: against the address and the account in the login limits (429 past them), against the pending sign-in's own cap, and by the provider's delay after wrong codes. The login limits are kept in each gateway's memory, so the per-person count is per process: a person's wrong codes are bounded cluster-wide by the pending sign-in's try cap (pending_tries, in the Registry, so every gateway shares it) and by the provider's lockout (also in the Registry), not by the per-person count, which only tightens each gateway. A request that names a pending sign-in is counted against its address before the Registry is read, whether or not the sign-in exists, and a read of a pending sign-in writes nothing. The [login] table of the unex record holds pending_seconds (how long a sign-in waits, default 300), pending_tries (default 5) and enrol_fresh_seconds (below); past the cap the sign-in ends and the person starts again. A sign-in is taken by one request, so a code is never spent twice.

Setting up a factor

Route Needs
GET /v1/user/factors a sign-in; says whether a factor is set up and whether the policy lets this sign-in set one up
POST /v1/user/factors/totp a sign-in the policy decides for enrol; answers { "uri", "recovery_codes" } once. A person who already has a factor replaces it only with { "code" } from it, or from a sign-in made within [login] enrol_fresh_seconds (default 300)
POST /v1/user/factors/totp/confirm the same, and { "code" } from the app; until then the old factor, if any, stands. Replacing a factor ends the person's other sign-ins
POST /v1/auth/enrol, POST /v1/auth/enrol/confirm a waiting sign-in (pending) the policy decides for enrol_first, by a rule that names it
DELETE /v1/user/access/factors/{person} account.manage at config:accounts; the person enrols again, and every sign-in they have ends

The provisioning link (shown as a QR code) and the recovery codes are shown once and kept nowhere as themselves. Beginning, confirming and resetting are audited (account.factor.enrol, account.factor.confirm, account.factor.reset, the person's ID as the target) before they are made, and no code, secret or link is in any audit record or log. The code that confirms a factor is spent, so a sign-in that waits continues with the next one the app shows. Letting a sign-in set up its own second step (enrol_first) means whoever holds its first factor can set up a factor for a person who has none; it is refused (403) for a person who has a factor or an enrolment waiting, so it never replaces one. Write that rule only for the networks that deserve it. Ending the sign-ins is audited first as account.factor.revoke. Beginning, confirming and the first-step enrolment are counted per person and per address in the login limits (429), and a code that cannot be one is refused before it is counted or recorded.

ai6ctl login --name NAME signs in and prints the token, asking for the password (UNEX_PASSWORD, --password-file or the first line of standard input) and, when the gateway answers 202, for a code (UNEX_CODE or the next line; --recovery presents a recovery code). ai6ctl factors status|enrol|confirm|reset PERSON sets up and resets factors; confirm asks for the code on standard input, which keeps it out of the shell history and the process list (it also takes it as an argument). Outer Office asks for the code after the password and has a Second factor section beside Keys that shows the QR code and the recovery codes once; it copies the recovery codes only when the button is pressed.

Signing in from a browser

Outer Office on the web signs in at its own origin. GET /v1/auth/methods, which needs no token, says what POST /v1/auth/login accepts for this request, as the sign-in policy offers it: password (a name and a secret) or proxy (an identity the reverse proxy asserts). The sign-in page shows the form, the proxy's button or both; when the gateway does not answer it shows the form. A wrong password and an unknown account read the same, a 429 counts its Retry-After down and holds Continue until then, and a 403 asks an administrator to check public_origin and the proxy. The token stays in the tab's memory, and signing out revokes it; a reload or a new tab gets a new one from the run cookie below.

Staying signed in

A sign-in lasts while it is used. A token lasts [gateway] access_token_ttl (an hour) or [gateway] session_idle (thirty minutes), whichever is shorter, and an open app renews it while its person works: POST /v1/auth/renew with the token moves its expiry and the sign-in's idle deadline on, its value stays the same, and so the chat, her tools and a proposal waiting for Confirm carry on. The answer's idle_ends_at says when the sign-in goes idle without another renewal. The app renews [refresh] renew_before (ten minutes) ahead of that, on its own timer, but only when the person has used the page since the last renewal (keys, pointer, scroll). With no input it does not renew, and renew_before ahead of the idle deadline it asks Stay signed in? with a countdown: Stay signed in renews, and when the countdown ends the app signs out and keeps the route for after. A renewal after the idle deadline is a 401, so a closed laptop does not stay signed in. It schedules by expires_in, the seconds the gateway says are left, so a wrong clock on the person's machine does not change when it asks.

[gateway] session_max is unset by default: there is no fixed cut while the person keeps working. A deployment may set one, in seconds after signing in, and then renewing stops there, with ends_at in the answer saying when, and renew_before ahead of that the app says so once. session_idle and session_max are choices to weigh. A token copied out of memory stays usable until the idle limit passes, renewing does not ask for the password again, and a directory that does not report a disabled account leaves a sign-in working while it is used; a person removed from the directory cannot renew. Lower session_idle, set session_max, or set it to 0 to turn renewal off; an idle limit longer than the default, or "none", is reported as a weakening at start.

A sign-in from a browser also gets a cookie, so a reload does not ask for the password: ai6_session, HttpOnly; Secure; SameSite=Strict; Path=/v1/auth, ending session_idle after the last renewal (and session_max after signing in, when set). Script on the page cannot read it, and the app keeps no token in browser storage. The gateway stores only its digest. When the app starts on the web with no token it calls POST /v1/auth/resume, which answers as a login does, with a new token; no cookie or a bad one answers 401 and the sign-in page shows with no message. A resume goes on from now, within the idle limit and session_max: a cookie not renewed for the idle limit is refused, and reloading never lengthens a sign-in past session_max. The person must still be in the directory, and a front proxy naming someone else on that request ends it.

What this gives up. Someone with the browser open on that machine stays signed in, with the person's own access, until the sign-in goes idle (or session_max runs out) or they sign out, and no password is asked for again. Closing the browser does not end it. On a shared machine, sign out, or turn the cookie off.

[gateway] session_cookie = false turns it off: a sign-in lives in the tab's memory and a reload signs in again, and a cookie handed out before the change is refused. session_max = 0 means no cookie either, as there is no renewal to come back to. A login with "session_cookie": false in its body gets none. Only a request carrying Origin gets one, which is what tells a browser from the desktop app, ai6ctl and other API clients; they are unchanged.

Signing out revokes the sign-in, not only the token presented: the cookie, and every token a reload or another tab got from it, stop at once, on every gateway sharing the Registry, and the browser is told to drop the cookie. Revoking any of those tokens through DELETE /v1/station/access-tokens/{token_id} does the same. Other sign-ins of the same person carry on. There is no way yet to end all of a person's sign-ins at once.

The cookie is sent only to /v1/auth/, and only resume and logout read it; it is not a bearer token, and no route takes its value as one. resume always wants the public origin (403 otherwise), so another site's page cannot use it. Refused cookies are counted by address like login tries, in a count of their own that costs nobody a password try, and past login_tries_per_address the answer is 429. Because Secure needs HTTPS, the browser must reach the app over the HTTPS origin public_origin names, as it must to sign in at all.

Signing in again finds the conversation that was open: the app keeps its ID per person on the device and asks for it in its hello. The gateway checks it is the person's, and opens a new one when it is gone. A proposal from the earlier sign-in stays unconfirmable, as only the sign-in it was made in may confirm it; the chat shows it as it stands.

The gateway serves no web files. A reverse proxy serves the build and passes the API on one HTTPS origin, which [unex] public_origin in ai6.cfg must name exactly, with its port unless that is 443:

Path Where it goes
/v1/ The gateway: every method, every path under it
/health The gateway (for checks; the app does not call it)
/pages/ The gateway, unless [unex.pages] origin gives her pages their own origin
Anything else The files of build/web, with no fallback to index.html: the app's routes are in the fragment of its URL, so / is the only page

The build has no base path baked in (oo_base.js takes it from where the page was loaded), so the same files serve at / or under any other path; a path with no trailing slash must be redirected to one by the proxy.

The proxy must not add a Content-Security-Policy of its own to /pages/: a browser enforces every policy it receives, so the app's would block a page's scripts, and each page has its own sandbox policy from the gateway. In nginx, an add_header in the location stops the server's being inherited. It must pass Cookie and Set-Cookie under /pages/ and /v1/auth/ as they are: a page opened by itself names its viewer by the page cookie a sign-in sets (ai6_pages, for /pages/), unless the page authenticator below names them.

Pages by themselves

A page's address, {pages base}/p/{id}/, opens by itself (a bookmark, a reload, a new tab), and every request under it names its viewer, never under /v1. In a browser that signed in to Outer Office the page cookie does that. To name viewers with what the connection already carries, give the unex record a page authenticator: page_authenticator, a request-taking Authenticator, and page_authenticator_config. It sees the request's headers (but not its cookies), its TCP peer and the client certificates the browser proved on the gateway's own TLS; Valid names the person through the directory, Unknown falls through to the page cookie, and anything else refuses. It is consulted for pages alone: the API answers 401 to a request that carries only a certificate or a proxy's header.

Behind a front door that verifies client certificates or signs people in, coqui_access_proxy reads what it forwards, trusted only from its own addresses:

# unex.toml, the unex record of a configuration directory
page_authenticator = "coqui_access_proxy"
page_authenticator_config = { trusted = ["127.0.0.1"], user_header = "X-Remote-User", certificate_header = "X-Client-Cert", certificate_encoding = "pem-url", account = [{ field = "subject.cn", by = "name" }] }

The proxy sets the header itself on every request (nginx: proxy_set_header X-Client-Cert $ssl_client_escaped_cert;), so a browser's own copy never reaches the gateway.

With no front door, the gateway serves TLS itself when ai6.cfg names its certificate ([unex.tls] certificate and key, PEM files), may then listen on any address, and asks every browser for a client certificate it does not require; coqui_access_mtls decides what one is worth:

# unex.toml, the unex record of a configuration directory
page_authenticator = "coqui_access_mtls"
page_authenticator_config = { trust = "ca", ca_file = "people-ca.pem", account = [{ field = "san.email", by = "email" }] }

Neither provider has a default account pick: with none, a certificate is answered by its claims (by = "claims") for a matcher to tie to a directory account, so name the pick as above to keep a certificate naming its account directly.

### Certificate pins

The gateway ties a certificate that answers by its claims to an account through the pins the
database holds, so every gateway and Station sharing the database reads the same ones (and sees a
change at its next sign-in; nothing is cached). An account holds:

- **Pins**: `sha256:<64 hex>` (the SHA-256 of a whole certificate) or `spki-sha256:<64 hex>` (of its
  public key, which a renewed certificate on the same key keeps). The certificate's UPN, email
  address or common name only nominates an account; the account must also hold a pin of this
  certificate, so a name a certificate carries is never enough alone.
- **Explicit map entries**: a certificate field and a value (`san.email` and `alice@example.org`,
  compared without regard to case) that name the account without a pin. Two accounts naming one
  certificate refuse it.

An account holds at most `[login] max_pins` pins (default 4) and as many entries; there is no
floor, so `0` allows none. A change that would pass it is refused whole. A chief's account is
changed only by a chief.

| Route | Needs |
| --- | --- |
| `GET /v1/user/accounts/{name}/pins` | `account.manage` at `config:accounts`; `{ "pins", "matches", "max_pins" }` |
| `POST /v1/user/accounts/{name}/pins` | the same; `{ "add", "remove", "match_add", "match_remove" }`, removals first, each list optional |

Each pin and entry added or removed is audited first (`account.pin.add`, `account.pin.remove`,
`account.pin.map.add`, `account.pin.map.remove`; the account and the pin or entry as the target; a
refusal as `account.refused`). `ai6ctl accounts pins NAME` lists them, and `--add`, `--remove`,
`--map-add field=value` and `--map-remove field=value` change them. Outer Office shows them from
the Accounts tab (the certificate button on an account's row), on the web as on the desktop.

A browser holding certificates offers them when it connects, prompting where it cannot choose.
A page on an origin of its own (`[unex.pages] origin`) has no sign-in to set the cookie there,
so the page authenticator or an app's [hand-off](assistant.md#pages-she-publishes) names its
viewers. A front door's access log sees a hand-off's token in the query: it works once, for
seconds, and is spent by the time the log is read.

### Behind a reverse proxy

Five paths under `/v1/` use WebSocket upgrades. They are `/v1/socket/{run_id}`
(a Run's terminal, subprotocol `ai6.guatiao`), `/v1/socket/attach` (a person attached to a charge's
or a Mission's Run), `/v1/user/moneypenny` (her chat),
`/v1/socket/browser/link` (the browser's Noise link), and `/v1/assistant/agent-link` (the link a
person's [own agent](assistant.md#your-own-agent) dials). The first four send no ping, so the proxy's idle
timeout closes a quiet one; give them a long one, as one location for `/v1/socket/` and one for
`/v1/user/moneypenny`. The agent link carries its own heartbeat (`[assistant.own_agent] idle_ping`,
30 seconds), so its proxy timeout need only be longer than that. It is proved in-band by a key, not
by a bearer or a cookie, so it holds through a proxy that ends TLS. For
every request under `/v1/` the proxy must:

- set `X-Forwarded-Proto: https`, replacing what the client sent, and pass `Origin` unchanged:
  `POST /v1/auth/login`, `POST /v1/auth/renew`, `POST /v1/auth/resume`, `POST /v1/attach`,
  `POST /v1/auth/link-keys` (a cookie sign-in must send its `ai6_session` cookie too) and
  `/v1/socket/` answer `403` otherwise, and an app whose renewals are refused that way is signed out
  when its token ends;
- pass `Cookie` and `Set-Cookie` as they are, which proxies do unless told otherwise;
- set the header `client_address_header` names to the client's address, as its own line added
  after any the client sent: the gateway reads the last line of that header and, in it, the
  rightmost comma-separated entry, so a client's own earlier lines are ignored. Without it all
  clients share one login count, and the sign-in policy sees no address at all: a request whose
  header is missing or is not an address has none, never its peer's, so a rule on `networks` does
  not match it. An IPv4-mapped IPv6 address (`::ffff:10.1.2.3`) is the IPv4 address;
- speak HTTP/1.1 to the gateway, not buffer answers (`/v1/moneypenny/mcp` streams), and accept a
  body as large as the `unex` record's `frame_bytes` (256 KiB by default).

The app fetches only from its own origin, so its page can carry this policy: `default-src 'self';
script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:;
connect-src 'self'; frame-ancestors 'none'; base-uri 'self'`. The engine compiles WebAssembly and
sets inline styles, and a public `ai6.cfg`'s `[oo.assets] cdn` other than `none` needs those hosts added. Each `[oo.agents] origins` entry (an agent the web page may dial by hand) needs the same `wss:` origin in `connect-src`; with none listed the page dials none. Run
`dart run tool/build_guatiao_wasm.dart` before the build, or Run terminals say the protocol
could not be initialized. Serve `.wasm` as `application/wasm`.

#### nginx

One `server` for the app's origin, with the gateway on `127.0.0.1:7082` and the build in
`/opt/ai6/web`. The gateway's `client_address_header` is `X-Forwarded-For` here, which the proxy
replaces rather than appends to, so a client cannot choose its own login count.

```nginx
server {
    listen 443 ssl;
    server_name ai6.example.org;
    ssl_certificate     /etc/ssl/ai6.example.org.crt;
    ssl_certificate_key /etc/ssl/ai6.example.org.key;

    root /opt/ai6/web;
    index index.html;
    client_max_body_size 256k;           # the unex record's frame_bytes
    types { application/wasm wasm; }

    add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'" always;

    # The WebSockets for browser links, plain Run and chat sockets, and a person's own agent.
    location ~ ^/v1/(socket/|user/moneypenny$|assistant/agent-link$) {
        proxy_pass http://127.0.0.1:7082;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_read_timeout 1d;
        proxy_send_timeout 1d;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    # Everything else of the API; /v1/moneypenny/mcp streams and a Station's job poll is held open.
    location /v1/ {
        proxy_pass http://127.0.0.1:7082;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_read_timeout 1h;
        proxy_set_header Host $host;
        proxy_set_header Connection "";
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    # Its own add_header keeps the server's policy off pages, which carry their own.
    location /pages/ {
        proxy_pass http://127.0.0.1:7082;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_read_timeout 5m;
        proxy_set_header Host $host;
        proxy_set_header Connection "";
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $remote_addr;
        add_header X-Robots-Tag noindex always;
    }

    location = /health {
        proxy_pass http://127.0.0.1:7082;
    }

    location / {
        expires -1;
        try_files $uri $uri/ =404;
    }
}

A WebSocket path left to the plain /v1/ location loses its Upgrade header there, and the gateway answers the handshake 400; the app shows the connection as lost.

Caddy

Caddy passes WebSocket upgrades and streams without being told, and sets X-Forwarded-Proto and X-Forwarded-For itself; client_address_header is X-Forwarded-For.

ai6.example.org {
    request_body {
        max_size 256KB
    }
    @api path /v1/* /health
    handle @api {
        reverse_proxy 127.0.0.1:7082 {
            flush_interval -1
            stream_timeout 24h
        }
    }
    handle /pages/* {
        reverse_proxy 127.0.0.1:7082 {
            flush_interval -1
        }
        header X-Robots-Tag noindex
    }
    handle {
        root * /opt/ai6/web
        header Content-Security-Policy "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'"
        file_server
    }
}

Checking it

A WebSocket handshake through the proxy answers 101 Switching Protocols; 400 means the upgrade was dropped on the way:

curl -s -o /dev/null -w '%{http_code}\n' --max-time 5 \
  -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' \
  -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' https://ai6.example.org/v1/socket/attach

curl then waits on the open socket until --max-time; the code it prints is the answer.

Roles, the chief and who may change them

The policy has four built-in role names and two places to write more.

Role What it holds Written
chief every action, including any added later; not stored and not editable only through the chief list (chief = [...] in the access record, [unex.access] chief in ai6.cfg)
controller everything an operator does, plus roster.manage, config.manage, agent.configure, station.configure, station.enroll, pool.manage, approval.class, mission.review, mission.verify, mission.delete, run.delete, access.manage, account.manage, audit.read, access.read and run.context seeded; ordinary data you may edit or delete
operator the read actions (mission.read, run.read, agent.read, roster.read, config.read, station.read, pool.read, cable.read) and mission.create, mission.control, run.input, cable.send, approval.decide, issue.link, issue.comment, issue.update, issue.create and assistant.own_agent seeded
auditor the read actions, audit.read, access.read, run.context and mission.verify, and assistant.own_agent seeded

The seeded controller role includes station.enroll on new installations. In an existing access policy, grant station.enroll to the roles and Station scopes responsible for enrollment.

The seeded roles hold assistant.own_agent on new installations too, which lets a person link their own agent. An existing access policy is never rewritten, so a deployment that wants it grants it to the roles that should have it, at config:assistant.

The first start of Universal Exports with user access and no access record writes the last three (audited access.seeded); a record that exists, even without roles, is never seeded again, and a read-only configuration directory keeps them in memory. assistant.memory.admin is in none of them: only the chief holds it until a chief adds it to a role.

The chief is the head of SIS (C): the owner. chief is never a stored role and no stored rule can bind or shadow it; its rules are evaluated before every other. [unex.access] chief in ai6.cfg names subjects that are always chief, so a lost policy cannot lock everyone out; they cannot be removed through the API. A change that would leave no chief is refused, and only a chief changes the chief list or an account that is a chief.

Tiers

A request is allowed when any tier allows it; within a tier the first matching rule decides.

Tier Who writes it What it can grant What it can never do
Chief ai6.cfg, the chief list every action, anywhere be removed through the API, or shadowed
Global (access) whoever holds access.manage at config:access any action at any scope; a role bound at operation:<id> grants only its Operation actions there grant what the writer does not hold
Compartment (compartment) whoever holds compartment.manage on it, with compartment.cover on what it covers mission.status, mission.read, product.read, cable.send, cable.read on what it covers; Compartments grant anything else, or count towards what an editor may hand out
Operation (operation_access) whoever holds access.manage at that Operation Operation roles within the global delegable cap, bound at the Operation or one under it narrow or shadow a global grant, bind at *, station: or config:, or reuse a built-in role name

An Operation policy therefore only adds. Its administrator is the built-in controller bound at operation:X in the global policy ("Controller for X", as SIS has Controllers by region), not a separate role.

Delegation never escalates

An editor may add an action to a role, or bind a role at a scope, only if they hold that action there through the access tiers. A rule that reaches down the tree needs the action held at every Operation it reaches. Removing an action or a rule needs only access.manage. The global delegable cap lists the Operation actions an Operation's own roles may hold; by default every one but access.manage, approval.class, compartment.cover, mission.delete and run.delete, so a delegate cannot appoint deputies, give standing green ink, open the Operation to a compartment or delete its Missions. A cap that adds any of those is shown as a weakening. A compartment grant does not count towards what an editor may hand out. What a changed tree or cap leaves without effect is skipped and listed as orphaned; the rest of the record stays in force.

Changing them: routes

Every write names the revision it read (If-Match; 428 without, 409 when stale or the provider is read-only), is checked by the guards (400 with the reason) and audited (access.update, access.remove, access.refused, account.update, account.secret, account.refused; never a secret). With an authorizer plugin the chief tier still applies and the writes answer 409.

Route Needs
GET /v1/user/access access.read at config:access
PUT, DELETE /v1/user/access/roles/{role}, PUT /v1/user/access/{rules,delegable} access.manage at config:access
PUT /v1/user/access/chief the same, and a chief
GET, PUT, DELETE /v1/user/access/sign-in access.read / access.manage at config:access (the sign-in policy)
DELETE /v1/user/access/factors/{person} account.manage at config:accounts (setting up a factor)
GET /v1/user/access/check?subject=&action=&resource= access.read at the resource
GET /v1/user/operations/{op}/access, PUT/DELETE .../access/roles/{role}, PUT .../access/rules access.read / access.manage at the Operation
GET /v1/user/accounts, PUT /v1/user/accounts/{name}, POST /v1/user/accounts/{name}/secret account.manage at config:accounts; a groups change also access.manage at config:access
GET, POST /v1/user/accounts/{name}/pins account.manage at config:accounts (certificate pins)

Accounts are made, disabled and reset, never deleted through the API; a new password is shown once and is in no audit record or log. ai6ctl access and ai6ctl accounts, the Access page of Outer Office and Moneypenny (access, propose_access_change, propose_account_change, always confirmed by the person) reach the same routes with the person's own rights.

Login limits

Universal Exports counts every password or key try against the client address and against the account name before an Authenticator is asked. A try past either count is refused with 429 Too Many Requests and a Retry-After, even if its secret is right. The defaults are 5 a minute per address and 10 in ten minutes per name; a method the sign-in policy does not offer from here is refused before it is counted, so it costs its address and its name nothing; the unex record's login_tries_per_address, login_tries_per_name and client_address_header change them. The gateway listens on loopback behind a reverse proxy, so name the header the proxy fills with the client address (x-forwarded-for or x-real-ip) or all clients share one count.