Plan: Configuration as a git source — a deployment runs from signed config repos, separate from CRAIG source

Status

In progress

Epic: &121. Plan issue: #2947. ADR: ADR-087, accepted with this plan. Unit issues are filed when the plan is approved, one per unit below.

A Design + Scope plan: GitLab owns tracking; the plan freezes when the first unit starts.

Context

One repository holds CRAIG’s source and two deployments' configuration. The 2026-11-06 survey (#2947):

  • Rulesets live in rulesets/{federal,georgia,texas,testonia}. craig-rules keeps them in its own database (rule_sets, insert-only rule_set_snapshots with content_sha256, migration 20260821230000), and devstack/seed/seed.sh loads them over the API. craig-placement reads <rulesets_dir>/<j>/field_ownership.toml (crates/craig-common/src/settings.rs:656) and craig-composition reads <rulesets_dir>/<j>/<surface>.toml (services/craig-composition/src/loader.rs:267), both at boot. The Dockerfile copies rulesets/ into three images (Dockerfile, three COPY rulesets/ lines). tools/craig-seed/src/afcars_policy.rs:15-18 bakes federal-afcars-2020.json and georgia-afcars-crosswalk.json in with include_str!.

  • State reference data is compiled. crates/craig-state-ga/src/lib.rs mixes code (the partner adapter factories, audit codecs, mock routes and outbound triggers it registers) with ADR-072 Tier-2 data (rates, holidays, legal status and identifier codes, subsidy constants, terminology, theme). crates/craig-state-tx-stub/src/lib.rs is data only. Cargo features compile candidates in (candidate_bundles!, activation.rs:31) and CRAIG__ACTIVE_STATE_BUNDLES picks one (resolve_active_bundle, activation.rs:97).

  • Provenance stops at the database. A decision reaches its ruleset revision (rule_evaluations.rule_set_revision), but nothing records which commit of which repository that revision came from. No service exposes a version.

  • In-repo checks assume the layout: twin parity (xtask/src/cmd/rules_twins.rs), the scenarios audit, policy drift, the jurisdiction-literals census (tokens from rulesets/ subdirectories), and test suites that read ../../rulesets/<j>/… by path.

Decisions already made (recorded on #2947)

  • CRAIG_CONFIG_SOURCE tracks a branch head (branches as channels, e.g. ga/production) or a tag. Every decision is stamped with the resolved commit SHA, which the version endpoint exposes.

  • A deploy-time fetch into a read-only directory; publishing is a new worktree plus an atomic, SHA-named symlink flip. CRAIG owns the fetcher: git-sync 4.5.1 cannot gate publication (canopy’s spike, canopy #3254). No component is shared with canopy; the design and the must-pass test are.

  • Verification before the flip, modelled on Flux’s HEAD / Tag / TagAndHEAD modes, against a trust root held outside the config repo. A refusal keeps the last good tree and fails loudly.

  • File-level layering, first match by path, no content merge.

  • Git is the only authority for a config-managed deployment’s rulesets: craig-rules' write API answers 409 config-managed; rollback is moving the branch or tag.

Design

The boundary

Configuration is anything that varies by jurisdiction or deployment and is data: JDM rulesets and their citations.toml, policy-source.toml and scenario packs; surface baselines; field_ownership.toml; ADR-072 Tier-2 reference data (rates, holidays, codes, subsidy constants, identifier kinds); terminology overlays; theme.

Source is the engine, the configuration schema, Tier-3 invariants, and code — partner adapters included. Config may select and parametrize code that ships in source (an adapter list), never carry code.

Federal law is a base config repo (craig-config-federal), not source: it changes on its own legal cadence, and a deployment pins it like any layer. Every US jurisdiction layers over it.

testonia stays in source as the fixture jurisdiction (fixtures/config/testonia/), a complete, valid config layer, so unit tests and a fresh checkout need no network.

Secrets are not configuration. They stay in each deployment’s secret store; secrets/dev.yaml stays the devstack’s. A config repo holding a secret is refused by its own CI (gitleaks, as source does).

A config repository

A jurisdiction repo’s root is today’s rulesets/<j>/ tree, unchanged in shape so every in-repo reader and xtask verb keeps its path: *.json (the JDM rulesets), citations.toml, citation-exceptions.toml, policy-source.toml, authz-unsupplied-keys.toml, field_ownership.toml, the surface baselines flat as dashboard.toml and case_detail.toml (what loader.rs:267 reads), scenarios/, evidence/; plus a new craig-config.toml manifest and (from U5) bundle/. The federal repo is today’s rulesets/federal/ (its JSON, sources.toml, citations.toml, citation-exceptions.toml). Today’s root rulesets/scenario-packs.toml is replaced by each layer’s scenarios/ directory being the registry: a pack is active because it is in the layer. U1 keeps the current layout under path: sources byte for byte; U4 moves it.

schema = 1                  # the config schema major; a loader refuses one it does not know
layer = "jurisdiction"      # base | jurisdiction | deployment
jurisdiction = "georgia"    # jurisdiction layers only; the deployment's jurisdiction comes from here

Three repos under gitlab.com/gadhs/application/ccwis/: craig-config-federal, craig-config-georgia and craig-config-texas, created in U4 by git filter-repo from rulesets/<j>/ so each file keeps its history.

Sources, layers and the published tree

CRAIG_CONFIG_SOURCE is an ordered list, lowest precedence first: federal=git+https://…/craig-config-federal.git#tag=federal-2026.11.0, georgia=git+https://…/craig-config-georgia.git#branch=ga/production. A source is git+https://, git+ssh:// or a local path:. A URL carrying credentials (userinfo) is refused; credentials come from the standard git credential environment (a deploy token through GIT_ASKPASS, or a mounted deploy key).

The fetcher publishes each source under CRAIG_CONFIG_ROOT/<name>/current → <name>/<sha>/. A file path resolves to the highest-precedence layer that holds it; listing a directory is the union of paths, each resolved the same way. No content is merged.

The fetcher: craig-config-fetch (new, tools/craig-config-fetch)

One binary, two commands:

  • resolve turns each source’s branch or tag into a commit SHA and prints the pinned list. A rollout runs it once and hands every replica the same pinned list, so replicas move together.

  • sync takes a list (pinned or not) and, per source: fetch → git worktree add at <name>/<sha>.tmp → verify → rename to <name>/<sha> → write current.tmp → rename(2) over current. Each step is idempotent; an existing verified <sha> is reused.

Verification (per source, mode head, tag or tag-and-head as in Flux): git verify-commit --raw and/or git verify-tag --raw, then the signer must be on the source’s trust root: an SSH allowed_signers file (gpg.format=ssh) or an OpenPGP fingerprint list (CRAIG’s committers sign with OpenPGP today). The check reads the signer from the raw status lines rather than trusting keyring trust levels. Trust roots live at CRAIG_CONFIG_TRUST_DIR/<name>.{allowed_signers,openpgp}, mounted from the deployment, never from the config repo. path: sources are not verified; they are stamped path and a service refuses one unless CRAIG_CONFIG_ALLOW_UNVERIFIED=true (the devstack’s working-copy mode only).

Erratum (2026-11-07): the OpenPGP trust root is <name>.openpgp (fingerprints) plus <name>.openpgp.asc (their public keys), imported into an ephemeral per-run keyring so no deployment keyring is read; a listed fingerprint with no key, or an absent key file, refuses (#2971).

Refusal leaves current untouched, exits non-zero, writes CRAIG_CONFIG_ROOT/<name>/status.json ({ok:false, sha, reason}), and logs the reason; services read the status at boot and refuse to start on a source whose last sync failed and which has no previous good tree.

The image ships git, ssh-keygen and gpg. In compose it is a one-shot service the stack depends on; in Kubernetes an init container. Periodic polling is out of scope (below).

Loading and stamping

A new crate crates/craig-config owns the manifest, the source grammar, the layered resolver and ConfigSnapshot { layers: Vec<Layer { name, sha, root }>, jurisdiction }. Services build one snapshot at boot and hold it in an Arc; a new config applies by restart (a rollout), never mid-decision.

  • craig-placement and craig-composition read through the resolver instead of rulesets_dir (setting retired).

  • craig-rules reconciles at boot from the snapshot’s resolved *.json: for each ruleset whose canonical content_sha256 differs from the active revision, insert a rule_set_snapshots row with operation = 'import' then one with 'promote' (both within the migration’s CHECK list), actor_sub = 'config:<layer>@<sha>', reason = 'config reconcile <layer>@<sha>' (the promote/rollback/delete reason constraint), in one transaction per ruleset; a ruleset no layer provides any more gets a 'delete' snapshot and is deactivated, never removed (evaluations reference it). Replicas reconcile concurrently: each ruleset’s transaction takes SELECT … FOR UPDATE on its rule_sets row and re-checks the hash, so the second replica finds nothing to do. A new migration adds rule_set_snapshots.config_layers jsonb ([{name, sha}], the whole set) and config_source text (the layer that supplied the file). Every decision then reaches its commit: evaluation → revision → layers.

  • In config-managed mode (a snapshot is present) the write routes (create, update, import, delete, promote, rollback) answer 409 config-managed with a typed problem; evaluate and promote-preview stay.

  • GET /version joins /healthz and /readyz in craig-api’s shared router (crates/craig-api/src/lib.rs:582): {service, build: <git describe>, config: [{name, sha}]}, unauthenticated like the probes (it carries no secret; Kerckhoffs).

  • devstack/seed/seed.sh stops loading rulesets; craig-rules' reconcile does it.

State reference data (U5)

Tier-2 data moves to bundle/ in the jurisdiction repos (TOML and FTL, one file per contribution kind), loaded by a generic ConfigBundle that implements StateBundle from the snapshot and fails closed on a schema error. craig-state-tx-stub is deleted (its data moves to craig-config-texas). craig-state-ga becomes craig-partners-ga (adapters, codecs, mock routes, triggers only), compiled in by feature and activated by bundle/adapters.toml; an adapter name no compiled crate provides refuses boot. CRAIGACTIVE_STATE_BUNDLES and each service’s JURISDICTION setting retire: the manifest names the jurisdiction. ADR-072 is amended: Tier 2 is config bundle data, boot-resolved and fail-closed.

CI and the reference config repos

config-sources.lock at the source root pins {name, url, sha} for federal, georgia and texas. cargo xtask config fetch runs craig-config-fetch sync over it into target/config/, verifying against ci/config-trust/ (public keys and fingerprints; committing them is fine). Tests resolve paths through craig_test_lib::config::layer(name) instead of ../../rulesets/<j>. Bumping a pin is a source MR whose battery runs against the new config.

Twin parity, the scenarios audit and policy drift run in source over the locked georgia and texas layers; they are CRAIG’s checks on its reference configs. The jurisdiction-literals census takes its tokens from the lock file plus testonia. Each config repo gets a pipeline that runs cargo xtask rules check and the schema validation from the craig-tools image at the CRAIG version it targets.

Layering choice

File-level, first match by path: a decision’s inputs are whole files from known layers, both SHAs stamped, so "which value applied" is a lookup, not a computation. Key-level merge is not built; if a deployment needs one it is a new decision.

Risks

Risk Class Mitigation and the test that pins it

A failed sync keeps serving the previous current, so a deployment runs stale config without noticing.

fail-open

status.json says ok:false; /readyz goes unready on a stale source after the rollout’s sync failed (services read the status at boot), and the fetcher’s non-zero exit fails the rollout step itself. Test: a refused head leaves current, writes the status, exits non-zero; a service booted against it reports unready (U2, U1).

A reader opens files while current flips, and reads half from the old tree and half from the new.

silent

Services resolve current once at boot to its <sha> target and read through that real path for the life of the process; the flip is a single rename(2). Concurrency test (U2): a reader thread holding the resolved path keeps reading the old tree while 1,000 flips run; it never sees a mixed file.

Two craig-rules replicas reconcile the same ruleset at boot and double-promote or interleave.

fail-closed

Row lock plus re-check (above). Concurrency test (U3): two reconciles started together against one database produce exactly one import and one promote per changed ruleset.

A trust-root file is empty, missing or unreadable, so verification trivially passes or trivially fails.

fail-closed

An absent or empty trust root refuses every signer; the fetcher names the file. Test (U2): a good head against an empty allowed_signers is refused.

The path: escape hatch (CRAIG_CONFIG_ALLOW_UNVERIFIED) leaks into a real deployment.

fail-open

The flag is read only when every source is path:; a git+ source with the flag set refuses boot. /version reports verified:false. Test (U1): a git+ source plus the flag refuses.

Erratum (2026-11-07): loading a git+ source in craig-config (resolve current once, stamp its SHA, honour status.json) was promised by § Risks but delivered by neither U1 nor U2; it lands with U4 (#2955).

Scope — units (one MR each, in order)

Unit Delivers Proves (tests)

U1

crates/craig-config: manifest, source grammar, resolver over path: sources, ConfigSnapshot. craig-placement, craig-composition and craig-seed read through it, with the in-repo tree as path: sources (no behaviour change; afcars_policy.rs loads its two files at boot instead of include_str!). GET /version on every service. Docs: configuration-reference.adoc (the new settings), services.adoc (/version).

Property: the highest layer wins for every path, and listing is the union (proptest). Contract: unknown schema major, credential-bearing URL and git+ plus the unverified flag each refused; /version shape per service. Regression: placement and composition load the same bytes as before (golden over the loaded set).

U2

tools/craig-config-fetch (resolve, sync, verification, refusal), its image, the compose one-shot.

Must-pass (shared with canopy): an unsigned head and an untrusted-key head each leave current on the last good SHA, exit non-zero and write status.json; a good head flips; a tag in tag mode; replaying sync is idempotent; SSH and OpenPGP trust roots each refuse an off-list signer; an empty trust root refuses a good head. Concurrency: the reader-during-flip test (§ Risks). Real git and real keys in a temp dir; runs in the fast gate. Docs: deployment-guide.adoc (the fetcher, trust dirs, the compose one-shot).

U3

craig-rules reconcile, the config_layers / config_source migration, 409 config-managed on the write routes, seed.sh stops loading rulesets.

Reconcile inserts exactly the changed rulesets with the operations and reasons above and stamps the layers; a removed ruleset is deactivated, not deleted; each write route answers 409 (refusal, and its utoipa row); an evaluation’s revision reaches the commit SHA (devstack). Concurrency: two reconciles, one import and one promote per ruleset. Docs: api/craig-rules.adoc regenerated, data-model-rules.adoc (the two columns).

U4

The three config repos created with history; config-sources.lock; cargo xtask config fetch; tests through craig_test_lib::config; Dockerfiles stop copying rulesets/; rulesets/ leaves source; testonia moves to fixtures/config/testonia/; the devstack fetches GA (and TX for craig-intake-tx).

The full battery green against the locked repos; twin parity, scenarios audit and drift over the locked layers; each config repo’s own pipeline green. Docs: local-dev.adoc and devstack.adoc (fetching config), the rulesets.adoc page repointed at the repos, CHANGELOG.adoc ops note (retired rulesets_dir, the new required CRAIG_CONFIG_SOURCE).

U5

ConfigBundle, bundle/ data in the GA and TX repos, craig-partners-ga, craig-state-tx-stub deleted, the activation and jurisdiction settings retired, ADR-072 amended.

A bundle schema error refuses boot; an unknown adapter name refuses boot; GA and TX bundles load from config with the values today’s crates compile in (golden over the contribution set). Docs: ADR-072 amendment, shared-crates.adoc (the state crates' new shape), CHANGELOG.adoc ops note (retired CRAIGACTIVE_STATE_BUNDLES and JURISDICTION).

U6

cargo xtask lints config-in-source: no config kind outside fixtures/config/, no image copies config, census tokens from the lock. The battery’s TX lane (craig-intake-tx today) widened to a TX devstack profile.

The lint fails on a planted ruleset, surface file and bundle file (fixtures); the TX lane runs against the TX repo. Docs: quality-gates.adoc (the lint). Closes #2947 with the plan’s Status set to Done.

Erratum (2026-11-07): U1 resolves X1 (per-layer manifests hidden by highest-layer-wins, #2952): the resolver refuses a highest-layer-wins read of craig-config.toml, policy-source.toml, citations.toml and citation-exceptions.toml, and ConfigSnapshot::read_per_layer returns every layer’s copy in layer order; a missing layer directory refuses the snapshot naming it.

Erratum (2026-11-07): U4 keeps CI compile-once and pull-only: the xtask job’s one cargo build also builds craig-config-fetch, shipped as target/ci/bin/craig-config-fetch, which xtask config fetch runs when the checkout holds it (else cargo run), and a fetch with every layer at its pin starts no fetcher; each job fetches for itself rather than taking target/config/ as an artifact. The compose craig-config-fetch service drops its image: and joins infra_images::compose_built_services, so build publishes it under the tree and the stack jobs pull it.

Erratum (2026-11-15): § State reference data (U5) is stale where it gives craig-partners-ga "adapters, codecs, mock routes, triggers only": no audit codecs exist, the mock routes are the crate craig-partners-ga-mock, and the outbound trigger matrix is bundle data (bundle/outbound_triggers.toml); the crate holds the adapter factories only (plan config-bundle).

Preconditions the maintainer owns: creating the three GitLab projects (U4), and the signing keys listed in ci/config-trust/ (whose commits the reference repos accept).

Every unit also carries its CHANGELOG.adoc == Unreleased entry and regenerates any API page it touches; the plan’s Status moves to In progress when U1 starts.

Out of scope (issues filed at approval)

  • Periodic polling of a branch channel and in-process hot reload; v1 applies config by rollout.

  • OCI artifact bundles (ORAS + cosign) for air-gapped installs; gitsign trust roots.

  • Rewriting the ~186 source files that mention Georgia in comments or citations; U6 polices data, not prose.

  • A key-level merge between layers.

  • Canopy’s implementation (separate, same design and must-pass test).

Verification

Each unit’s tests above, plus: the devstack and CI run only from fetched, verified config after U4; GET /version on every service shows the locked SHAs; an evaluation row joined to its revision names the config commit; the must-pass refusal test runs in the fast gate (no devstack needed).

Edit this page · latest