Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions docs/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ In the Docker stacks that is the `.env` of the host that runs the server. Then r

| Key | Default | What it does |
|---|---|---|
| `mode` | `off` | `off` or `local` (`portal` is for the project's own instance, see [Configuration](configuration.md#user-accounts)). Anything else stops startup. The rest of the block is not checked while this is `off`. |
| `mode` | `off` | `off`, `local` or `portal` (see [Portal sign-in](#portal-sign-in)). Anything else stops startup. The rest of the block is not checked while this is `off`. |
| `registration` | `open` | `open` or `closed`. When closed, `POST /auth/register` answers `403 registration_closed` and `features.registration` is `false`. People who already have an account keep signing in. |
| `mail.host` | none | Required. |
| `mail.port` | `587` | 1 to 65535. |
Expand All @@ -57,7 +57,7 @@ In the Docker stacks that is the `.env` of the host that runs the server. Then r
| `mail.starttls` | `true` | When true the send fails if the server does not offer STARTTLS; Beacon never falls back to plain text. Set `false` only for a trusted local relay. |
| `mail.tls_skip_verify` | `false` | `true` accepts a mail server certificate that cannot be verified (self-signed, private CA, wrong name). The connection is still encrypted, but the server is not checked, so use it only for a mail server you run yourself on a network you trust. Applies to account mail and alert mail. Startup logs a warning while it is on. No effect with `starttls: false`. |

`BEACON_SMTP_PASSWORD` is the only account secret that comes from the environment. A mistake in the
`BEACON_SMTP_PASSWORD` is the only secret `local` accounts read from the environment. A mistake in the
block stops startup with an error naming the key. An `smtp` block left under `accounts` stops startup
too, with a message saying it moved to `mail`. Port 465 (implicit TLS) is not supported; use a
submission port that offers STARTTLS.
Expand Down Expand Up @@ -273,6 +273,69 @@ An hourly task (`users_cleanup`) deletes, once they are more than a week past th

A live session or token is never touched by it.

## Portal sign-in

`accounts.mode: portal` is designed to work only with the project's own MeshMapper instance,
which signs its users in through the MeshMapper portal. Users sign in at the portal and Beacon
trusts its answer. The portal is not part of Beacon and its side is not documented here. It is
not supported for other deployments: use `local`.

```yaml
accounts:
mode: portal
portal:
url: https://portal.example.org
client_id: beacon-example
```

```
BEACON_PORTAL_SECRET=...
```

| Setting | What it does |
|---|---|
| `accounts.portal.url` | The portal's base address. Must be an `https` URL with no credentials, query or fragment. |
| `accounts.portal.client_id` | The id the portal knows this server by. Required. |
| `BEACON_PORTAL_SECRET` | This server's client secret at the portal. Environment only, never in the file. Required. |

A missing or malformed value stops startup with an error naming it. `DOMAIN` (or `WEB_DOMAIN`)
is needed as for `local`. The `mail` block is not read, and nothing is mailed.

How a sign-in goes:

1. The web app sends the browser to `GET /api/v1/auth/portal/start?return=<path>`. The server
stores a one-time state and a PKCE verifier for 10 minutes, sets the `beacon_portal` cookie,
and redirects to `<portal.url>/portal.php` with `client_id`, `state`, an S256
`code_challenge` and `redirect_uri`. `return` must be a path on the same site; anything else
becomes `/`.
2. The portal signs the user in and sends the browser back to
`<public address>/api/v1/auth/portal/callback` with `code` and `state`. That is the
redirect address to register at the portal.
3. The server checks `state` against the cookie (each state works once), then posts the code,
the verifier, `client_id` and the secret to `<portal.url>/portal_beacon_api.php?action=token`.
It waits at most 10 seconds and accepts the answer only if it is `200` with a JSON `user`
object of `id`, `username` and `display_name`.
4. `id` is the account key: the first sign-in with a new `id` creates the user, later ones
find it and refresh its username and display name. A username someone else holds gets a
numeric suffix; a blank one becomes `member`.
5. The browser lands on `<public address><return>` with the session cookie set. Any failure,
a cancel at the portal included, lands on `<public address>/?view=signin&error=portal`,
and the server logs `portal sign-in failed` with the reason at `WARN`.

What differs from `local`:

- `/api/v1/info` reports `features.accounts: "portal"` and `features.portalUrl`, and
`features.registration` is always `false`. `accounts.registration` changes nothing.
- A portal user has no password and no email address in Beacon. The sign-up, verify, sign-in
and reset routes, and `POST /me/password` and `POST /me/email`, answer `404 portal_managed`.
- Deleting the account is confirmed with the username instead of the password.
- Email alerts are not available: `alerts.email.enabled: true` stops startup. Push alerts work.
- On a read-only server both portal routes answer `503 read_only`.
- A user disabled in Beacon cannot sign in, whatever the portal says.

Each portal route is limited to 20 requests a minute per client. The routes are in the
[API contract](api-contract.md#user-accounts).

## Disabling accounts again

Set `accounts.mode: off` and restart. The routes answer `404 accounts_disabled` and clients hide
Expand Down
34 changes: 16 additions & 18 deletions docs/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ on `/packets` and `v1:<epoch µs>:<id>` on `/nodes` and `/observers`.
| `/channels` | Can't be combined with a positive `cursor` (`400`). | When `hasMore` |

- `nextCursor` stays on every page with `hasMore` (except a sorted `/nodes` list, which has
none) and keeps its meaning: rows strictly older than that millisecond. Paging by `cursor`
alone gives the same pages as before and still skips rows tied on the boundary millisecond.
none) and means rows strictly older than that millisecond. Paging by `cursor` alone skips
rows tied on the boundary millisecond.
- On `/packets`, `/nodes` and `/observers`, send both: `cursor` set to `nextCursor` and
`pageCursor` set to `nextPageCursor` when the page has both, `cursor` alone otherwise. A server
older than 2.1.0 ignores `pageCursor` and still moves forward by `cursor`. Treat
Expand Down Expand Up @@ -197,11 +197,10 @@ Comma-separated list params (`iatas`, `scopes`, `payloadTypes`, `routeTypes`) ta

`/packets` params: `payloadType` or `payloadTypes` (comma-separated integers), `payloadTypeName` (`advert`, `group_text`, `trace`, ...; used when no number is given), `routeType` or `routeTypes`, the location filters, `scope` or `scopes` (comma-separated), `since`, `until`, `hashPrefix` (4 to 16 hex characters of the packet hash), `cursor`, `pageCursor`, `limit`. Filters OR within themselves and AND across each other. The cursor is epoch ms: global `lastHeardAt` order without an IATA filter, and the time heard at the requested sites when one is set, so a filtered list stays bounded to those IATAs. With `hashPrefix` the order and cursor use global `lastHeardAt` even when an IATA filter is set.

With an IATA or region filter and no `hashPrefix` (a region page), the list is ordered by the time the packet was last heard at the requested sites, newest first. While the server trusts its site read model (see [Operations](operations.md#read-models-packets-by-site)), `pageCursor` applies and those pages are the same as before with three differences:
With an IATA or region filter and no `hashPrefix` (a region page), the list is ordered by the time the packet was last heard at the requested sites, newest first. While the server trusts its site read model (see [Operations](operations.md#read-models-packets-by-site)), `pageCursor` applies to those pages:

- Packets heard at the same site time are ordered by `packetHash`, descending.
- A `pageCursor` page returns the rows in the cursor's millisecond that a millisecond `cursor` skips, as on `/packets` without a region (see [Exact page cursors](#exact-page-cursors)).
- Where many observers heard a site's packets, the previous statement could end a page short, end a walk early or move `nextCursor` past rows it never returned; the new page returns those rows.

While it does not, region pages answer `503` with `Retry-After: 30`; see [Pages that wait for server data](#pages-that-wait-for-server-data).

Expand Down Expand Up @@ -764,13 +763,12 @@ edges spanning more than 180 degrees are rejected.
| `GET /observers/{observerId}/adverts` | Page of adverts the observer heard. Cursor is the observation ID. |

An observer's `brokers` are the brokers it was seen on in the last 30 days, and the `broker` filter
of `/observers` and `/observers/directory` matches only within those 30 days (both from 2.3.1; before,
neither had a time limit). Take the filter's values from `GET /brokers/sources`.
of `/observers` and `/observers/directory` matches only within those 30 days (both from 2.3.1; an older
server applies no time limit). Take the filter's values from `GET /brokers/sources`.

`/observers` pages by each observer's last-seen time, which the summary does not include. Since
2.1.0 `nextCursor` is that time for the last row and is present whenever `hasMore` is true.
Before, it came from the last status message and was missing when the last row had none, so a
walk by `cursor` skipped most observers. Paging by `cursor` alone can still skip observers that
`/observers` pages by each observer's last-seen time, which the summary does not include.
`nextCursor` is that time for the last row and is present whenever `hasMore` is true (a server
before 2.1.0 can leave it out). Paging by `cursor` alone can skip observers that
share a millisecond (presence updates often stamp many at once); `pageCursor` reaches all of them.

The `points` of the telemetry response are ordered by time. `interval=1h` returns the stored snapshots as they
Expand Down Expand Up @@ -934,7 +932,7 @@ To page `/routes`, send the last item's `lastSeen` as `cursor` and its `id` as `

The single `iata` is matched exactly as sent, so lowercase matches nothing. An `iata` that ends in a blank (`YYZ` followed by a space) matches no region and returns `200 []`.

`iatas` is new in 2.1.0: older servers, and 2.1.0 development builds from before it, ignore it and answer with every IATA's routes. A client that asks for a region checks each route's `iata`; when one is outside the list, it pages without `iatas` and filters, as before.
`iatas` is read from 2.1.0. An older server ignores it and answers with every IATA's routes, so a client that asks for a region checks each route's `iata`; when one is outside the list, it pages without `iatas` and filters the rows itself.

`/routes` and `/routes/search` return a plain array of routes:

Expand Down Expand Up @@ -1130,7 +1128,7 @@ Swagger shows. Servers older than this endpoint return `404`. See
| Flag | Meaning |
|---|---|
| `polling` | True when [repeater polling](repeater-polling.md) is enabled on this server. Clients show the reading charts only when it is true. |
| `accounts` | A string: `"off"`, `"local"` or `"portal"`. `"local"` and `"portal"` mean [user accounts](#user-accounts) are on; `"portal"` is sign-in through the MeshMapper portal. |
| `accounts` | A string: `"off"`, `"local"` or `"portal"`. `"local"` and `"portal"` mean [user accounts](#user-accounts) are on; `"portal"` is sign-in through the MeshMapper portal ([Portal sign-in](accounts.md#portal-sign-in)). |
| `registration` | True when new sign-ups are open. Only meaningful when `accounts` is `"local"`; always `false` for `"portal"`. |
| `portalUrl` | The portal's base address. Present only when `accounts` is `"portal"`. |
| `telemetryRequests` | True when [telemetry requests](#telemetry-requests) are on: polling and accounts are on, `BEACON_SECRET_KEY` is set and `polling.requests_per_user` is not 0. |
Expand Down Expand Up @@ -1301,7 +1299,7 @@ Backup details are in [Backup and export](backup-export.md).

### User accounts

Off unless `accounts.mode` is `local` ([User accounts](accounts.md)) or `portal` (the project's own MeshMapper instance only, see [Configuration](configuration.md#user-accounts)). With it off every route below,
Off unless `accounts.mode` is `local` ([User accounts](accounts.md)) or `portal` (the project's own MeshMapper instance only, see [Portal sign-in](accounts.md#portal-sign-in)). With it off every route below,
under `/api/v1/auth` and `/api/v1/me`, answers `404` with code `accounts_disabled`, and no cookie is set.
These are separate from the operator records at `/admin/accounts`.

Expand Down Expand Up @@ -1548,7 +1546,7 @@ Oldest first. `poller` and `latestReadingAt` are `null` when there is none; `lat
newest trusted reading. `statusReasonDays` (integer) is present only with the `offline` code. A
password is never returned, only `hasPassword`. `updatedAt` is when the request last changed: an
edit by the user, or a change of `status` or `statusReasonCode` made by the server (from 2.3.1;
before, a status change that followed an election or a claim left it unchanged).
an older server leaves it unchanged when the status change follows an election or a claim).

`poller.state` is what the poller's own latest live claim says about this repeater, so a user can see
why a poll is not working even while `status` is `active`. `poller.stateAt` is epoch ms when that claim
Expand Down Expand Up @@ -1993,7 +1991,7 @@ corescope-claim/v1|<origin_id>|<poll_url>|<timestamp>|<community>|<accepts_reque

From 2.3.1 Beacon checks it, whatever `polling.foreign_claims` is set to:

- A claim with neither field is unsigned. It is handled as before.
- A claim with neither field is unsigned. It is processed without a signature check.
- A claim with `sig` that does not verify is dropped. So is one with only one of the two fields,
either of them `null`, a `poll_url` that is not a host, a `sig` that is not 128 hex characters, a
missing `request_slots`, `max_slots` or node `misses`, the same node listed twice, a node
Expand Down Expand Up @@ -2033,8 +2031,8 @@ A foreign observer:
- that sends readings and no claim, as the firmware's local mode does, is a local poller from 2.3.3:
its node has `isPoller` `true` and `isLocalPoller` `true` while it has no stored claim of either
kind and a foreign reading from it arrived in the last 24 hours. `isForeignPoller` is `false` for
it. A claim, once one arrives, makes it this server's own or foreign instead. Before 2.3.3 such an
observer has neither flag. A missing `isLocalPoller` is `false`.
it. A claim, once one arrives, makes it this server's own or foreign instead. A server before 2.3.3
sets neither flag for such an observer. A missing `isLocalPoller` is `false`.
- has its readings stored and marked foreign. Each is trusted, and so shown, when Beacon has heard
that observer receive the repeater's zero-hop adverts within `polling.evidence_window`: the same
evidence an election counts. With `polling.authority: approved` the observer must also be
Expand Down Expand Up @@ -2139,7 +2137,7 @@ corescope-reading/v1|<v>|<origin_id>|<timestamp>|<node_id>|<method>|<sampled_at>

From 2.3.1 Beacon checks it:

- A message with no `sig` is unsigned. It is handled as before.
- A message with no `sig` is unsigned. It is processed without a signature check.
- A message with `sig` that does not verify is dropped and logged as a warning. So is one with more
or fewer than one reading, a `sig` that is `null` or not 128 hex characters, a time in another
form, a missing or negative `reply_hops`, a `node_id` that is not 64 hex characters, a
Expand Down
33 changes: 22 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ to open).
| `BEACON_SECRET_KEY` | unset | 32 random bytes in base64. Seals the guest passwords of [telemetry requests](telemetry-requests.md). See [BEACON_SECRET_KEY](#beacon_secret_key). |
| `BEACON_PUSH_SECRET` | unset | The Push secret from registering the server with the push server. Required when `alerts.push.enabled` is true; has no YAML key. See [Alerts](alerts.md#push). |
| `BEACON_SMTP_PASSWORD` | unset | Password for `mail.username`. Read only when `accounts.mode` is `local`; it has no YAML key. See [User accounts](#user-accounts). |
| `BEACON_PORTAL_SECRET` | unset | This server's client secret at the sign-in portal. Required when `accounts.mode` is `portal`, where a missing one stops startup; it has no YAML key. See [User accounts](#user-accounts). |
| `LOG_LEVEL` | `info` | `debug`, `info`, `warn` or `error`. Overrides `log.level`. Anything else stops startup. |
| `LOG_FORMAT` | `text` | `text` or `json`. Overrides `log.format`. Anything else stops startup. |
| `BEACON_CPU_PROFILE_DIR`, `BEACON_CPU_PROFILE_UNTIL` | unset | Enable a bounded CPU capture in production. See [Profiling](profiling.md). |
Expand Down Expand Up @@ -178,11 +179,7 @@ layout sets the sizes.
- **`single`** is the rollback: one API pool (`api_legacy`) on the server's own settings, and
every guard family only observes, whatever `guards.enforce` says.

`database.slow_pool_size` is no longer read. It sized the `api_slow` pool of the 2.1 development
builds, which ran region and message statements that could read whole site histories; those
pages now seek from their window (see
[Deep region and message pages](operations.md#deep-region-and-message-pages)) and run on the
pools above. A config that still sets the key loads as before, and the server logs
`database.slow_pool_size` is not read. A config that sets it still loads, and the server logs
`config: database.slow_pool_size is no longer used and is ignored; remove it` at `WARN` at
startup. Remove the key.

Expand Down Expand Up @@ -424,17 +421,31 @@ except a leftover `smtp` block, which always stops startup (it moved to the top-

| Key | Default | What it does |
|---|---|---|
| `mode` | `off` | `off` or `local`. |
| `registration` | `open` | `open` or `closed`. |
| `mode` | `off` | `off`, `local` or `portal`. |
| `registration` | `open` | `open` or `closed`. Sign-up is always closed in `portal` mode, whatever this says. |
| `portal.url` | none | Required with `portal`. The portal's base address: an `https` URL with no credentials, query or fragment. |
| `portal.client_id` | none | Required with `portal`. The id the portal knows this server by. |

Accounts need the server's public address, for the links in mail and the cookie's `Secure` flag. It
is `https://` followed by `WEB_DOMAIN` from the environment, or `DOMAIN` when `WEB_DOMAIN` is not
set (plain `http` for `localhost` and `127.0.0.1`). The Docker stacks already set `DOMAIN`. With
neither set, `mode: local` stops startup with an error naming `DOMAIN`. The old `accounts.public_url`
key is no longer read; a leftover one is ignored with a warning at startup.
neither set, `mode: local` or `mode: portal` stops startup with an error naming `DOMAIN`. The old
`accounts.public_url` key is no longer read; a leftover one is ignored with a warning at startup.

A third mode, `portal`, exists for the project's own MeshMapper instance. It is not supported for
other deployments.
`portal` is designed to work only with the project's own MeshMapper instance: users sign in at
the MeshMapper portal and Beacon keeps no password or email address. The portal is not part of
Beacon and is not documented here. It is not supported for other deployments: use `local`. The client secret is `BEACON_PORTAL_SECRET` in
the environment, never in the file. `portal` does not read the `mail` block, and
`alerts.email.enabled: true` stops startup with it. See
[Portal sign-in](accounts.md#portal-sign-in).

```yaml
accounts:
mode: portal
portal:
url: https://portal.example.org
client_id: beacon-example
```

`local` sends its mail through the top-level `mail` block, which email alerts share. It is checked only
when `accounts.mode` is `local`.
Expand Down
Loading