| 1 | # The identity registry compiler, driven end to end. What it renders is |
| 2 | # checkable against something already written down: the known-signers file |
| 3 | # the instance maintains by hand today is exactly what the registry must |
| 4 | # compile to, so the golden case is a byte-for-byte comparison against the |
| 5 | # artifact this compiler exists to replace. The grants it compiles are then |
| 6 | # read by the pre-receive hook a host renders: the approve grant, also |
| 7 | # accepted as request, and restack, whose holder adds a version to another |
| 8 | # principal's ready change and writes its restack report. A registry naming |
| 9 | # the approve grant under either name compiles the same grants, and the |
| 10 | # hook reads a grants file naming either: a holder under either name, or |
| 11 | # both, files a request and updates and deletes another principal's change |
| 12 | # record, and a principal holding neither, including one named approve, |
| 13 | # does none of that. A grant named approve at a boundary of another kind |
| 14 | # compiles to nothing. The registry is read past a replacement ref planted |
| 15 | # to forge it, and from the commit its ref resolved to while a push moves |
| 16 | # that ref mid-read. A registry enrolling a real YubiKey key from the test |
| 17 | # vectors, with the attestation the device wrote, compiles it into both |
| 18 | # approval signers files; that attestation offered for another key, or |
| 19 | # altered, fails the compilation, and so does the example registry, whose |
| 20 | # attestation chains to a test-only root. A registry holding a grant or a |
| 21 | # key under a field spelled another way, beside the field the schema |
| 22 | # spells, fails the compilation, and so does an export holding a key twice. |
| 23 | # |
| 24 | # The schema's own rejections live with the other schemas, in schema.nix. |
| 25 | { |
| 26 | pkgs, |
| 27 | packages, |
| 28 | hosts, |
| 29 | ... |
| 30 | }: |
| 31 | { |
| 32 | # The compiler's Go tests: the key hash pinned against the reference vector attest is held to, expiry, |
| 33 | # the renders it must refuse, and the approval files, over a real |
| 34 | # YubiKey's attestation and signature. |
| 35 | identity-unit = packages.identity-unwrapped.unit; |
| 36 | |
| 37 | identity-e2e = pkgs.runCommand "valley-identity-e2e" { |
| 38 | nativeBuildInputs = [ |
| 39 | pkgs.git |
| 40 | pkgs.openssh |
| 41 | packages.identity |
| 42 | # attest, so the compiled verifier line is checked against the |
| 43 | # implementation that reads it and not only against a fixed vector. |
| 44 | packages.attest |
| 45 | # cue, for the unwrapped compiler the mid-read push races. |
| 46 | pkgs.cue |
| 47 | ]; |
| 48 | # The compiler without its wrapper, so a git placed first on PATH is |
| 49 | # the one it runs, and the schema the wrapper would name. |
| 50 | identityUnwrapped = "${packages.identity-unwrapped}/bin/identity"; |
| 51 | identitySchema = ../../schema/identity.cue; |
| 52 | registry = ../../examples/identity/registry; |
| 53 | compiled = ../../examples/identity/compiled; |
| 54 | expired = ../../examples/identity/expired; |
| 55 | attested = ../../examples/identity/attested; |
| 56 | # The test vectors: the-valley operator's own approval key and its |
| 57 | # YubiKey's certificates, the compiled files they make, and the |
| 58 | # example's synthetic chain (identity/testdata/README.md). |
| 59 | testdata = ../../identity/testdata; |
| 60 | # The fail-safe case. Any invalid registry would do; this one fails on a |
| 61 | # property of the floor rather than on a typo, so the check also |
| 62 | # observes that a floor violation is what stops a compilation. |
| 63 | invalid = ../../examples/identity/rejected/external-governs-registry.cue; |
| 64 | # A host compiling the registry, whose rendered pre-receive hook reads |
| 65 | # the compiled grants. The check follows the hook out of its init |
| 66 | # script, so what it drives is what such a host would run. |
| 67 | identityInitScript = hosts.identityHost.config.systemd.services.valley-init.script; |
| 68 | passAsFile = [ "identityInitScript" ]; |
| 69 | } (builtins.readFile ./identity-e2e.sh); |
| 70 | } |