Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/host-promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# host's deploy/<host> branch per run and records what it did on the
# rollout-state branch; the fleet's flake provides `rolloutPlan`
# (nixos-modules.lib.rolloutPlan). It reads the cluster with the kubeconfig
# it's given and never writes to it. Without `apply` it's a dry run.
# it's given and never writes to it. Without `apply` it's a dry run; with it,
# the discord-webhook secret is required: a run without one fails before it
# reads anything, as nobody would hear of a move or a halt.
#
# The caller runs it on a schedule for every environment, and by hand for
# resume, abandon and approve:
Expand Down Expand Up @@ -38,8 +40,10 @@
# kubeconfig: ${{ matrix.environment == 'staging' && secrets.KUBECONFIG_STAGING || matrix.environment == 'production' && secrets.KUBECONFIG_PRODUCTION || '' }}
# discord-webhook: ${{ secrets.CI_WEBHOOK }}
#
# Runs of one environment never overlap (the concurrency group), which
# rollout-state's writes rely on. GitHub cancels a run that is waiting in the
# Runs of one environment never overlap (the concurrency group); one started
# elsewhere, such as by hand, can, and a run that finds its environment's
# rollout-state changed since it read it stops without pushing rather than
# drop the other's move. GitHub cancels a run that is waiting in the
# group when another one queues: a scheduled run the next one repeats, but
# also a resume, abandon or approve dispatched while a run is in progress.
# Check that a manual run ran, and dispatch it again if it was cancelled.
Expand Down Expand Up @@ -71,7 +75,7 @@ on:
description: A read-only kubeconfig for the environment's cluster
required: true
discord-webhook:
description: A plain Discord webhook URL (https://discord.com/api/webhooks/<id>/<token>) for the notices; a URL of any other form, such as one ending in /slack, fails the run before it does anything, and a notice the webhook refuses fails the run
description: A plain Discord webhook URL (https://discord.com/api/webhooks/<id>/<token>) for the notices. A run with apply and no URL, or any run with a URL of another form (such as one ending in /slack), fails before it does anything; a dry run needs none. A notice the webhook refuses fails the run
required: false
jobs:
promote:
Expand Down
143 changes: 131 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ is [tests/server.nix](tests/server.nix).
| `static-network` | a static, MAC-matched uplink with systemd-networkd |
| `digitalocean` | a droplet installed with nixos-anywhere over one of DigitalOcean's own images: disko's layout on `/dev/vda` (a BIOS boot partition for GRUB, ext4 root), and both NICs from the droplet metadata, reached over link-local as cloud-init does, since DigitalOcean serves DHCP only to custom images. The public NIC gets IPv4, the anchor IP, IPv6, default routes and DNS; the VPC NIC its address and routes to other private networks; MACs are checked first, before `network-online.target`, and the unit is an outside health check. Nothing runs from user data or vendor data; the droplet's SSH keys log in only to `metadataKeysUser`, if set. Droplets have no hardware watchdog, so reboot trials run without one |
| `raid1-disks` | disko layout: mdadm RAID1 for the ESP and root on every listed disk (the root RAID0 with `rootLevel = 0`), GRUB on each |
| `updater` | `ethpandaops.updater`, for one dedicated host: jobs on timers against GitHub repositories, which hold no credential and push only through the pusher ([updater/](updater)), the one process with the GitHub App keys. Each task (`updater-<repository>-<task>`) runs as its repository's own user, fetches with a read token the pusher gives it, holds while the hold file is on the default branch, and runs its command at the default branch's tip, which calls `updater-push` for each ref it wants moved. The pusher answers only the deciders' group, tells the repository from the caller's uid and the task from its unit, and checks every update against the task's rules: its refs, the remote's ref unmoved, fast-forwards only outside the proposal prefix, deploy branches only to commits on the default branch with a system the host built, changed paths within the task's (except on state branches no host applies), and a flake.lock that keeps its inputs and their sources. Each of a task's refs is exactly one class (the default branch, a proposal, a deploy branch or a state branch), which decides its rules: evaluation fails for a ref in none or in two, and for a state branch or proposal prefix that could hold a branch hosts apply by default. Then it pushes with a token for that repository alone, or with `apply = false` answers what it would push. It also opens, updates and closes the pull request (or, where pull requests can't be opened, the issue) proposing a branch under the task's proposal prefix into the default branch (`updater-propose`), with a token for that repository's pull requests and issues. The daily jobs in `ci/` run as tasks ([below](#as-updater-tasks)). `updater_*` metrics: each task's outcome, last run and last success, and the pusher's refusals |
| `updater` | `ethpandaops.updater`, for one dedicated host: jobs on timers against GitHub repositories, which hold no credential and push only through the pusher ([updater/](updater)), the one process with the GitHub App keys. Each task (`updater-<repository>-<task>`) runs as its repository's own user, fetches with a read token the pusher gives it, holds while the hold file is on the default branch, and runs its command at the default branch's tip, which calls `updater-push` for each ref it wants moved. The pusher answers only the deciders' group, tells the repository from the caller's uid and the task from its unit, and checks every update against the task's rules: its refs, the remote's ref unmoved, fast-forwards only outside the proposal prefix, deploy branches only to commits on the default branch with a system the host built, changed paths within the task's (except on state branches no host applies), and a flake.lock that keeps its inputs and their sources. Each of a task's refs is exactly one class (the default branch, a proposal, a deploy branch or a state branch), which decides its rules: evaluation fails for a ref in none or in two, and for a state branch or proposal prefix that could hold a branch hosts apply by default. Then it pushes with a token for that repository alone, or with `apply = false` answers what it would push. It also opens, updates and closes the pull request (or, where pull requests can't be opened, the issue) proposing a branch under the task's proposal prefix into the default branch (`updater-propose`), with a token for that repository's pull requests and issues. A task's secrets (`credentials`) reach it as files systemd loads for its unit alone, each named by `<name>_FILE`; no task can read the files themselves. The daily jobs in `ci/` run as tasks ([below](#as-updater-tasks)), and so does the promoter ([below](#the-promoter-as-an-updater-task)). `updater_*` metrics: each task's outcome, last run and last success, and the pusher's refusals |

Every box-side check writes `nixhost_*` metrics through node-exporter's
textfile collector; alert rules live with the scraper.
Expand Down Expand Up @@ -166,9 +166,11 @@ A task holds no credential, so there:
The task's policy has to allow what the job writes: `refs` with the default
branch for `mode: push` and the proposal prefix for proposals, and `paths`
for its files (`flake.lock`, `keys/*.keys`, the whitelist, the `.nix` files
that pin the kernel). refresh-keys still needs its `WEBHOOK`, a secret the
module has no option for yet: a task's `environment` is in the Nix store,
which every user on the host can read.
that pin the kernel). refresh-keys takes its webhook as the task's
credential `WEBHOOK` (`credentials.WEBHOOK = "/run/secrets/…"`), which it
reads from `WEBHOOK_FILE`: a task's `environment` is in the Nix store, which
every user on the host can read, but a credential is a file systemd loads
for that task's unit alone.

Either way, a run can be replayed at the inputs it had: `UPDATER_NOW`
(epoch seconds) is the clock every cutoff and date is taken at, and
Expand Down Expand Up @@ -230,10 +232,16 @@ moving one `deploy` branch for all: environment by environment (staging, then
production), canaries first, then groups in order, with `last` groups at the
end. Each host pulls its own `deploy/<host>` branch, and the promoter
(`rollout/promoter`, run by `host-promote.yaml`) is the only writer of those
branches and of `rollout-state`, where it keeps what it did. It reads each
host's state from the annotations `node-report` writes on its Node, so every
host sets `ethpandaops.kubernetes`. It never writes to a cluster: comin
applies the commit, and kured drains and reboots.
branches and of `rollout-state`, where it keeps what it did. A run that
finds its environment's `rollout-state` changed since it read it (another
run of the same environment, by hand or on a second runner) stops without
pushing. It reads each host's state from the annotations `node-report`
writes on its Node, so every host sets `ethpandaops.kubernetes`. It never
writes to a cluster: comin applies the commit, and kured drains and reboots.
A run that moves anything (`--apply`) needs a webhook for its notices
(`ROLLOUT_DISCORD_WEBHOOK`, host-promote's `discord-webhook`) and refuses to
start without one; `ROLLOUT_RUN_URL` gives the notices a link to the run's
log where it isn't a GitHub Actions run.

- **Where a host stands:** `ethpandaops.rollout.{group,canary,lead}` and
`ethpandaops.host.environment`. The fleet's flake exports
Expand All @@ -258,17 +266,128 @@ applies the commit, and kured drains and reboots.
time budget in a state (deploy, kured's lock, drain, boot, readiness), a
failed readiness check, a health check failing with the rollback breaker
open, the cluster staying worse than when the roll started, a target that
fails provenance or doesn't evaluate, and a `testing-*` branch. A person
resumes, abandons the target, or lands a fix; `rollout/hold` on the source
branch pauses it.
fails provenance or doesn't evaluate, and a `testing-*` branch. A cluster
API that doesn't answer (a single server rebooting) counts as the host in
flight not being back: it waits on the budget of the state the host was
last seen in, then halts. A person resumes, abandons the target, or lands
a fix; `rollout/hold` on the source branch pauses it. A halt posts again
every `budgets.repost` minutes (240) until a person acts, and so does a
wait past `waitNotice` while it lasts.
- **What fails a run without moving anything:** a cluster API that doesn't
answer with no host in flight, and an environment whose installed hosts in
the plan have none of their deploy branches on the remote (the wrong
remote, the branches deleted, a token that can't read them), and a
`lib.mkFleet` host that's installed (its `host.json`; `fleet install`
pushes the branch first) without its deploy branch, which converging would
otherwise skip. One that isn't installed yet has no branch to look for.
- **Between environments:** a later one takes a commit only after the one
before converged on it and its promote soak passed for the worst class
across both; a commit that changes it more than the one before saw waits
for `approve`. Only a range of `Urgency:` commits with evidence (a
for `approve`, and so does every commit for an environment listed in
`approveEvery`. Only a range of `Urgency:` commits with evidence (a
nixpkgs-only security fix, or a revert that restores the last converged
systems, signed where the hosts require it) shortens soaks or preempts a
roll.

### The promoter as an updater task

The promoter also runs as a task of `nixosModules.updater`, which sets
`UPDATER_TASK`; without it, in GitHub Actions, it issues the same git
pushes and gh reads as before (`rollout/promoter/test_promote.py` holds it
to a recording). As a task it holds no credential, so:

- nothing fetches: it reads the branches as the run's own fetch left them;
- gh reads with the pusher's read token, in gh's own environment alone;
- a deploy branch moves through `updater-push`, from where the run read it,
with `--toplevel` the system it built for that host at the target;
- `rollout-state` moves the same way, from the commit the write was built
on. A refusal stops the run without pushing anything: it can't fetch to
rebuild, and the next run starts from a fresh fetch. So run every
environment of a fleet, in order, in one task, as the workflow's matrix
does: its own runs never race, and a refusal means a run outside it,
such as one by hand, wrote first. Create `rollout-state` once beforehand
(any commit will do): the pusher creates no branch outside a proposal
prefix;
- with the repository's `apply = false` every write answers dry-run, and the
run succeeds having moved nothing and posted nothing;
- its notices say to ask for `resume`, `abandon` and `approve` with the
request workflow, below, rather than the promote workflow.

The webhook and kubeconfig are the task's credentials:

```nix
ethpandaops.updater.repositories.fleet-a.tasks.promote = {
schedule = "*:0/10";
# requests first, so a resume is in the state the runs read.
command = [ "bash" "-c" ''
promote() { nix run --inputs-from . nixos-modules#host-promote -- "$@"; }
status=0
promote requests --requesters ${requesters} \
--context staging=staging --context production=production --apply || status=1
promote --env staging --context staging --apply || status=1
promote --env production --context production --apply || status=1
exit $status
'' ];
refs = [ "refs/heads/deploy/*" "refs/heads/rollout-state" ];
deployRefs = [ "refs/heads/deploy/*" ];
stateRefs = [ "refs/heads/rollout-state" ];
credentials = {
ROLLOUT_DISCORD_WEBHOOK = config.sops.secrets.promoter-webhook.path;
KUBECONFIG = config.sops.secrets.promoter-kubeconfig.path;
};
# kubectl takes the file's path in KUBECONFIG; %d is the unit's
# credentials directory.
environment.KUBECONFIG = "%d/KUBECONFIG";
};
```

`requesters` is a file of the GitHub logins that may ask, one per line (`#`
comments), from the updater host's own configuration, such as
`pkgs.writeText "requesters" "alice\nbob\n"`: never from the fleet
repository, which anyone who can push to it could change.

**Asking without GitHub Actions runners.** GitHub's "Run workflow" button
runs the promote workflow on a runner; with the promoter on the updater, a
person dispatches a request workflow instead, whose one job never runs, so
it needs no runner:

```yaml
# .github/workflows/request.yaml, on the default branch
name: request
run-name: ${{ inputs.environment }} ${{ inputs.action }}${{ inputs.commit && format(' {0}', inputs.commit) || '' }}
on:
workflow_dispatch:
inputs:
environment: { type: choice, options: [staging, production] }
action: { type: choice, options: [resume, abandon, approve] }
commit: { description: "approve: the full commit id", type: string, default: "" }
permissions: {}
jobs:
# The request is the run's name: the job never runs (dispatch is the
# only event), so no runner is needed.
request:
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- run: "true"
```

`host-promote requests` lists that workflow's runs and acts on each once,
oldest first, through `--action`, naming who asked in the notice. It takes
a run only when it was dispatched on the default branch from that file
there, by a login in the requesters file who also triggered it, under
`--max-age-hours` (24) ago, with a run-name of exactly
`<environment> resume`, `<environment> abandon` or
`<environment> approve <full commit id>`. The run's id goes into the
environment's state in the same write as the action, so neither another
pass nor a rebuilt updater host acts on it twice; one it refuses gets one
notice saying who asked for what and why not, and its id goes into
`_requests.json` on the state branch. Each record keeps the last 200 ids,
and a run older than the window is never acted on, which bounds what a lost
record could replay. Runs on other branches, from other events or other
files are ignored. Without `--apply` it says what it would do. It runs with
a plain gh token too, outside the updater.

### Alarms

`node-report` writes what the host finds wrong with itself as
Expand Down
19 changes: 19 additions & 0 deletions ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ updater_read_token() {
fi
}

# from_file <name>: when the variable is empty and <name>_FILE names a file,
# the variable gets the file's content, unexported, so no command's
# environment carries it: an updater task's secrets arrive as files
# (nixosModules.updater's credentials, <name>_FILE in the credentials
# directory), never in its environment. A file that can't be read fails.
# Otherwise, as in GitHub Actions, nothing changes.
from_file() {
local from_file_var="$1_FILE" from_file_value
if [ -n "${!1:-}" ] || [ -z "${!from_file_var:-}" ]; then
return 0
fi
if ! from_file_value=$(cat -- "${!from_file_var}"); then
echo "::error::$from_file_var names ${!from_file_var}, which can't be read"
return 1
fi
printf -v "$1" '%s' "$from_file_value"
export -n "${1?}"
}

# utc <format> [relative]: date -u, now or at the relative time from now
# ("-24 hours"). Now is UPDATER_NOW (epoch seconds) when it's set: a run's
# clock is one of its inputs, so it can be replayed later as it ran.
Expand Down
12 changes: 7 additions & 5 deletions ci/refresh-keys.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# refresh-keys --host <host> [--branch master] [--mode push|pr]: refresh
# keys/<login>.keys from github.com/<login>.keys for the people already
# listed (never adding or removing anyone), build the host, commit and land
# it (lib.sh), which starts check. WEBHOOK (a plain Discord webhook URL)
# gets every change and problem; without it, or with a URL of another form,
# the run fails before it changes anything rather than change keys
# unannounced. RUN_URL links the notice to the run.
# it (lib.sh), which starts check. WEBHOOK (a plain Discord webhook URL),
# or else the file WEBHOOK_FILE names (an updater task's credential
# WEBHOOK), gets every change and problem; without it, or with a URL of
# another form, the run fails before it changes anything rather than change
# keys unannounced. RUN_URL links the notice to the run.
#
# keys/github-ids.json pins each login to its GitHub account ID, so a renamed
# account whose old name someone else registers doesn't hand them a login.
Expand Down Expand Up @@ -36,8 +37,9 @@ if [ -z "$host" ]; then
echo "refresh-keys: --host is required" >&2
exit 2
fi
from_file WEBHOOK || exit 1
if [ -z "${WEBHOOK:-}" ]; then
echo "::error::No webhook: pass one as host-refresh-keys' webhook secret (CI_WEBHOOK in its example). Key changes aren't deployed without a notice."
echo "::error::No webhook: pass one as host-refresh-keys' webhook secret (CI_WEBHOOK in its example), or as an updater task's credential WEBHOOK. Key changes aren't deployed without a notice."
exit 1
fi
if ! discord_webhook "$WEBHOOK"; then
Expand Down
2 changes: 1 addition & 1 deletion fleet/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ ci_webhook_secret() {
return 2
}
jq -e 'any(.secrets[]; .name == "CI_WEBHOOK")' <<<"$s" >/dev/null || {
echo "no CI_WEBHOOK secret: refresh-keys fails without it"
echo "no CI_WEBHOOK secret: refresh-keys and the promoter's applying runs fail without it"
echo "fix: fleet secrets ci-webhook"
return 1
}
Expand Down
Loading
Loading