Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
076892b
refactor(db)!: replace the conditions migration history with one base…
Medformatik Nov 23, 2026
4faf36d
fix(ci): require drizzle-kit to report no drift in the migrations gate
Medformatik Nov 24, 2026
90b4491
test(db): refuse hidden statements and extra seed rows in the custom …
Medformatik Nov 24, 2026
616b19b
docs: describe flow lineage and the migrations without old migration …
Medformatik Nov 24, 2026
3ecb3f7
fix(db): keep migration history in conditions and migrate only from i…
Medformatik Nov 24, 2026
8dddf97
feat(db): grant the tile and contributions roles exactly what they use
Medformatik Nov 24, 2026
bada9d1
feat(db): grant the consumer roles at every ingest start
Medformatik Nov 24, 2026
d0deebf
fix(security): encrypt OAuth grants and private keys at rest
Medformatik Nov 24, 2026
f547e57
fix(ci): pin the qualification script that now gives images a secrets…
Medformatik Nov 24, 2026
dfebb16
fix(security): refuse a secrets key other than the one the ingest ser…
Medformatik Nov 24, 2026
9f5b3c4
docs: say where the secrets key lives standalone and under OpenMapX
Medformatik Nov 24, 2026
15ba199
test(scripts): type the manifest field description the heavy-feeds ch…
Medformatik Nov 24, 2026
9c6a588
feat(db): drop unused crowd columns and erase a reporter's rows with it
Medformatik Nov 24, 2026
67a6704
feat(storage): delete inactive reporters and expired crowd bookkeepin…
Medformatik Nov 24, 2026
85906b1
docs: state how long crowd reporters and their bookkeeping are kept
Medformatik Nov 24, 2026
ac1075f
docs: say that the first ingest process to start seals the secrets key
Medformatik Nov 24, 2026
2ca20fd
feat(db): strip a deleted reporter's key from what it reported
Medformatik Nov 24, 2026
9cb3774
fix(storage): delete reporters under the crowd lock and keep spent to…
Medformatik Nov 24, 2026
ad0b2d4
test(model-registry): fail when a crowd-reported property starts keep…
Medformatik Nov 24, 2026
ff82b2f
docs: say where a reporter's key remains and how a deletion removes it
Medformatik Nov 24, 2026
b423f4a
perf(db): drop indexes the primary keys serve and index the records s…
Medformatik Nov 24, 2026
c887416
refactor(db): identity ids, a date for the JMA budget day and checks …
Medformatik Nov 24, 2026
4d8471b
refactor(db): name every constraint and index after its table and col…
Medformatik Nov 24, 2026
24745e6
perf(db): store fixed-width columns first in the observation tables
Medformatik Nov 24, 2026
c81d394
test(db): check names, identity, value sets, column order and indexes…
Medformatik Nov 24, 2026
086fc07
perf(storage): read and delete a series' history in its retention class
Medformatik Nov 24, 2026
f32fdb8
docs: list the baseline's schema differences and where a hand delete …
Medformatik Nov 24, 2026
c1195cb
fix(core): serve a series' history by its current retention, not by i…
Medformatik Nov 24, 2026
7d7cb48
fix(storage): delete every reading of a series that is gone, in every…
Medformatik Nov 24, 2026
f3c01ff
refactor(ingest): count binding statuses from a map that must name ev…
Medformatik Nov 24, 2026
b8e18bc
refactor(db): grant the contributions role no sequence, its inserts n…
Medformatik Nov 24, 2026
f861291
docs: say the GeoNet CHECK was renamed, not added, and name the purpo…
Medformatik Nov 24, 2026
43fcceb
fix(openlr): build the routing graph in its own schema
Medformatik Nov 24, 2026
50ea1b2
fix(ingest): order SMN messages deterministically
Medformatik Nov 24, 2026
8df4e26
docs(openlr): describe the identity line id
Medformatik Nov 24, 2026
a45e505
fix(ci): seal the image qualifier's key check without bundled core code
Medformatik Nov 24, 2026
fa96d41
test(core): scan custom migration statements as PostgreSQL reads them
Medformatik Nov 24, 2026
131e062
fix(ingest): open stored issuer and instance keys before sealing the …
Medformatik Nov 24, 2026
b934560
fix(federation): read the secrets key and settings before the schema …
Medformatik Nov 24, 2026
c885ca8
fix(core): name the ingest restart when a role cannot read the history
Medformatik Nov 24, 2026
8cd0f26
docs(core): explain the grant window and build's absent key check
Medformatik Nov 24, 2026
8b93faa
refactor(scripts): put SERVICE_FIELDS' doc comment back on it
Medformatik Nov 24, 2026
2e1b5da
docs(release): list every operator step and schema difference of the …
Medformatik Nov 24, 2026
1286af0
docs(federation): mount the secrets key in the OpenMapX compose example
Medformatik Nov 24, 2026
4398382
docs: name the heavy-feeds process as a migrator on the ingest role
Medformatik Nov 24, 2026
de84f5f
docs(ingest): say the start also opens the stored private keys
Medformatik Nov 24, 2026
959ec8e
docs: state the extra day spent tokens are kept
Medformatik Nov 24, 2026
e43bcb6
docs: drop stale migration numbers and bigserial mentions
Medformatik Nov 24, 2026
ec4b732
docs(ci): describe the qualifier's throwaway secrets key and key check
Medformatik Nov 24, 2026
7b86c55
docs: reflow paragraphs the baseline edits left half wrapped
Medformatik Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
# PostgreSQL/PostGIS connection (REQUIRED — the service refuses to start without it)
DATABASE_URL=postgres://openconditions:openconditions@localhost:5432/openconditions

# Secrets key (REQUIRED): 64 hex characters, from `openssl rand -hex 32`, made
# once. The OAuth2 grants' tokens are encrypted with it; every other
# OpenConditions service of the instance gets a copy of this same key. Keep it in
# your recovery set and out of database backups.
# OPENCONDITIONS_SECRETS_KEY_FILE may name a file holding it instead.
OPENCONDITIONS_SECRETS_KEY=

# HTTP server (optional; defaults shown)
PORT=4100
HOST=0.0.0.0
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ jobs:
- name: Credential guide up to date
run: pnpm check-credentials

- name: Migrations match the schema code
run: pnpm check:migrations

- name: Test
run: pnpm test
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ build/
.env
.env.*
!.env.example
.secrets-key

# Logs
*.log
Expand Down
14 changes: 4 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ covered by our [Code of Conduct](CODE_OF_CONDUCT.md).
- **The data model** — record classes and the registry live in
[`@openconditions/model`](packages/model) and its domain modules (roads:
[`@openconditions/model-roads`](packages/model-roads)); read helpers and the
database schema in [`@openconditions/core`](packages/core).
database schema in [`@openconditions/core`](packages/core). Schema changes
follow [database migrations](docs/database-migrations.md).
- **The OpenLR resolver** — the Python map-matcher in
[`services/openlr-resolver`](services/openlr-resolver).
- **Bug reports / feature requests** — file an issue with reproduction steps and
Expand Down Expand Up @@ -61,6 +62,7 @@ TypeScript / Node:
pnpm lint # Biome + the import-boundary gate
pnpm typecheck # tsc across the workspace (turbo)
pnpm check-credentials
pnpm check:migrations # migrations match the schema code (on a committed tree)
pnpm check:model
pnpm check:feed-schemas
pnpm feeds:lint
Expand All @@ -70,15 +72,7 @@ pnpm check:packed-packages # actual tarball / external ESM, CJS and strict TS co
pnpm verify:full # all Node checks above, including the packed consumer
```

`verify:full` includes lint/import boundaries, workspace and script types, generated credentials,
model artifacts, feed schemas, feed lint, the full Node suite and the packed-package consumer. The latter uses the pinned pnpm CLI and may fetch pinned consumer tools/type dependencies from npm; it retains the actual tarball identity and consumer lock in its receipt. See the [OCPI qualification instructions](packages/ocpi/README.md#qualify-a-tarball-without-publishing) for supplied immutable bytes. It needs Docker/PostGIS for database
tests. For the same OpenLR cross-check as CI, install the hash-pinned
`packages/openlr/python/requirements.txt` into your Python environment, put it on `PATH` and set
`OPENLR_CROSSCHECK=required`. This command does not run the separate resolver checks, independent
interop, dependency audits or container qualification below, or prove live provider/deployment behavior. For a docs-only change,
use scoped Prettier checks; for Node behavior, run focused tests while iterating and `verify:full` before
review. Resolver, wire-format/federation and dependency changes also need their corresponding checks
below. CI retains every applicable gate on every PR.
`verify:full` includes lint/import boundaries, workspace and script types, generated credentials, the migrations drift gate, model artifacts, feed schemas, feed lint, the full Node suite and the packed-package consumer. The latter uses the pinned pnpm CLI and may fetch pinned consumer tools/type dependencies from npm; it retains the actual tarball identity and consumer lock in its receipt. See the [OCPI qualification instructions](packages/ocpi/README.md#qualify-a-tarball-without-publishing) for supplied immutable bytes. It needs Docker/PostGIS for database tests. For the same OpenLR cross-check as CI, install the hash-pinned `packages/openlr/python/requirements.txt` into your Python environment, put it on `PATH` and set `OPENLR_CROSSCHECK=required`. This command does not run the separate resolver checks, independent interop, dependency audits or container qualification below, or prove live provider/deployment behavior. For a docs-only change, use scoped Prettier checks; for Node behavior, run focused tests while iterating and `verify:full` before review. Resolver, wire-format/federation and dependency changes also need their corresponding checks below. CI retains every applicable gate on every PR.

Model artifact drift is checked once in CI and `verify:full`, by
`scripts/__tests__/model-artifacts.test.ts` during `pnpm test`. That command builds the workspace
Expand Down
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ services/ deployable services (AGPL-3.0)
openlr-resolver/ Python/FastAPI OpenLR → geometry map-matcher (dormant)
```

The ingest service owns and migrates the `conditions` schema itself, idempotently, on boot.
The ingest service owns and migrates the `conditions` schema itself, idempotently, on boot. The contributions and federation services apply no migrations: they wait at boot until the schema reaches their version (see [database migrations](docs/database-migrations.md#who-migrates)).

Instances federate their records with each other: the [federation onboarding guide](docs/federation-onboarding.md) covers running and peering an instance, and the [federation wire protocol](docs/federation-protocol.md) specifies what instances exchange.

Expand All @@ -122,11 +122,15 @@ Requires Node 24+ and pnpm 11+ (and a reachable PostGIS).
pnpm install
pnpm build

# Once: the secrets key, kept in a file Git ignores and reused on every start.
[ -f .secrets-key ] || (umask 077 && openssl rand -hex 32 > .secrets-key)

DATABASE_URL=postgres://postgres:postgres@localhost:5432/openconditions \
OPENCONDITIONS_SECRETS_KEY_FILE="$PWD/.secrets-key" \
pnpm --filter @openconditions/ingest dev
```

The service applies its migrations, starts polling the enabled feeds, and serves on `:4100`.
The service applies its migrations, starts polling the enabled feeds, and serves on `:4100`. Keep `.secrets-key`: a start with another key refuses to read what the first one stored (see [secrets encrypted at rest](#secrets-encrypted-at-rest)).

### Public API

Expand Down Expand Up @@ -185,15 +189,7 @@ their occupancy), the charging domain (charging sites, charge-point status and t
webcam layer and its stills) and the hazards domain (the weather alert, wildfire, earthquake and natural event
overlays).

OpenMapX passes a community service's `container.environment` to the container verbatim, so the services'
configuration is `configSchema` fields: set the database URL (and the contributions API's grant secret and
reviewer token) once as secrets in the admin services panel. Until they are set, both services stop at boot
and their containers restart in a loop; once they are, apply the change and the services start. Set any
setting there, or as `SERVICE_OPENCONDITIONS_INGEST_<KEY>` in OpenMapX's `.env`. Settings kept in OpenMapX's
`.env` are applied with `pnpm openmapx services start openconditions-ingest` (which resets every setting saved
only in the admin form, so keep all of them in one place). Settings saved in the form are applied with
**Save & Apply**. See
[services/ingest/README.md](services/ingest/README.md#configuration-under-openmapx).
OpenMapX passes a community service's `container.environment` to the container verbatim, so the services' configuration is `configSchema` fields: set the database URL, the secrets key (the same value in every OpenConditions service, see [secrets encrypted at rest](#secrets-encrypted-at-rest)) and the contributions API's grant secret and reviewer token once as secrets in the admin services panel. Until they are set, both services stop at boot and their containers restart in a loop; once they are, apply the change and the services start. Set any setting there, or as `SERVICE_OPENCONDITIONS_INGEST_<KEY>` in OpenMapX's `.env`. Settings kept in OpenMapX's `.env` are applied with `pnpm openmapx services start openconditions-ingest` (which resets every setting saved only in the admin form, so keep all of them in one place). Settings saved in the form are applied with **Save & Apply**. See [services/ingest/README.md](services/ingest/README.md#configuration-under-openmapx).

See OpenMapX's _Building an external extension_ guide for the full flow. OpenMapX's built-in OpenConditions
integration reads roads situations, routing evidence, fuel features, parking sites, charging sites, cameras and
Expand All @@ -203,6 +199,25 @@ charging layer, the webcam layer and the hazard overlays. A request carrying `Au
public-scope. Reads with a bbox fetch stale on-demand feeds first, waiting at most
`OPENCONDITIONS_ON_DEMAND_DEADLINE_MS` (default 3000). See [services/ingest/README.md](services/ingest/README.md).

## Secrets encrypted at rest

OpenConditions keeps three kinds of secret in its tables: the OAuth grants of feeds that need an account login (the access and refresh tokens, for example EUMETSAT's), the contributions API's token-issuer private keys, and the federation service's instance private keys. They are stored encrypted with AES-256-GCM under one key, `OPENCONDITIONS_SECRETS_KEY`. The OpenConditions tables never hold that key. Each value is bound to its table, column and row, so a value copied to another row does not decrypt. A dump of the OpenConditions tables therefore holds none of these secrets in clear.

The key is 64 hexadecimal characters; surrounding whitespace is ignored. Generate it once, for the ingest service, with `openssl rand -hex 32`. Every other OpenConditions service of the instance that reads these secrets gets a copy of that same value, never a newly generated one: the heavy-feeds ingest process, the contributions API and, when federation is enabled, the federation service. The ingest service's feed-auth command reads the ingest container's key. After migrating, the ingest service seals a fixed check value with its key in `conditions.secrets_key_check`, once. On a fresh install, whichever ingest process starts first, the ingest service or the heavy-feeds ingest process, seals its key, so start the ingest service first, or make sure every service holds the same key before the first start. Every other service waits for that row at start and refuses to start when its key does not open it, with an error saying that its key differs from the one the ingest service sealed. A service that needs the key also refuses to start without it or with a value that is not a key. At start each service decrypts every secret it keeps. A key that cannot decrypt one stops the start with a "wrong key" error that names the table and row, never the key or the value.

Where the key lives depends on how OpenConditions runs:

- **Standalone**, the key lives only where the operator puts it: a file named by `OPENCONDITIONS_SECRETS_KEY_FILE` (or the variable `OPENCONDITIONS_SECRETS_KEY` itself), and the operator's recovery set. A database backup holds only the encrypted secrets and is of no use for them without the key, as long as the key file stays out of the backup.
- **Under OpenMapX**, each service's credentials in the admin services panel are separate, so the key is entered once per service: generated for `openconditions-ingest` and copied into the others. OpenMapX mounts it as a file and sets `OPENCONDITIONS_SECRETS_KEY_FILE`. A service that runs from its own compose file beside the extension, such as the federation service or a heavy-feeds ingest process started that way, has no entry in that panel: give it the copy as a mounted file and point `OPENCONDITIONS_SECRETS_KEY_FILE` at it, as the [federation guide's compose example](docs/federation-onboarding.md#deploying-it) does. OpenMapX's credential vault stores the key in OpenMapX's own table `public.service_secret`, in the same database, encrypted with OpenMapX's secrets key (the file `infra/docker/secrets/secrets-key` its render generates). A full database backup therefore holds the OpenConditions key, encrypted, next to the secrets it protects. Such a backup is safe for these secrets only while OpenMapX's secrets key file stays out of it, which is how OpenMapX keeps that file: out of backups, in the recovery set.

Both keys belong in your recovery set: the OpenConditions secrets key and, under OpenMapX, OpenMapX's secrets key. There is no tool to re-encrypt the secrets under a new key, so a lost key and a compromised key both mean starting over:

1. Generate a new key and enter it in every OpenConditions service (under OpenMapX, in each service's credentials).
2. Delete the rows of `conditions.secrets_key_check`, `conditions.oauth_grant`, `conditions.issuer_key` and `conditions.federation_instance_key`, then start the services; the ingest service seals the check row with the new key.
3. Log in to every OAuth grant again with the ingest container's feed-auth command (`node dist/feed-auth.js login <grant>`).

The consequences go beyond the logins. The contributions API makes new issuer keys, and crowd tokens issued under the deleted keys no longer redeem. The federation service makes a new instance key, which changes this instance's federation identity: peers that pinned the old key no longer trust this instance until they pin the new one. A database backup taken before the restart brings back rows the new key cannot open, so a service started on such a restore stops with "wrong key" until the old key is back or the steps above are repeated.

## Crowd reporting

Pseudonymous contributors can augment the official feeds with signed
Expand Down
13 changes: 3 additions & 10 deletions docs/container-qualification.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@ There is no registry login, push, package write, OIDC or privileged artifact con

## What must execute

`scripts/qualify-container-images.py qualify` builds the selected fixed recipe into an untagged OCI
archive. The image must run as a non-root user, become healthy using its actual image healthcheck, and
pass runtime/native probes on a fresh internal Docker network and owned PG16 database. No host port is
published, no operator database or credentials are used, and provider egress is unavailable. Test-only
grant/reviewer credentials are freshly generated. Database readiness uses a real TCP query to the
fixture database, rather than accepting the image's temporary bootstrap server.

- Every Node service applies its bundled migrations, returns its status document and exercises native
WebCrypto. Federation's default-disabled status is recorded; this does not prove enabled peer or
public-host behavior. Independent federation interoperability remains a separate CI gate.
`scripts/qualify-container-images.py qualify` builds the selected fixed recipe into an untagged OCI archive. The image must run as a non-root user, become healthy using its actual image healthcheck, and pass runtime/native probes on a fresh internal Docker network and owned PG16 database. No host port is published, no operator database or credentials are used, and provider egress is unavailable. Test-only grant/reviewer credentials and a random secrets key (`OPENCONDITIONS_SECRETS_KEY`) are freshly generated for every image. Database readiness uses a real TCP query to the fixture database, rather than accepting the image's temporary bootstrap server.

- Ingest applies its bundled migrations. For contributions-api and federation, which apply none and wait at boot for the schema version, the script first applies the source's migrations to the fixture database and records them as the ingest service does. For contributions-api, which also waits for the secrets key check, the script then seals that check row with the throwaway key, as the ingest service does, from a small Node script run inside the image; the service verifies the row with its own code at start, so a seal that drifted from the service's format fails qualification. Every Node service returns its status document and exercises native WebCrypto. Federation's default-disabled status is recorded; this does not prove enabled peer or public-host behavior. Independent federation interoperability remains a separate CI gate.
- Ingest additionally exercises its compiled osmium binary on a real OSM fixture, verifies baked feed
credentials and migration metadata, and makes an Impit native request to its own health endpoint.
Polling is explicitly excluded and the remote feed layer stays off.
Expand Down
1 change: 1 addition & 0 deletions docs/crowd-reporting-limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ publication.
- **Per-record privacy class.** Every crowd record carries the
`crowd_pseudonym` privacy class; the reporter's key rests in its provenance
and is stripped at every egress (API, emitters, federation, archive).
- **Retention.** A reporter row holds the public key, the reputation, the entitlement window and when the reporter last enrolled. It holds no OSM account id and no e-mail address. The ingest service's records sweep deletes a reporter once both its last enrollment and the end of its entitlement lie more than 12 months back. The deletion takes its votes, refusals and token quotas with it and removes its key from the evidence it gave, which stays as keyless evidence. Token quotas are deleted once their UTC day has ended, and spent tokens a day after their issuer key's validity has ended. The key also rests in the provenance of what the reporter reported: its latest crowd readings, its crowd situations and their revisions, and the federation journal's entries of those situations (peers never receive it; it is removed when an entry is served). The delete removes the key from the readings, situations and revisions, and from the journal entries of every situation still stored, in the same transaction, through a trigger on `conditions.reporter`, so a delete by hand (`DELETE FROM conditions.reporter WHERE key_id = …`) erases the reporter as the sweep does. A hand delete within about 37 days of a situation purge can leave outbox journal entries holding the key until the daily journal prune; the sweep never hits this case, and peers never receive the key. A hand delete should take the crowd's lock first (`SELECT pg_advisory_xact_lock(hashtext('crowd'))` in the same transaction), as the sweep does, so that a report landing at that moment cannot write the key back; a vote or report the reporter was submitting at that moment fails instead of landing. After the delete, one place still holds the key on purpose: the block list keeps a blocked key for as long as the block stands, so a blocked key that enrolls again stays blocked. Crowd readings keep no history, so the history tables never hold a key.
- **Probe/speed data is a separate, later, gated layer.** Continuous
speed/flow contribution (with distributed aggregation and differential privacy)
is out of scope here and is not covered by this page.
Expand Down
Loading
Loading