gunk-dev/the-valley

web-published.sh

sourcef961a59e125emain's published tip history
5.3 KiB
1# The signed fixture valley-web's tests read (web-published in
2# nix/packages.nix): the real publisher's output, written with --out, over
3# a small valley made with the packaged CLI and real git. Anyone may read
4# app. alice alone may read site, and the operator alone docs, so the two
5# named readers see different private projects. notes' policy/read lets
6# bob alone read it, and no grant names bob, so it has no effective
7# reader. site and docs each have an alias, a former name, a knot with a
8# comment, an abandoned knot and a ready change. Three of app's knots are
9# each blocked by an open knot, an abandoned knot and a missing knot of
10# one other project: site, docs or notes. $out holds the export the
11# publisher wrote, as published/, and the export key's verifier line, as
12# verifier.
13set -euo pipefail
14
15export HOME="$TMPDIR/home"
16export XDG_CACHE_HOME="$TMPDIR/cache"
17export XDG_STATE_HOME="$TMPDIR/xdg-state"
18export GIT_CONFIG_NOSYSTEM=1
19export GIT_CONFIG_GLOBAL="$TMPDIR/gitconfig"
20printf '[user]\n\tname = operator\n\temail = operator@example.org\n[init]\n\tdefaultBranch = main\n' > "$GIT_CONFIG_GLOBAL"
21cd "$TMPDIR"
22
23commit() {
24 git -C "work/$1" add --all
25 git -C "work/$1" commit --quiet -m "$1: $2"
26 git -C "work/$1" push --quiet origin main
27}
28
29declare -A id=(
30 [valley]=f83927d5a4ed068cdd02a8cdaa09f26d
31 [app]=9da6809f038df92138c131cd16bed76d
32 [site]=273d5668702918ea7ae079de374db96b
33 [docs]=5b1e0c7a9f3d2e4c6a8b0d1f3e5c7a92
34 [notes]=8e3b6f1d2a4c7e9b0d5f3a1c6e8b2d47
35)
36declare -A readers=(
37 [valley]='operator: true'
38 [app]='anyone: true'
39 [site]='alice: true'
40 [docs]='operator: true'
41 [notes]='bob: true'
42)
43read_policy() {
44 printf 'package read\n\nproject: "%s"\nidentity: "%s"\nreaders: {%s}\n' "$1" "${id[$1]}" "${readers[$1]}"
45}
46
47for name in valley app site docs notes; do
48 git init --quiet --bare "srv/$name.git"
49 git init --quiet "work/$name"
50 git -C "work/$name" remote add origin "$TMPDIR/srv/$name.git"
51 git -C "work/$name" config valley.principal operator
52 mkdir -p "work/$name/policy/read"
53 read_policy "$name" > "work/$name/policy/read/read.cue"
54done
55
56# The instance: the operator governs the registry, and the operator and
57# alice, who holds no key, may read every project at the edge. Anyone may
58# read app alone.
59mkdir -p work/valley/policy/instance work/valley/identity
60echo 'package verification' > work/valley/policy/instance/floor.cue
61cat > work/valley/identity/registry.cue << EOF
62package identity
63
64boundaries: {
65 registry: kind: "registry"
66 web: {kind: "edge-read", destination: "example.org"}
67}
68genesis: "operator"
69principals: operator: {
70 kind: "human"
71 keys: [{class: "ssh-ed25519", bound: "hardware", public: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyForARejectedFixtureAAAAAAAAAAA"}]
72 grants: {
73 govern: boundary: "registry"
74 read: {boundary: "web", projects: "all"}
75 }
76}
77principals: alice: {kind: "human", keys: [], grants: read: {boundary: "web", projects: "all"}}
78anyone: grants: read: {boundary: "web", projects: {app: "${id[app]}"}}
79EOF
80commit valley "the instance"
81projects=$(printf 'app\ndocs\nnotes\nsite\nvalley\n' | git -C srv/valley.git hash-object -w --stdin)
82git -C srv/valley.git update-ref refs/the-valley/projects "$projects"
83
84for name in app site docs notes; do
85 echo "$TMPDIR/srv/valley.git" > "work/$name/policy/valley"
86 printf '# %s\n\n%s-readme-text\n' "$name" "$name" > "work/$name/README.md"
87 commit "$name" "the first commit"
88done
89# Each private project's knots, comment and ready change carry its name,
90# so a page that shows any of them to another reader is caught.
91declare -A waits=([site]=first [docs]=second [notes]=third)
92declare -A change=([site]=ssssssssssssssssssssssssssssssss [docs]=tttttttttttttttttttttttttttttttt)
93for name in site docs notes; do
94 open=$(cd "work/$name" && valley knot new outcome "$name-knot-text" --json | jq -r .knot.id)
95 ended=$(cd "work/$name" && valley knot new outcome "$name-abandoned-text" --json | jq -r .knot.id)
96 (cd "work/$name" && valley knot set "$ended" status=abandoned > /dev/null)
97 (cd "work/$name" && valley knot comment "$open" -m "$name-comment-text" > /dev/null)
98 (cd work/app && valley knot new outcome "Waits on the ${waits[$name]} private project" \
99 --blocked-by "$name:$open" --blocked-by "$name:$ended" --blocked-by "$name:oc-0000000" > /dev/null)
100done
101for name in site docs; do
102 git -C "work/$name" checkout --quiet -b "$name-change-handle"
103 echo "$name-change-text" > "work/$name/change.md"
104 git -C "work/$name" add --all
105 git -C "work/$name" commit --quiet -m "$name-change-subject"
106 git -C "work/$name" push --quiet origin "$name-change-handle"
107 (cd "work/$name" && valley ready --change "${change[$name]}" "$name-change-handle" > /dev/null)
108 git -C "work/$name" checkout --quiet main
109done
110
111cat > host.cue << 'EOF'
112package valley
113
114groups: core: name: "tools"
115projects: app: group: "core"
116projects: site: {group: "core", aliases: ["portal"], formerNames: ["homepage"]}
117projects: docs: {group: "core", aliases: ["handbook"], formerNames: ["manual"]}
118projects: notes: group: "core"
119projects: valley: {}
120EOF
121cue export --out json "$schema" host.cue > host.json
122echo '{"operator": "operator"}' > principals.json
123
124mkdir -p "$out"
125valley-web-publish --instance-repo "$TMPDIR/srv/valley.git" --instance valley-host --destination example.org \
126 --host "$TMPDIR/host.json" --state "$TMPDIR/publisher" --principals "$TMPDIR/principals.json" --out "$out/published"
127cp publisher/verifier "$out/verifier"