| 1 | # A guide to working in the valley |
| 2 | |
| 3 | This guide follows the jobs people do in a valley. Start with the [README](../README.md) for a short |
| 4 | tour, [Concepts and glossary](./concepts.md) for the terms used here, and |
| 5 | [Reference](./reference.md) for every command flag, environment variable, ref rule, and schema. |
| 6 | |
| 7 | - [Client setup](#client-setup) gets an author or reviewer connected. |
| 8 | - [Authoring a change](#authoring-a-change) takes a local commit to review. |
| 9 | - [Reviewing and approving changes](#reviewing-and-approving-changes) takes a ready change to |
| 10 | `main`. |
| 11 | - [Planning work with knots](#planning-work-with-knots) records and connects work. |
| 12 | - [Recovering from failure](#recovering-from-failure) explains what to do when work stops. |
| 13 | - [Running a valley host](#running-a-valley-host) sets up a NixOS deployment. |
| 14 | - [Contributing to the-valley](#contributing-to-the-valley) runs the project's development checks. |
| 15 | |
| 16 | The commands below describe implemented behavior. Host names, principals, verification policy, and |
| 17 | service settings are deployment choices. Replace the example values with those your administrator |
| 18 | provides. The [README's current status](../README.md#configuration-and-current-status) lists what is |
| 19 | not built. |
| 20 | |
| 21 | ## Client setup |
| 22 | |
| 23 | The client lets you propose work, review changes, and read the live plan. You need git, SSH access |
| 24 | to the valley host, and Nix with flakes enabled. |
| 25 | |
| 26 | 1. Clone the-valley's source from the URL your administrator provides. From that checkout, run: |
| 27 | |
| 28 | ```sh |
| 29 | nix run .#valley -- help |
| 30 | nix shell .#valley |
| 31 | valley --version |
| 32 | ``` |
| 33 | |
| 34 | `nix run` runs one command. `nix shell` puts the packaged `valley` on your path for the rest of |
| 35 | this guide. `valley help` prints a command summary; `valley help <verb>` prints help for one |
| 36 | verb. The package supplies the helpers its commands need. |
| 37 | |
| 38 | 2. Clone the project you will work on and name the principal associated with your SSH key: |
| 39 | |
| 40 | ```sh |
| 41 | git clone git@valley.example:demo |
| 42 | cd demo |
| 43 | git config valley.principal operator |
| 44 | git config user.name "Your name" |
| 45 | git config user.email you@example.com |
| 46 | ``` |
| 47 | |
| 48 | Use your own git author name and email. `valley.principal` names you in change records and knots. |
| 49 | It does not grant permission. The host checks the principal associated with the key you actually |
| 50 | use. |
| 51 | |
| 52 | 3. Check that the client can verify merged landings. You do not need to configure anything. The host |
| 53 | publishes its trusted signers file and the integrator's signing name in the instance repository, |
| 54 | and the client reads them when it needs them. This command shows the publication: |
| 55 | |
| 56 | ```sh |
| 57 | git ls-remote git@valley.example:instance refs/the-valley/signers |
| 58 | ``` |
| 59 | |
| 60 | Use the instance repository your project's `policy/valley` names. If it prints nothing, the host |
| 61 | publishes nothing, and some submitted versions appear `uncertain`; see |
| 62 | [recovery](#an-uncertain-landing). To use other values than the host's, set them yourself. A |
| 63 | setting wins over the publication: |
| 64 | |
| 65 | ```sh |
| 66 | export VALLEY_KNOWN_SIGNERS="$HOME/.config/valley/known-signers" |
| 67 | export VALLEY_INTEGRATOR_SIGNER=integrator |
| 68 | ``` |
| 69 | |
| 70 | 4. If approval runs checks on your machine, configure your Ed25519 attestation key and its |
| 71 | registered signing name: |
| 72 | |
| 73 | ```sh |
| 74 | export VALLEY_ATTEST_KEY="$HOME/.ssh/valley-attest" |
| 75 | export VALLEY_ATTEST_NAME=operator |
| 76 | ``` |
| 77 | |
| 78 | When every required check already has eligible evidence on `origin` (for example, from a check |
| 79 | worker), approval needs no signing key. When a check has to run locally, the host must trust that |
| 80 | signing key. Your SSH principal must also be allowed to approve. These are separate parts of |
| 81 | [identity](./concepts.md#principals-and-grants); see |
| 82 | [Environment variables and configuration](./reference.md#environment-variables-and-configuration) |
| 83 | for every client setting. |
| 84 | |
| 85 | To install updates into your user Nix profile, name the-valley's source repository: |
| 86 | |
| 87 | ```sh |
| 88 | valley self-update --repo git@valley.example:the-valley --branch main |
| 89 | ``` |
| 90 | |
| 91 | It builds the selected commit, tests the new client, and installs it. For repeated use, save the |
| 92 | repository with `git config --global valley.selfUpdate.repo git@valley.example:the-valley`, then run |
| 93 | `valley self-update`. Without a configured repository, self-update is off. Run |
| 94 | `valley self-update --help` for rollback and pinning. |
| 95 | |
| 96 | The installed package includes Bash and Zsh completions. For a shell using the checkout directly, |
| 97 | source `completions/valley.bash` in Bash. In Zsh, add the checkout's `completions` directory to |
| 98 | `fpath` before running `autoload -Uz compinit; compinit`. |
| 99 | |
| 100 | ## Authoring a change |
| 101 | |
| 102 | A change starts with a local commit. This example uses a new git branch called `greeting` to carry |
| 103 | it. Run it in a project with an initial `main` and verification policy already set up. |
| 104 | |
| 105 | ### Create and ready the first version |
| 106 | |
| 107 | ```sh |
| 108 | git fetch origin |
| 109 | git switch -c greeting origin/main |
| 110 | printf 'Hello from the valley.\n' > greeting.txt |
| 111 | git add greeting.txt |
| 112 | git commit -m 'Add a greeting' |
| 113 | valley checks |
| 114 | ``` |
| 115 | |
| 116 | `valley checks` lists what this diff requires. It does not run the checks. Run the commands named by |
| 117 | your project's policy before asking for review. For a Nix check named `prose-format` in this |
| 118 | repository, for example: |
| 119 | |
| 120 | ```sh |
| 121 | nix build --no-link .#checks.x86_64-linux.prose-format -L |
| 122 | ``` |
| 123 | |
| 124 | For this new, unpushed commit, stamp a stable Change ID and publish the first version: |
| 125 | |
| 126 | ```sh |
| 127 | valley ready --stamp |
| 128 | valley status greeting |
| 129 | ``` |
| 130 | |
| 131 | `ready` prints a handle and version, such as `demo kqxm v1 ready`. Use the handle it actually prints |
| 132 | in later commands. The handle identifies the change even when its commit changes. `status` reports |
| 133 | readiness, any request, and the latest integration result. To see the required checks alongside |
| 134 | pending changes, run `valley pending --checks`. |
| 135 | |
| 136 | If the commit already carries a `Change-Id` trailer or a jj `change-id` header, push it first and |
| 137 | run `valley ready` without `--stamp`: |
| 138 | |
| 139 | ```sh |
| 140 | git push -u origin HEAD |
| 141 | valley ready |
| 142 | ``` |
| 143 | |
| 144 | Without `--stamp`, `ready` uses the pushed tip by default. Keep the full Change ID when recording a |
| 145 | new revision. The [change concept](./concepts.md#a-change-ready-approve-submitted) explains how |
| 146 | headers, trailers, and `--change <id>` preserve it. |
| 147 | |
| 148 | ### Revise or pause |
| 149 | |
| 150 | Pause a ready change before editing it: |
| 151 | |
| 152 | ```sh |
| 153 | valley unready kqxm |
| 154 | ``` |
| 155 | |
| 156 | It becomes a draft. If it has an approval, ask a principal allowed to approve to |
| 157 | [delete the outstanding request](#withdraw-or-revoke-an-approval) before you ready a replacement. |
| 158 | Otherwise, readying the edited change can let the old version land: its request still names the old |
| 159 | head. |
| 160 | |
| 161 | Edit the files, then amend the commit while keeping its `Change-Id` trailer: |
| 162 | |
| 163 | ```sh |
| 164 | git add greeting.txt |
| 165 | git commit --amend --no-edit |
| 166 | git push --force-with-lease origin HEAD |
| 167 | valley ready |
| 168 | valley status kqxm |
| 169 | ``` |
| 170 | |
| 171 | The new head becomes the next version of the same change. If you make a new commit without its |
| 172 | trailer or header, use `valley ready --change <full-change-id>` after pushing it. |
| 173 | |
| 174 | ### Withdraw or revoke an approval |
| 175 | |
| 176 | To abandon the change, run `valley withdraw kqxm`. This marks it withdrawn. The integrator removes |
| 177 | outstanding requests on its next pass while the change is still withdrawn. Do not ready a withdrawn |
| 178 | change again until that removal is confirmed. For immediate revocation, a principal allowed to |
| 179 | approve can delete its request: |
| 180 | |
| 181 | ```sh |
| 182 | git push origin :refs/the-valley/integration-requests/main/c-<full-change-id> |
| 183 | ``` |
| 184 | |
| 185 | Replace the whole `<full-change-id>` placeholder before running this command. If an older request |
| 186 | uses a branch name, delete that request too. Use |
| 187 | `git ls-remote origin 'refs/the-valley/integration-requests/main/*'` to list them. Neither pausing |
| 188 | nor withdrawing undoes a completed landing. See the |
| 189 | [integrator's final readiness check](./concepts.md#the-host-the-hook-and-the-integrator) for the |
| 190 | limit when a landing is already in progress. |
| 191 | |
| 192 | ### Restack onto main |
| 193 | |
| 194 | Rebase a ready change when it needs the latest `main`. Before replacing an approved version, |
| 195 | [revoke its outstanding request](#withdraw-or-revoke-an-approval). |
| 196 | |
| 197 | ```sh |
| 198 | valley rebase kqxm |
| 199 | valley status kqxm |
| 200 | ``` |
| 201 | |
| 202 | This rebases the whole stack beneath the named change, pushes the new heads, and records new |
| 203 | versions. It leaves your local checkout in place. Read its output before editing locally again; |
| 204 | fetch the remote updates and reconcile your local branch with them. If a record update fails, finish |
| 205 | with the exact `valley ready` command it prints. |
| 206 | |
| 207 | Get the rebased version reviewed and approved again. A host that runs the restacker rebases ready |
| 208 | changes for you after each landing, and its versions need approval in the same way. Automatic |
| 209 | approval carry is not built. For conflicts or an uncertain landing, use |
| 210 | [recovery](#recovering-from-failure). |
| 211 | |
| 212 | ## Reviewing and approving changes |
| 213 | |
| 214 | A principal allowed to approve can turn a ready change into an integration request. Start in a clone |
| 215 | of the project with the [client signing settings](#client-setup). |
| 216 | |
| 217 | ```sh |
| 218 | valley pending |
| 219 | valley review kqxm |
| 220 | ``` |
| 221 | |
| 222 | Use a handle from `pending`. Review pages the diff and offers actions at the terminal. Choose |
| 223 | `[s]kip` to leave it alone or `[a]pprove` to run its required checks and approve the head you saw. A |
| 224 | draft or withdrawn layer stops review from offering approval for that layer or anything above it. A |
| 225 | stack is shown from the bottom up; approving its top includes the layers below. |
| 226 | |
| 227 | For a revised change, review automatically compares it with an earlier approved version when one can |
| 228 | be identified. A clean restack gets a short summary. Use `[v]iew full diff` to see the whole change. |
| 229 | The [comparison rules](./architecture.md#review-against-the-approved-version) explain what can be |
| 230 | compared. |
| 231 | |
| 232 | You can also approve from the command line: |
| 233 | |
| 234 | ```sh |
| 235 | valley approve kqxm |
| 236 | valley status kqxm |
| 237 | ``` |
| 238 | |
| 239 | On a terminal, `approve` asks you to confirm the head and title. For automation, pass the exact |
| 240 | reviewed commit with `valley approve --head <sha> kqxm`. Approval reuses eligible evidence already |
| 241 | on `origin` for the commit's content tree (see [`valley approve`](./reference.md#valley-approve)), |
| 242 | runs and signs any remaining required checks, and publishes the new evidence and request together. |
| 243 | When every required check is covered, nothing runs and no signing key is needed. It does not wait |
| 244 | for landing. An enabled integrator processes the request; `status` tells you what happened. |
| 245 | |
| 246 | After a successful landing, update your local `main`: |
| 247 | |
| 248 | ```sh |
| 249 | git fetch origin |
| 250 | git switch main |
| 251 | git merge --ff-only origin/main |
| 252 | ``` |
| 253 | |
| 254 | To inspect all recorded changes, including submitted and withdrawn ones, use |
| 255 | `valley changes --json`. For changes across the instance, use `valley pending --all` or |
| 256 | `valley changes --json --all`; see [CLI JSON outputs](./reference.md#cli-json-outputs) for their |
| 257 | output schemas. These need access to the instance and project repositories. |
| 258 | |
| 259 | ### Watch activity and inspect results |
| 260 | |
| 261 | `status` and `changes --json` read the records on the host. Use them to inspect landing results. If |
| 262 | your deployment provides access to its NATS bus, configure a NATS context for that endpoint and run: |
| 263 | |
| 264 | ```sh |
| 265 | valley tail |
| 266 | ``` |
| 267 | |
| 268 | It streams events until you interrupt it. Bus access is a deployment choice; the default host bus |
| 269 | listens on loopback. An administrator can use `journalctl -u valley-integrator@demo` on the host for |
| 270 | service logs. |
| 271 | |
| 272 | An administrator can republish the host's current refs with `replay`. On a host with |
| 273 | `services.valley.bus.enable = true` at its default address, enter `nix shell .#valley` from a |
| 274 | checkout of the-valley, then run: |
| 275 | |
| 276 | ```sh |
| 277 | sudo -u git env NATS_URL=nats://127.0.0.1:4222 "$(command -v valley)" replay /srv/git/demo.git |
| 278 | ``` |
| 279 | |
| 280 | Use the deployment's bus address and credentials if they differ. This writes current-state events to |
| 281 | the bus; it is not a history viewer. See |
| 282 | [events and mirrors](./architecture.md#after-a-push-events-and-mirrors). |
| 283 | |
| 284 | ### Read the host's telemetry |
| 285 | |
| 286 | Telemetry lets a session see what the host's components are doing without a shell on the host: the |
| 287 | check worker and the builds it runs, the integrators, the registry compiler, the signers publisher, |
| 288 | the publish queues, the bus, the web publisher, backups, `valley-init` and the build slice. It is |
| 289 | diagnostics. It never approves anything and never stands in for evidence. |
| 290 | |
| 291 | An observer reads it with the same SSH key it pushes with: |
| 292 | |
| 293 | ```sh |
| 294 | valley telemetry sources # what the host runs, and each source's state |
| 295 | valley telemetry snapshot # the worker's pass, its failures and open runs |
| 296 | valley telemetry read --source=worker # the worker's records and its systemd lifecycle |
| 297 | valley telemetry read --source=worker --logs # with the build output, marked untrusted |
| 298 | valley telemetry follow --seconds=300 --logs # what happens next, for five minutes |
| 299 | valley telemetry --remote git@valley-host:app.git sources # outside a checkout |
| 300 | ``` |
| 301 | |
| 302 | `follow` and `read` end with a cursor. Pass it to `--since` to carry on where the last one stopped. |
| 303 | A gap in what the host still holds, an error, or an answer that broke off is said, so silence always |
| 304 | means nothing happened. Each answer is bounded: a read returns at most 1000 records and 4 MiB, and a |
| 305 | follow lasts at most 300 seconds. |
| 306 | |
| 307 | `--logs` shows what checks and services printed. That text comes from whoever wrote the check, so it |
| 308 | is marked untrusted and its control characters are escaped. Leave `--logs` off unless the output is |
| 309 | what you need. |
| 310 | |
| 311 | To publish a workstation's approvals and check runs to the host, so a session can see them while |
| 312 | they run: |
| 313 | |
| 314 | ```sh |
| 315 | git config --global valley.telemetry true |
| 316 | ``` |
| 317 | |
| 318 | Each approval attempt, from `valley approve` or from `valley review`, then records its steps and its |
| 319 | checks' progress in a spool on the workstation, and they are sent in the background to the valley |
| 320 | the checkout's remote named when the attempt began, and to no other. A host that is down or |
| 321 | unreachable never slows or fails an approval; `valley telemetry flush` sends what is left later. |
| 322 | |
| 323 | ## Planning work with knots |
| 324 | |
| 325 | The plan graph records work and the relationships between its knots. Read it from a clone of the |
| 326 | primary valley repository: |
| 327 | |
| 328 | ```sh |
| 329 | valley plan |
| 330 | valley plan --all |
| 331 | ``` |
| 332 | |
| 333 | The first command shows this project's plan. The second reads projects published by the serving |
| 334 | host. A source mirror does not carry the plan graph. See |
| 335 | [project storage](./concepts.md#records-project-storage-the-plan-graph-and-knots). |
| 336 | |
| 337 | Create an outcome and inspect the ID it prints: |
| 338 | |
| 339 | ```sh |
| 340 | valley knot new outcome 'Greeting reaches readers' --owner operator |
| 341 | valley knot list --status active |
| 342 | ``` |
| 343 | |
| 344 | Use that ID in place of `oc-1234567` below: |
| 345 | |
| 346 | ```sh |
| 347 | valley knot show oc-1234567 |
| 348 | valley knot set oc-1234567 status=in-progress |
| 349 | valley knot new bug 'Greeting needs an example' --parent oc-1234567 |
| 350 | valley knot link oc-1234567 --change valley:demo/<full-change-id> |
| 351 | ``` |
| 352 | |
| 353 | Replace `<full-change-id>` with the change's full ID. The link connects the plan to the work that |
| 354 | fulfills it. A dependency uses `--blocked-by <knot-id>` instead. When the outcome is complete: |
| 355 | |
| 356 | ```sh |
| 357 | valley knot set oc-1234567 status=done |
| 358 | valley plan |
| 359 | ``` |
| 360 | |
| 361 | Comments record findings on a knot. `valley knot show` prints each comment's ID in brackets. A |
| 362 | comment's author or a holder of the `approve` grant can replace a comment's text with `--edit`: |
| 363 | |
| 364 | ```sh |
| 365 | valley knot comment oc-1234567 -m 'Waiting on the example.' |
| 366 | valley knot show oc-1234567 |
| 367 | valley knot comment oc-1234567 --edit <comment-id> -m 'The example landed.' |
| 368 | ``` |
| 369 | |
| 370 | The plan graph keeps every earlier text in its commit history. `valley knot log` lists the commits |
| 371 | that touched a knot or its comments, and `valley knot show --at <commit>` shows the knot at that |
| 372 | commit: |
| 373 | |
| 374 | ```sh |
| 375 | valley knot log oc-1234567 |
| 376 | valley knot show oc-1234567 --at <commit> |
| 377 | ``` |
| 378 | |
| 379 | Use `valley knot schema` to see each type's fields and allowed statuses. Knot writes validate the |
| 380 | resulting graph and push it directly; they do not go through change approval. See |
| 381 | [`valley knot`](./reference.md#valley-knot) for every subcommand and flag, and |
| 382 | [the plan graph](./architecture.md#the-plan-graph) for validation and concurrent edits. |
| 383 | |
| 384 | ## Recovering from failure |
| 385 | |
| 386 | Start with `valley status <handle>`. It distinguishes work waiting for an integrator from a request |
| 387 | that the integrator has judged. Keep the command's full output when asking your administrator for |
| 388 | help. |
| 389 | |
| 390 | ### A stale or rejected request |
| 391 | |
| 392 | A `stale` result means the change conflicts with `main` or required evidence is missing or does not |
| 393 | transfer across `main` movement. Read the reason in `status`. If the base moved, |
| 394 | [revoke the outstanding request](#withdraw-or-revoke-an-approval), restack the ready change, then |
| 395 | ask for a fresh review and approval: |
| 396 | |
| 397 | ```sh |
| 398 | valley rebase kqxm |
| 399 | valley status kqxm |
| 400 | ``` |
| 401 | |
| 402 | For missing or expired evidence, the approver must rerun approval with trusted signing settings. If |
| 403 | approval reports that evidence from this signer already exists for the tree, follow its recovery |
| 404 | message; retrying the same head does not replace that evidence. |
| 405 | |
| 406 | A `reject` result means the evidence is invalid, such as a signature or statement that does not |
| 407 | match what it claims. Keep the reason and ask the administrator to inspect the evidence and signing |
| 408 | configuration before trying again. See [checks and evidence](./concepts.md#checks-and-evidence). |
| 409 | |
| 410 | If `valley rebase` reports a conflict, it pushes nothing. For a single change, start from its remote |
| 411 | head on a clean local branch, run `git fetch origin` and `git rebase origin/main`, resolve the |
| 412 | reported files, and use `git add <resolved-files>` followed by `git rebase --continue`. Use |
| 413 | `git rebase --abort` to abandon that local attempt. Push with `--force-with-lease`, then run |
| 414 | `valley ready --change <full-change-id>`. For a stack, resolve each layer in order; do not publish |
| 415 | only the top while lower change records still name old heads. |
| 416 | |
| 417 | ### A refused push |
| 418 | |
| 419 | A refusal means the host did not accept that ref update. The message identifies the boundary: |
| 420 | |
| 421 | - **Protected ref:** push the work to a topic branch and use readiness and approval. A deployment |
| 422 | may seal `main` against every SSH principal. |
| 423 | - **Push hold:** ask the administrator to finish maintenance and remove the hold. Client settings |
| 424 | cannot bypass it. |
| 425 | - **Record ownership or non-fast-forward record update:** fetch again and use `valley ready`, |
| 426 | `unready`, or `withdraw` as the owner or a principal allowed to approve. Do not force a |
| 427 | hand-edited record over someone else's update. |
| 428 | - **A ref named like another ref:** push the branch or tag under a name that does not begin with |
| 429 | `refs/`. |
| 430 | - **Malformed or oversized record or knot:** read the named validation error. Use the CLI to make |
| 431 | valid records and `valley knot schema` to inspect the knot model. Reduce oversized content before |
| 432 | retrying. |
| 433 | |
| 434 | The [push rules](./architecture.md#what-a-push-may-write) and |
| 435 | [ref layout table](./reference.md#project-storage-ref-layout-and-bounds) explain each boundary. |
| 436 | |
| 437 | ### An uncertain landing |
| 438 | |
| 439 | An `uncertain` result means the client cannot prove whether the version was submitted. It can follow |
| 440 | a `failed` outcome or incomplete landing evidence. It can also mean the client had no signers to |
| 441 | verify the landing with. In that case the command says on stderr that a transfer statement could not |
| 442 | be verified, and why. Check that the host publishes its signers (step 3 of |
| 443 | [Client setup](#client-setup)). If it does not, ask the administrator for the signers file and the |
| 444 | integrator's signing name, set `VALLEY_KNOWN_SIGNERS` and `VALLEY_INTEGRATOR_SIGNER` to them, and |
| 445 | rerun `valley status <handle>`. |
| 446 | |
| 447 | If it remains uncertain, ask the administrator to inspect `main`, the outcome record, and the |
| 448 | integrator logs together. Do not assume that a consumed request means a successful landing. Resolve |
| 449 | the uncertainty before rebasing or approving again. The |
| 450 | [landing definitions](./concepts.md#a-change-ready-approve-submitted) describe the evidence needed |
| 451 | to resolve this state. |
| 452 | |
| 453 | ## Running a valley host |
| 454 | |
| 455 | A valley host serves repositories over SSH and runs the integrator on NixOS. This recipe creates an |
| 456 | instance repository named `instance` and a project named `demo`. It uses static keys and grants |
| 457 | first. All names, keys, checks, mirrors, and backup destinations are deployment choices; see |
| 458 | [NixOS host options](./reference.md#nixos-host-options) and |
| 459 | [CUE configuration schemas](./reference.md#cue-configuration-schemas) for the full option tables. |
| 460 | |
| 461 | ### Declare the host |
| 462 | |
| 463 | In your NixOS configuration directory, create `valley.cue`: |
| 464 | |
| 465 | ```cue |
| 466 | package valley |
| 467 | projects: { |
| 468 | instance: protection: {refs: ["refs/heads/main"], writers: []} |
| 469 | demo: protection: {refs: ["refs/heads/main"], writers: []} |
| 470 | } |
| 471 | ``` |
| 472 | |
| 473 | Both projects seal `main` against SSH pushes. The integrator writes locally on the host. |
| 474 | [`examples/hosts/protected.cue`](../examples/hosts/protected.cue) exercises four protection modes |
| 475 | for tests; it is not a production recipe. |
| 476 | |
| 477 | To publish a project on the web, place it in a group. Declare the group under a permanent |
| 478 | identifier, and set `group` on the project to that identifier: |
| 479 | |
| 480 | ```cue |
| 481 | groups: demos: name: "demos" |
| 482 | projects: demo: group: "demos" |
| 483 | ``` |
| 484 | |
| 485 | The web publisher exports only projects that belong to a group. The group's `name` is the first URL |
| 486 | segment and the project's web name is the second, giving `/demos/demo/…` here. A project's web name |
| 487 | defaults to its identifier unless the project sets `name`. When a group changes its `name`, keep the |
| 488 | old name in `aliases`. When a project changes its web name, keep the old name in `formerNames` so |
| 489 | existing links redirect (see [Groups and web URLs](./architecture.md#groups-and-web-urls)). |
| 490 | |
| 491 | Add the-valley as an input named `valley` to your NixOS flake, using your administrator's source |
| 492 | URL. Import `valley.nixosModules.valley-host` in the host's modules. In a module that receives that |
| 493 | input, start with: |
| 494 | |
| 495 | ```nix |
| 496 | { valley, ... }: { |
| 497 | imports = [ valley.nixosModules.valley-host ]; |
| 498 | services.openssh.enable = true; |
| 499 | services.valley = { |
| 500 | enable = true; |
| 501 | config = ./valley.cue; |
| 502 | authorizedKeys = [{ |
| 503 | principal = "operator"; |
| 504 | key = "ssh-ed25519 REPLACE_WITH_OPERATOR_PUBLIC_KEY"; |
| 505 | }]; |
| 506 | grants.approve = [ "operator" ]; |
| 507 | }; |
| 508 | } |
| 509 | ``` |
| 510 | |
| 511 | Pass the input through `specialArgs = { inherit valley; };` in `nixpkgs.lib.nixosSystem` if using |
| 512 | this module's argument. Replace the key with the public SSH key that the operator uses to push. The |
| 513 | `approve` grant is the grant that lets a principal approve. It is also accepted as `request`, and |
| 514 | `grants.request` declares the same grant as `grants.approve`. Keep administrative SSH access |
| 515 | separate from this git account. |
| 516 | |
| 517 | Apply your configuration using your normal NixOS deployment command. For a local flake with a host |
| 518 | named `valley-host`, run this on the host from that configuration directory: |
| 519 | |
| 520 | ```sh |
| 521 | sudo nixos-rebuild switch --flake .#valley-host |
| 522 | sudo systemctl start valley-init |
| 523 | sudo systemctl status valley-init --no-pager |
| 524 | ``` |
| 525 | |
| 526 | `valley-init` creates `/srv/git/instance.git` and `/srv/git/demo.git`, installs hooks, and creates |
| 527 | no initial commit. It publishes the project list once `instanceProject` is configured. Keep the |
| 528 | integrator disabled until both repositories have a `main`. |
| 529 | |
| 530 | ### Seed the initial source |
| 531 | |
| 532 | Create the initial source on the host in `/var/tmp/valley-seed`. Use an ordinary administrator |
| 533 | account with git's author name and email configured: |
| 534 | |
| 535 | ```sh |
| 536 | mkdir -p /var/tmp/valley-seed/instance/policy/instance |
| 537 | mkdir -p /var/tmp/valley-seed/demo/policy |
| 538 | cd /var/tmp/valley-seed/instance |
| 539 | git init --initial-branch=main |
| 540 | printf '# Instance\n' > README.md |
| 541 | cat > policy/instance/floor.cue <<'CUE' |
| 542 | package verification |
| 543 | floor: { |
| 544 | checks: readme: {runner: "command", command: "test -s README.md", validity: "1h"} |
| 545 | classes: source: {paths: {"**": true}, requires: {readme: true}} |
| 546 | unclassified: readme: true |
| 547 | } |
| 548 | CUE |
| 549 | git add README.md policy |
| 550 | git commit -m 'Seed instance policy' |
| 551 | cd /var/tmp/valley-seed/demo |
| 552 | git init --initial-branch=main |
| 553 | printf '# Demo\n' > README.md |
| 554 | printf 'git@valley.example:instance\n' > policy/valley |
| 555 | git add README.md policy |
| 556 | git commit -m 'Seed demo' |
| 557 | ``` |
| 558 | |
| 559 | Replace `valley.example` before committing. `policy/valley` names the instance repository whose |
| 560 | `policy/instance/` supplies this project's floor. The floor here requires only a nonempty README. It |
| 561 | is a smoke check to prove the approval path works. Choose checks that verify your actual projects |
| 562 | before admitting production work. A project's optional `policy/project/*.cue` can add requirements; |
| 563 | it cannot weaken the floor. See [policy](./architecture.md#policy). |
| 564 | |
| 565 | Seed these commits through a local host write. The following commands are for the empty repositories |
| 566 | just created: |
| 567 | |
| 568 | ```sh |
| 569 | sudo chown -R git:git /var/tmp/valley-seed |
| 570 | sudo -u git git -C /srv/git/instance.git fetch /var/tmp/valley-seed/instance main:refs/heads/main |
| 571 | sudo -u git git -C /srv/git/demo.git fetch /var/tmp/valley-seed/demo main:refs/heads/main |
| 572 | ``` |
| 573 | |
| 574 | Local writes bypass `pre-receive`, so this works while SSH writes to `main` are sealed. Keep these |
| 575 | seed directories free of private keys. Another bootstrap choice is to allow a temporary writer and |
| 576 | remove it after seeding; this recipe keeps the sealed configuration throughout. |
| 577 | |
| 578 | ### Provision signing and enable integration |
| 579 | |
| 580 | On the approver's machine, create its attestation key if it does not have one. From the-valley's |
| 581 | checkout, export its public verifier entry: |
| 582 | |
| 583 | ```sh |
| 584 | ssh-keygen -t ed25519 -N '' -f "$HOME/.ssh/valley-attest" |
| 585 | nix run .#attest -- key --key "$HOME/.ssh/valley-attest" --name operator > operator.signer |
| 586 | ``` |
| 587 | |
| 588 | Keep the private key on that machine. Copy only `operator.signer` to the administrator on the host. |
| 589 | On the host, create the integrator's separate key at a runtime path: |
| 590 | |
| 591 | ```sh |
| 592 | sudo install -d -m 0750 -o root -g git /var/lib/valley-secrets |
| 593 | sudo ssh-keygen -t ed25519 -N '' -f /var/lib/valley-secrets/integrator |
| 594 | sudo chgrp git /var/lib/valley-secrets/integrator |
| 595 | sudo chmod 0640 /var/lib/valley-secrets/integrator |
| 596 | ``` |
| 597 | |
| 598 | On the host, clone the-valley's source from the URL your administrator provides. From that checkout, |
| 599 | enter `nix shell .#attest`. Export the integrator entry and combine the two public entries: |
| 600 | |
| 601 | ```sh |
| 602 | sudo "$(command -v attest)" key --key /var/lib/valley-secrets/integrator --name integrator > integrator.signer |
| 603 | cat operator.signer integrator.signer > known-signers |
| 604 | sudo install -m 0644 known-signers /var/lib/valley-secrets/known-signers |
| 605 | ``` |
| 606 | |
| 607 | Add this to `services.valley` and apply the NixOS configuration again: |
| 608 | |
| 609 | ```nix |
| 610 | integrator = { |
| 611 | enable = true; |
| 612 | instanceProject = "instance"; |
| 613 | signingKeyFile = "/var/lib/valley-secrets/integrator"; |
| 614 | signingName = "integrator"; |
| 615 | knownSignersFile = "/var/lib/valley-secrets/known-signers"; |
| 616 | }; |
| 617 | ``` |
| 618 | |
| 619 | The integrator runs as `valley-integrator` in the `git` group. Its key and signers file must be |
| 620 | readable by that account. Private keys belong at runtime paths, never in the Nix store. |
| 621 | |
| 622 | The module requires a nonempty `authorizedKeys`, a signing key, a source for trusted signers, and |
| 623 | exactly one of `instanceProject` or `instancePolicy`. With `instanceProject`, it also requires the |
| 624 | instance's `main` to be protected. `instancePolicy` instead names a directory of floor CUE files on |
| 625 | a host that does not serve the instance repository. Set `signingName` explicitly to the name |
| 626 | published in the signers file. |
| 627 | |
| 628 | The host publishes the `known-signers` file and the integrator's signing name for clients, at |
| 629 | `refs/the-valley/signers` in the instance repository. `valley-signers` writes it at boot, on |
| 630 | activation, and whenever the file changes, so clients need no signer settings. Follow |
| 631 | [Authoring a change](#authoring-a-change) in a clone of `demo`, then approve it as `operator`. |
| 632 | Verify that `valley status <handle>` reports the landing. On the host, inspect: |
| 633 | |
| 634 | ```sh |
| 635 | sudo systemctl status valley-integrator@demo --no-pager |
| 636 | sudo journalctl -u valley-integrator@demo -n 50 --no-pager |
| 637 | sudo journalctl -u valley-signers -n 20 --no-pager |
| 638 | ``` |
| 639 | |
| 640 | ### Use a governed identity registry |
| 641 | |
| 642 | A deployment can maintain principals and keys in the instance source instead of listing all of them |
| 643 | in NixOS. Start with the [registry example](../examples/identity/registry/registry.cue) and |
| 644 | [schema](../schema/identity.cue). Write your own `identity/*.cue` in the instance repository, with |
| 645 | your public keys, signing names, boundaries, and grants. Do not deploy the example's keys. |
| 646 | |
| 647 | Include a registry governor, the operator's push and approval grants, and a signing entry whose |
| 648 | `signs` value matches the integrator's `signingName`. Land the registry through the static setup |
| 649 | above. Then set `services.valley.identity.enable = true` and remove `integrator.knownSignersFile` |
| 650 | from the NixOS configuration. Apply it and inspect the compilation: |
| 651 | |
| 652 | ```sh |
| 653 | sudo systemctl start valley-identity |
| 654 | sudo journalctl -u valley-identity -n 50 --no-pager |
| 655 | ``` |
| 656 | |
| 657 | It reads the integrated registry and writes `/var/lib/valley-identity/known-signers`, authorized |
| 658 | keys, and grants. Distribute that public signers file to clients. Keep a nonempty static |
| 659 | `authorizedKeys` list for bootstrap access. Static grants remain effective alongside compiled |
| 660 | grants; remove a static approval grant if the registry should be its sole source. See |
| 661 | [identity](./architecture.md#identity) for expiry and validation rules. |
| 662 | |
| 663 | ### Publish source mirrors |
| 664 | |
| 665 | A mirror lets readers fetch the source without accessing the primary host. Add a mirror URL to the |
| 666 | project's declaration and apply the host configuration: |
| 667 | |
| 668 | ```cue |
| 669 | projects: demo: mirrors: ["git@mirror.example:team/demo.git"] |
| 670 | ``` |
| 671 | |
| 672 | Provision the `git` Unix user's SSH private key and pinned `known_hosts` under `/srv/git/.ssh`. The |
| 673 | directory should be owned by `git` with mode `0700`; the private key should have mode `0600`. Verify |
| 674 | the mirror's host key through its administrator. The publisher runs as `git` and uses that account's |
| 675 | SSH configuration. |
| 676 | |
| 677 | For an existing mirror, inspect its refs before cutover. Remove unwanted old refs explicitly; the |
| 678 | publisher does not clean up old topic branches or project storage. Start with an empty mirror when |
| 679 | possible. See [mirror cutover](./architecture.md#after-a-push-events-and-mirrors). |
| 680 | |
| 681 | After a test landing, inspect the publisher: |
| 682 | |
| 683 | ```sh |
| 684 | sudo systemctl start valley-publish@demo |
| 685 | sudo journalctl -u valley-publish@demo -n 50 --no-pager |
| 686 | git ls-remote git@mirror.example:team/demo.git |
| 687 | ``` |
| 688 | |
| 689 | Its `main` should match the primary. The publisher sends `main` and tags, not the plan graph or |
| 690 | other project storage. A mirror is not a backup of the valley. |
| 691 | |
| 692 | ### Back up and test a restore |
| 693 | |
| 694 | Backups preserve the whole data directory. Add an offsite policy to `valley.cue`: |
| 695 | |
| 696 | ```cue |
| 697 | backup: { |
| 698 | target: "restic-sftp" |
| 699 | cadence: "nightly" |
| 700 | retention: {daily: 7, weekly: 4, monthly: 6} |
| 701 | } |
| 702 | ``` |
| 703 | |
| 704 | Provision four files outside the Nix store: the restic repository URL, its encryption password, the |
| 705 | SFTP private key, and pinned SSH host keys. Keep a recoverable copy of the password away from this |
| 706 | host. Point the module at those runtime files: |
| 707 | |
| 708 | ```nix |
| 709 | backup = { |
| 710 | repositoryFile = "/var/lib/valley-secrets/restic-repository"; |
| 711 | passwordFile = "/var/lib/valley-secrets/restic-password"; |
| 712 | sshKeyFile = "/var/lib/valley-secrets/restic-ssh"; |
| 713 | knownHostsFile = "/var/lib/valley-secrets/restic-known-hosts"; |
| 714 | }; |
| 715 | ``` |
| 716 | |
| 717 | After applying the configuration, take a backup and inspect its result: |
| 718 | |
| 719 | ```sh |
| 720 | sudo systemctl start restic-backups-valley |
| 721 | sudo journalctl -u restic-backups-valley -n 50 --no-pager |
| 722 | ``` |
| 723 | |
| 724 | The service runs as root and snapshots `services.valley.dataDir`, `/srv/git` by default. Test a |
| 725 | restore into a separate empty directory. With `restic` available, run these in a root shell: |
| 726 | |
| 727 | ```sh |
| 728 | export RESTIC_REPOSITORY_FILE=/var/lib/valley-secrets/restic-repository |
| 729 | export RESTIC_PASSWORD_FILE=/var/lib/valley-secrets/restic-password |
| 730 | restic -o 'sftp.args=-i /var/lib/valley-secrets/restic-ssh -o UserKnownHostsFile=/var/lib/valley-secrets/restic-known-hosts -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes' snapshots |
| 731 | restic -o 'sftp.args=-i /var/lib/valley-secrets/restic-ssh -o UserKnownHostsFile=/var/lib/valley-secrets/restic-known-hosts -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes' restore latest --target /var/tmp/valley-restore |
| 732 | git -c safe.directory=/var/tmp/valley-restore/srv/git/demo.git -C /var/tmp/valley-restore/srv/git/demo.git fsck --full |
| 733 | git -c safe.directory=/var/tmp/valley-restore/srv/git/instance.git -C /var/tmp/valley-restore/srv/git/instance.git fsck --full |
| 734 | ``` |
| 735 | |
| 736 | Expect a snapshot, a completed restore, and no corrupt or missing objects. Git may report dangling |
| 737 | objects; those alone do not indicate corruption. Inspect the restored `main` and `refs/the-valley/*` |
| 738 | as well. This verifies the restored repository, not a transaction across every ref written while the |
| 739 | backup ran. |
| 740 | |
| 741 | ### Hold pushes for maintenance |
| 742 | |
| 743 | To refuse incoming pushes across every project, create the hold on the host: |
| 744 | |
| 745 | ```sh |
| 746 | sudo touch /srv/git/.valley-hold |
| 747 | ``` |
| 748 | |
| 749 | Remove it after maintenance with `sudo rm /srv/git/.valley-hold`. Use your configured `dataDir` if |
| 750 | it differs. The hold stops SSH pushes; stop the relevant integrator services separately if |
| 751 | maintenance also requires local integration writes to stop. |
| 752 | |
| 753 | ### Serve telemetry from the host |
| 754 | |
| 755 | A host serves telemetry once the administrator enables the collector and names who may read and who |
| 756 | may report (`deployment choice`): |
| 757 | |
| 758 | ```nix |
| 759 | services.valley.telemetry = { |
| 760 | enable = true; |
| 761 | observers = [ "operator" ]; # read every source on the host |
| 762 | reporters = [ "alice" ]; # send records about their own approvals and checks |
| 763 | }; |
| 764 | ``` |
| 765 | |
| 766 | A principal is named by its key's tag, as for a push. `observe` is host-wide: the shared units' logs |
| 767 | span every project, so give it only to principals that may see every project's activity. `report` |
| 768 | grants no reading. A workstation that should read its own reports back needs `observe` too. |
| 769 | |
| 770 | A component on another machine, such as a web receiver, can report with a principal of its own: |
| 771 | |
| 772 | ```nix |
| 773 | services.valley.telemetry.reporters = [ "receiver" ]; |
| 774 | services.valley.telemetry.remoteSources = [ |
| 775 | { name = "remote-receiver"; description = "the web receiver at example.org"; principal = "receiver"; } |
| 776 | ]; |
| 777 | ``` |
| 778 | |
| 779 | The source reads as `unavailable` until that principal reports and as `stale` after an hour of |
| 780 | silence. No component of the-valley reports this way by itself yet; see |
| 781 | [Not deployed or not wired yet](architecture.md#not-deployed-or-not-wired-yet). |
| 782 | |
| 783 | The collector reads the journal, so how far back unit lifecycle and output reach is the host's |
| 784 | journal retention, which each `source` line reports as `journal_since`. |
| 785 | |
| 786 | ### Find refs named like other refs |
| 787 | |
| 788 | The push hook refuses to create or update a ref named like another ref: `refs/`, `refs/heads/`, |
| 789 | `refs/tags/` or `refs/remotes/` followed by a full ref name. When the ref it is named for is |
| 790 | missing, git reads, fetches and pushes to such a ref in its place. A host may hold some already, |
| 791 | made before the hook refused them. List them once, in every repository the host serves: |
| 792 | |
| 793 | ```sh |
| 794 | for repo in /srv/git/*.git; do |
| 795 | sudo -u git git -C "$repo" for-each-ref --format="$repo %(refname)" \ |
| 796 | refs/refs/ refs/heads/refs/ refs/tags/refs/ refs/remotes/refs/ |
| 797 | done |
| 798 | ``` |
| 799 | |
| 800 | Each line names a repository and a ref. Once any work on a ref has been pushed under another name, |
| 801 | delete the ref on the host: |
| 802 | |
| 803 | ```sh |
| 804 | sudo -u git git -C /srv/git/demo.git update-ref -d refs/heads/refs/heads/main |
| 805 | ``` |
| 806 | |
| 807 | Use your configured `dataDir` if it differs. |
| 808 | |
| 809 | ### Run the web edge |
| 810 | |
| 811 | The web edge is a read-only web server for the valley's projects. The publisher on the valley host |
| 812 | pushes signed exports to the edge over HTTP, and the edge never connects back to the valley host. A |
| 813 | project reaches the edge when a reader's grant and the project's `policy/read` both allow that |
| 814 | reader — `anyone` or a named principal — to read it there. The edge serves each project only to the |
| 815 | readers its authorization names, and readers can sign in at the edge with read links. On the edge, |
| 816 | `valley-web-receive` receives uploads into a state directory and `valley-web` serves them. They run |
| 817 | as two processes under two Unix users over that shared state directory (see |
| 818 | [The receiver](./architecture.md#the-receiver)). |
| 819 | |
| 820 | Generate a shared bearer token and install the same file on both hosts outside the Nix store, |
| 821 | readable by root alone: |
| 822 | |
| 823 | ```sh |
| 824 | head -c 32 /dev/urandom | base64 | sudo install -m 0400 /dev/stdin /run/keys/valley-web-receiver-token |
| 825 | ``` |
| 826 | |
| 827 | On the valley host, enable the publisher with the receiver URL and token file: |
| 828 | |
| 829 | ```nix |
| 830 | imports = [ the-valley.nixosModules.default the-valley.nixosModules.web-publisher ]; |
| 831 | services.valley.webPublisher = { |
| 832 | enable = true; |
| 833 | destination = "example.org"; |
| 834 | receiver = "https://example.org"; |
| 835 | receiverTokenFile = "/run/keys/valley-web-receiver-token"; |
| 836 | allowedAddresses = [ "192.0.2.10" ]; |
| 837 | }; |
| 838 | ``` |
| 839 | |
| 840 | Set `allowedAddresses` to the receiver's IP addresses. The unit allows connections only to addresses |
| 841 | on that list, permits any port on a listed address, and checks only the destination IP address. When |
| 842 | the receiver changes to a new address, passes fail until `allowedAddresses` includes it. The |
| 843 | publisher connects to the receiver directly and ignores `HTTP_PROXY` and `HTTPS_PROXY`. |
| 844 | |
| 845 | On NixOS, name lookups go through the C library to `nscd` (`services.nscd.enable`, enabled by |
| 846 | default), which queries DNS outside the unit. If `nscd` is disabled, add the resolver address from |
| 847 | `/etc/resolv.conf` to `allowedAddresses` as well. |
| 848 | |
| 849 | Before each pass, `valley-web-publish-egress-check` verifies that the IP filter is active by sending |
| 850 | a UDP datagram to `198.51.100.1` and starting the pass only when the filter blocks it. Leave |
| 851 | `198.51.100.1` out of `allowedAddresses`, and ensure the host has a route to it, such as a default |
| 852 | route. If the check stops the pass, `journalctl -u valley-web-publish` logs the reason from |
| 853 | `valley-web-publish-egress-check`. |
| 854 | |
| 855 | Run the publisher once to generate the export signing key and read its verifier line: |
| 856 | |
| 857 | ```sh |
| 858 | sudo systemctl start valley-web-publish |
| 859 | sudo cat /var/lib/valley-web-publish/verifier |
| 860 | ``` |
| 861 | |
| 862 | Until the receiver pins that verifier line, it refuses every upload with `bad-signature` and the |
| 863 | publisher pass fails. |
| 864 | |
| 865 | On an edge host running NixOS, enable `services.valley.webReceiver`. Configure `listen` on the |
| 866 | address the publisher reaches and `webListen` behind the reverse proxy that serves the edge's public |
| 867 | domain: |
| 868 | |
| 869 | ```nix |
| 870 | imports = [ the-valley.nixosModules.web-receiver ]; |
| 871 | services.valley.webReceiver = { |
| 872 | enable = true; |
| 873 | instance = "valley-host"; |
| 874 | destination = "example.org"; |
| 875 | verifiers = [ "valley-host/web-export+1a2b3c4d+AQ..." ]; |
| 876 | tokenFile = "/run/keys/valley-web-receiver-token"; |
| 877 | listen = "192.0.2.10:8081"; |
| 878 | webListen = "127.0.0.1:8080"; |
| 879 | origin = "https://example.org"; |
| 880 | }; |
| 881 | ``` |
| 882 | |
| 883 | Set `origin` to the public HTTPS origin that browsers send for the edge: `https://` and a lowercase |
| 884 | host, plus a port when the port is not `443`. When `origin` is set, readers can sign in with read |
| 885 | links (see [Issue and revoke read links](#issue-and-revoke-read-links)), and `valley-web` stores |
| 886 | their sessions in `/var/lib/valley-web/browser`. The module creates that directory with owner |
| 887 | `valley-web` and mode `0700`, and `valley-web` cannot write anywhere else. When `origin` is unset, |
| 888 | `valley-web` serves every request as `anyone`. Serve the origin over HTTPS, because the session |
| 889 | cookie has the `Secure` attribute and browsers store it only over HTTPS. |
| 890 | |
| 891 | On an edge host that does not run NixOS, build and load the container image from a checkout of |
| 892 | the-valley: |
| 893 | |
| 894 | ```sh |
| 895 | nix build .#valley-web-image |
| 896 | docker load < result |
| 897 | ``` |
| 898 | |
| 899 | `docker load` prints the image name and tag. Install the verifier line and a copy of the token where |
| 900 | the receiver's user (uid 990) can read them, then run two containers sharing one volume — writable |
| 901 | in `valley-web-receive` and read-only in `valley-web`: |
| 902 | |
| 903 | ```sh |
| 904 | sudo install -d -m 0750 -o 990 -g 990 /etc/valley-web |
| 905 | sudo install -m 0400 -o 990 -g 990 /run/keys/valley-web-receiver-token /etc/valley-web/token |
| 906 | echo 'valley-host/web-export+1a2b3c4d+AQ...' | sudo install -m 0444 -o 990 /dev/stdin /etc/valley-web/verifiers |
| 907 | |
| 908 | docker run -d --name valley-web-receive --user valley-web-receive \ |
| 909 | --memory 2g --memory-swap 2g \ |
| 910 | -v valley-web:/var/lib/valley-web -v /etc/valley-web:/etc/valley-web:ro \ |
| 911 | -p 192.0.2.10:8081:8081 valley-web:<tag> \ |
| 912 | valley-web-receive --state /var/lib/valley-web/store --listen :8081 \ |
| 913 | --instance valley-host --destination example.org \ |
| 914 | --verifiers /etc/valley-web/verifiers --token-file /etc/valley-web/token |
| 915 | |
| 916 | docker run -d --name valley-web --user valley-web \ |
| 917 | --memory 1g --memory-swap 1g --ulimit core=0 \ |
| 918 | -v valley-web:/var/lib/valley-web:ro -v valley-web-browser:/var/lib/valley-web/browser \ |
| 919 | -p 127.0.0.1:8080:8080 valley-web:<tag> \ |
| 920 | valley-web --state /var/lib/valley-web/store --listen :8080 --origin https://example.org |
| 921 | ``` |
| 922 | |
| 923 | A new `valley-web` volume inherits the owner and permissions of `/var/lib/valley-web` from the |
| 924 | image: the receiver's user with mode `0750`. `valley-web` reads that volume through the shared |
| 925 | group. The second volume, `valley-web-browser`, holds the browser state and is the only directory |
| 926 | `valley-web` writes. A new volume mounted at `/var/lib/valley-web/browser` inherits its owner and |
| 927 | permissions from the image: `valley-web`'s user (uid 991, gid 990) with mode `0700`. The receiver's |
| 928 | container does not mount `valley-web-browser`. `valley-web` holds link secrets and session tokens in |
| 929 | memory; it marks its own process non-dumpable, and `--ulimit core=0` disables core dumps for the |
| 930 | container as well. If an existing `valley-web` volume lacks a `browser/` directory for the mount |
| 931 | point, create it once on the host before starting `valley-web`: |
| 932 | |
| 933 | ```sh |
| 934 | sudo install -d -m 0700 -o 991 -g 990 "$(docker volume inspect -f '{{.Mountpoint}}' valley-web)/browser" |
| 935 | ``` |
| 936 | |
| 937 | A bind mount used in place of either volume needs the same owner and mode. Omit |
| 938 | `-v valley-web-browser:…` and `--origin` to serve `anyone` alone. Both containers take the store |
| 939 | descriptor `/var/lib/valley-web/store`, which the receiver creates on its first start. When |
| 940 | upgrading from a release where `--state` was a directory, stop the old receiver, start the new one, |
| 941 | and upgrade the host after the edge (see |
| 942 | [Upgrading the edge and the host](./reference.md#upgrading-the-edge-and-the-host)). Then delete the |
| 943 | first layout's state from the volume by hand: `active`, `high-water`, `exports/`, `staging/`, |
| 944 | `trash/` and `lock`, beside the descriptor. Leaving them is harmless, because the first layout held |
| 945 | public projects only. |
| 946 | |
| 947 | Give each container its own memory limit. When a container reaches `--memory`, the kernel reclaims |
| 948 | memory or kills a process inside that container alone. Setting `--memory-swap` equal to `--memory` |
| 949 | disables swap for the container, matching the NixOS module's units. A limit keeps a spike in one |
| 950 | container from taking the other's memory or the host's only when the host has room for both limits |
| 951 | and for its own work. So keep the sum of both limits below the host's physical memory, with explicit |
| 952 | headroom left for the host's own work. The `2g` and `1g` limits above match the module's defaults |
| 953 | for `receiverMemoryMax` and `webMemoryMax`; sizing them for the edge's uploads and readers is a |
| 954 | deployment choice. |
| 955 | |
| 956 | The receiver caps the state directory at `--max-storage` (8 GiB by default). Because `--max-storage` |
| 957 | is best effort, place the state directory on a fixed-size filesystem or under a disk quota slightly |
| 958 | larger than `--max-storage` (see [Bounds](./architecture.md#bounds)). For containers, apply that |
| 959 | bound to the filesystem backing the volume. On NixOS, mount a bounded filesystem at the receiver's |
| 960 | state directory (`/var/lib/valley-web` by default). |
| 961 | |
| 962 | Because every upload request carries the token, reach the receiver over HTTPS, through a reverse |
| 963 | proxy that terminates TLS, or over a private network. On the next pass, the publisher prints |
| 964 | `the receiver stored authorization <n>`, then `the receiver activated sequence <n>`, and |
| 965 | `valley-web` serves the export. |
| 966 | |
| 967 | To take a project off the web at once, withdraw every reader's grant for it, or remove every reader |
| 968 | from its `policy/read`, and start a pass: `sudo systemctl start valley-web-publish`. A project stays |
| 969 | on the edge while any reader may still read it, so removing one reader keeps the project for the |
| 970 | others. The pass sends its authorization before doing any content work, and the edge stops serving |
| 971 | the project at the next request, even if the content work stalls or fails. Running |
| 972 | `valley-web-publish --policy-only` with the unit's other flags sends only the authorization. |
| 973 | |
| 974 | ### Issue and revoke read links |
| 975 | |
| 976 | A read link lets one person read, at the edge, what one registry principal may read there. The |
| 977 | principal needs an edge-read grant in the registry and a project whose `policy/read` names it. A |
| 978 | reader who signs nothing may hold no keys, as long as every grant it holds is an edge read. Run |
| 979 | these commands as root on the valley host: |
| 980 | |
| 981 | ```bash |
| 982 | valley-web-link issue --principal alice --note laptop |
| 983 | ``` |
| 984 | |
| 985 | The command refuses a principal who may read no project at the destination. Otherwise, it prints the |
| 986 | link once, such as `https://example.org/-/redeem#lk-0123456789abcdef.<secret>`. Send it to its |
| 987 | holder over a private channel. The host keeps no copy of the secret. |
| 988 | |
| 989 | After the next pass delivers the link to the edge, the holder opens it in a browser and clicks |
| 990 | **Continue as reader**. That redeems the link once and starts a session in the browser. To switch to |
| 991 | a new link in a browser that is already signed in, open the new link and click **Sign out and |
| 992 | continue with this link**. Clicking **Sign out** in the navigation ends the session, and signing in |
| 993 | again requires a new link. If the page cannot tell whether the server used the link, click the |
| 994 | button again to retry. If the earlier attempt started a session, the retry continues to `/`; if the |
| 995 | server reports that the link cannot be used, issue a new link. |
| 996 | |
| 997 | After signing in, the browser goes to `/`. A reader who may read more than one project lands on the |
| 998 | projects page, `/-/projects`, which lists each project they may read under its group. Each entry |
| 999 | links to the project's source and to its knots. A reader who may read exactly one project lands on |
| 1000 | that project's source instead. Every page of a project has a header that names it as |
| 1001 | `<group>/<project>`, with two tabs: **source** and **knots**. The **projects** link at the top of |
| 1002 | every project page and every listing page returns to the list. The list's **all knots** link shows |
| 1003 | the knots of every project the reader may read (see |
| 1004 | [Web server (`valley-web`)](./reference.md#web-server-valley-web) for the routes). |
| 1005 | |
| 1006 | ```bash |
| 1007 | valley-web-link list |
| 1008 | valley-web-link revoke lk-0123456789abcdef |
| 1009 | valley-web-link revoke --principal alice |
| 1010 | valley-web-link revoke --all |
| 1011 | ``` |
| 1012 | |
| 1013 | After every issue or revoke, the command starts a policy pass and reports every link whose delivery |
| 1014 | is still `pending`. If a link is pending after that pass, it starts the pass once more. `enforced` |
| 1015 | means the receiver acknowledged an authorization that reflects the link's current state. If a link |
| 1016 | is still `pending`, the command exits 1. A revoked link still works at the edge until a pass |
| 1017 | delivers the revocation. Check `journalctl -u valley-web-publish-policy`, then run the same command |
| 1018 | again: a repeated `revoke` retries the delivery. |
| 1019 | |
| 1020 | A command that changes links waits for a policy pass that is reading the links and signing, for up |
| 1021 | to a minute, and says so while it waits. If the wait runs out, the command exits 1 having changed |
| 1022 | nothing. Run it again. |
| 1023 | |
| 1024 | Restoring the valley host from a backup restores the read links as they were at the backup. A link |
| 1025 | revoked after the backup works again once the next pass delivers it. To cut off every link after a |
| 1026 | restore, revoke them all, then issue new links to the people who should keep access: |
| 1027 | |
| 1028 | ```bash |
| 1029 | valley-web-link revoke --all |
| 1030 | valley-web-link issue --principal alice --note laptop |
| 1031 | ``` |
| 1032 | |
| 1033 | `valley-web` creates `browser/state` only when the stored authorization has no link bindings. Any |
| 1034 | link issued before `browser/state` exists cannot be redeemed. Follow these steps when enabling |
| 1035 | reader sign-in for the first time, or after the edge loses `browser/state` or its whole state |
| 1036 | directory: |
| 1037 | |
| 1038 | 1. Run `valley-web-link revoke --all` to revoke every link and deliver an authorization with no |
| 1039 | bindings. |
| 1040 | 2. Confirm that `browser/state` exists in the edge's state directory. `valley-web` creates it when |
| 1041 | it starts or on the first request after that authorization arrives. |
| 1042 | 3. Issue new links. |
| 1043 | |
| 1044 | If `valley-web` logs that the browser state is unavailable, it serves requests without a session |
| 1045 | cookie as `anyone` and answers `503` to requests that carry the session cookie. `valley-web` never |
| 1046 | overwrites an unreadable `browser/state`. To recover, run `valley-web-link revoke --all`, stop |
| 1047 | `valley-web`, remove `browser/state`, start `valley-web` again, and issue new links. |
| 1048 | |
| 1049 | Revoked links stay in the credential file until you prune them: |
| 1050 | |
| 1051 | ```bash |
| 1052 | valley-web-link prune |
| 1053 | ``` |
| 1054 | |
| 1055 | `prune` removes every revoked link whose revocation is `enforced`, and keeps those still `pending`. |
| 1056 | It starts no policy pass, since the edge already refuses every link it removes. The file holds at |
| 1057 | most 1 MiB. `issue` refuses once the file would come within 64 KiB of that, and says to prune. |
| 1058 | `revoke` is never refused for the file's size. |
| 1059 | |
| 1060 | To pause a principal's access without revoking links, set or shorten its `expires` in the registry. |
| 1061 | Its links stop working after the next policy pass past that day, and extending the date restores |
| 1062 | them. |
| 1063 | |
| 1064 | ## Contributing to the-valley |
| 1065 | |
| 1066 | Contributors work in a checkout of this repository. Read [AGENTS.md](../AGENTS.md) before editing. |
| 1067 | You can enter the default package's build environment: |
| 1068 | |
| 1069 | ```sh |
| 1070 | nix develop |
| 1071 | ``` |
| 1072 | |
| 1073 | This flake defines no dedicated development shell. `nix develop` does not supply the full toolchain. |
| 1074 | For the CLI and Go work, use an explicit tool shell from the repository root: |
| 1075 | |
| 1076 | ```sh |
| 1077 | nix shell .#valley .#attest --inputs-from . nixpkgs#go nixpkgs#cue |
| 1078 | ``` |
| 1079 | |
| 1080 | Each Go component has its own module. Run fast tests from the component you changed, for example: |
| 1081 | |
| 1082 | ```sh |
| 1083 | (cd status && go test ./...) |
| 1084 | ``` |
| 1085 | |
| 1086 | There is no root Go module. To test every Go module from the repository root: |
| 1087 | |
| 1088 | ```sh |
| 1089 | for module in attest change composed delta identity integrator knot note rebase restack selfupdate sigverify status valleyhook; do |
| 1090 | (cd "$module" && go test ./...) || exit 1 |
| 1091 | done |
| 1092 | ``` |
| 1093 | |
| 1094 | In Nix, building a Go package does not run its unit tests. Those tests run only in the module's |
| 1095 | `*-unit` check, such as `valleyhook-unit` for `valleyhook/` or `valley-go-unit` for `status/`: |
| 1096 | |
| 1097 | ```sh |
| 1098 | nix build --no-link .#checks.x86_64-linux.valleyhook-unit -L |
| 1099 | ``` |
| 1100 | |
| 1101 | Run a single Nix check by name. For documentation, format first, then check formatting, links, and |
| 1102 | the style rules, then the policy that selects checks: |
| 1103 | |
| 1104 | ```sh |
| 1105 | nix run .#fmt |
| 1106 | nix build --no-link .#checks.x86_64-linux.prose-format -L |
| 1107 | nix build --no-link .#checks.x86_64-linux.own-policy -L |
| 1108 | ``` |
| 1109 | |
| 1110 | Stage new Markdown files before formatting so the formatter sees them. Review the diff afterward. |
| 1111 | Use [nix/checks](../nix/checks/) to find the integration checks for the component you changed. Run |
| 1112 | them one at a time; VM checks need the virtualization facilities their definitions specify. The full |
| 1113 | flake suite is invoked with `nix flake check` when your task permits it and the machine can run all |
| 1114 | its checks. |
| 1115 | |
| 1116 | Each check is given only the files it reads. [nix/checks.nix](../nix/checks.nix) and |
| 1117 | [nix/packages.nix](../nix/packages.nix) narrow each source to those files with `lib.fileset`. An |
| 1118 | edit to any other file leaves the check's derivation unchanged, so the check's evidence transfers to |
| 1119 | the edited tree. When a check starts to read a new file, give the check that file. The sandbox fails |
| 1120 | a check that reads a file it was not given. |
| 1121 | |
| 1122 | Editing a Go test changes only that module's `*-unit` check, not the other checks that use the |
| 1123 | package. A Go package's source leaves out test files, and its `*-unit` check adds them back. |
| 1124 | |
| 1125 | The NixOS host module uses three of the flake's programs: the integrator, the identity compiler, and |
| 1126 | `valleyhook`. Four checks test what the module renders without running those programs: |
| 1127 | `module-eval`, `mirror-e2e`, `bus-e2e`, and `init-e2e`. Those checks render the module with stand-in |
| 1128 | scripts in place of the three programs ([nix/checks/hosts.nix](../nix/checks/hosts.nix)), so editing |
| 1129 | one of the programs leaves those four checks unchanged. Checks that run one of the programs use the |
| 1130 | real package. |
| 1131 | |
| 1132 | To see which checks an edit gives a new derivation, run the measurement script on a commit: |
| 1133 | |
| 1134 | ```sh |
| 1135 | nix/tools/drv-churn.sh --expect nix/tools/drv-churn.expected |
| 1136 | ``` |
| 1137 | |
| 1138 | It applies a fixed list of representative edits to the commit's tree, one at a time, and evaluates |
| 1139 | every check's derivation after each. With `--expect`, it fails if any edit changes other checks than |
| 1140 | the recorded table says. When a change means to alter the table, write the new one with `--write`. |
| 1141 | With `--history origin/main~20..origin/main` instead, it replays the paths each of those commits |
| 1142 | touched. Run `nix/tools/drv-churn.sh --help` for every option. |
| 1143 | |
| 1144 | The [architecture](./architecture.md) explains component invariants and the checks that cover them. |
| 1145 | The [reference](./reference.md) documents CLI flags, ref bounds, wire formats, JSON outputs, and |
| 1146 | [schema](../schema/) definitions alongside the [concept glossary](./concepts.md#glossary). |