gunk-dev/the-valley

web.nix

source1391837a95fbmain's published tip history
17.9 KiB
1# The web UI (web/): the shared export contract, the publisher, the
2# receiver, and the web server. Each check but web-image runs the unit
3# test derivation defined in nix/packages.nix, or, for
4# web-reader-state-crash, the crash tests of valley-web's. web-image is a
5# runCommand that unpacks the container image.
6{
7 pkgs,
8 packages,
9 ...
10}:
11{
12 # The projection over the shared fixture, which holds every disclosure
13 # rule: what reaches export.json, hidden projects' edges, a knot that
14 # waits on a hidden knot marked with waiting_on_hidden alone, the field
15 # gone once its one hidden blocker is done, the display mapping, each
16 # public project's group, web name, former names and short aliases with
17 # only public projects' groups, and names that collide refused, each
18 # case for the reason it names. The content digest; strict reading of
19 # export.json, with keys spelled exactly, none twice, and nothing after
20 # its document; the names checked, and the groups validated, stopping
21 # at each cancellation check; each of VerifyManifest's steps, in order;
22 # the manifest's grammar and its agreement with export.json; the
23 # streaming body check; bundle acceptance against real git, refusing
24 # wrong tips, prerequisites, extra refs, corrupt objects and a header
25 # past its bound, writing a commit-graph git verifies, and serving no
26 # commit main does not reach, nor one named in the other object
27 # format's length, alone or among several; git's
28 # output read within its limit, with git stopped past it or when its
29 # reader stops early; and the receiver's state directory. For the state
30 # directory: staging/ stays private to the receiver and exports/ stays
31 # group- and world-readable under any umask; readers hold
32 # a generation through activations, every file of a generation is synced
33 # before high-water names it, a repository interrupted by a crash is
34 # rebuilt, recovery verifies a generation before activating it and keeps
35 # one whose git check was interrupted, and injected sweep and swap
36 # failures are reported separately from the commit; Stage and Activate
37 # wait for a held store lock only until their context expires, leaving
38 # staging and the active generation unchanged on cancellation; the
39 # serving lock refused, though free, under a done context; a
40 # manifest's capacity sweep stops once its context is done, leaving the
41 # rest of the trash and releasing the lock; and an activation that
42 # exceeds MaxStorage is refused, with the repository whose build passed
43 # the cap removed, while repositories built before it remain. The
44 # publisher refuses a host declaration that is malformed, null where cue
45 # exports an object, or names a project by something that is not a name,
46 # before a pass. An end-to-end pass uploads to a real valley-web-receive
47 # with its bearer token, a real valley-web serves the activated export, a
48 # pass with a wrong token fails as unauthenticated while the edge keeps
49 # serving, and a pass after withdrawing anyone's grant removes the project
50 # from the edge. The Markdown renderer: CommonMark and GFM examples for
51 # each construct it reads, hostile HTML, schemes and attribute values
52 # rendered inert, its fuzz target's seeds held to the fixed tag set,
53 # adversarial inputs of 1 MiB rendered within a time bound and an
54 # allocation ceiling, a document cut at its output bound into whole
55 # HTML, a done context stopping it, and the repository's README.md and
56 # docs/ rendered with every link between them naming a heading. go vet
57 # runs after the tests.
58 web-unit = packages.web.unit;
59
60 # Read access, which the publisher reads its consents through: both
61 # consents read out of real commits under the real schemas, an explicit
62 # empty reader set and an empty scope letting no one read, anyone's
63 # restrictions, no principal name special, a policy for another project
64 # and a grant for another identity covering nothing, other destinations'
65 # grants and expired principals' left out, policy/web never read, tree
66 # entries with a directory part or named twice refused before anything
67 # is copied out, a directory named twice on the way to a document
68 # refused, redeclared definitions widening nothing, a field spelled in
69 # another case than the schema's refused, and the coverage report over a
70 # real valley, with the registry read at its ref. go vet runs after them.
71 readaccess-unit = packages.readaccess.unit;
72
73 # The server and valley-web over the shared fixture, uploaded to a real
74 # store, and real git. The plan page's reading order, its free to start
75 # legend, its one card of ready changes, and the export's age, marked
76 # stale after five minutes; a knot's body and comments, with the edited
77 # one marked; a hidden project answering every route under its group,
78 # under no group and under its short alias exactly as a missing one,
79 # though its repository is in the generation; a blocked knot's chip
80 # naming its published blockers and, once, unpublished work; groups and
81 # projects named source, knots and web-export served on every route
82 # under /<group>/<project>, and their roots redirected to their trees,
83 # while the server's own paths under /-/ are never a group's; two groups
84 # each serving a project named app; a group's alias, a project's former
85 # name and a project's short alias answering with a permanent redirect
86 # that keeps the path and query as sent, a bare "?" too, and leads a
87 # browser that resolves its dot segments to a path on the same origin;
88 # the index of groups, aliases and former names stopping at each
89 # cancellation check; every 404 the one page made at
90 # start, the box of text with no site name; a commit
91 # main's tip does not reach, and every other object ID or name, refused
92 # with the one 404; hostile README, file, file name, commit subject and
93 # knot text rendered inert, and large and binary files not shown; a
94 # reference into the hidden project naming nothing of it; a directory
95 # past MaxRead listed in part, and a 5 MiB commit message ending its
96 # page of history early; the directories along a path sharing one
97 # MaxRead; the older links of history showing every commit once through
98 # a merge whose lines run across pages, and every link of a page past
99 # MaxFrontier lines, or one ended before a merge past MaxLeftToShow,
100 # reaching every commit; a merge whose parents pass a record of git log
101 # shown, first on a page and further down, with its first MaxParents
102 # followed; a source request's git slot held for a bound of its own from
103 # admission, through its git, answering 503 and giving back its slot,
104 # taken only once its view is ready, so a slow export read holds none,
105 # and given back before it renders; a SHA-256
106 # project served by full commit IDs alone; a file of MaxFile newlines shown to MaxLines;
107 # a chain of knots near the graph's limit shown to MaxPlanDepth, with
108 # the plan's structure built once; each route's policy on every
109 # response, the knots page's admitting its inline stylesheet and script
110 # by their hashes and every other route's no script, with every
111 # response private and unstored, carrying no ETag and never answered
112 # 304; anyone and two named readers, over signed fixtures holding
113 # private projects, each served on every route, alias, landing,
114 # reference, Markdown page and archive from the union of what anyone
115 # and their principal may read, under the project's publication
116 # identity, with what they may not see answering as missing and taking
117 # no git slot; a knot whose one blocker is in a project the reader may
118 # not see, done or open, read the same, field and page, from an export
119 # without that project and one holding it for another reader; the
120 # projection leaving the export unchanged and hiding other projects
121 # from four derived lists and the edges, and stopping inside them when
122 # cancelled; a private project named like a knot ID, the target of a
123 # public knot, named on no page of a reader who may not see it, with
124 # every other reference held to its own field's shapes; readers who
125 # may see the same projects sharing one index; the views of what
126 # anyone may see, and a loader, kept for anonymous requests while
127 # named views fill every other place, with a request that finds no
128 # room holding no loader, git slot or generation, and answering 503 at
129 # its deadline or nothing once its reader goes away; the waiting
130 # places past MaxNamedWaiting kept for anonymous requests, which a new
131 # generation's load serves while named readers fill theirs; a stopped
132 # build keeping its place until its worker ends, so no more than
133 # MaxViews workers build named views; a named reader's Markdown page, archive,
134 # knot and redirect rendered again when their grant is withdrawn while
135 # they render; a request keeping its view and its generation while another activates; an export
136 # read once per generation, however many requests wait for it, across
137 # activations; a load started only by a request taking a loader slot,
138 # with requests that wait for one ending at their deadline or when
139 # their reader goes away, leaving no load behind and holding no
140 # generation; a load reading export.json from a slow pipe stopped part
141 # way once its one request's deadline passes, caching nothing and
142 # giving back its generation; a flood during a load keeping
143 # MaxLoadWaiting requests waiting and answering the rest 503, with the
144 # server's goroutines and open files bounded; source requests past
145 # MaxGit and MaxWaiting answering 503, with an activation while they
146 # wait and a deadline that covers the wait, while redirects, missing
147 # pages and hidden projects answer as ever; a request held past its
148 # deadline before it renders answering 503; a page past MaxResponse on
149 # a knot, and past a smaller bound on a file, a directory, a page of
150 # history and the plan, answering the one short page that says it is
151 # too large; readers that never read holding no git slot and no
152 # generation, and, asking for more than MaxBuffered in large pages of
153 # three sizes, holding no more of the heap than it and no more than
154 # MaxLarge, their pages' starts counted, with a large page it has no
155 # room for answering 503 while the plan, a knot and a directory still
156 # render; and valley-web run as a process of its own, serving and
157 # stopping on SIGTERM, non-dumpable with --origin and dumpable without
158 # it, and serving every page from a read-only state
159 # directory that the receiver wrote under umask 0077, with the test
160 # simulating another owner, since it cannot change users. Readers'
161 # sessions: a link redeemed once into a session that renews its
162 # host-only cookie on every response its last check admits, 404s
163 # alike for a hidden and a missing project, and is refused beside a
164 # valid session before anything is consumed; every refused link
165 # answering one fixed 403; a reader post holding to its origin, media
166 # type, header, size and strict JSON object, a redemption's credential
167 # a string, or answering 403; the
168 # session cookie counted across every Cookie header, with two of it,
169 # a malformed, unknown, signed-out or revoked one, or one whose link
170 # is bound to another principal or verifier, read as anyone;
171 # /-/session naming the link of a valid session alone, and answering
172 # GET and HEAD alone; the reader pages, which render with nothing
173 # published, under their own
174 # policy, the one that admits the reader script and lets it connect to
175 # this origin; a changed browser state answering 503 to a request that
176 # carries the cookie and serving anyone; no state made under an
177 # authorization that binds a link, a binding stored while it is made
178 # waiting for it, and the state made once a request reads one that
179 # binds none; a full state refusing a redemption and taking a logout;
180 # concurrent redemptions of one link with one winner; a redemption
181 # queued behind a slow one stopping at its deadline and consuming
182 # nothing, a GET and a redemption behind a stalled first state or
183 # logout answering 503 at their deadline, a transaction whose context
184 # is done once it holds a lock changing nothing, and a response whose
185 # deadline passes at its last check answering 503, unrenewed; a
186 # revocation or a logout while a page, a Markdown page, an archive, a
187 # knot or a redirect renders answering that response as anyone's,
188 # unrenewed; and
189 # the browser state itself (web/readerstate/), opened only by its one
190 # owner, over a directory its user alone may reach, refusing a link
191 # files, a FIFO, an open mode and a document it cannot read, failing
192 # at each step of a transaction into an unavailable state, changing
193 # nothing when a deadline passes while a transaction encodes, and
194 # promoting no abandoned state.new. go vet runs after the tests.
195 web-server-unit = packages.valley-web.unit;
196
197 # The browser state's transactions in valley-web run as a process of
198 # its own over a real store: a redemption, a logout, and the making of
199 # the state, killed with SIGKILL at each step of its transaction, from
200 # encoding the next document to publishing the new snapshot, and failed
201 # at each, then run again. Before the rename, a killed redemption's link
202 # redeems once on the restart; from it, the link is consumed; a failed one
203 # leaves the state unavailable, a cookie answered 503 and anyone served,
204 # until the restart. A logout is never acknowledged before its commit:
205 # before the rename its session holds after the restart, and from it
206 # the token works no more. The making of the state interrupted before
207 # its rename, with links bound before the restart, makes no state on
208 # the restart, and redemption stays closed. A redemption whose 204
209 # reached the reader keeps its session through a crash right after it,
210 # and a logout whose 204 did keeps its token dead. No link redeems
211 # twice, and no log or state holds a link's secret or a session's
212 # token. A second
213 # valley-web over the same browser state refuses to start, as does one
214 # with no browser directory, an open one, or an origin that is not an
215 # HTTPS origin.
216 web-reader-state-crash = packages.valley-web.unit.overrideAttrs {
217 pname = "valley-web-reader-state-crash";
218 subPackages = [ "cmd/valley-web" ];
219 checkFlags = [ "-run=^TestCrash" ];
220 postCheck = "";
221 };
222
223 # The receiver binary, valley-web-receive, run as a subprocess over the
224 # shared fixture's signed export and real git. A three-step upload
225 # activates an export that a separate valley-web process serves from the
226 # same state directory, and re-posting the manifest or commit is refused
227 # as replayed. A private export, with app anyone's, site alice's alone
228 # and docs bob's alone, goes through the receiver to a valley-web that
229 # signs readers in: alice and bob each redeem a link the authorization
230 # binds, and each, and anyone, is served the knots, source and archives
231 # of what they may read, with every other project 404, until a
232 # withdrawal of alice's grant takes site from her next request. Manifests with no token, a wrong token, a non-Bearer
233 # scheme, or two Authorization headers, and a body, a commit and an
234 # unused path with no token, are refused as unauthenticated without
235 # staging anything. Stale, future-dated, foreign-key, and
236 # foreign-destination manifests are refused; a manifest older than the
237 # staged one is refused as superseded while newer manifests replace staged
238 # bodies; and committing an unstaged sequence fails as no-manifest. Bodies
239 # with a hash mismatch, a size mismatch (with or without Content-Length),
240 # a Content-Encoding header, or an undeclared hash are refused; a
241 # concurrent upload of the same body receives 503; and an interrupted body
242 # upload leaves no partial file in staging, fails commit as incomplete
243 # while keeping the active export intact, and activates once re-sent in
244 # full. Manifests and bodies past --max-body or --max-upload fail as
245 # too-large before staging, while uploads at both caps succeed; a manifest
246 # reusing one bundle across eight projects fails when it exceeds
247 # --max-storage, and uploads within the cap succeed. When stalled
248 # manifests fill all 4 request slots, the next authenticated request gets
249 # 503 and an unauthenticated request still gets 401 while valley-web keeps
250 # serving, and uploads resume once the stalled clients disconnect. When 32
251 # connections stall in headers, valley-web keeps serving and a subsequent
252 # upload succeeds once the header timeout closes them. OPTIONS * with a
253 # withheld body on all 32 connections returns immediately so a following
254 # upload succeeds. A manifest request canceled while waiting for the store
255 # lock stages nothing. A commit whose client disconnects, and a SIGTERM
256 # during a commit, kill the process group of the commit's git: a shell
257 # that stalls in commit-graph and its forked child holding git's output
258 # open both die, the bundle stays staged, and the receiver exits only once
259 # the commit has ended. On SIGTERM the receiver drains and exits within its
260 # timeout even with all connections held, and CLI usage, token-file, and
261 # verifier-file errors exit without printing the token. Every test request,
262 # dial, and wait for a subprocess is bounded. go vet runs after the tests.
263 web-receiver-unit = packages.valley-web-receive.unit;
264
265 # The edge container image, unpacked layer by layer: /bin/valley-web and
266 # /bin/valley-web-receive resolve to store paths inside the image, and
267 # the image holds the git each program runs at its pinned store path; /etc/passwd and /etc/group define
268 # valley-web-receive, valley-web, and their shared valley-web group;
269 # /var/lib/valley-web is the sole declared volume and is owned by
270 # valley-web-receive:valley-web with mode 0750; and the image defaults to
271 # user valley-web with no default entrypoint or command. Inside the
272 # volume, /var/lib/valley-web/browser is valley-web:valley-web, mode
273 # 0700: the browser state's directory.
274 web-image = pkgs.runCommand "valley-web-image" {
275 nativeBuildInputs = [ pkgs.jq ];
276 image = packages.valley-web-image;
277 } (builtins.readFile ./web-image.sh);
278}