gunk-dev/the-valley

identity.nix

source9ee95920e399main's published tip history
4.1 KiB
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. It is read at its ref by that exact name: with
16# refs/heads/registry missing, a branch named refs/heads/refs/heads/registry
17# is no registry, and the compilation fails. A registry enrolling a real YubiKey key from the test
18# vectors, with the attestation the device wrote, compiles it into both
19# approval signers files; that attestation offered for another key, or
20# altered, fails the compilation, and so does the example registry, whose
21# attestation chains to a test-only root. A registry holding a grant or a
22# key under a field spelled another way, beside the field the schema
23# spells, fails the compilation, and so does an export holding a key twice.
24#
25# The schema's own rejections live with the other schemas, in schema.nix.
26{
27 pkgs,
28 packages,
29 hosts,
30 ...
31}:
32{
33 # The compiler's Go tests: the key hash pinned against the reference vector attest is held to, expiry,
34 # the renders it must refuse, the approval files, over a real YubiKey's
35 # attestation and signature, and a run compiling again until the ref and
36 # the day hold still. In a real repository, a push moving the ref
37 # mid-read mixes no two registries, and the same run then compiles the
38 # commit the push moved the ref to; each round stamps the approval
39 # signers files with the commit and the day it compiled.
40 identity-unit = packages.identity-unwrapped.unit;
41
42 identity-e2e = pkgs.runCommand "valley-identity-e2e" {
43 nativeBuildInputs = [
44 pkgs.git
45 pkgs.openssh
46 packages.identity
47 # attest, so the compiled verifier line is checked against the
48 # implementation that reads it and not only against a fixed vector.
49 packages.attest
50 # cue, which a stand-in placed first on PATH wraps for the unwrapped
51 # compiler.
52 pkgs.cue
53 ];
54 # The compiler without its wrapper, so a stand-in placed first on PATH
55 # is the one it runs, and the schema the wrapper would name.
56 identityUnwrapped = "${packages.identity-unwrapped}/bin/identity";
57 identitySchema = ../../schema/identity.cue;
58 registry = ../../examples/identity/registry;
59 compiled = ../../examples/identity/compiled;
60 expired = ../../examples/identity/expired;
61 attested = ../../examples/identity/attested;
62 # The test vectors: the-valley operator's own approval key and its
63 # YubiKey's certificates, the compiled files they make, and the
64 # example's synthetic chain (identity/testdata/README.md).
65 testdata = ../../identity/testdata;
66 # The fail-safe case. Any invalid registry would do; this one fails on a
67 # property of the floor rather than on a typo, so the check also
68 # observes that a floor violation is what stops a compilation.
69 invalid = ../../examples/identity/rejected/external-governs-registry.cue;
70 # A host compiling the registry, whose rendered pre-receive hook reads
71 # the compiled grants. The check follows the hook out of its init
72 # script, so what it drives is what such a host would run.
73 identityInitScript = hosts.identityHost.config.systemd.services.valley-init.script;
74 passAsFile = [ "identityInitScript" ];
75 } (builtins.readFile ./identity-e2e.sh);
76}