gunk-dev/the-valley

web.nix

sourceb9df3fe59e29main's published tip history
18.3 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; the real publisher's signed output, admitted as a receiver
113 # admits it, serving anyone and an ungranted reader its public project
114 # alone and each of two named readers its own private project, with
115 # the export's and each reader's projection of the derived fields and
116 # edges of knots blocked in either private project and in an unexported
117 # one, and no page naming a private project to a reader who may not see
118 # it; anyone and two named readers, over signed fixtures holding
119 # private projects, each served on every route, alias, landing,
120 # reference, Markdown page and archive from the union of what anyone
121 # and their principal may read, under the project's publication
122 # identity, with what they may not see answering as missing and taking
123 # no git slot; a knot whose one blocker is in a project the reader may
124 # not see, done or open, read the same, field and page, from an export
125 # without that project and one holding it for another reader; the
126 # projection leaving the export unchanged and hiding other projects
127 # from four derived lists and the edges, and stopping inside them when
128 # cancelled; a private project named like a knot ID, the target of a
129 # public knot, named on no page of a reader who may not see it, with
130 # every other reference held to its own field's shapes; readers who
131 # may see the same projects sharing one index; the views of what
132 # anyone may see, and a loader, kept for anonymous requests while
133 # named views fill every other place, with a request that finds no
134 # room holding no loader, git slot or generation, and answering 503 at
135 # its deadline or nothing once its reader goes away; the waiting
136 # places past MaxNamedWaiting kept for anonymous requests, which a new
137 # generation's load serves while named readers fill theirs; a stopped
138 # build keeping its place until its worker ends, so no more than
139 # MaxViews workers build named views; a named reader's Markdown page, archive,
140 # knot and redirect rendered again when their grant is withdrawn while
141 # they render; a request keeping its view and its generation while another activates; an export
142 # read once per generation, however many requests wait for it, across
143 # activations; a load started only by a request taking a loader slot,
144 # with requests that wait for one ending at their deadline or when
145 # their reader goes away, leaving no load behind and holding no
146 # generation; a load reading export.json from a slow pipe stopped part
147 # way once its one request's deadline passes, caching nothing and
148 # giving back its generation; a flood during a load keeping
149 # MaxLoadWaiting requests waiting and answering the rest 503, with the
150 # server's goroutines and open files bounded; source requests past
151 # MaxGit and MaxWaiting answering 503, with an activation while they
152 # wait and a deadline that covers the wait, while redirects, missing
153 # pages and hidden projects answer as ever; a request held past its
154 # deadline before it renders answering 503; a page past MaxResponse on
155 # a knot, and past a smaller bound on a file, a directory, a page of
156 # history and the plan, answering the one short page that says it is
157 # too large; readers that never read holding no git slot and no
158 # generation, and, asking for more than MaxBuffered in large pages of
159 # three sizes, holding no more of the heap than it and no more than
160 # MaxLarge, their pages' starts counted, with a large page it has no
161 # room for answering 503 while the plan, a knot and a directory still
162 # render; and valley-web run as a process of its own, serving and
163 # stopping on SIGTERM, non-dumpable with --origin and dumpable without
164 # it, and serving every page from a read-only state
165 # directory that the receiver wrote under umask 0077, with the test
166 # simulating another owner, since it cannot change users. Readers'
167 # sessions: a link redeemed once into a session that renews its
168 # host-only cookie on every response its last check admits, 404s
169 # alike for a hidden and a missing project, and is refused beside a
170 # valid session before anything is consumed; every refused link
171 # answering one fixed 403; a reader post holding to its origin, media
172 # type, header, size and strict JSON object, a redemption's credential
173 # a string, or answering 403; the
174 # session cookie counted across every Cookie header, with two of it,
175 # a malformed, unknown, signed-out or revoked one, or one whose link
176 # is bound to another principal or verifier, read as anyone;
177 # /-/session naming the link of a valid session alone, and answering
178 # GET and HEAD alone; the reader pages, which render with nothing
179 # published, under their own
180 # policy, the one that admits the reader script and lets it connect to
181 # this origin; a changed browser state answering 503 to a request that
182 # carries the cookie and serving anyone; no state made under an
183 # authorization that binds a link, a binding stored while it is made
184 # waiting for it, and the state made once a request reads one that
185 # binds none; a full state refusing a redemption and taking a logout;
186 # concurrent redemptions of one link with one winner; a redemption
187 # queued behind a slow one stopping at its deadline and consuming
188 # nothing, a GET and a redemption behind a stalled first state or
189 # logout answering 503 at their deadline, a transaction whose context
190 # is done once it holds a lock changing nothing, and a response whose
191 # deadline passes at its last check answering 503, unrenewed; a
192 # revocation or a logout while a page, a Markdown page, an archive, a
193 # knot or a redirect renders answering that response as anyone's,
194 # unrenewed; and
195 # the browser state itself (web/readerstate/), opened only by its one
196 # owner, over a directory its user alone may reach, refusing a link
197 # files, a FIFO, an open mode and a document it cannot read, failing
198 # at each step of a transaction into an unavailable state, changing
199 # nothing when a deadline passes while a transaction encodes, and
200 # promoting no abandoned state.new. go vet runs after the tests.
201 web-server-unit = packages.valley-web.unit;
202
203 # The browser state's transactions in valley-web run as a process of
204 # its own over a real store: a redemption, a logout, and the making of
205 # the state, killed with SIGKILL at each step of its transaction, from
206 # encoding the next document to publishing the new snapshot, and failed
207 # at each, then run again. Before the rename, a killed redemption's link
208 # redeems once on the restart; from it, the link is consumed; a failed one
209 # leaves the state unavailable, a cookie answered 503 and anyone served,
210 # until the restart. A logout is never acknowledged before its commit:
211 # before the rename its session holds after the restart, and from it
212 # the token works no more. The making of the state interrupted before
213 # its rename, with links bound before the restart, makes no state on
214 # the restart, and redemption stays closed. A redemption whose 204
215 # reached the reader keeps its session through a crash right after it,
216 # and a logout whose 204 did keeps its token dead. No link redeems
217 # twice, and no log or state holds a link's secret or a session's
218 # token. A second
219 # valley-web over the same browser state refuses to start, as does one
220 # with no browser directory, an open one, or an origin that is not an
221 # HTTPS origin.
222 web-reader-state-crash = packages.valley-web.unit.overrideAttrs {
223 pname = "valley-web-reader-state-crash";
224 subPackages = [ "cmd/valley-web" ];
225 checkFlags = [ "-run=^TestCrash" ];
226 postCheck = "";
227 };
228
229 # The receiver binary, valley-web-receive, run as a subprocess over the
230 # shared fixture's signed export and real git. A three-step upload
231 # activates an export that a separate valley-web process serves from the
232 # same state directory, and re-posting the manifest or commit is refused
233 # as replayed. A private export, with app anyone's, site alice's alone
234 # and docs bob's alone, goes through the receiver to a valley-web that
235 # signs readers in: alice and bob each redeem a link the authorization
236 # binds, and each, and anyone, is served the knots, source and archives
237 # of what they may read, with every other project 404, until a
238 # withdrawal of alice's grant takes site from her next request. Manifests with no token, a wrong token, a non-Bearer
239 # scheme, or two Authorization headers, and a body, a commit and an
240 # unused path with no token, are refused as unauthenticated without
241 # staging anything. Stale, future-dated, foreign-key, and
242 # foreign-destination manifests are refused; a manifest older than the
243 # staged one is refused as superseded while newer manifests replace staged
244 # bodies; and committing an unstaged sequence fails as no-manifest. Bodies
245 # with a hash mismatch, a size mismatch (with or without Content-Length),
246 # a Content-Encoding header, or an undeclared hash are refused; a
247 # concurrent upload of the same body receives 503; and an interrupted body
248 # upload leaves no partial file in staging, fails commit as incomplete
249 # while keeping the active export intact, and activates once re-sent in
250 # full. Manifests and bodies past --max-body or --max-upload fail as
251 # too-large before staging, while uploads at both caps succeed; a manifest
252 # reusing one bundle across eight projects fails when it exceeds
253 # --max-storage, and uploads within the cap succeed. When stalled
254 # manifests fill all 4 request slots, the next authenticated request gets
255 # 503 and an unauthenticated request still gets 401 while valley-web keeps
256 # serving, and uploads resume once the stalled clients disconnect. When 32
257 # connections stall in headers, valley-web keeps serving and a subsequent
258 # upload succeeds once the header timeout closes them. OPTIONS * with a
259 # withheld body on all 32 connections returns immediately so a following
260 # upload succeeds. A manifest request canceled while waiting for the store
261 # lock stages nothing. A commit whose client disconnects, and a SIGTERM
262 # during a commit, kill the process group of the commit's git: a shell
263 # that stalls in commit-graph and its forked child holding git's output
264 # open both die, the bundle stays staged, and the receiver exits only once
265 # the commit has ended. On SIGTERM the receiver drains and exits within its
266 # timeout even with all connections held, and CLI usage, token-file, and
267 # verifier-file errors exit without printing the token. Every test request,
268 # dial, and wait for a subprocess is bounded. go vet runs after the tests.
269 web-receiver-unit = packages.valley-web-receive.unit;
270
271 # The edge container image, unpacked layer by layer: /bin/valley-web and
272 # /bin/valley-web-receive resolve to store paths inside the image, and
273 # the image holds the git each program runs at its pinned store path; /etc/passwd and /etc/group define
274 # valley-web-receive, valley-web, and their shared valley-web group;
275 # /var/lib/valley-web is the sole declared volume and is owned by
276 # valley-web-receive:valley-web with mode 0750; and the image defaults to
277 # user valley-web with no default entrypoint or command. Inside the
278 # volume, /var/lib/valley-web/browser is valley-web:valley-web, mode
279 # 0700: the browser state's directory.
280 web-image = pkgs.runCommand "valley-web-image" {
281 nativeBuildInputs = [ pkgs.jq ];
282 image = packages.valley-web-image;
283 } (builtins.readFile ./web-image.sh);
284}