.gitbay/wiki/Admin.org

f8b976a97290a20d552056a999511f5d27d8e8ec
gitbay/.gitbay/wiki/Admin.org rendered · source · history · blame · raw

1038 lines · 54015 bytes

   1#+title: gitbay admin guide
   2
   3One static binary (=gitbayd=), one SQLite file, bare repositories on
   4disk, and the system =git=. Schema migrations run automatically on
   5startup and on every admin command.
   6
   7* Install
   8
   9Build from source (=go build ./cmd/gitbayd=), install via the vanity
  10module path (=go install gitbay.org/gitbay/cmd/gitbayd@latest=), or use
  11a release build: =deploy/release.sh <tag>= cross-compiles reproducible
  12linux/amd64, linux/arm64, and darwin/arm64 binaries with a SHA256SUMS
  13manifest (CGO off, trimpath, stripped — byte-identical per commit and
  14toolchain).
  15
  16#+begin_src sh
  17install -m 755 gitbayd /usr/local/bin/
  18adduser --system --group --home /var/lib/gitbay --shell /usr/sbin/nologin gitbay
  19install -d -o gitbay -g gitbay -m 750 /var/lib/gitbay
  20gitbayd --config /etc/gitbay/config.toml check-config
  21gitbayd --config /etc/gitbay/config.toml admin secrets init
  22chown gitbay:gitbay /etc/gitbay/secret.key
  23#+end_src
  24
  25=admin secrets init= refuses when the key file already exists, so a
  26reinstall on the same host should skip it — =deploy/install.sh= does
  27this with a file check before running it.
  28
  29=deploy/= in the source tree has a cloud-init file, a hardened systemd
  30unit, and a nightly backup timer. Run as the unprivileged =gitbay= user;
  31the unit's =AmbientCapabilities=CAP_NET_BIND_SERVICE= covers ports
  3222/80/443 without root.
  33
  34** The SSH port decision
  35
  36- =ssh.mode = "embedded"= (default): gitbayd itself listens, normally on
  37  22 — move the host's admin sshd to another port. Remotes read
  38  =git@host:owner/repo= with no port gymnastics.
  39- =ssh.mode = "system"=: the host sshd owns 22 and invokes gitbayd via
  40  =AuthorizedKeysCommand=:
  41  #+begin_example
  42  AuthorizedKeysCommand /usr/local/bin/gitbayd --config /etc/gitbay/config.toml authorized-keys %t %k
  43  AuthorizedKeysCommandUser gitbay
  44  #+end_example
  45  sshd requires that binary to be root-owned and not group/world
  46  writable. Unknown keys fail authentication inside sshd, so system mode
  47  requires =registration.mode = "closed"= (check-config enforces this).
  48  Under the forced command the CLI's leading =--term=<cols>[,color]=
  49  argument works as is; a client that sets =GITBAY_TERM= instead needs
  50  =AcceptEnv GITBAY_TERM= in =sshd_config=, since that env request is
  51  handled by the host's sshd, not gitbayd.
  52
  53* Configuration reference
  54
  55=/etc/gitbay/config.toml=. =check-config= validates and names every
  56contradiction; =--no-host-checks= skips port/path probes.
  57=gitbayd admin config show= prints the configuration in effect as TOML,
  58every default filled in and =smtp_pass= redacted. A file that fails
  59validation still prints, followed by the contradiction.
  60
  61** [server]
  62- =root= (default =/var/lib/gitbay=) — repositories, database, host
  63  keys, ACME cache all live here.
  64- =site_url= (required) — canonical =https://host=; drives ACME, clone
  65  URLs, mail links.
  66- =secret_key_file= (default =/etc/gitbay/secret.key=) — the keys that
  67  seal CI secrets, webhook secrets, mirror tokens and push device
  68  tokens in the database. Must be outside =root=, mode 0600, readable
  69  by the daemon's user. See "Secret key" below.
  70- =source_repo= (optional, =owner/name=) — the repository this instance
  71  develops itself in. Startup warns when the running build's commit is
  72  not on that repository's default branch, which is how a binary built
  73  from an unmerged branch stops being invisible. Leave it unset unless
  74  the instance hosts its own source.
  75
  76** [ssh]
  77- =mode= — =embedded= | =system= (above).
  78- =port= (22) — embedded listener port.
  79- =host_keys= — list of private key paths; empty generates an ed25519
  80  key at =<root>/ssh/host_ed25519=.
  81
  82** [http]
  83- =addr= (=:443=), =tls= — =acme= | =files= | =off=.
  84- =acme=: certificates via TLS-ALPN-01 on the HTTPS port, cached at
  85  =<root>/acme=; =acme_email= for the CA account; =acme_http_addr=
  86  (=:80=, ="off"= to disable) adds HTTP-01 and an https redirect —
  87  failing to bind it is a warning, not fatal. Requires an =https://=
  88  site_url with a public DNS name.
  89- =files=: =cert_file= + =key_file=.
  90- =off=: plain HTTP — development, or behind a TLS-terminating proxy.
  91- The HTTPS listener accepts TLS 1.2 and 1.3 only (=serverTLS= in
  92  =cmd/gitbayd/tls.go=), with the default cipher suites of the Go
  93  release the binary was built with. =openssl s_client -connect
  94  <host>:443 -tls1_1= fails the handshake.
  95
  96=trusted_proxies= lists the addresses or CIDRs of reverse proxies in
  97front of the daemon. A request from one of them is attributed, for API
  98rate limiting, to the last =X-Forwarded-For= hop that is not itself a
  99trusted proxy; from anyone else the header is ignored. Empty, the
 100default, is right when gitbayd terminates TLS itself.
 101
 102A reverse proxy in front of gitbay must not buffer responses, or the
 103build page's live log arrives only when the build ends;
 104=X-Accel-Buffering: no= covers nginx.
 105
 106** [web]
 107- =mode= — =view_only= (default) | =accounts=. In view_only the mutating
 108  web routes are never registered; in accounts, browser sessions are
 109  minted over SSH (=web login=), and users with write access can create
 110  repos, comment, and make simple file edits (which commit unsigned,
 111  honestly). =password_auth= is reserved and currently rejected.
 112- =title= — the instance's display name in the rail and page titles;
 113  empty falls back to the site host. Lower case is the convention for
 114  gitbay itself.
 115- =privacy_notice= — operator text shown on =/privacy= under the fixed
 116  statement.
 117
 118** [registration]
 119- =mode= — =closed= (default) | =invite= | =open=. invite/open require
 120  [mail]. See the user guide for the flows.
 121
 122- =pending_expiry= (empty, never) — a duration such as ="168h"=; a
 123  self-registered account still unverified after that long is removed,
 124  hourly and at start, audited as =pending.expired=.
 125
 126- =notify_admin= (false) — mail every instance admin when an account
 127  becomes active: an invite redeemed, or an open-mode signup that
 128  verified its address. The unverified row an open signup creates is
 129  not reported, because anyone can post the form and mailing on that
 130  would point a flood at the admins. Recipients are the verified
 131  primary addresses of active admins who have activity mail on, the
 132  same rule any other notice follows, so an admin with no verified
 133  address hears nothing. The notice is queued, so a dead SMTP host
 134  shows up in the admin page's Mail table instead of failing the
 135  registration. Requires [mail].
 136
 137** [mail]
 138- =smtp_host= (host:port; 587 assumed, 465 with =tls = "implicit"=),
 139  =from=, optional =smtp_user= / =smtp_pass=. Required for invite/open
 140  registration and self-service =email add=; in closed mode you may omit
 141  it entirely and assert addresses by hand (below).
 142- =tls= — =starttls= (default) or =implicit= (TLS from the first byte,
 143  for relays on 465).
 144- =require_tls= — with =starttls=, a relay that does not offer STARTTLS
 145  gets no mail: delivery fails and retries, and the admin page's Mail
 146  table shows the error. Unset, it is on for every relay except
 147  =localhost= and loopback addresses; set =false= to allow plaintext
 148  to a remote relay.
 149
 150** [push]
 151Push notifications to Apple devices, delivered by gitbayd talking to
 152APNs directly over HTTP/2, authenticated by an ES256 JWT signed with an
 153operator-supplied provider key. Off unless configured.
 154
 155- =enabled= (false).
 156- =key_file= — path to the =.p8= provider key from Apple's developer
 157  portal (Certificates, Identifiers & Profiles → Keys). It belongs at
 158  =/etc/gitbay/apns.p8=, mode 0600, owned by the account gitbayd runs
 159  as. Read and validated at startup: it must parse as a PEM-wrapped
 160  PKCS#8 EC (P-256) private key, or the daemon refuses to start rather
 161  than fill a queue nobody is watching.
 162- =key_id=, =team_id= — the key's id and your Apple developer team id,
 163  both from the same portal page.
 164- =topic= — the app's bundle identifier. *An APNs key belongs to a
 165  bundle ID.* gitbay.org pushes to the App Store build under its own
 166  bundle id; a self-hoster who wants push ships their own iOS build
 167  under their own bundle id, with its own =.p8= key from their own
 168  developer account, and points =topic= at that id. There is no way to
 169  push to someone else's build, by design — this is Apple's model, not
 170  gitbay's.
 171- =environment= — =production= or =sandbox=, naming the APNs host
 172  rather than taking a URL, so a typo cannot aim the key at a host that
 173  is not Apple's.
 174
 175All five of =key_file=, =key_id=, =team_id=, =topic= and =environment=
 176are required when =enabled= is true; validation runs at config load,
 177so a misconfigured =[push]= is caught before the daemon serves
 178anything. The delivery queue (a device's undelivered and attempted
 179pushes) is capped the same way the mail queue is, by =[retention]
 180push=.
 181
 182** [backup]
 183- =age_recipients= (optional) — age public keys (=age1...=). When set,
 184  =admin backup= encrypts every archive to them and appends =.age= to
 185  its name. Generate the pair off the host with =age-keygen=; only the
 186  public key goes here, so the host writes archives it cannot read.
 187  The restic copy is unaffected: the offsite job stages its own
 188  =VACUUM INTO= of the live database and snapshots =/var/lib/gitbay=,
 189  not the archives.
 190
 191** [api]
 192- =enabled= (false) — the JSON API surface; see [[API]]. Off
 193  means no credential-bearing HTTP endpoint exists at all.
 194
 195** [webhooks]
 196- =allow_local= (false) — permit webhook and mirror targets on
 197  loopback, private, shared (100.64.0.0/10), link-local or multicast
 198  addresses. Leave off unless you know why you need it (SSRF).
 199
 200** [limits]
 201- =clone_timeout= (3600s) — cap on =repo import= fetches.
 202- =max_blob_bytes= (100MB) — cap on raw file serving over the web.
 203- =max_asset_bytes= (512MB) — cap per uploaded release asset.
 204- =max_snippet_bytes= (1MB) — cap per snippet file.
 205- =max_snippets_per_user= (0, unlimited) — snippets an account may own.
 206- =max_repos_per_user= (0, unlimited) — repositories an account may own
 207  directly; =repo create=, =fork= and =import= refuse past it.
 208  Organizations are not capped.
 209- =max_bytes_per_user= (0, unlimited) — disk the account's own
 210  repositories may take; a push may be no larger than what is left.
 211- =pack_concurrency= (3), =pack_per_principal= (2), =pack_queue= (32),
 212  =pack_queue_wait= (="60s"=) — git pack generation (clones, fetches,
 213  =git archive --remote=, web archive downloads) over SSH, smart HTTP
 214  and git:// shares one
 215  budget: this many at once, this many per account (per client
 216  address when anonymous: an IPv4 address, or an IPv6 /64), and this
 217  many waiting for at most the wait. Anonymous clients together hold
 218  at most =pack_concurrency= − 1 slots when it is above 1: an account
 219  (SSH key, bearer token or web session) can take the last slot when it
 220  is free, and anonymous clients cannot hold it.
 221  Past that an SSH client gets "the server is busy…" and exit 1, HTTP
 222  gets 503 with =Retry-After: 30=, git:// an =ERR= line; the daemon
 223  logs a =pack limit= warning naming the transport and whether the
 224  client was signed in, at most once a minute per transport. An SSH client
 225  that disconnects while queued leaves the queue; an HTTP or git:// one
 226  keeps its place until the wait runs out. A running clone is killed
 227  when its client disconnects, or when no write to the client completes
 228  for two minutes: a client reading below about 550 B/s, or an HTTP
 229  request body that takes over two minutes with nothing written back,
 230  is cut. Ref listings (info/refs, protocol v2
 231  =ls-refs=), pushes and =repo download= are outside the budget. For the
 232  three counts 0 means the default and a negative value turns that
 233  bound off. The defaults suit a four-core host; see [[Performance]].
 234  With =ssh.mode = "system"= each SSH session is its own process and
 235  SSH clones are not counted.
 236- =max_pack_bytes= (2 GiB) — the largest pack one push may send,
 237  enforced as =receive.maxInputSize= and lowered to what an owner's
 238  storage quota has left.
 239- =ssh_auth_rate= (10) — SSH authentication failures per client address
 240  per minute on the embedded listener; see below.
 241
 242** [git_daemon]
 243- =enabled= (false), =port= (9418) — the anonymous =git://= listener.
 244  Serves only public repositories that additionally ran
 245  =repo settings git-daemon <repo> on=.
 246
 247** [mirrors]
 248- =pull_interval_minutes= (15) — how often pull mirrors fetch their
 249  upstream. Push mirrors sync shortly after each local ref update.
 250  Mirror URLs pass the same SSRF rules as webhook targets, when saved
 251  and again before every sync; git then connects only to the addresses
 252  that were checked (=http.curloptResolve=) and does not follow
 253  redirects, so a mirror of a renamed repository fails until its URL
 254  is updated. Needs git 2.37 or later on the server; with an older git
 255  the worker logs an error at start and syncs no mirror, recording the
 256  reason on each. Sync ignores the system and global gitconfig.
 257
 258** [go_import]
 259Vanity Go module paths, one per line: ="host/module" = "owner/repo"=.
 260Requests with =?go-get=1= at or under the module path answer with the
 261go-import meta tag pointing at the repository's HTTPS clone URL, so
 262=go install host/module/cmd/...@latest= resolves. The repository should
 263be public (the module path itself confirms it exists).
 264
 265* Users, email, invites
 266
 267Every =gitbayd admin= subcommand except =backup=, =gc= and the one-shot
 268backfills is a wrapper that dispatches the registry command of the same
 269name as the host: an admin context with no account behind it, so its
 270audit rows carry no actor and =source: host=. The same commands run in an
 271instance admin's SSH session (=ssh git@<host> admin ...=) and write the
 272same rows with the key fingerprint as source. One implementation, two
 273credentials.
 274
 275#+begin_src sh
 276gitbayd admin user create alice --key alice.pub --email a@example.org --verified [--admin]
 277gitbayd admin email verify alice a@example.org   # admin assertion, no SMTP needed
 278gitbayd admin invite --email b@example.org       # mails a code; prints it if no SMTP
 279#+end_src
 280
 281"Verified" means SMTP-confirmed or host-admin-asserted; the database
 282records which. Verified emails are what make commit signatures
 283meaningful — an unverified address never produces a =verified= badge.
 284
 285* Audit and account control
 286
 287The audit log is the security feed (events are the product feed): every
 288successful mutating command with its argv and source credential (SSH key
 289fingerprint or API), every refused one (exit 3 or 4) as =refused
 290<command>=, refused pushes as =refused git-receive-pack= (the access
 291check) or =refused push= (a branch or tag rule, a release anchor or an
 292unsigned commit, with the repository and ref names), hook socket
 293requests failing the peer or push-token check as =refused hook= (never
 294the token), registrations, admin actions, force-pushes, and auth
 295failures/throttling. A refusal row
 296keeps the flag names and the first positional, not the values.
 297Refusals are recorded up to ten a minute per account and 600 a minute
 298across the instance; past either, one =refused.throttled= row stands
 299for the rest of that minute. The caps bound the embedded listener, the
 300web and the API; under =ssh.mode = "system"= each =gitbayd shell=
 301connection counts separately. Secrets never appear — they travel on
 302stdin, never in argv.
 303
 304Each row carries the SHA-256 of the row before it. =gitbayd admin audit
 305verify= opens the store as other admin commands do, applying pending
 306migrations, so run it with the binary that matches the daemon. It
 307recomputes the chain and exits 1 naming the first row that was
 308edited or whose predecessor was removed. The chain is unkeyed: whoever
 309can write the database can recompute every hash after an edit, and
 310verify then finds nothing. It catches an edit only when the later
 311hashes were not recomputed. Retention removing the oldest
 312rows is not a break. Rows written before the chain existed are counted
 313and skipped; when every row is such a row, verify warns and exits 1,
 314since clearing the hash columns looks the same. After an upgrade that
 315clears with the first new audit row.
 316
 317Removing the newest rows leaves no break, and neither do rows written
 318afterwards under the freed ids. The database cannot show either. The
 319daemon logs every row it writes to its journal, outside the database
 320(=journalctl -u gitbayd -g 'INFO audit '=), and verify prints the last
 321id and hash: comparing them with the newest journal line is the check
 322for any change, recomputed hashes included. Rows written by
 323host =gitbayd admin= commands, and by =gitbayd shell= when =ssh.mode =
 324"system"=, are not copied to the journal.
 325
 326#+begin_src sh
 327gitbayd admin audit [--actor u|-] [--action prefix] [--since 24h|7d|date] [--limit n] [--json]
 328gitbayd admin audit verify           # check the hash chain; exit 1 names the first bad row
 329ssh git@<host> audit ...             # the same, from an admin session
 330ssh git@<host> admin user list [--state active|pending|disabled|admin]
 331ssh git@<host> admin user show <name>   # keys, emails, orgs, tokens, sessions
 332ssh git@<host> admin user limits <name> [--repos n|default] [--bytes n|default]   # per-account caps
 333ssh git@<host> admin user promote <name>   # grant instance admin
 334ssh git@<host> admin user demote <name>    # remove it; the last admin is refused
 335gitbayd admin user promote <name>    # host-local: recovery when no admin key is reachable
 336gitbayd admin user disable <name>    # suspend: SSH, web, API all refused;
 337gitbayd admin user enable <name>     #   sessions dropped, nothing deleted
 338gitbayd admin user delete <name> --yes  # only for accounts anchoring nothing:
 339                                     #   refused (with each blocker named) while
 340                                     #   the account owns repos, authored
 341                                     #   issues/MRs/comments/reviews, or is an
 342                                     #   org's only admin
 343#+end_src
 344
 345=--actor= takes a username, or =-= for rows with no actor: host commands
 346and auth failures. =--action= is a prefix, so =cmd repo= catches every
 347repository command and =admin= every host or admin-session action.
 348=--since= is a duration back from now (=30m=, =24h=, =7d=) or a date.
 349
 350=admin user list= pages by username (=--limit=, =--cursor=) and carries
 351each account's state and =last_seen=, the newest use of any of its SSH
 352keys or API tokens. =admin user show= adds the keys with their last use,
 353each address with how it was verified, PGP keys, org roles, the owned
 354repository count, API token names, and live browser sessions. Both are
 355Both are refused to non-admins, like =audit=, on every surface.
 356
 357=/admin/users= is the same list in a browser, linked from the admin
 358page: the state filter the command takes, keyset paging on its cursor,
 359and a row per account with promote, demote, disable and enable, each
 360dispatching the command. Demote and disable ask for the username to be
 361typed, since both take someone's access away. Creating and deleting an
 362account, issuing an invite and asserting an address stay on the command
 363line: each takes a key, mints a credential, or cannot be undone. A
 364non-admin gets the 404 a missing page would, so the URL confirms
 365nothing.
 366
 367Promotion needs an active account: a pending or disabled one is refused.
 368Demotion is refused when it would leave no admin, over SSH, in the
 369browser and on the host alike, so the host-local =promote= is the way
 370back in when the only admin key is lost.
 371
 372Instance admin carries no right on anyone's repository: policy does not
 373consult it, and a private repository still answers not-found to an
 374admin. Moderation goes through explicit overrides that skip the access
 375check and write their own audit row:
 376
 377#+begin_src sh
 378ssh git@<host> admin repo list [--owner o] [--visibility public|private]  # size, last push
 379ssh git@<host> admin repo archive|unarchive <owner/name>
 380ssh git@<host> admin repo visibility <owner/name> public|private
 381ssh git@<host> admin repo delete <owner/name> --yes
 382#+end_src
 383
 384Each lands in the audit log as =admin repo.<action>= naming the
 385repository, on top of the =cmd= row every mutating command gets.
 386
 387=limits.ssh_auth_rate= (10) throttles per-IP authentication *failures*
 388per minute — successful auths never count and clear the slate.
 389=limits.max_pack_bytes= is enforced as =receive.maxInputSize= on every
 390push.
 391
 392=limits.write_rate= (60) bounds *mutating commands per account per
 393minute*. It is counted in the dispatcher, so SSH, the JSON API and the
 394web spend one budget and a caller cannot refresh it by changing surface;
 395=limits.api_rate= stays in front of it, bounding a network source rather
 396than an account. A command is one token whatever it writes, so a bundle
 397import costs one and only a loop of separate commands spends the budget.
 398Read-only commands, the runner protocol (a build streams its log in many
 399small writes) and the host CLI are exempt. Refusals exit 4 and say when
 400to retry. A negative value turns the limit off; it matters most with
 401=registration = "open"=, where every write also queues notification mail
 402and webhook deliveries.
 403
 404* Queues
 405
 406Every background worker keeps a backlog and a failure state. An instance
 407admin reads them all in one place:
 408
 409#+begin_src sh
 410gitbay dashboard --json | jq .queues   # webhooks, mail, push, mirrors, builds, deps
 411#+end_src
 412
 413Per worker: pending, retrying (pending with a failed attempt) and
 414dead-lettered counts with the oldest pending age, and the retrying or
 415failed rows themselves, capped at twenty each. Builds list what is
 416running and then what is pending, each since when, so a build no runner
 417is scoped to claim is visible here rather than only in its repository;
 418mirrors list the ones whose last sync failed;
 419dependency checks list the ones whose last check errored. Non-admins get
 420no =queues= key at all.
 421
 422Push rows name the device id, never the token. Watch this one after
 423configuring =[push]=: a =key_id= or =team_id= Apple did not issue passes
 424config validation, which can only check that the =.p8= parses, and then
 425every send comes back =403 InvalidProviderToken= and dead-letters on its
 426first attempt.
 427
 428In accounts mode the same read renders at =/admin=, linked from the rail
 429for admins. Anyone else gets a 404 there.
 430
 431A dead-lettered mail is logged as =notification dead-lettered mail=<id>=,
 432with the address redacted out of the relay's error. The id is the queue
 433row: find it in the Mail table on =/admin=, or in =dashboard --json=,
 434where the recipient and the unredacted error are. That is deliberate —
 435see the Threat-Model page.
 436
 437* Maintenance
 438
 439#+begin_src sh
 440gitbayd admin stats [--json]         # counts, database size, per-repo disk
 441ssh git@<host> admin stats [--json]  # the same, from an admin session
 442gitbayd admin gc [--repo owner/name] # git gc: repack and prune; per-repo sizes
 443gitbayd admin gc --aggressive        # thorough repack; slow, rarely needed
 444gitbayd admin gc --lfs               # also drop LFS objects no pointer names (older than a day)
 445#+end_src
 446
 447A history rewrite leaves the commits it removed reachable through
 448=refs/merge-requests/N/head= of the merge requests that landed them, so
 449they stay fetchable by anyone who can read the repository. Nothing drops
 450a head ref on its own — an open or source-gone MR is merged through it,
 451and a merged or closed one keeps its diff readable through it — so the
 452cleanup is a command an instance admin runs, naming the MRs:
 453
 454#+begin_src sh
 455ssh git@<host> admin mr prune owner/name 1 2 3 --yes
 456#+end_src
 457
 458It refuses an open or source-gone MR, deletes the named refs, runs
 459=git gc --prune=now= on that one repository so the objects go at once
 460rather than after git's two-week grace, leaves a system comment on each
 461MR, and audits as =admin mr.prune=. The MR keeps its title, comments,
 462reviews and head sha; =mr diff= and the MR page say the head is gone.
 463Run it when nothing is pushing to that repository: without the grace, a
 464push caught between leaving quarantine and writing its ref loses its
 465objects. Objects also survive in offsite backups until those are
 466rewritten; see "Removing a repository's history from every snapshot".
 467
 468=deploy/cloud-init.yaml= ships a =gitbay-gc.timer= that runs =admin gc=
 469weekly (Sunday 07:00 UTC). Imported repositories keep whatever pack
 470layout the source sent, so a first manual =admin gc= after a bulk
 471import is worthwhile.
 472
 473* Backup and restore
 474
 475#+begin_src sh
 476gitbayd admin backup --out /var/backups/gitbay/backup.tar.gz
 477gitbayd admin backup --verify /var/backups/gitbay/backup.tar.gz   # read it back
 478#+end_src
 479
 480One archive: a consistent SQLite snapshot (taken *before* the
 481repositories are read, so the database never references objects the
 482archive missed), every repository, and the SSH host keys. Excluded:
 483hook socket, regenerated hook scripts, WAL files. Safe to run against a
 484live daemon. =--out= must be outside =server.root=, or the next full
 485backup would carry the archive. Each run removes the snapshot
 486directories (=.gitbay-snap-*=) and temporary archives (=.*.tmp-*=) a
 487killed run left beside its archive once they are a day old, and prints
 488each one it removes.
 489
 490=--verify= reads an archive back: the snapshot must pass SQLite's
 491integrity check, every repository the snapshot names must be in the
 492archive, and each must pass =git fsck --connectivity-only=. It
 493extracts the repositories to a temporary directory for that, so it
 494needs free space the size of the repositories. A database-only archive
 495is checked for integrity and says so. Exit is non-zero on damage, a
 496missing repository or a missing object.
 497
 498A full backup holds =<root>/backup.lock= from its database snapshot to
 499its last repository. While it runs, =repo delete=, =repo rename=,
 500=repo transfer=, =admin repo delete=, =org rename=, =admin mr prune=
 501and =gitbayd admin gc= refuse with "a backup is running"; retry when it
 502finishes. Database-only backups take no lock. A pack that git's own
 503automatic gc removes during the walk is skipped; each repository's refs
 504are archived before its objects, so the refs still find their objects,
 505and =--verify= reports it if one does not.
 506
 507Verifying an archive of unknown origin: run it as an unprivileged
 508user. The connectivity check runs git with =--git-dir= on each
 509extracted repository, so a directory that is not a repository fails
 510rather than git checking an enclosing one. =objects/info/alternates=
 511and a =commondir= directly in a =*.git= directory are not extracted,
 512so an archive cannot use either to have git read another repository's
 513objects or refs on the host. Git still reads each archived
 514repository's own =config=.
 515
 516Archives carry a directory entry for every directory, including an
 517empty one, so a bare repository whose refs are all packed restores as
 518a repository. Archives written before this release do not: extracting
 519one can leave a repository's =refs/= directory missing, which stops
 520git from recognizing it as a repository at all. =gitbayd admin backup
 521--verify <archive>= names the repositories this affects; the fix is
 522=mkdir -p <root>/repos/<owner>/<name>.git/refs= for each one, after
 523which it opens normally.
 524
 525With =[backup] age_recipients= set the archive is =<name>.tar.gz.age=
 526and =--verify= needs the private key:
 527
 528#+begin_src sh
 529gitbayd admin backup --verify gitbay-20260927-090000.tar.gz.age --identity ~/.config/gitbay/backup-identity.txt
 530age -d -i ~/.config/gitbay/backup-identity.txt gitbay-20260927-090000.tar.gz.age | tar -xz -C /new/root
 531#+end_src
 532
 533The identity lives off the host (with the secret key file and the
 534restic credentials), so verifying an encrypted archive happens there
 535or on a restore host.
 536
 537Restore: extract into an empty directory, point =server.root= at it,
 538restore =server.secret_key_file= from its own copy (mode 0600, owned
 539by the account gitbayd runs as), then start gitbayd. No archive carries
 540the key file, and without it gitbayd refuses to start. Host keys are
 541preserved, so clients keep their known_hosts entries; hooks regenerate
 542at startup.
 543
 544** Schedule and recovery point
 545
 546Two timers, because the two halves of the data have different exposure.
 547
 548- =gitbay-backup.timer=, nightly. The full archive above, last 7 kept.
 549- =gitbay-db-backup.timer=, hourly. =admin backup --db-only=, which
 550  writes the SQLite snapshot alone, last 48 kept. A few MB against the
 551  full archive's hundreds, which is what makes the frequency affordable.
 552
 553The split follows what a loss would actually cost. Repositories are git,
 554so a mirror or any clone is a second copy; the database is the only copy
 555of issues, merge requests, comments and review state. So the recovery
 556point is about an hour for the data that exists nowhere else, and a day
 557for the data that does.
 558
 559Continuous replication (litestream and similar) was considered and not
 560adopted. It would take the database's recovery point to seconds, but the
 561repositories would still be on the nightly archive, so a restore could
 562produce a database referencing commits the repository backup does not
 563have. Consistency between the two halves is worth more here than latency
 564on one of them. Revisit if repository replication becomes continuous
 565too.
 566
 567** Offsite copies
 568
 569bay1 also takes a nightly restic snapshot of =/var/lib/gitbay= and
 570=/var/lib/gitbay-stage= (a database copy and =config.toml=, staged
 571there) to an S3 bucket at Scaleway, with a key that can only add
 572snapshots. Nothing else under =/etc/gitbay= is in it: not the secret
 573key file, not =apns.p8=. The key that can
 574remove them lives on the operator's machine, in
 575=~/.config/gitbay/offsite.env=, and never on bay1: a compromised host
 576cannot destroy its own history. Forgetting, pruning and rewriting all
 577run from there.
 578
 579*** Removing a repository's history from every snapshot
 580
 581A history rewrite plus =admin mr prune= takes commits off the server,
 582but every snapshot taken before it still holds them, and the retention
 583window is the only thing that ages them out. To remove them now,
 584rewrite the snapshots without that repository rather than forgetting
 585the snapshots: everything else in them stays restorable. The next
 586nightly run adds the repository back in its current state.
 587
 588Repositories are stored under the name they had on disk when each
 589snapshot was taken, so a renamed repository needs every name it has
 590carried. Check what an older snapshot holds before choosing the paths:
 591
 592#+begin_src sh
 593set -a; . ~/.config/gitbay/offsite.env; set +a
 594restic $RESTIC_OPTS snapshots
 595restic $RESTIC_OPTS ls <old-snapshot> /var/lib/gitbay/repos/<owner>
 596#+end_src
 597
 598Then dry-run, apply, prune, and confirm nothing matches:
 599
 600#+begin_src sh
 601EXCL="--exclude /var/lib/gitbay/repos/<owner>/<name>.git --exclude /var/lib/gitbay/repos/<owner>/<old-name>.git"
 602restic $RESTIC_OPTS rewrite --dry-run $EXCL     # "would modify N snapshots"
 603restic $RESTIC_OPTS rewrite --forget $EXCL      # new snapshots replace the originals
 604restic $RESTIC_OPTS prune                       # drops the data nothing references
 605restic $RESTIC_OPTS find <name>.git <old-name>.git   # expect no output
 606#+end_src
 607
 608=--forget= is what makes the originals go; without it the rewritten
 609snapshots sit beside them and the data stays referenced. Snapshot IDs
 610change; their times do not. Done for krz/keycask (formerly rust-pass)
 611on 2026-09-18, across 22 snapshots.
 612
 613** Secret key
 614
 615CI secrets, webhook secrets, mirror tokens and APNs device tokens are
 616stored sealed: AES-256-GCM under a key in =server.secret_key_file=,
 617each value prefixed with the id of the key that sealed it
 618(=gbs1:<id>:=). The key file is not in the database, not under
 619=server.root=, and therefore in neither the local archives nor the
 620main restic repository. It must be copied off the host separately;
 621without it a restored database's secrets cannot be opened, and
 622gitbayd refuses to start against them. A separate restic repository
 623for it and =apns.p8= is planned (runbook D of the data-at-rest plan)
 624and not yet in place, so today the only off-host copy is one the
 625operator makes by hand after =init= and after every =rotate=.
 626
 627#+begin_src sh
 628gitbayd admin secrets init     # once; deploy/install.sh does it on first install
 629gitbayd admin secrets check    # open every value, count by key
 630gitbayd admin secrets rotate   # new key, reseal, retire the old one (as root)
 631#+end_src
 632
 633- Missing file: every gitbayd process that opens the database refuses
 634  to run and names the path, including =serve= and, in system mode,
 635  =authorized-keys=. =migrate= does not need it.
 636- Backups: =admin backup= and =admin backup --verify= do not need the
 637  key file; a restore does.
 638- Wrong key: =serve= stops at startup naming the first row that does
 639  not open; =secrets check= does the same without starting anything.
 640- Upgrade: the first start after the upgrade seals every value still
 641  in clear and logs =sealed secret values=.
 642- Rotation: =rotate= adds a key, reseals every value under it in one
 643  transaction, then removes the old keys. Run it as root, since it
 644  replaces the key file in =/etc/gitbay=; the file keeps its owner.
 645  The daemon re-reads the file when it changes, so it needs no
 646  restart. Copy the new file off the host afterwards. =init= and
 647  =rotate= hold an flock on =<key file>.lock= while they run, so a
 648  second run waits for the first.
 649- Push devices are looked up by the SHA-256 of their token
 650  (=push_devices.token_hash=), since two seals of one token differ.
 651
 652** Restore drill
 653
 654A restore onto a clean host, run quarterly and after any change to the
 655backup code (=cmd/gitbayd/backup.go=, the offsite job), and recorded
 656below. The disaster it rehearses is losing bay1, so the local archives
 657are gone with it and the sources are the main offsite restic
 658repository (repositories, LFS, the staged database, =config.toml=),
 659the off-host copy of =secret.key= and =apns.p8= (a keys repository once
 660runbook D creates it; until then the operator's hand-made copy), and
 661the operator's password manager (=offsite.env=, the keys repository's
 662password and token once it exists, =backup-identity.txt=). The steps are in the data-at-rest
 663plan's operator runbook
 664(=docs/plans/2026-09-27-data-at-rest-and-backup.md=).
 665
 666Time to service runs from the clean host's first root login to the
 667first successful =git clone= over SSH from it. The recovery point is
 668the time of the newest restic snapshot restored.
 669
 670No drill has been run yet; the procedure above is written but
 671unexercised, and #259 stays open until the first row below is
 672recorded.
 673
 674| Date | Host | Snapshot restored (UTC) | Time to service | DB integrity | Connectivity | LFS | Release assets | Host key | Secrets | Notes |
 675|------+------+-------------------------+-----------------+--------------+--------------+-----+----------------+----------+---------+-------|
 676
 677* Upgrades
 678
 679Replace the binary, restart the unit. Migrations apply automatically and
 680are transactional; hook scripts under =<root>/hooks= are rewritten at
 681startup to point at the current binary path.
 682
 683* CI runner
 684
 685=gitbay-runner= executes builds queued by pushes and merge requests. It
 686polls over SSH with a key of scope =runner=, which reaches only the
 687runner protocol and read-only git (a runner executes arbitrary
 688repository code, so the key it holds must not do more). A runner key
 689claims builds only for the repositories it is attached to, by =repo
 690runner add= from a repository admin or an instance admin; an admin key
 691claims any. Users attach their own runners: see the Users page. For an
 692instance runner, run it as a dedicated unprivileged user on a non-admin
 693account. =admin user create --key= registers a full-scope key, so the
 694runner key is added afterwards through a bootstrap key that is then
 695removed, and attached to each repository it should build:
 696
 697#+begin_src sh
 698useradd --system --create-home --home-dir /var/lib/gitbay-runner ci-runner
 699sudo -u ci-runner ssh-keygen -t ed25519 -N "" -f /var/lib/gitbay-runner/.ssh/id_ed25519
 700ssh-keygen -t ed25519 -N "" -f /tmp/ci-bootstrap
 701gitbayd --config /etc/gitbay/config.toml admin user create ci --key /tmp/ci-bootstrap.pub
 702ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys add --scope runner < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
 703ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys remove "$(ssh-keygen -lf /tmp/ci-bootstrap.pub | awk '{print $2}')"
 704rm /tmp/ci-bootstrap /tmp/ci-bootstrap.pub
 705gitbay-runner -remote git@127.0.0.1 -workdir /var/lib/gitbay-runner/work
 706#+end_src
 707
 708#+begin_src sh
 709gitbay repo runner add krz/site < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
 710#+end_src
 711
 712=-jobs N= runs N builds at once. Claiming is one transaction that
 713selects and updates, and each build works in its own =build-<id>=
 714directory, so workers do not collide; idle polls are staggered across
 715the interval so N of them do not wake together. The drop-in's weights
 716below are per service, not per build, so raising =-jobs= divides them
 717rather than multiplying the host's load.
 718
 719=admin runners= shows which account each runner polls as, and what each
 720may claim. A runner key claims builds only for the repositories it is
 721attached to: with none attached it claims nothing, and =-repos= may only
 722narrow within them. An admin's full-scope key claims any repository —
 723that is what =-repos= was for — and still works for the protocol during
 724a rotation. A merge request head from a fork is built in the target
 725repository as untrusted: the claim carries no secrets, and only a runner
 726started with =-untrusted= takes it. Same-repository heads were built by
 727their branch push and are not built again.
 728
 729=make deploy-runner= also installs
 730=deploy/gitbay-runner.override.conf= as a systemd drop-in: =Nice=10=,
 731=CPUWeight=30=, =IOWeight=30=, so a build never starves the host's sshd,
 732the daemon or the backup timers, and =NoNewPrivileges=,
 733=ProtectSystem=full=, =ProtectKernelTunables=, =ProtectControlGroups=
 734and =RestrictSUIDSGID=, so a step cannot reach outside its workspace
 735and the runner's home. The e2e suite alone starts sixty
 736daemon instances; without the drop-in a deploy's copy over the admin
 737sshd stalled. Both deploy targets copy with =rsync --partial=, which
 738resumes a stalled transfer.
 739
 740Under =-isolation podman=, the default and what bay1 runs, each build
 741is confined to a container (see Container isolation below). Under
 742=-isolation none= steps run directly on the host as the runner's user,
 743so treat that machine as executing whatever your users push, and
 744install the toolchains your builds need on it.
 745
 746A runner claims the oldest pending build among the repositories its key
 747is attached to — for an admin key, the oldest in the instance. =-repos=
 748narrows within that set, which is what makes a runner outside the server
 749practical: one on a machine that should build a single project, or that
 750holds credentials for one deployment, stays on it.
 751
 752Oldest-first is across everything the key may claim, so a repository
 753with a deep queue holds every other repository the same runner serves;
 754bay1 measured a 15-minute average wait on a day of merge request
 755stacks from one repository. A runner attached to one repository cannot
 756be starved. That is the rule, decided in krz/gitbay#207: a runner
 757serving several repositories takes them oldest-first, and an operator
 758who wants one repository never to wait on another runs a second
 759runner attached to it alone. Nothing caps what an account queues,
 760and nothing needs to (krz/gitbay#206): a schedule tick queues nothing
 761while the job's last build is pending or running, so a repository
 762with no runner holds one row per scheduled job rather than one per
 763tick, and a build runs only on a runner its owner attaches, so a busy
 764schedule spends the owner's compute. Pushes are bounded by what an
 765account can push.
 766
 767#+begin_src sh
 768gitbay-runner -remote git@gitbay.org -repos krz/site,krz/docs \
 769  -workdir /var/lib/gitbay-runner/work
 770#+end_src
 771
 772Add =-untrusted= only with =-isolation podman=.
 773
 774gitbay.org's runner is attached to the forge's own repositories and
 775the isolation canary, nothing else, because it shares the host with
 776the forge; its unit names no =-repos=, the attachments are the
 777boundary. Any other repository builds on a runner its owner attaches.
 778
 779=-repos= narrows an admin runner; for a runner key the attachments are
 780the boundary, held by the server, and =-repos= may only name
 781repositories among them. =-untrusted= makes a runner claim merge
 782request heads from forks; the bay1 unit sets it because it isolates in
 783podman. A runner without it builds trusted commits only.
 784
 785=gitbay dashboard= and =ssh git@<host> admin runners= list every key
 786that has polled as a runner: the account, the key's fingerprint, when it
 787last polled, the repositories it may claim — its attachments for a runner
 788key, the =-repos= it asked for or =any= for an admin key — and the build
 789it holds; =admin runners remove <fingerprint>= (=forget= until the next release) drops the row for a key
 790that polled by mistake, the key itself untouched. =admin runners= also
 791heads the list with the queue: builds
 792pending now, and over the last day how many were claimed, how long they
 793waited to be claimed (average and worst), and
 794how many the reaper ended instead of a runner reporting them. A build a runner claimed and never
 795reported is failed by the scheduler's minute tick, whether or not any
 796runner is still alive: within about two minutes of its log stream ending
 797with no outcome reported — the runner reports right after closing the
 798stream, retrying for half a minute if gitbayd is unreachable — or, if no
 799stream was ever seen, at the deadline.
 800
 801Instance admin on the runner account only authorizes the claim/report
 802protocol; it grants no repo access. A build that pushes back — a pages
 803deploy, an archive publish, an automated MR branch — needs an explicit
 804grant on that repo: =repo access grant <owner/name> ci write=. Private
 805repos likewise need at least read for the clone.
 806
 807** Container isolation
 808
 809Builds run in a rootless podman container, one per job, with the
 810workspace bind mounted and nothing else: the clone happens outside with
 811the runner's key, so a step cannot read it. =-isolation none= keeps the
 812old behaviour — steps on the host as the runner's user — for an instance
 813where every repository is trusted. There is no automatic fallback: a
 814runner started with =-isolation podman= that cannot find a working
 815podman exits rather than running a build unsandboxed.
 816
 817gitbay's own jobs name =localhost/gitbay-ci:2=, built from
 818=deploy/Containerfile.ci= on the runner host. A job's image must carry
 819what its steps need: the suite drives real git, git-lfs, gpg and sshd and
 820asserts they exist before running, so the stock runner default would fail
 821it immediately. Build or rebuild it with:
 822
 823#+begin_src sh
 824ssh -p 2222 root@<host> 'cat > /tmp/Containerfile.ci' < deploy/Containerfile.ci
 825ssh -p 2222 root@<host> 'su - ci-runner -s /bin/sh -c \
 826  "podman build -t localhost/gitbay-ci:2 -f /tmp/Containerfile.ci /tmp"'
 827#+end_src
 828
 829The tag is deliberate rather than =:latest=: changing the file means
 830bumping the tag in =.gitbay/ci.yml=, so a running branch's image does not
 831change under it.
 832
 833=-image= names the image a job runs in when it declares none, and is
 834required under =-isolation podman=: there is no built-in default,
 835because an image this host does not have would fail every build. A job
 836overrides it with =image:= in =.gitbay/ci.yml=, validated as a reference
 837so a config file cannot turn it into podman arguments.
 838
 839=-cpus= and =-memory= cap one build (podman's units, e.g. =-cpus 2
 840-memory 4g=); unset means uncapped. The runner applies them itself: it
 841creates a cgroup per build under its own delegated service cgroup,
 842writes the limits there, and starts every podman process for the build
 843inside it, with podman's cgroup handling off. Podman's own =--memory=
 844and =--cpus= never applied under rootless cgroupfs, which is what a
 845system service gets (krz/gitbay#188). The unit therefore needs
 846=Delegate=yes=, which the drop-in sets; without it the runner refuses
 847to start when a limit is set, and logs that builds run unconfined when
 848none is. bay1 runs =-cpus 3 -memory 6g= per build inside =MemoryMax=6G=
 849and =CPUQuota=300%= on the unit, on a 7.7GB four-core host with no
 850swap: the memory cap is what keeps the forge alive when a build
 851allocates without bound, and it sits above the e2e suite's 5GB peak
 852rather than at a fair share. =OOMPolicy=continue= keeps systemd from
 853stopping the runner when a build is OOM-killed.
 854
 855A trusted build's home is its repository's, under
 856=<workdir>/trusted-home/<owner>/<name>=, mounted into its containers as
 857=HOME=: caches persist between trusted builds of one repository and are
 858never read by another's. An untrusted build — a merge request head from
 859a fork — gets =<workdir>/build-<id>-home=, new and empty, removed when
 860the build ends. Homes under =<workdir>/home= are from runners before
 861krz/gitbay#255, which shared them with untrusted builds; nothing reads
 862them any more, and they can be deleted.
 863
 864*Images are provisioned, never pulled by a build.* The runner passes
 865=--pull=never=. Two reasons, and the second is the better one: the
 866service runs with =RestrictSUIDSGID=yes= so podman cannot unpack a layer
 867holding a setuid file, which is nearly every distribution image; and on
 868an instance where anyone can push a =ci.yml=, =image:= would otherwise
 869mean "fetch and run anything from the internet". An operator pulls or
 870builds what is allowed and a build picks among those. A job naming an
 871image the host does not have fails with a message saying so.
 872
 873#+begin_src sh
 874su - ci-runner -s /bin/sh -c "podman pull docker.io/library/alpine:3.20"
 875su - ci-runner -s /bin/sh -c "podman images"
 876#+end_src
 877
 878Prepare a host before pointing an isolating runner at it:
 879
 880#+begin_src sh
 881ssh -p 2222 root@<host> 'sh -s' < deploy/runner-podman-setup.sh
 882make deploy-runner
 883#+end_src
 884
 885The script installs podman, delegates a subuid/subgid range to
 886=ci-runner=, checks that user namespaces are enabled rather than
 887assuming, enables lingering, and verifies rootless podman actually runs
 888as that user. It is idempotent.
 889
 890It also installs nftables. =make deploy-runner= ships
 891=deploy/gitbay-runner-egress.nft= to =/etc/gitbay-runner/egress.nft=
 892with =gitbay-runner-egress.service=, which loads it and which the
 893runner's unit requires; it checks the file with =nft -c=, reloads the
 894unit, and runs =deploy/runner-egress-check.sh= as =ci-runner= before
 895restarting the runner: =127.0.0.1:22= and the public 22 must answer,
 8962222 must not. The table limits the runner's user to =127.0.0.1:22=,
 897DNS on loopback, and 22, 80 and 443 on the host's public address; the
 898Threat-Model page says why. A restart of =nftables.service= flushes it;
 899=systemctl reload gitbay-runner-egress= restores it.
 900
 901The drop-in sets =NoNewPrivileges=no=, without which rootless podman
 902cannot call =newuidmap= and the runner refuses to start. That is a
 903considered trade, explained in the file and in the Threat-Model; if you
 904run with =-isolation none=, set it back to =yes=.
 905
 906*Restarting the runner is safe.* On SIGTERM it stops claiming, finishes
 907the build in flight, reports it, and exits; the drop-in's
 908=TimeoutStopSec=50min= covers the longest build, and its =KillMode=mixed=
 909is what makes the signal reach the runner alone — under systemd's default
 910the build's container and the log session are signalled with it, and the
 911runner drains a build that is already dead. So =make deploy-runner=
 912waits for a running build rather than orphaning it, and a build's result
 913is retried for half a minute if gitbayd is restarting at that moment. A
 914second SIGTERM ends the runner at once, abandoning the build to the
 915reaper. The suite checks all three: =TestRunnerDrainsOnSIGTERM= signals
 916the process, =TestRunnerDropInLetsTheDrainHappen= reads the drop-in's
 917=KillMode= and =TimeoutStopSec=, and =TestRunnerDrainUnderSystemd= runs
 918the runner as a transient user unit under =systemd-run= and stops it
 919under both kill modes. That last one needs a systemd user manager, so it
 920skips in the container CI runs in; run it on a Linux host with
 921=go test ./e2e -run TestRunnerDrainUnderSystemd -v=.
 922
 923*Validate podman mode on a scratch repository before pointing the runner
 924at real ones.* Every deploy that switched the whole instance to
 925containers and failed took CI down with it. Instead: create a throwaway
 926repository the runner account can read (public, or granted read — a
 927private one is "not found" to the runner and the build stays pending),
 928give it one job that names the CI image, attach the runner's key to it,
 929and deploy the runner with =-repos= naming only that repository. The
 930production unit, with its real hardening, then claims nothing else;
 931other repositories' builds queue until =-repos= is removed again, which
 932is a pause, not an outage.
 933
 934#+begin_src sh
 935gitbay repo create cmc/runner-scratch   # then push a .gitbay/ci.yml naming the image
 936# on the host:
 937gitbay repo runner add cmc/runner-scratch < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
 938sed -i 's#^ExecStart=/usr/local/bin/gitbay-runner #&-repos cmc/runner-scratch #' /etc/systemd/system/gitbay-runner.service.d/override.conf
 939systemctl daemon-reload && systemctl restart gitbay-runner
 940gitbay build log cmc/runner-scratch 1   # green: remove -repos, redeploy, delete the scratch repository
 941#+end_src
 942
 943*Do not deploy an isolating runner to a host that has not been
 944prepared.* The runner is specified to refuse to start without a working
 945podman rather than fall back to running builds unsandboxed — a fallback
 946that silently drops isolation is worse than a stopped runner, because
 947nothing surfaces it. On an unprepared host that refusal stops every
 948build on the instance.
 949
 950The service drop-in carries =Delegate=yes= for rootless cgroup
 951management and =ReadWritePaths= for podman's store under
 952=/var/lib/gitbay-runner=, which =ProtectSystem=full= would otherwise
 953make read-only. Those paths are prefixed =-= so they are ignored when
 954absent: the drop-in installs on unprepared hosts too, and a unit that
 955refused to start would stop every build.
 956=gitbay-runner-prune.timer= prunes unused images weekly, as the runner's
 957user: rootless storage belongs to that user, and root's prune would not
 958see it. An unpruned image store on a 40GB host is a slow outage.
 959
 960* LFS storage
 961
 962Objects live content-addressed under =[lfs] root= (default
 963=<server.root>/lfs=); =[lfs] max_object_bytes= caps a single object
 964(512MB default). Storage sits behind a small interface — an
 965S3-compatible backend is a drop-in with the server proxying, and
 966presigned URLs a later optimization. LFS objects do not travel with
 967push mirrors (mirrors move git refs only), and gc does not yet collect
 968orphaned objects.
 969
 970* Pages
 971
 972=[pages] domain = "example.site"= serves public repos' =pages= branches
 973on =<owner>.<domain>=. DNS needs a wildcard record =*.<domain>= to the
 974server; ACME issues per-subdomain certificates on demand (only for
 975owners that exist). The domain must not be the site host or a parent of
 976it — pages content runs its own scripts and must stay off the forge's
 977origin.
 978
 979Users with repo admin claim custom domains with =repo domain add=.
 980Claims activate only after a DNS TXT challenge proves control of the
 981domain (=repo domain verify=, audit-logged); pending claims serve
 982nothing, get no certificates, and expire after 7 days. ACME issues
 983certificates only for verified hosts, so stray DNS pointed at the
 984server gets nothing.
 985
 986* Security
 987
 988The [[Threat-Model]] file is the reference for what the forge
 989trusts and refuses to do. Operational checklist:
 990
 991- *Software checks.* =deploy/audit.sh= runs =go vet=, =govulncheck=
 992  (the module list is deliberately short — review it on each release),
 993  and a short fuzz pass over every attacker-facing parser (pkt-line,
 994  commit, SSHSIG armor, OpenPGP key, SSH tokenizer). Run it before
 995  tagging a release. CI's own =vuln= job runs =govulncheck= nightly
 996  against main rather than per push, because =@latest= scans today's
 997  advisory database and an advisory lands without anyone pushing;
 998  =build trigger krz/gitbay vuln= runs it on demand.
 999- *Web responses* carry a scripts-forbidden CSP, =X-Frame-Options:
1000  DENY=, =nosniff=, =no-referrer=, and HSTS when TLS is on — no
1001  configuration needed.
1002- *Host sandboxing.* The systemd unit in =deploy/cloud-init.yaml= runs
1003  gitbayd unprivileged with =ProtectSystem=strict=, =PrivateDevices=,
1004  =LockPersonality=, =MemoryDenyWriteExecute=,
1005  =SystemCallFilter=@system-service=, and =RestrictAddressFamilies= to
1006  INET/INET6/UNIX. It keeps =CAP_NET_BIND_SERVICE= only, to bind 22/80/443.
1007- *OS patches* apply via =unattended-upgrades= (security origins,
1008  auto-reboot 04:30 if required).
1009- *Admin sshd (2222)* is throttled by =MaxStartups=/=MaxAuthTries= and
1010  watched by =fail2ban=; gitbayd's own port 22 is throttled by
1011  =limits.ssh_auth_rate= (auth failures per IP per minute), and every
1012  account's writes by =limits.write_rate=.
1013- *Monitoring.* =gitbay-monitor.timer= writes a reading hourly to
1014journald and, when =/etc/gitbay/monitor.url= exists, posts it to that
1015webhook: disk, service, the daemon's own =/healthz= answer, certificate
1016expiry, and the age of the newest full backup and database snapshot.
1017It exits non-zero on an alert so the unit shows in =systemctl
1018--failed=: a stopped service, =/healthz= not answering =ok=, disk ≥ 85%,
1019a certificate under 21 days, a full backup over 25 hours old, or a
1020database snapshot over 2 hours old.
1021
1022=GET /healthz= is unauthenticated and cache-free: whether the database
1023answers and which commit serves, 503 when it does not.
1024- *Database.* =gitbay.db= and its WAL live under =/var/lib/gitbay= (mode
1025  0750, owned by =gitbay=). The nightly archive plus provider snapshots
1026  are the recovery path; for tighter RPO, add continuous replication
1027  (litestream) against the same file — it coexists with the WAL.
1028
1029* Odds and ends
1030
1031- deleting a fork marks MRs sourced from it =source_gone=; their diffs
1032  remain viewable and mergeable because the target repo owns the
1033  objects.
1034- =refs/merge-requests/*= is server-owned and unpushable by clients;
1035  only =admin mr prune= removes one (see Maintenance).
1036- audit-relevant activity (issue/MR lifecycle, imports, pushes) lands in
1037  the =events= table, which also feeds webhooks.
1038- the daemon idles under 10MB RSS; the smallest VPS tier is adequate.