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-onlyrule_set_snapshotswithcontent_sha256, migration20260821230000), anddevstack/seed/seed.shloads 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 copiesrulesets/into three images (Dockerfile, threeCOPY rulesets/lines).tools/craig-seed/src/afcars_policy.rs:15-18bakesfederal-afcars-2020.jsonandgeorgia-afcars-crosswalk.jsonin withinclude_str!. -
State reference data is compiled.
crates/craig-state-ga/src/lib.rsmixes 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.rsis data only. Cargo features compile candidates in (candidate_bundles!,activation.rs:31) andCRAIG__ACTIVE_STATE_BUNDLESpicks 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 fromrulesets/subdirectories), and test suites that read../../rulesets/<j>/…by path.
Decisions already made (recorded on #2947)
-
CRAIG_CONFIG_SOURCEtracks 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:
-
resolveturns 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. -
synctakes a list (pinned or not) and, per source: fetch →git worktree addat<name>/<sha>.tmp→ verify → rename to<name>/<sha>→ writecurrent.tmp→rename(2)overcurrent. 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 canonicalcontent_sha256differs from the active revision, insert arule_set_snapshotsrow withoperation = '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 takesSELECT … FOR UPDATEon itsrule_setsrow and re-checks the hash, so the second replica finds nothing to do. A new migration addsrule_set_snapshots.config_layers jsonb([{name, sha}], the whole set) andconfig_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-managedwith a typed problem; evaluate and promote-preview stay. -
GET /versionjoins/healthzand/readyzin 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.shstops 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.
Risks
| Risk | Class | Mitigation and the test that pins it |
|---|---|---|
A failed |
fail-open |
|
A reader opens files while |
silent |
Services resolve |
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 |
The |
fail-open |
The flag is read only when every source is |
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 |
|
Property: the highest layer wins for every path, and listing is the union (proptest). Contract: unknown schema
major, credential-bearing URL and |
U2 |
|
Must-pass (shared with canopy): an unsigned head and an untrusted-key head each leave |
U3 |
craig-rules reconcile, the |
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: |
U4 |
The three config repos created with history; |
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: |
U5 |
|
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,
|
U6 |
|
The lint fails on a planted ruleset, surface file and bundle file (fixtures); the TX lane runs against the TX repo.
Docs: |
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).