Skip to content
Draft
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
40 changes: 39 additions & 1 deletion .github/workflows/release-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
exclude_discovery: ${{ steps.request.outputs.exclude_discovery }}
manifest: ${{ steps.request.outputs.manifest }}
image_names: ${{ steps.request.outputs.image_names }}
reference_host_profiles: ${{ steps.request.outputs.reference_host_profiles }}
steps:
- name: Checkout protected workflow revision
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -77,6 +78,7 @@ jobs:
REQUEST_RELEASE_ID: ${{ github.event.client_payload.release_id }}
REQUEST_SOURCE_SHA: ${{ github.event.client_payload.source_sha }}
REQUEST_ID: ${{ github.event.client_payload.request_id }}
REFERENCE_HOST_COORDINATOR: ${{ toJSON(github.event.client_payload.coordinator_reference_host) }}
shell: bash
run: |
set -euo pipefail
Expand Down Expand Up @@ -120,6 +122,23 @@ jobs:
release_image_names="${selected_images% }"
fi
fi
reference_host_profiles='["breg","casework"]'
case "${REFERENCE_HOST_COORDINATOR}" in
null | false) ;;
true)
if [[ "${REQUEST_UNIT}" != stack ||
" ${release_image_names} " != *" registry-session "* ||
" ${release_image_names} " != *" coordinator "* ]]; then
echo "Coordinator reference host requires a Stack candidate with Session and Coordinator images" >&2
exit 1
fi
reference_host_profiles='["breg","casework","coordinator"]'
;;
*)
echo "Coordinator reference host opt-in must be a JSON boolean" >&2
exit 1
;;
esac
if [[ ! "${REQUEST_RELEASE_ID}" =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]]; then
echo "release_id is invalid" >&2
exit 1
Expand Down Expand Up @@ -252,6 +271,7 @@ jobs:
echo "tag=${tag}"
echo "manifest=${manifest}"
echo "image_names=${release_image_names}"
echo "reference_host_profiles=${reference_host_profiles}"
} >> "${GITHUB_OUTPUT}"

- name: Validate manifests, pins, recipes, and scanner policy fixtures
Expand Down Expand Up @@ -2728,7 +2748,7 @@ jobs:
strategy:
fail-fast: false
matrix:
profile: [breg, casework]
profile: ${{ fromJSON(needs.validate.outputs.reference_host_profiles) }}
permissions:
actions: read
attestations: read
Expand Down Expand Up @@ -2797,8 +2817,26 @@ jobs:
run: |
set -euo pipefail
stage="${RUNNER_TEMP}/reference-host-inputs"
profile="$(jq -er '.profile' "${stage}/inputs.json")"
if [[ "${profile}" == coordinator ]]; then
input_sha256="$(sha256sum "${stage}/inputs.json")"
version="$(jq -er '.release.version' "${stage}/inputs.json")"
tool_sha256="$(jq -er '.assets.coordinatorctl.sha256 | select(test("^[a-f0-9]{64}$"))' "${stage}/inputs.json")"
printf '%s %s\n' "${tool_sha256}" "${stage}/coordinatorctl" | sha256sum --check --strict --quiet
if ! tool_version="$(timeout --kill-after=1s 5s "${stage}/coordinatorctl" --version)" ||
[[ "${tool_version}" != "coordinatorctl ${version}" ]]; then
echo "Candidate coordinatorctl must report the sealed release version" >&2
exit 1
fi
node --test "${stage}/source/deploy/examples/business-registration/tests/coordinator.test.mjs"
fi
bash "${stage}/source/release/scripts/candidate-host-smoke.sh" \
"${stage}" "${RUNNER_TEMP}/candidate-host-receipt.json" --with-deps
if [[ "${profile}" == coordinator ]]; then
sha256sum --check --strict --quiet <<<"${input_sha256}"
python3 release/scripts/candidate_host_inputs.py verify-coordinator-receipt \
--stage "${stage}" --receipt "${RUNNER_TEMP}/candidate-host-receipt.json"
fi

- name: Retain the checked reference host receipt
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
70 changes: 68 additions & 2 deletions deploy/examples/business-registration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,72 @@ is refused, the protected page asks for sign-in again, and the second registrar
can still read its Record. It checks application requests for browser-sent
Authorization headers throughout.

## Add the Coordinator proof

The [Coordinator overlay](coordinator/compose.yaml) adds an independent,
synthetic workflow. It reads ThunderID's public discovery document over
verified HTTPS and returns the issuer identifier. A separate, short-lived
fixture bearer can start and read this one workflow. The proof discovers the
active revision, starts a run once, checks that a read without a bearer
returns 401, and reads back the same run and revision until the expected
output is finished. Business submissions still use the BReg Action. This
fixture has no business trigger, registry access or Casework authority.

Use the release source and a verified release manifest that contains both the
`registry-session` and `coordinator` image records. Stage the signed
`coordinatorctl` executable for Linux amd64 with the same-version tools in
`REFERENCE_ARTIFACTS` and verify it against that manifest. Complete the BReg
manual startup above before adding the overlay. Use the same Compose project
and environment file.

```bash
reference_image_digest() {
jq -er --arg name "$1" '
[.images[] | select(.name == $name) | .digest]
| select(length == 1) | .[0]
| select(test("^sha256:[0-9a-f]{64}$") and . != ("sha256:" + ("0" * 64)))' \
"$RELEASE_MANIFEST"
}
REFERENCE_SESSION_DIGEST=$(reference_image_digest registry-session)
REFERENCE_COORDINATOR_DIGEST=$(reference_image_digest coordinator)
export REFERENCE_SESSION_DIGEST REFERENCE_COORDINATOR_DIGEST

umask 077
mkdir -p "$REFERENCE_CONFIG/coordinator"
"$REFERENCE_ARTIFACTS/coordinatorctl" --format json package \
--project "$RECIPE/coordinator/workflow" \
--output "$REFERENCE_CONFIG/coordinator/package" \
> "$REFERENCE_CONFIG/coordinator/package-report.json"
coordinator_digest=$(jq -er '.packageDigest' "$REFERENCE_CONFIG/coordinator/package-report.json")
node "$RECIPE/coordinator/prepare.mjs" "$REFERENCE_CONFIG" "$coordinator_digest"

compose+=(--file "$RECIPE/coordinator/compose.yaml")
"${compose[@]}" pull session coordinator
coordinator_admin=("${compose[@]}" run -T --rm coordinator-admin \
--runtime-config /run/coordinator/runtime.yaml --posture production)
"${coordinator_admin[@]}" check --deny-warnings
"${coordinator_admin[@]}" provision --admin-url-file /run/coordinator/secrets/admin-database-url
"${coordinator_admin[@]}" apply
"${coordinator_admin[@]}" deployment-status
"${compose[@]}" up --wait --wait-timeout 60 --no-build session coordinator
timeout --kill-after=5s 90s "${compose[@]}" run -T --rm --no-deps coordinator-proof
```

The setup uses the existing private PostgreSQL server and creates a separate
`reference_coordinator` database with distinct migration and runtime roles
and verified TLS. The administrator and migration URLs are mounted only for
setup. The proof's signing key is mounted only for the one-shot proof. The
Coordinator listener binds loopback inside the private upstream namespace,
with no edge route or host port. Use the extended Compose command for teardown.

For a source-checkout run, build `registry-coordinator` with the same build
command as the other reference binaries, and pass `coordinator` in place of
`casework` to `tests/run-reference.sh`. This selects the existing local
overlay plus the [Coordinator local overlay](coordinator/compose.local.yaml),
using the local `coordinator` and `coordinatorctl` executables. The runner
checks the BReg browser journey and includes the Coordinator run ID, workflow
ID, revision and finished state in its receipt.

## Remove the instance

Stop the containers and remove the project's volumes, networks and the
Expand All @@ -474,8 +540,8 @@ Keep the audit files if you need them, then delete `REFERENCE_CONFIG` with root,
because some files belong to UIDs 999 and 10001. Also delete `REFERENCE_CA`,
`BUSINESS_BUNDLE` and the identity work directory.

To replay the BReg or Casework proof with an attested candidate, follow the
[candidate reference-host replay](../../../release/OPERATIONS.md#replay-the-candidate-reference-host-locally).
To replay the BReg, Casework, or Coordinator proof with an attested candidate,
follow the [candidate reference-host replay](../../../release/OPERATIONS.md#replay-the-candidate-reference-host-locally).

## Check browser route parity

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Add after compose.yaml and coordinator/compose.yaml for local development.
services:
coordinator:
image: ubuntu:24.04@sha256:73b999393d07f2bf65a40373778a44dc9a6d54ad7718d29247d8ff9413c4d6a8
entrypoint: [/opt/native/coordinator]
volumes:
- ${REFERENCE_ARTIFACTS}/coordinator:/opt/native/coordinator:ro
coordinator-admin:
image: ubuntu:24.04@sha256:73b999393d07f2bf65a40373778a44dc9a6d54ad7718d29247d8ff9413c4d6a8
entrypoint: [/opt/native/coordinatorctl]
volumes:
- ${REFERENCE_ARTIFACTS}/coordinatorctl:/opt/native/coordinatorctl:ro
47 changes: 47 additions & 0 deletions deploy/examples/business-registration/coordinator/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
x-coordinator: &coordinator
image: ${REFERENCE_COORDINATOR_REPOSITORY:-ghcr.io/registrystack/coordinator}@${REFERENCE_COORDINATOR_DIGEST:?Set REFERENCE_COORDINATOR_DIGEST to the verified Coordinator image digest}
user: "${REFERENCE_UID:-1000}:${REFERENCE_GID:-1000}"
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]

services:
coordinator:
<<: *coordinator
network_mode: service:upstreams
command: [--runtime-config, /run/coordinator/runtime.yaml, --posture, production]
environment:
SSL_CERT_FILE: /run/trust/https-ca.pem
volumes:
- ${REFERENCE_CONFIG}/coordinator/runtime:/run/coordinator:ro
- ${REFERENCE_CONFIG}/coordinator/package:/run/coordinator-package:ro
- ${REFERENCE_CONFIG}/coordinator/audit:/var/lib/registry-coordinator
- ${REFERENCE_CONFIG}/trust:/run/trust:ro
depends_on:
postgres: {condition: service_healthy}
issuer-ready: {condition: service_completed_successfully}

coordinator-admin:
<<: *coordinator
profiles: [setup]
networks: [database]
entrypoint: [/usr/local/bin/coordinatorctl]
volumes:
- ${REFERENCE_CONFIG}/coordinator/admin:/run/coordinator:ro
- ${REFERENCE_CONFIG}/coordinator/package:/run/coordinator-package:ro
- ${REFERENCE_CONFIG}/coordinator/audit:/var/lib/registry-coordinator
depends_on:
postgres: {condition: service_healthy}

coordinator-proof:
image: node:24.22.3@sha256:dc26ae92c9fb15cf6b1d63e20f0944b2efe0f115b20e00be48fb23fceb061c54
user: "${REFERENCE_UID:-1000}:${REFERENCE_GID:-1000}"
network_mode: service:upstreams
read_only: true
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
profiles: [setup]
entrypoint: [node, /run/reference/prove.mjs, /run/proof/signing-key.pem]
volumes:
- ./coordinator/prove.mjs:/run/reference/prove.mjs:ro
- ${REFERENCE_CONFIG}/coordinator/proof:/run/proof:ro
39 changes: 39 additions & 0 deletions deploy/examples/business-registration/coordinator/prepare.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { generateKeyPairSync, randomBytes } from 'node:crypto'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { isAbsolute, join } from 'node:path'

const [root, digest, ...extra] = process.argv.slice(2)
const digestSlot = 'sha256:' + '0'.repeat(64)
if (!root || !isAbsolute(root) || !/^sha256:[a-f0-9]{64}$/u.test(digest) || digest === digestSlot || extra.length) {
throw new Error('Pass the absolute reference config directory and the sealed Coordinator package digest.')
}

const template = await readFile(new URL('runtime.yaml', import.meta.url), 'utf8')
if (template.split(digestSlot).length !== 2) throw new Error('Expected one Coordinator package digest slot.')
const runtime = template.replace(digestSlot, digest)
const adminUrl = await readFile(join(root, 'breg/admin/secrets/admin-database-url'))
const databaseCa = await readFile(join(root, 'trust/postgres-ca.pem'))
const databaseUrl = role => `postgresql://reference_coordinator_${role}:${randomBytes(32).toString('hex')}@postgres:5432/reference_coordinator?sslmode=verify-full`
const { privateKey, publicKey } = generateKeyPairSync('rsa', { modulusLength: 2048 })
const jwk = { ...publicKey.export({ format: 'jwk' }), alg: 'RS256', use: 'sig', kid: 'reference-coordinator' }
const serving = {
'runtime-database-url': databaseUrl('runtime'),
'database-ca': databaseCa,
'audit-key': randomBytes(32),
'admission-key': randomBytes(32),
'state-key': randomBytes(32),
'oidc-jwks': JSON.stringify({ keys: [jwk] }),
}

const path = (...parts) => join(root, 'coordinator', ...parts)
const write = (value, ...parts) => writeFile(path(...parts), value, { flag: 'wx', mode: 0o600 })
for (const [area, secrets] of Object.entries({
admin: { ...serving, 'admin-database-url': adminUrl, 'migration-database-url': databaseUrl('migration') },
runtime: serving,
})) {
await mkdir(path(area, 'secrets'), { recursive: true, mode: 0o700 })
await write(runtime, area, 'runtime.yaml')
for (const [name, value] of Object.entries(secrets)) await write(value, area, 'secrets', name)
}
for (const area of ['audit', 'proof']) await mkdir(path(area), { mode: 0o700 })
await write(privateKey.export({ type: 'pkcs8', format: 'pem' }), 'proof', 'signing-key.pem')
127 changes: 127 additions & 0 deletions deploy/examples/business-registration/coordinator/prove.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { createPrivateKey, randomUUID, sign } from 'node:crypto'
import { readFile } from 'node:fs/promises'
import { resolve } from 'node:path'
import { setTimeout as sleep } from 'node:timers/promises'
import { pathToFileURL } from 'node:url'

const workflow = 'reference-coordinator'
const outcome = 'issuer-checked'
const issuer = 'https://identity.reference.test:9443'
const service = 'http://127.0.0.1:8108'

function fixtureToken(key) {
const now = Math.floor(Date.now() / 1000)
const client = 'reference-coordinator-producer'
const encode = value => Buffer.from(JSON.stringify(value)).toString('base64url')
const header = encode({ alg: 'RS256', kid: workflow, typ: 'at+jwt' })
const claims = encode({
iss: 'https://coordinator-fixture.reference.test', aud: 'urn:example:reference-coordinator',
sub: client, client_id: client, scope: 'coordinator:reference', iat: now, exp: now + 120,
jti: randomUUID(),
})
const unsigned = header + '.' + claims
return unsigned + '.' + sign('sha256', Buffer.from(unsigned), key).toString('base64url')
}

async function json(response, expected, phase) {
if (response.status !== expected) {
await response.body?.cancel()
throw new Error(`Coordinator ${phase} returned HTTP ${response.status}.`)
}
const chunks = []
let bytes = 0
for await (const chunk of response.body) {
bytes += chunk.length
if (bytes > 64 * 1024) throw new Error(`Coordinator ${phase} exceeded 64 KiB.`)
chunks.push(chunk)
}
try {
return JSON.parse(Buffer.concat(chunks).toString('utf8'))
} catch {
throw new Error(`Coordinator ${phase} returned invalid JSON.`)
}
}

export async function proveCoordinator(key, { fetch = globalThis.fetch, pause = sleep } = {}) {
const request = (path, method, headers = {}, body) => fetch(new URL(path, service), {
method, headers, body, redirect: 'error', signal: AbortSignal.timeout(2000),
})
let ready
for (let attempt = 0; attempt < 15; attempt++) {
const probe = await request('/ready', 'GET').catch(error => {
if (error instanceof TypeError || error.name === 'TimeoutError') return undefined
throw error
})
if (probe && probe.status !== 503) {
ready = await json(probe, 200, 'readiness')
break
}
await probe?.body?.cancel()
await pause(500)
}
if (ready?.ready !== true || ready.posture !== 'production'
|| !Array.isArray(ready.developmentSettings) || ready.developmentSettings.length !== 0) {
throw new Error('Coordinator did not become ready in production posture.')
}
const auth = { Authorization: 'Bearer ' + fixtureToken(key) }
const contract = await json(await request('/v1/workflows/' + workflow, 'GET', auth), 200, 'workflow discovery')
const { workflowRevision } = contract
if (contract.workflow !== workflow || !/^sha256:[a-f0-9]{64}$/u.test(workflowRevision)) {
throw new Error('Coordinator did not discover the expected workflow revision.')
}
const start = await json(await request('/v1/runs', 'POST', {
...auth, 'Content-Type': 'application/json', 'Idempotency-Key': randomUUID(),
}, JSON.stringify({ workflow, workflowRevision, input: {} })), 200, 'admission')
const { runId } = start
if (start.workflow !== workflow || start.workflowRevision !== workflowRevision
|| !/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/u.test(runId)) {
throw new Error('Coordinator admitted a different run.')
}
const path = '/v1/runs/' + runId
const refusal = await request(path, 'GET')
await refusal.body?.cancel()
if (refusal.status !== 401) throw new Error('Coordinator did not refuse the unauthenticated run read.')

const deadline = performance.now() + 35_000
for (let attempt = 0; attempt < 40 && performance.now() < deadline; attempt++) {
const readback = await json(await request(path, 'GET', auth), 200, 'run read')
if (readback.runId !== runId || readback.workflow !== workflow || readback.workflowRevision !== workflowRevision) {
throw new Error('Coordinator returned a different run.')
}
if (readback.state === 'finished') {
if (readback.outcome !== outcome || readback.output?.issuer !== issuer
|| Object.keys(readback.output).length !== 1 || readback.uncertain !== false
|| readback.restoreReviewRequired !== false) {
throw new Error('Coordinator did not return the expected completion.')
}
return {
workflow: readback.workflow,
workflowRevision: readback.workflowRevision,
runId: readback.runId,
state: readback.state,
outcome: readback.outcome,
output: readback.output,
uncertain: readback.uncertain,
restoreReviewRequired: readback.restoreReviewRequired,
}
}
if (readback.state !== 'running') {
const state = ['failed', 'cancelled', 'expired', 'attention', 'cancel-requested', 'cancelled-after-effect']
.includes(readback.state) ? readback.state : 'unknown'
throw new Error(`Coordinator run reached state ${state}.`)
}
await pause(1000)
}
throw new Error('Coordinator did not finish within the completion deadline.')
}

if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
try {
const key = createPrivateKey(await readFile(process.argv[2]))
console.log(JSON.stringify(await proveCoordinator(key)))
} catch (error) {
const diagnostic = error.message.startsWith('Coordinator ') ? error.message : 'Coordinator proof exchange failed.'
console.error(diagnostic)
process.exitCode = 1
}
}
Loading
Loading