gunk-dev/the-valley

web-published.sh

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