chadtmiller.com/group-host
atmosphere group host
0
0
# Signing in
An app writes a group's records and acts in its spaces by signing in as
the group, as it would for any account. But a group has no password and
no single owner, so there's nothing to type into a sign-in form. Whoever
signs an app in as a group is one of its members, signed in as
themselves, approving the app with the roles they hold there. So what
the app gets must never exceed what that member may do, when they
approve it and at every write after, since their roles can change while
the app is still signed in.
## Who signs in to what
| Who | Signs in to | How | Holds |
|---|---|---|---|
| A person | the console | OAuth at their own PDS | a signed cookie |
| An app | a group | OAuth at this host, or an app password | a grant |
| The console | a group | `getGroupAuth` | a 15-minute token |
| An MCP client | a member, in one group | OAuth at `/mcp` | an MCP grant |
A grant is what an approval leaves behind: the group, the member who
approved, the app and the scope it may use. Every token an app holds as
a group belongs to one. The grant records the member and never one of
their roles, so the host asks the member's roles again at every use.
The host's `org.atgrp.*` methods take a person as the caller, named by
the console's cookie or by service auth (a JWT a PDS signs for an
account, [atproto](https://atproto.com/specs/xrpc)). An MCP client acts
as the member who connected it, never as the group ([MCP](mcp.md)).
## An app signing in as a group
The group's DID document names this host as its PDS, and the host names
itself as the only authorization server. So an app runs
[atproto OAuth](https://atproto.com/specs/oauth) against the host as it
would against any account's server. Where a PDS would ask for a
password, the host sends the browser to the console. The member signs
in there as themselves, picks the group and approves, and the console
tells the host with `approveAuthorization`. Who approved is never a
guess. It's whoever signed the service auth (their own PDS vouching for
them) or holds the console's cookie, and the grant is theirs.
The console offers the group the app names in `login_hint`, if it's
here and switched on, or else every switched-on group where the member
holds a role. For each, the member sees what the app would get and what
the host would withhold. The app's logo comes through the host, so a
reader's browser never asks the app's server for anything.
The approval page stands alone, one card without the console's header
and footer, so nothing on it leads away from answering. The card's top
names the host as its operator does (its logo and name) and who is
signed in, and the scopes as asked sit behind "Technical details" at
its foot, beside the links to the operator's pages. Behind the card is
the operator's background, `BACKGROUND_LIGHT_URL` or
`BACKGROUND_DARK_URL` by the reader's colour scheme
([configuration](../reference/config.md)).
The token response names the group in `sub`, and the host adds
`member`, the DID of the member who approved. The host fetches client
metadata only from a public address, so a client id can't point it into
its own network. A grant lapses after 14 days unrefreshed for a public
client and 90 days for a confidential one, since nothing but the DPoP
key ties a public client to its grant. The
[API reference](../reference/api.md#signing-apps-in-as-a-group) lists
the routes, methods and lifetimes.
### App passwords
For apps that sign in only with a handle and password, a member whose
roles hold `repo:*` makes an app password, which stays theirs. It holds
80 random bits, so the host keeps a fast SHA-256 of it. Its sessions are
grants like any other, with Bearer tokens bound to no key and a fixed
scope of `atproto transition:generic` (the repo, blobs and other
services, never a space). A privileged one adds `transition:chat.bsky`.
The host can't narrow a scope that broad, so it follows the maker
bluntly. The next time it checks the maker (at each sign-in, use,
refresh or listing) and finds they no longer hold `repo:*`, it forgets
every app password they made in that group, and their sessions, for good.
### Apps that start groups
An app that starts groups calls `provisionGroup` to make a group and
sign in to it at once, so its user isn't sent through approval straight
after. The caller becomes the founder, and the app proves itself in the
same request with a DPoP proof (and a client assertion if it's
confidential). Only apps in `PROVISIONING_CLIENTS` may call it. The
host narrows the scope to the founder's roles as an approval would, and
the session is an ordinary grant.
## Narrowing at approval
The first check runs at approval. The host reads every scope by
atproto's [permission grammar](https://atproto.com/specs/permission),
whether it's an app's scope, a role's permission or a space's policy,
and a scope the grammar doesn't take is no scope. Then it keeps each
part of the request the member's roles grant at that moment:
- `atproto` is always kept.
- `repo:C` is kept if the roles hold `repo:C` or `repo:*`, and the
`transition:` scopes only if they hold `repo:*`.
- `space:T?...` is kept if some group space of type T lets the roles
write what's asked. A read-only one is kept even where there's no such
space yet, since reading is checked again for each credential.
- `space:*?...` becomes one scope per space the roles read, with the
collections they may write there.
- `manage=` is kept if the roles or the space's policy let the member
manage spaces of that type. Only the `space.create` role grants
`create`, since a policy grants just `update` and `delete`. `blob:` is
kept only if something kept writes.
- `space:org.atgrp.inbox?...` for someone else's inbox is kept when the
roles hold `invite` and the scope asks to write invites alone.
Everything else is withheld, such as `identity:`, `account:` and any
other space scope for another authority. The `rpc:` scopes come below.
The host's four
[permission sets](https://atproto.com/guides/permission-sets) for a
group session are upper bounds. `authManageAdmin` holds
`authManageBasic`, `authManageMembers` and `authModerate`, and the host
keeps the parts the roles grant, under a tier's name when they make up a
whole one. So a moderator whose app asks for `authManageAdmin` gets
`authModerate`. Another app's set is read as that app publishes it,
through its `_lexicon` TXT record (asked of `DNS_SERVERS`), its record proved by its publisher's key. Its repo and
`rpc` parts are kept as `repo:` and `rpc:` scopes would be, and its space
permissions give a group session nothing. A set that doesn't resolve is
withheld.
Last, the host expands each set into the scopes it held at approval and
turns `authority=self` into the group's DID. So a set that grows later
reaches an app only when a member approves it again. A refresh keeps
the scope and doesn't ask the roles, since each write and call does.
## Checking each write
The second check runs at every write. A token writes only as its own
group, and its scope must cover the record (`ScopeMissing`
otherwise). Then the member's roles, at that moment, must let them write
it as the group (`Forbidden` otherwise). In a space, its policy decides
([spaces](spaces.md)).
The checks run under the group's write lock, with the commit, and a
group's commits run one at a time. So no change to the member's roles
slips in between the check and the write. An invite is the exception.
Its checks run just before its write to the inbox, outside the lock. A
member whose roles shrink gives every app they signed in less at once.
A member who leaves or is
removed ends every grant they approved, MCP grants included.
A switched-off group refuses writes and uploads. Its apps' tokens still
refresh, and `getSession` answers `active: false` with status
`deactivated`, so an app can carry on once the group is switched on.
`applyWrites` takes at most 200 writes, and writes are rate-limited per
group ([limits](limits.md)).
## Spaces and the host's methods
To read a space, an app buys a delegation token with
`getDelegationToken`, for a scope that reads the space and a member who
reads it now, and the host keeps it as the grant's. When the grant ends
or its member comes to read less, the host revokes what it bought
([spaces](spaces.md#reading-a-space-through-the-host)).
An app calls the host's own methods as the group with `rpc:` scopes. At
approval the host keeps one only for a method its sets list, aimed at
this host, and only if the roles hold that method's action. A bare
`rpc:` scope never reaches an internal method. At each call the roles
must still hold the action.
## Calling other services as the group
An app speaks for the group elsewhere by sending the host an
`atproto-proxy` header naming a service. The host sends the call on with
service auth the group signs, good for a minute and for that method
alone ([atproto](https://atproto.com/specs/xrpc)). `getServiceAuth`
hands an app such a token directly.
The host can't see what another service's method does. So only a member
who may do anything as the group may let an app speak for it there. An
`rpc:` scope for another service is kept at approval only if the roles
hold `repo:*`, and the member must still hold it at each call. Methods
that manage the account itself are never sent on. The
[API reference](../reference/api.md) lists the refusals.
## Signing people in to the console
The console's methods take a person as the caller, so the host needs
only to know who's at the browser. It's an OAuth client of each
person's PDS and asks for `atproto` alone, which proves the account and
grants nothing. It takes the tokens only once the account's own
authorization server, followed again from its DID, is the one that
issued them ([atproto OAuth](https://atproto.com/specs/oauth)). Then it
revokes the session, so it keeps none of a person's tokens.
A sign-in under way is kept in the database by its `state`, so any
process can answer the callback. The browser holds that `state` in a
cookie, and the host honours the callback only there. So a link to
someone else's approval can't sign a person in as them.
A signed-in person holds a cookie with their DID and its expiry, signed
with an HMAC, which lasts 30 days. The host stores no session for it,
only the time of each DID's last sign-out. Any cookie signed before that
names no one, in any browser. On https the cookie takes the `__Host-`
prefix, so a group's address can't set one, and a request whose `Origin`
isn't the console's names no one. Moving an account here asks a wider
scope ([moving](moving.md)).
## The console acting as the group
The console doesn't run OAuth against its own host. To write as a group,
it asks `getGroupAuth` for one space, as the member, with a DPoP proof.
It gets a 15-minute token that's never refreshed, scoped to what the
space's policy lets the member's roles write (in the members space, the
roles' own writes too), and checked at each write like any grant. Asked
for someone's inbox, it gets a token that writes invites there if the
roles hold `invite`. An MCP tool that writes runs the same way.
## Seeing and ending grants
A member whose roles hold `group.configure` sees every grant in force
with `listGroupTokens` and ends any with `revokeGroupToken`. An app ends
its own at `/oauth/revoke`. Beside the grants, `listGroupTokens` returns
the group's activity log, which shows who did what through which app.
OAuth, `getGroupAuth` and MCP tokens are 32 random bytes, and the host
stores only their SHA-256. An app password's session tokens are JWTs
signed with a key derived from the rotation key, found by their hash.
So revoking a grant deletes its row, and the next call with its token
fails, with no token left to run until it lapses. DPoP nonces need
nothing stored. Each is an HMAC of a three-minute time step, and the
host checks one by computing it again (accepting one step either side).
The nonce key, like the console's client and cookie keys, is derived
from the rotation key, which itself signs only PLC operations.