.gitbay/wiki/Admin.org

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

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