.gitbay/wiki/Admin.org

1436 lines · 77707 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, each gzipped, with
  13a SHA256SUMS manifest over the =.gz= files (CGO off, trimpath, stripped —
  14the decompressed binary is byte-identical per commit and toolchain).
  15
  16#+begin_src sh
  17gunzip -c gitbayd-<tag>-linux-amd64.gz > gitbayd
  18install -m 755 gitbayd /usr/local/bin/
  19adduser --system --group --home /var/lib/gitbay --shell /usr/sbin/nologin gitbay
  20install -d -o gitbay -g gitbay -m 750 /var/lib/gitbay
  21gitbayd --config /etc/gitbay/config.toml check-config
  22gitbayd --config /etc/gitbay/config.toml admin secrets init
  23chown gitbay:gitbay /etc/gitbay/secret.key
  24#+end_src
  25
  26=admin secrets init= refuses when the key file already exists, so a
  27reinstall on the same host should skip it — =deploy/install.sh= does
  28this with a file check before running it.
  29
  30=deploy/= in the source tree has a cloud-init file, a hardened systemd
  31unit, and a nightly backup timer. Run as the unprivileged =gitbay= user;
  32the unit's =AmbientCapabilities=CAP_NET_BIND_SERVICE= covers ports
  3322/80/443 without root.
  34
  35** The SSH port decision
  36
  37- =ssh.mode = "embedded"= (default): gitbayd itself listens, normally on
  38  22 — move the host's admin sshd to another port. Remotes read
  39  =git@host:owner/repo= with no port gymnastics.
  40- =ssh.mode = "system"=: the host sshd owns 22 and invokes gitbayd via
  41  =AuthorizedKeysCommand=:
  42  #+begin_example
  43  AuthorizedKeysCommand /usr/local/bin/gitbayd --config /etc/gitbay/config.toml authorized-keys %t %k
  44  AuthorizedKeysCommandUser gitbay
  45  #+end_example
  46  sshd requires that binary to be root-owned and not group/world
  47  writable. Unknown keys fail authentication inside sshd, so system mode
  48  requires =registration.mode = "closed"= (check-config enforces this).
  49  Under the forced command the CLI's leading =--term=<cols>[,color]=
  50  argument works as is; a client that sets =GITBAY_TERM= instead needs
  51  =AcceptEnv GITBAY_TERM= in =sshd_config=, since that env request is
  52  handled by the host's sshd, not gitbayd.
  53
  54* Configuration reference
  55
  56=/etc/gitbay/config.toml=. =check-config= validates and names every
  57contradiction; =--no-host-checks= skips port/path probes.
  58=gitbayd admin config show= prints the configuration in effect as TOML,
  59every default filled in and =smtp_pass= redacted. A file that fails
  60validation still prints, followed by the contradiction.
  61
  62** [server]
  63- =root= (default =/var/lib/gitbay=) — repositories, database, host
  64  keys, ACME cache all live here.
  65- =site_url= (required) — canonical =https://host=; drives ACME, clone
  66  URLs, mail links.
  67- =secret_key_file= (default =/etc/gitbay/secret.key=) — the keys that
  68  seal CI secrets, webhook secrets, mirror tokens and push device
  69  tokens in the database. Must be outside =root=, mode 0600, readable
  70  by the daemon's user. See "Secret key" below.
  71- =source_repo= (optional, =owner/name=) — the repository this instance
  72  develops itself in. Startup warns when the running build's commit is
  73  not on that repository's default branch, which is how a binary built
  74  from an unmerged branch stops being invisible. Leave it unset unless
  75  the instance hosts its own source.
  76
  77** [ssh]
  78- =mode= — =embedded= | =system= (above).
  79- =port= (22) — embedded listener port.
  80- =host_keys= — list of private key paths; empty generates an ed25519
  81  key at =<root>/ssh/host_ed25519=.
  82
  83** [http]
  84- =addr= (=:443=), =tls= — =acme= | =files= | =off=.
  85- =acme=: certificates via TLS-ALPN-01 on the HTTPS port, cached at
  86  =<root>/acme=; =acme_email= for the CA account; =acme_http_addr=
  87  (=:80=, ="off"= to disable) adds HTTP-01 and an https redirect —
  88  failing to bind it is a warning, not fatal. Requires an =https://=
  89  site_url with a public DNS name.
  90- =files=: =cert_file= + =key_file=.
  91- =off=: plain HTTP — development, or behind a TLS-terminating proxy.
  92- The HTTPS listener accepts TLS 1.2 and 1.3 only (=serverTLS= in
  93  =cmd/gitbayd/tls.go=), with the default cipher suites of the Go
  94  release the binary was built with. =openssl s_client -connect
  95  <host>:443 -tls1_1= fails the handshake.
  96
  97=trusted_proxies= lists the addresses or CIDRs of reverse proxies in
  98front of the daemon. A request from one of them is attributed, for API
  99rate limiting, to the last =X-Forwarded-For= hop that is not itself a
 100trusted proxy; from anyone else the header is ignored. Empty, the
 101default, is right when gitbayd terminates TLS itself.
 102
 103A reverse proxy in front of gitbay must not buffer responses, or the
 104build page's live log arrives only when the build ends;
 105=X-Accel-Buffering: no= covers nginx.
 106
 107** [web]
 108- =mode= — =view_only= (default) | =accounts=. In view_only the mutating
 109  web routes are never registered; in accounts, browser sessions are
 110  minted over SSH (=web login=), and users with write access can create
 111  repos, comment, and make simple file edits (which commit unsigned,
 112  honestly). =password_auth= is reserved and currently rejected.
 113- =title= — the instance's display name in the rail and page titles;
 114  empty falls back to the site host. Lower case is the convention for
 115  gitbay itself.
 116- =privacy_notice= — operator text shown on =/privacy= under the fixed
 117  statement.
 118- =abuse_url=, =terms_url= (empty) — linked from every page's footer as
 119  "Report abuse" and "Terms"; no link when empty. gitbay.org points them
 120  at the [[Abuse][Abuse]] and [[Terms][Terms]] wiki pages.
 121- =apple_app_ids= (empty) — iOS app IDs (=TEAMID.bundle.id=) allowed to
 122  open this instance's links, served at
 123  =/.well-known/apple-app-site-association=. Empty leaves the path a
 124  404. The gitbay iOS app is =ZCNAX3VL9D.org.gitbay.gitbay=; its
 125  entitlement names gitbay.org only, so listing it elsewhere does
 126  nothing.
 127
 128** [registration]
 129- =mode= — =closed= (default) | =invite= | =open=. invite/open require
 130  [mail]. See the user guide for the flows.
 131
 132- =pending_expiry= (empty, never) — a duration such as ="168h"=; a
 133  self-registered account still unverified after that long is removed,
 134  hourly and at start, audited as =pending.expired=.
 135
 136- =notify_admin= (false) — mail every instance admin when an account
 137  becomes active: an invite redeemed, or an open-mode signup that
 138  verified its address. The unverified row an open signup creates is
 139  not reported, because anyone can post the form and mailing on that
 140  would point a flood at the admins. Recipients are the verified
 141  primary addresses of active admins who have activity mail on, the
 142  same rule any other notice follows, so an admin with no verified
 143  address hears nothing. The notice is queued, so a dead SMTP host
 144  shows up in the admin page's Mail table instead of failing the
 145  registration. Requires [mail].
 146
 147** [mail]
 148- =smtp_host= (host:port; 587 assumed, 465 with =tls = "implicit"=),
 149  =from=, optional =smtp_user= / =smtp_pass=. Required for invite/open
 150  registration and self-service =email add=; in closed mode you may omit
 151  it entirely and assert addresses by hand (below).
 152- =tls= — =starttls= (default) or =implicit= (TLS from the first byte,
 153  for relays on 465).
 154- =require_tls= — with =starttls=, a relay that does not offer STARTTLS
 155  gets no mail: delivery fails and retries, and the admin page's Mail
 156  table shows the error. Unset, it is on for every relay except
 157  =localhost= and loopback addresses; set =false= to allow plaintext
 158  to a remote relay.
 159
 160** [mail.inbound]
 161Reply by mail: a reply to issue or merge request mail posts a comment
 162(#295). gitbayd polls a mailbox over IMAP; no port is opened for it.
 163Off unless =enabled=, and it requires =[mail] smtp_host=, since the
 164replies answer mail gitbayd sends.
 165
 166#+begin_src toml
 167[mail.inbound]
 168enabled       = true
 169imap_host     = "imap.example.org"       # host:port; 993, or 143 with tls = "starttls"
 170tls           = "implicit"               # or "starttls"; there is no plaintext setting
 171user          = "reply@gitbay.example"
 172password_file = "/etc/gitbay/imap.pass"  # one line, mode 0600, owned by gitbayd's user
 173mailbox       = "INBOX"                  # default
 174poll_interval = "1m"                     # default; at least 10s
 175reply_address = "reply@gitbay.example"
 176require_dkim  = true                     # recommended; see below
 177trusted_authserv_id = "mx.example.org"   # the mail host's Authentication-Results id
 178#+end_src
 179
 180- The password is read from =password_file= at every connection and
 181  never appears in the config, argv or the log. An unreadable file, or
 182  one readable by group or others, stops the daemon at start.
 183- =reply_address= is what each Reply-To is built from:
 184  =reply@gitbay.example= becomes =reply+<token>@gitbay.example=. The
 185  mailbox must receive that. Hosts that deliver subaddresses to the
 186  mailbox need nothing more; others need a wildcard rule. Migadu, for
 187  one, sent =threads+x@gitbay.org= nowhere until a rewrite from
 188  =threads+*= to =threads@gitbay.org= was added. A domain catch-all only
 189  works if it points at this mailbox, which then also holds everything
 190  else sent to the domain. Send a test to =<reply_address>+test= and
 191  expect a =refused mail reply= audit row with "malformed reply token"
 192  within a poll interval (=gitbay audit --action 'refused mail'=). Point
 193  the domain's MX at the mail host as for any other mailbox; nothing
 194  about it involves gitbayd.
 195- Use a mailbox that holds nothing else. gitbayd reads every unseen
 196  message in it and marks each one =\Seen= when it is handled, posted
 197  or refused. A message that fails for a reason that may pass (the
 198  database busy, the server refusing that one fetch) stays unseen and is
 199  tried again on the next poll, up to five times, then is marked seen
 200  and audited. A dropped connection or a timeout ends the poll and
 201  counts against no message. A
 202  message over 10 MiB is refused by its size without being fetched. A
 203  server that sends more than about 11 MiB, or more than a thousand
 204  untagged responses, for one command has its connection closed; one
 205  poll handles at most ten thousand messages.
 206- Whatever the settings, a message is refused when a header field name
 207  is not RFC 5322 =ftext= (=From : x=, a space or a non-ASCII byte in a
 208  name), when it does not have exactly one =From=, or when it has more
 209  than one =To=, =Cc=, =Message-ID=, =Content-Type= or
 210  =Content-Transfer-Encoding=.
 211- =require_dkim= (default false) should be on for any instance
 212  reachable from the internet. With it, a reply is posted only when
 213  gitbayd itself verifies one of its DKIM signatures (RFC 6376) with a
 214  =d== in relaxed alignment with the From domain (the same
 215  organizational domain by the public suffix list; =d=github.io= aligns
 216  with nothing) and an =h== that covers =From=, the =To= or =Cc= holding
 217  the reply address, =Content-Type=, and =Message-ID= when the message
 218  has one. A =Content-Transfer-Encoding= outside =h== is accepted only
 219  when it is =7bit=, =8bit= or =binary=, which leave the decoded body as
 220  it is; Thunderbird, for one, does not sign it. An unsigned
 221  =quoted-printable= or =base64= is refused. The reply
 222  address is read only from =To= or =Cc=: a reply that reached the
 223  mailbox by Bcc, with the address only in =Delivered-To=, is refused
 224  ("reply address not in To or Cc"). It needs nothing from the mail
 225  host, so it works where the host adds no =Authentication-Results=.
 226  rsa-sha256 (keys of 1024 bits or more) and ed25519-sha256 are
 227  accepted, with simple or relaxed canonicalization; rsa-sha1, a body
 228  length tag (=l==), an expired =x== and a =t== more than fifteen
 229  minutes ahead are refused. Only the first five signatures are
 230  checked. The key is looked up at =<s>._domainkey.<d>= with a
 231  five-second timeout and cached for fifteen minutes (the resolver does
 232  not report the record's TTL); a lookup that fails for a reason that
 233  may pass (a timeout, SERVFAIL) leaves the message for the next poll,
 234  up to the five tries above, while a missing key refuses it.
 235  Signatures are checked on the message as fetched. Each passing
 236  signature is recorded with the =Message-ID=, so a copy of the same
 237  signed message posts once even with unsigned fields changed.
 238- Either =require_dkim= or =trusted_authserv_id= passing is enough to
 239  authenticate =From=; when both are set, a reply needs only one of
 240  them, and a refusal names both reasons. With only
 241  =trusted_authserv_id=, the reply address may come from any recipient
 242  field (=Delivered-To=, =X-Original-To=, =Envelope-To=, =To=, =Cc=),
 243  since the mail host vouches for the sender and not for the fields.
 244  Set both when the mail host adds =Authentication-Results= for most
 245  senders but not all.
 246- =trusted_authserv_id= names the authserv-id the mail host writes at
 247  the start of its =Authentication-Results= header (Gmail's is =mx.google.com=).
 248  With it set, a reply is posted only when the topmost header with that
 249  id shows =dmarc=pass= with =header.from= equal to the From domain, or
 250  =dkim=pass= with a =header.d= in relaxed alignment with it (the same
 251  organizational domain by the public suffix list; a public suffix such
 252  as =github.io= aligns with nothing). The header is parsed per RFC
 253  8601, so text inside a quoted string or a comment (a quoted MAIL FROM
 254  local part, a reason) is never read as a result. Lower headers
 255  claiming the same id are the sender's and are not read. This is only safe when the mail host
 256  removes incoming =Authentication-Results= headers that claim its id,
 257  as RFC 8601 asks; Gmail, Fastmail and Migadu do. Check yours before
 258  relying on it. With neither this nor =require_dkim= set, the daemon
 259  logs a warning at start and =admin mail inbound check= repeats it:
 260  =From= is then whatever the sender wrote. Mail between two addresses
 261  at the same host may carry no =Authentication-Results= at all: at
 262  Migadu, mail from another
 263  Migadu-hosted domain is delivered through its outbound path and gets
 264  none, so setting the id alone refuses every reply from such users.
 265  That mail does carry a DKIM signature aligned with =From= (for
 266  example =d=cleberg.net; s=key1; a=rsa-sha256; c=simple/simple;
 267  h=from:to:subject:date:message-id:mime-version:content-type=), which
 268  is why gitbay.org sets =require_dkim= instead.
 269- =gitbay admin mail inbound check= logs in, opens the mailbox
 270  read-only (EXAMINE) and reports the message and unseen counts and how
 271  =From= is authenticated (=require_dkim=, =trusted_authserv_id=), so a
 272  check never marks a reply seen before the poller reads it. It warns
 273  when neither is set. With inbound off it says so and exits 0. Poll
 274  failures are logged as =mail reply: poll failed= with the server and
 275  the IMAP error.
 276
 277A reply is posted when all of these hold, checked when it is read:
 278
 2791. It is not an automatic reply (=Auto-Submitted=, =Precedence: bulk=
 280   and the like).
 2812. A recipient header carries a reply address whose token verifies
 282   and has not expired (thirty days from the mail it came on).
 2833. The token's account exists, is active and not disabled, still has
 284   reply by mail on, and was created before the token was: an id freed
 285   by a delete and reused is not the account the token named. The same
 286   holds for the repository.
 2874. =From= is one of that account's verified addresses, and, with
 288   =require_dkim= or =trusted_authserv_id= set, a DKIM signature
 289   gitbayd verified or the mail host's result authenticated it.
 2905. The message has a =text/plain= part (HTML-only mail is refused, not
 291   converted), and what is left after quoted text and the signature
 292   are removed is not empty and fits a comment (64 KiB).
 2936. No earlier copy of the message (same =Message-ID=, account and
 294   thread) posted.
 2957. =issue comment= or =mr comment=, dispatched as the account, accepts
 296   it: the account can still read the repository, the thread exists,
 297   the repository is not archived, the write budget is not spent.
 298
 299The comment's audit row is =cmd issue comment= (or =mr comment=) with
 300=source: mail=. A refusal writes a =refused mail reply= row with the
 301reason and the =Message-ID=, never the message's content, at most sixty
 302a minute, and sends nothing back. See Threat-Model for why the token
 303and the sender address are both required.
 304
 305** [push]
 306Push notifications to Apple devices, delivered by gitbayd talking to
 307APNs directly over HTTP/2, authenticated by an ES256 JWT signed with an
 308operator-supplied provider key. Off unless configured.
 309
 310- =enabled= (false).
 311- =key_file= — path to the =.p8= provider key from Apple's developer
 312  portal (Certificates, Identifiers & Profiles → Keys). It belongs at
 313  =/etc/gitbay/apns.p8=, mode 0600, owned by the account gitbayd runs
 314  as. Read and validated at startup: it must parse as a PEM-wrapped
 315  PKCS#8 EC (P-256) private key, or the daemon refuses to start rather
 316  than fill a queue nobody is watching.
 317- =key_id=, =team_id= — the key's id and your Apple developer team id,
 318  both from the same portal page.
 319- =topic= — the app's bundle identifier. *An APNs key belongs to a
 320  bundle ID.* gitbay.org pushes to the App Store build under its own
 321  bundle id; a self-hoster who wants push ships their own iOS build
 322  under their own bundle id, with its own =.p8= key from their own
 323  developer account, and points =topic= at that id. There is no way to
 324  push to someone else's build, by design — this is Apple's model, not
 325  gitbay's.
 326- =environment= — =production= or =sandbox=, naming the APNs host
 327  rather than taking a URL, so a typo cannot aim the key at a host that
 328  is not Apple's.
 329
 330All five of =key_file=, =key_id=, =team_id=, =topic= and =environment=
 331are required when =enabled= is true; validation runs at config load,
 332so a misconfigured =[push]= is caught before the daemon serves
 333anything. The delivery queue (a device's undelivered and attempted
 334pushes) is capped the same way the mail queue is, by =[retention]
 335push=.
 336
 337** [backup]
 338- =age_recipients= (optional) — age public keys (=age1...=). When set,
 339  =admin backup= encrypts every archive to them and appends =.age= to
 340  its name. Generate the pair off the host with =age-keygen=; only the
 341  public key goes here, so the host writes archives it cannot read.
 342  The restic copy is unaffected: the offsite job stages its own
 343  =VACUUM INTO= of the live database and snapshots =/var/lib/gitbay=,
 344  not the archives.
 345
 346** [api]
 347- =enabled= (false) — the JSON API surface; see [[API]]. Off
 348  means no credential-bearing HTTP endpoint exists at all.
 349
 350** [webhooks]
 351- =allow_local= (false) — permit webhook, mirror and import targets on
 352  loopback, private, shared (100.64.0.0/10), link-local or multicast
 353  addresses. Leave off unless you know why you need it (SSRF).
 354
 355** [limits]
 356- =clone_timeout= (3600s) — cap on =repo import= fetches. An import
 357  takes http and https URLs only, passes the same address check as a
 358  mirror sync and is pinned the same way, so it needs git 2.37 too.
 359- =max_blob_bytes= (100MB) — cap on raw file serving over the web.
 360- =max_asset_bytes= (512MB) — cap per uploaded release asset.
 361- =max_snippet_bytes= (1MB) — cap per snippet file.
 362- =max_snippets_per_user= (0, unlimited) — snippets an account may own.
 363- =max_repos_per_user= (0, unlimited) — repositories an account may own
 364  directly; =repo create=, =fork=, =import= and =repo transfer= refuse
 365  past it.
 366- =max_bytes_per_user= (0, unlimited) — disk the account's own
 367  repositories may take; a push may be no larger than what is left, and
 368  a transfer in must fit.
 369- =max_orgs_per_user= (0, unlimited) — organizations an account may
 370  create. Membership in an org someone else created does not count.
 371- =max_repos_per_org=, =max_bytes_per_org= (0, unlimited) — the same two
 372  caps for each organization.
 373- =pack_concurrency= (3), =pack_per_principal= (2), =pack_queue= (32),
 374  =pack_queue_wait= (="60s"=) — git pack generation (clones, fetches,
 375  =git archive --remote=, web archive downloads, =repo download= over
 376  SSH and the API) over SSH, smart HTTP and git:// shares one
 377  budget: this many at once, this many per account (per client
 378  address when anonymous: an IPv4 address, or an IPv6 /64), and this
 379  many waiting for at most the wait. Anonymous clients together hold
 380  at most =pack_concurrency= − 1 slots when it is above 1: an account
 381  (SSH key, bearer token or web session) can take the last slot when it
 382  is free, and anonymous clients cannot hold it.
 383  Past that an SSH client gets "the server is busy…" and exit 1, HTTP
 384  gets 503 with =Retry-After: 30=, git:// an =ERR= line; the daemon
 385  logs a =pack limit= warning naming the transport and whether the
 386  client was signed in, at most once a minute per transport. An SSH client
 387  that disconnects while queued leaves the queue; an HTTP or git:// one
 388  keeps its place until the wait runs out. A running clone is killed
 389  when its client disconnects, or when no write to the client completes
 390  for two minutes: a client reading below about 550 B/s, or an HTTP
 391  request body that takes over two minutes with nothing written back,
 392  is cut. Ref listings (info/refs, protocol v2
 393  =ls-refs=) and pushes are outside the budget. A busy =repo download=
 394  exits 1 with the same message; over the API it is a 503 with
 395  =Retry-After: 60=. For the
 396  three counts 0 means the default and a negative value turns that
 397  bound off. The defaults suit a four-core host; see [[Performance]].
 398  With =ssh.mode = "system"= each SSH session is its own process and
 399  SSH clones are not counted.
 400- =push_concurrency= (2), =push_per_principal= (1), =push_queue= (16),
 401  =push_queue_wait= (="60s"=) — =git receive-pack= over SSH, on a
 402  budget of its own so clones cannot starve pushes or the reverse:
 403  this many at once, this many per account or deploy key, and this
 404  many waiting for at most the wait. One principal may have up to half
 405  of =push_queue= (at least one) waiting, so parallel pushes from one
 406  account queue rather than being refused, but cannot fill the queue.
 407  A deploy key is its own principal, apart from the account that
 408  registered it, so an account with deploy keys can hold
 409  =push_per_principal= slots per key;
 410  the global cap still holds. A bot account such as a runner's counts
 411  like any other account. The slot is taken after the access checks and held
 412  until receive-pack exits, which is after =post-receive= (merge
 413  detection, CI queueing, webhooks) has run. Past that the client gets
 414  "the server is busy: it is at its limit of concurrent pushes…" and
 415  exit 1, and the daemon logs a =push limit= warning at most once a
 416  minute. A client that disconnects while queued leaves the queue; one
 417  that disconnects mid-push ends receive-pack and frees its slot, and
 418  a revoked key kills it. 0 and negative values read as for =pack_*=.
 419  HTTP and git:// carry no pushes. With =ssh.mode = "system"= pushes
 420  are not counted and the two timeouts below do not apply.
 421- =push_idle= (="60s"=), =push_receive_timeout= (="15m"=) — a push
 422  holding a slot is killed, its process group with it, when its
 423  pre-receive has not started =push_receive_timeout= after it took the
 424  slot, or when no byte has been read from the client and none written
 425  to it for =push_idle=. The idle rule starts when the pack signature
 426  arrives from the client or pre-receive starts, whichever is first
 427  (a delete-only push sends no pack): before that the client may be
 428  silent while its =pack-objects= counts and compresses, and only
 429  =push_receive_timeout= applies. receive-pack runs with
 430  =receive.keepAlive= set to a quarter of =push_idle= (1 to 5 seconds),
 431  so the keepalives it sends to side-band clients while it indexes and
 432  runs hooks keep a working push alive. Once pre-receive has started
 433  only =push_idle= applies: post-receive is never cut short by the
 434  clock. A push killed before pre-receive answers updates no refs.
 435- =max_pack_bytes= (2 GiB) — the largest pack one push may send,
 436  enforced as =receive.maxInputSize= and lowered to what an owner's
 437  storage quota has left.
 438- =ssh_auth_rate= (10) — SSH authentication failures per client address
 439  per minute on the embedded listener; see below.
 440
 441** [git_daemon]
 442- =enabled= (false), =port= (9418) — the anonymous =git://= listener.
 443  Serves only public repositories that additionally ran
 444  =repo settings git-daemon <repo> on=.
 445
 446** [mirrors]
 447- =pull_interval_minutes= (15) — how often pull mirrors fetch their
 448  upstream. Push mirrors sync shortly after each local ref update.
 449  Mirror URLs pass the same SSRF rules as webhook targets, when saved
 450  and again before every sync; git then connects only to the addresses
 451  that were checked (=http.curloptResolve=) and does not follow
 452  redirects, so a mirror of a renamed repository fails until its URL
 453  is updated. Needs git 2.37 or later on the server; with an older git
 454  the worker logs an error at start and syncs no mirror, recording the
 455  reason on each. Sync ignores the system and global gitconfig.
 456
 457** [security]
 458The instance's code scan, which a repository admin turns on with
 459=repo security enable=. Off until =image= is set.
 460
 461- =image= ("") — the image the scan runs in, provisioned on every
 462  runner host that serves a scanned repository. Build it from
 463  =deploy/Containerfile.security= (Opengrep and its rules, both pinned
 464  by sha256); the file has the commands.
 465- =most_often= ("daily") and =least_often= ("monthly") — the range of
 466  frequencies a repository may choose with =repo settings
 467  security-frequency=, from =daily=, =weekly= (Sunday) and =monthly=
 468  (the 1st). A repository whose choice falls outside a narrowed range
 469  scans at the nearest frequency in it, from its next scan on.
 470- =default= ("daily") — the frequency of a repository that has not
 471  chosen one; within the range.
 472- =hour= (4) — the hour, UTC, every scan is due. =repo security run=
 473  queues one now.
 474- =schedule= is gone; a config that sets it is refused at load.
 475- =steps= — shell steps that write SARIF into =$GITBAY_RESULTS=. The
 476  default runs Opengrep with the rules in the image at
 477  =/opt/opengrep-rules=.
 478
 479The scan is a build of the reserved job =gitbay-security= on a runner
 480attached to the repository. It gets none of the repository's secrets
 481and sets no commit status. When its steps succeed the runner uploads
 482the SARIF (=runner results=, gitbay-runner from this release on) and
 483the findings replace the repository's last set; =gitbay-bot= keeps a
 484"Code scanning findings" issue, opened, rewritten and closed the way
 485the dependency issues are. An older runner runs the steps and uploads
 486nothing, so the issue stays as it was.
 487
 488Not every finding is listed. A rule from one of opengrep-rules' library
 489directories (=python/django=, =javascript/jquery=,
 490=typescript/react/portability/i18next=, …) counts only where a manifest
 491at the scanned commit names that library: =go.mod=, =requirements.txt=,
 492=pyproject.toml=, =package.json= or =Cargo.toml=, in any directory
 493outside =node_modules=, =vendor= and =third_party=. The =yaml/semgrep=
 494lints count only in a repository with a =.semgrep= config. Paths
 495=.gitattributes= marks =linguist-vendored= or =linguist-generated= are
 496set aside, as are the repository's =security-ignore= paths and
 497=security-exclude-rule= rules. A hit of
 498=html-templates/security/unquoted-attribute-var=, which matches in
 499generic mode and takes a quote inside ={{ }}= for the end of the
 500attribute, is checked against the template at the scanned commit: it
 501counts only where an expression there is an unquoted attribute value
 502or stands in for attributes. The issue says how many were set aside
 503and why. A finding a writer dismisses (=repo security dismiss=, by the
 504fingerprint the issue prints) stays out of the issue across scans until
 505it is reopened; the issue closes when nothing is left open.
 506
 507The bundled rules are =opengrep/opengrep-rules=, LGPL-2.1 with the
 508Commons Clause: an instance that sells hosting should supply its own.
 509
 510** [go_import]
 511Vanity Go module paths, one per line: ="host/module" = "owner/repo"=.
 512Requests with =?go-get=1= at or under the module path answer with the
 513go-import meta tag pointing at the repository's HTTPS clone URL, so
 514=go install host/module/cmd/...@latest= resolves. The repository should
 515be public (the module path itself confirms it exists).
 516
 517* Users, email, invites
 518
 519Every =gitbayd admin= subcommand except =backup=, =gc= and the one-shot
 520backfills is a wrapper that dispatches the registry command of the same
 521name as the host: an admin context with no account behind it, so its
 522audit rows carry no actor and =source: host=. The same commands run in an
 523instance admin's SSH session (=ssh git@<host> admin ...=) and write the
 524same rows with the key fingerprint as source. One implementation, two
 525credentials.
 526
 527#+begin_src sh
 528gitbayd admin user create alice --key alice.pub --email a@example.org --verified [--admin]
 529gitbayd admin email verify alice a@example.org   # admin assertion, no SMTP needed
 530gitbayd admin invite --email b@example.org       # mails a code; prints it if no SMTP
 531#+end_src
 532
 533"Verified" means SMTP-confirmed or host-admin-asserted; the database
 534records which. Verified emails are what make commit signatures
 535meaningful — an unverified address never produces a =verified= badge.
 536
 537* Audit and account control
 538
 539The audit log is the security feed (events are the product feed): every
 540successful mutating command with its argv and source credential (SSH key
 541fingerprint or API), every refused one (exit 3 or 4) as =refused
 542<command>=, refused pushes as =refused git-receive-pack= (the access
 543check) or =refused push= (a branch or tag rule, a release anchor or an
 544unsigned commit, with the repository and ref names), hook socket
 545requests failing the peer or push-token check as =refused hook= (never
 546the token), registrations, admin actions, force-pushes, and auth
 547failures/throttling. A refusal row
 548keeps the flag names and the first positional, not the values.
 549Refusals are recorded up to ten a minute per account and 600 a minute
 550across the instance; past either, one =refused.throttled= row stands
 551for the rest of that minute. The caps bound the embedded listener, the
 552web and the API; under =ssh.mode = "system"= each =gitbayd shell=
 553connection counts separately. Secrets never appear — they travel on
 554stdin, never in argv.
 555
 556Each row carries the SHA-256 of the row before it. =gitbayd admin audit
 557verify= opens the store as other admin commands do, applying pending
 558migrations, so run it with the binary that matches the daemon. It
 559recomputes the chain and exits 1 naming the first row that was
 560edited or whose predecessor was removed. The chain is unkeyed: whoever
 561can write the database can recompute every hash after an edit, and
 562verify then finds nothing. It catches an edit only when the later
 563hashes were not recomputed. Retention removing the oldest
 564rows is not a break. Rows written before the chain existed are counted
 565and skipped; when every row is such a row, verify warns and exits 1,
 566since clearing the hash columns looks the same. After an upgrade that
 567clears with the first new audit row.
 568
 569Removing the newest rows leaves no break, and neither do rows written
 570afterwards under the freed ids. The database cannot show either. The
 571daemon logs every row it writes to its journal, outside the database
 572(=journalctl -u gitbayd -g 'INFO audit '=), and verify prints the last
 573id and hash: comparing them with the newest journal line is the check
 574for any change, recomputed hashes included. Rows written by
 575host =gitbayd admin= commands, and by =gitbayd shell= when =ssh.mode =
 576"system"=, are not copied to the journal.
 577
 578#+begin_src sh
 579gitbayd admin audit [--actor u|-] [--action prefix] [--since 24h|7d|date] [--limit n] [--json]
 580gitbayd admin audit verify           # check the hash chain; exit 1 names the first bad row
 581ssh git@<host> audit ...             # the same, from an admin session
 582ssh git@<host> admin user list [--state active|pending|disabled|admin]
 583ssh git@<host> admin user show <name>   # keys, emails, orgs, tokens, sessions
 584ssh git@<host> admin user limits <name> [--repos n|default] [--bytes n|default] [--orgs n|default]   # per-account caps
 585ssh git@<host> admin org limits <org> [--repos n|default] [--bytes n|default]   # per-org caps
 586ssh git@<host> admin user promote <name>   # grant instance admin
 587ssh git@<host> admin user demote <name>    # remove it; the last admin is refused
 588gitbayd admin user promote <name>    # host-local: recovery when no admin key is reachable
 589gitbayd admin user disable <name>    # suspend: SSH, web, API all refused;
 590gitbayd admin user enable <name>     #   sessions dropped, nothing deleted
 591gitbayd admin user delete <name> --yes  # only for accounts anchoring nothing:
 592                                     #   refused (with each blocker named) while
 593                                     #   the account owns repos, authored
 594                                     #   issues/MRs/comments/reviews, or is an
 595                                     #   org's only admin
 596#+end_src
 597
 598=--actor= takes a username, or =-= for rows with no actor: host commands
 599and auth failures. =--action= is a prefix, so =cmd repo= catches every
 600repository command and =admin= every host or admin-session action.
 601=--since= is a duration back from now (=30m=, =24h=, =7d=) or a date.
 602
 603=admin user list= pages by username (=--limit=, =--cursor=) and carries
 604each account's state and =last_seen=, the newest use of any of its SSH
 605keys or API tokens. =admin user show= adds the keys with their last use,
 606each address with how it was verified, PGP keys, org roles, the owned
 607repository count, API token names, and live browser sessions. Both are
 608Both are refused to non-admins, like =audit=, on every surface.
 609
 610=/admin/users= is the same list in a browser, linked from the admin
 611page: the state filter the command takes, keyset paging on its cursor,
 612and a row per account with promote, demote, disable and enable, each
 613dispatching the command. Demote and disable ask for the username to be
 614typed, since both take someone's access away. Creating and deleting an
 615account, issuing an invite and asserting an address stay on the command
 616line: each takes a key, mints a credential, or cannot be undone. A
 617non-admin gets the 404 a missing page would, so the URL confirms
 618nothing.
 619
 620Promotion needs an active account: a pending or disabled one is refused.
 621Demotion is refused when it would leave no admin, over SSH, in the
 622browser and on the host alike, so the host-local =promote= is the way
 623back in when the only admin key is lost.
 624
 625Instance admin carries no right on anyone's repository: policy does not
 626consult it, and a private repository still answers not-found to an
 627admin. Moderation goes through explicit overrides that skip the access
 628check and write their own audit row:
 629
 630#+begin_src sh
 631ssh git@<host> admin repo list [--owner o] [--visibility public|private]  # size, last push
 632ssh git@<host> admin repo archive|unarchive <owner/name>
 633ssh git@<host> admin repo visibility <owner/name> public|private
 634ssh git@<host> admin repo delete <owner/name> --yes
 635#+end_src
 636
 637Each lands in the audit log as =admin repo.<action>= naming the
 638repository, on top of the =cmd= row every mutating command gets.
 639
 640=limits.ssh_auth_rate= (10) throttles per-IP authentication *failures*
 641per minute — successful auths never count and clear the slate.
 642=limits.max_pack_bytes= is enforced as =receive.maxInputSize= on every
 643push.
 644
 645=limits.write_rate= (60) bounds *mutating commands per account per
 646minute*. It is counted in the dispatcher, so SSH, the JSON API and the
 647web spend one budget and a caller cannot refresh it by changing surface;
 648=limits.api_rate= stays in front of it, bounding a network source rather
 649than an account. A command is one token whatever it writes, so a bundle
 650import costs one and only a loop of separate commands spends the budget.
 651Read-only commands, the runner protocol (a build streams its log in many
 652small writes) and the host CLI are exempt. Refusals exit 4 and say when
 653to retry. A negative value turns the limit off; it matters most with
 654=registration = "open"=, where every write also queues notification mail
 655and webhook deliveries.
 656
 657* Queues
 658
 659Every background worker keeps a backlog and a failure state. An instance
 660admin reads them all in one place:
 661
 662#+begin_src sh
 663gitbay dashboard --json | jq .queues   # webhooks, mail, push, mirrors, builds, deps
 664#+end_src
 665
 666Per worker: pending, retrying (pending with a failed attempt) and
 667dead-lettered counts with the oldest pending age, and the retrying or
 668failed rows themselves, capped at twenty each. Builds list what is
 669running and then what is pending, each since when, so a build no runner
 670is scoped to claim is visible here rather than only in its repository;
 671mirrors list the ones whose last sync failed;
 672dependency checks list the ones whose last check errored. Non-admins get
 673no =queues= key at all.
 674
 675Push rows name the device id, never the token. Watch this one after
 676configuring =[push]=: a =key_id= or =team_id= Apple did not issue passes
 677config validation, which can only check that the =.p8= parses, and then
 678every send comes back =403 InvalidProviderToken= and dead-letters on its
 679first attempt.
 680
 681In accounts mode the same read renders at =/admin=, linked from the rail
 682for admins. Anyone else gets a 404 there.
 683
 684A dead-lettered mail is logged as =notification dead-lettered mail=<id>=,
 685with the address redacted out of the relay's error. The id is the queue
 686row: find it in the Mail table on =/admin=, or in =dashboard --json=,
 687where the recipient and the unredacted error are. That is deliberate —
 688see the Threat-Model page.
 689
 690* Maintenance
 691
 692#+begin_src sh
 693gitbayd admin stats [--json]         # counts, database size, per-repo disk
 694ssh git@<host> admin stats [--json]  # the same, from an admin session
 695gitbayd admin gc [--repo owner/name] # git gc: repack and prune; per-repo sizes
 696gitbayd admin gc --aggressive        # thorough repack; slow, rarely needed
 697gitbayd admin gc --lfs               # also drop LFS objects no pointer names (older than a day)
 698#+end_src
 699
 700A history rewrite leaves the commits it removed reachable through
 701=refs/merge-requests/N/head= of the merge requests that landed them, so
 702they stay fetchable by anyone who can read the repository. Nothing drops
 703a head ref on its own — an open or source-gone MR is merged through it,
 704and a merged or closed one keeps its diff readable through it — so the
 705cleanup is a command an instance admin runs, naming the MRs:
 706
 707#+begin_src sh
 708ssh git@<host> admin mr prune owner/name 1 2 3 --yes
 709#+end_src
 710
 711It refuses an open or source-gone MR, deletes the named refs, runs
 712=git gc --prune=now= on that one repository so the objects go at once
 713rather than after git's two-week grace, leaves a system comment on each
 714MR, and audits as =admin mr.prune=. The MR keeps its title, comments,
 715reviews and head sha; =mr diff= and the MR page say the head is gone.
 716Run it when nothing is pushing to that repository: without the grace, a
 717push caught between leaving quarantine and writing its ref loses its
 718objects. Objects also survive in offsite backups until those are
 719rewritten; see "Removing a repository's history from every snapshot".
 720
 721=deploy/cloud-init.yaml= ships a =gitbay-gc.timer= that runs =admin gc=
 722weekly (Sunday 07:00 UTC). Imported repositories keep whatever pack
 723layout the source sent, so a first manual =admin gc= after a bulk
 724import is worthwhile.
 725
 726* Backup and restore
 727
 728#+begin_src sh
 729gitbayd admin backup --out /var/backups/gitbay/backup.tar.gz
 730gitbayd admin backup --verify /var/backups/gitbay/backup.tar.gz   # read it back
 731#+end_src
 732
 733One archive: a consistent SQLite snapshot (taken *before* the
 734repositories are read, so the database never references objects the
 735archive missed), every repository, and the SSH host keys. Excluded:
 736hook socket, regenerated hook scripts, WAL files. Safe to run against a
 737live daemon. =--out= must be outside =server.root=, or the next full
 738backup would carry the archive. Each run removes the snapshot
 739directories (=.gitbay-snap-*=) and temporary archives (=.*.tmp-*=) a
 740killed run left beside its archive once they are a day old, and prints
 741each one it removes.
 742
 743=--verify= reads an archive back: the snapshot must pass SQLite's
 744integrity check, every repository the snapshot names must be in the
 745archive, and each must pass =git fsck --connectivity-only=. Every
 746release asset the snapshot names must be in its repository with its
 747recorded size and sha256, and every LFS object in the archive must
 748hash to its name. LFS objects are named by pointer files in git
 749history rather than by the database, so a pointer whose object was
 750never uploaded is not caught, and with =[lfs] root= outside
 751=server.root= the archive holds no LFS objects at all. It extracts the
 752repositories to a temporary directory for the checks, so it needs free
 753space the size of the repositories. A database-only archive is checked
 754for integrity and says so. Exit is non-zero on damage, a missing
 755repository, a missing object, or a missing or altered asset or LFS
 756object.
 757
 758A full backup holds =<root>/backup.lock= from its database snapshot to
 759its last repository. While it runs, =repo delete=, =repo rename=,
 760=repo transfer=, =admin repo delete=, =org rename=, =admin mr prune=
 761and =gitbayd admin gc= refuse with "a backup is running"; retry when it
 762finishes. Database-only backups take no lock. A pack that git's own
 763automatic gc removes during the walk is skipped; each repository's refs
 764are archived before its objects, so the refs still find their objects,
 765and =--verify= reports it if one does not.
 766
 767Verifying an archive of unknown origin: run it as an unprivileged
 768user. The connectivity check runs git with =--git-dir= on each
 769extracted repository, so a directory that is not a repository fails
 770rather than git checking an enclosing one. =objects/info/alternates=
 771and a =commondir= directly in a =*.git= directory are not extracted,
 772so an archive cannot use either to have git read another repository's
 773objects or refs on the host. Git still reads each archived
 774repository's own =config=.
 775
 776Archives carry a directory entry for every directory, including an
 777empty one, so a bare repository whose refs are all packed restores as
 778a repository. Archives written before this release do not: extracting
 779one can leave a repository's =refs/= directory missing, which stops
 780git from recognizing it as a repository at all. =gitbayd admin backup
 781--verify <archive>= names the repositories this affects; the fix is
 782=mkdir -p <root>/repos/<owner>/<name>.git/refs= for each one, after
 783which it opens normally.
 784
 785With =[backup] age_recipients= set the archive is =<name>.tar.gz.age=
 786and =--verify= needs the private key:
 787
 788#+begin_src sh
 789gitbayd admin backup --verify gitbay-20260927-090000.tar.gz.age --identity ~/.config/gitbay/backup-identity.txt
 790age -d -i ~/.config/gitbay/backup-identity.txt gitbay-20260927-090000.tar.gz.age | tar -xz -C /new/root
 791#+end_src
 792
 793The identity lives off the host (with the secret key file and the
 794restic credentials), so verifying an encrypted archive happens there
 795or on a restore host.
 796
 797Restore: extract into an empty directory, point =server.root= at it,
 798restore =server.secret_key_file= from its own copy (mode 0600, owned
 799by the account gitbayd runs as), then start gitbayd. No archive carries
 800the key file, and without it gitbayd refuses to start. Host keys are
 801preserved, so clients keep their known_hosts entries; hooks regenerate
 802at startup.
 803
 804** Schedule and recovery point
 805
 806Two timers, because the two halves of the data have different exposure.
 807
 808- =gitbay-backup.timer=, nightly. The full archive above, last 7 kept.
 809- =gitbay-db-backup.timer=, hourly. =admin backup --db-only=, which
 810  writes the SQLite snapshot alone, last 48 kept. A few MB against the
 811  full archive's hundreds, which is what makes the frequency affordable.
 812
 813The split follows what a loss would actually cost. Repositories are git,
 814so a mirror or any clone is a second copy; the database is the only copy
 815of issues, merge requests, comments and review state. So the recovery
 816point is about an hour for the data that exists nowhere else, and a day
 817for the data that does.
 818
 819Continuous replication (litestream and similar) was considered and not
 820adopted. It would take the database's recovery point to seconds, but the
 821repositories would still be on the nightly archive, so a restore could
 822produce a database referencing commits the repository backup does not
 823have. Consistency between the two halves is worth more here than latency
 824on one of them. Revisit if repository replication becomes continuous
 825too.
 826
 827** Offsite copies
 828
 829bay1 also takes a nightly restic snapshot of =/var/lib/gitbay= and
 830=/var/lib/gitbay-stage= (a database copy and =config.toml=, staged
 831there) to an S3 bucket at Scaleway, with a key that can only add
 832snapshots. Nothing else under =/etc/gitbay= is in it: not the secret
 833key file, not =apns.p8=. The key that can
 834remove them lives on the operator's machine, in
 835=~/.config/gitbay/offsite.env=, and never on bay1: a compromised host
 836cannot destroy its own history. Forgetting, pruning and rewriting all
 837run from there.
 838
 839*** Removing a repository's history from every snapshot
 840
 841A history rewrite plus =admin mr prune= takes commits off the server,
 842but every snapshot taken before it still holds them, and the retention
 843window is the only thing that ages them out. To remove them now,
 844rewrite the snapshots without that repository rather than forgetting
 845the snapshots: everything else in them stays restorable. The next
 846nightly run adds the repository back in its current state.
 847
 848Repositories are stored under the name they had on disk when each
 849snapshot was taken, so a renamed repository needs every name it has
 850carried. Check what an older snapshot holds before choosing the paths:
 851
 852#+begin_src sh
 853set -a; . ~/.config/gitbay/offsite.env; set +a
 854restic $RESTIC_OPTS snapshots
 855restic $RESTIC_OPTS ls <old-snapshot> /var/lib/gitbay/repos/<owner>
 856#+end_src
 857
 858Then dry-run, apply, prune, and confirm nothing matches:
 859
 860#+begin_src sh
 861EXCL="--exclude /var/lib/gitbay/repos/<owner>/<name>.git --exclude /var/lib/gitbay/repos/<owner>/<old-name>.git"
 862restic $RESTIC_OPTS rewrite --dry-run $EXCL     # "would modify N snapshots"
 863restic $RESTIC_OPTS rewrite --forget $EXCL      # new snapshots replace the originals
 864restic $RESTIC_OPTS prune                       # drops the data nothing references
 865restic $RESTIC_OPTS find <name>.git <old-name>.git   # expect no output
 866#+end_src
 867
 868=--forget= is what makes the originals go; without it the rewritten
 869snapshots sit beside them and the data stays referenced. Snapshot IDs
 870change; their times do not. Done for krz/keycask (formerly rust-pass)
 871on 2026-09-18, across 22 snapshots.
 872
 873** Secret key
 874
 875CI secrets, webhook secrets, mirror tokens and APNs device tokens are
 876stored sealed: AES-256-GCM under a key in =server.secret_key_file=,
 877each value prefixed with the id of the key that sealed it
 878(=gbs1:<id>:=). The key file is not in the database, not under
 879=server.root=, and therefore in neither the local archives nor the
 880main restic repository. It must be copied off the host separately;
 881without it a restored database's secrets cannot be opened, and
 882gitbayd refuses to start against them. A separate restic repository
 883for it and =apns.p8= is planned (runbook D of the data-at-rest plan)
 884and not yet in place, so today the only off-host copy is one the
 885operator makes by hand after =init= and after every =rotate=.
 886
 887#+begin_src sh
 888gitbayd admin secrets init     # once; deploy/install.sh does it on first install
 889gitbayd admin secrets check    # open every value, count by key
 890gitbayd admin secrets rotate   # new key, reseal, retire the old one (as root)
 891#+end_src
 892
 893- Missing file: every gitbayd process that opens the database refuses
 894  to run and names the path, including =serve= and, in system mode,
 895  =authorized-keys=. =migrate= does not need it.
 896- Backups: =admin backup= and =admin backup --verify= do not need the
 897  key file; a restore does.
 898- Wrong key: =serve= stops at startup naming the first row that does
 899  not open; =secrets check= does the same without starting anything.
 900- Upgrade: the first start after the upgrade seals every value still
 901  in clear and logs =sealed secret values=.
 902- Rotation: =rotate= adds a key, reseals every value under it in one
 903  transaction, then removes the old keys. Run it as root, since it
 904  replaces the key file in =/etc/gitbay=; the file keeps its owner.
 905  The daemon re-reads the file when it changes, so it needs no
 906  restart. Copy the new file off the host afterwards. =init= and
 907  =rotate= hold an flock on =<key file>.lock= while they run, so a
 908  second run waits for the first.
 909- Push devices are looked up by the SHA-256 of their token
 910  (=push_devices.token_hash=), since two seals of one token differ.
 911
 912** Restore drill
 913
 914A restore onto a clean host, run quarterly (January, April, July,
 915October) and after any change to the backup code
 916(=cmd/gitbayd/backup.go=, =cmd/gitbayd/restoredrill.go=, the offsite
 917job), and recorded below. The disaster it rehearses is losing bay1, so
 918the local archives are gone with it and the sources are the main
 919offsite restic repository (repositories, LFS, the staged database,
 920=config.toml=), the off-host copy of =secret.key= and =apns.p8= (a keys
 921repository once runbook D creates it; until then the operator's
 922hand-made copy), and the operator's password manager (=offsite.env=,
 923the keys repository's password and token once it exists,
 924=backup-identity.txt=). The full steps are runbook C of the
 925data-at-rest plan (=docs/plans/2026-09-27-data-at-rest-and-backup.md=).
 926
 927=gitbayd admin restore-drill= does the archive half. It extracts a
 928full archive into an empty or absent directory, runs every =--verify=
 929check on the extracted copy, and prints what was restored, the newest
 930issue, issue comment, merge request comment and push in the restored
 931database, and the elapsed time. Exit is non-zero if any check fails.
 932
 933#+begin_src sh
 934gitbayd admin restore-drill /var/backups/gitbay/gitbay-20260927-090000.tar.gz --into /srv/drill
 935gitbayd admin restore-drill <archive>.tar.gz.age --identity backup-identity.txt --into /srv/drill
 936#+end_src
 937
 938=admin backup --verify= extracts the archive under =$TMPDIR=. A host
 939whose =/tmp= is a tmpfs smaller than a full archive (bay1's is 3.9 GB
 940of memory) fails with "no space left on device"; point =TMPDIR= at a
 941directory on disk that the backup's user owns:
 942
 943#+begin_src sh
 944install -d -o gitbay -g gitbay -m 700 /var/backups/gitbay/verify-tmp
 945cd /var/backups/gitbay
 946sudo -u gitbay env TMPDIR=/var/backups/gitbay/verify-tmp gitbayd admin backup --verify <archive>
 947#+end_src
 948
 949What to restore, and from where:
 950
 951| Item                          | Source                                                      | Path on the drill host                         |
 952|-------------------------------+-------------------------------------------------------------+------------------------------------------------|
 953| Database                      | staged copy in =/var/lib/gitbay-stage= (restic), or an archive | =<root>/gitbay.db=                          |
 954| Repositories                  | =/var/lib/gitbay/repos= (restic), or an archive              | =<root>/repos=                                 |
 955| LFS objects                   | =/var/lib/gitbay/lfs= (restic), or an archive                | =<root>/lfs= (or =[lfs] root=)                 |
 956| Release assets                | inside each repository (=gitbay-releases/=)                  | with the repositories                          |
 957| Host keys                     | =/var/lib/gitbay/ssh= (restic), or an archive                | =<root>/ssh= (or =[ssh] host_keys=)            |
 958| =config.toml=                 | =/var/lib/gitbay-stage/config.toml= (restic)                 | =/etc/gitbay/config.toml=                      |
 959| =secret.key=, =apns.p8=       | the off-host copy; no archive or main snapshot carries them | =/etc/gitbay/=, mode 0600, owned by =gitbay=   |
 960
 961From the offsite path (restic is not run by any gitbay command):
 962
 963#+begin_src sh
 964restic restore latest --target / --include /var/lib/gitbay --include /var/lib/gitbay-stage
 965cp /var/lib/gitbay-stage/gitbay.db /var/lib/gitbay/gitbay.db
 966gitbayd --config /etc/gitbay/config.toml admin backup --out /tmp/drill.tar.gz
 967gitbayd admin restore-drill /tmp/drill.tar.gz --into /tmp/drill-root
 968#+end_src
 969
 970The second archive is how the restic tree gets the same checks and
 971timestamps; =/tmp/drill-root= is discarded afterwards.
 972
 973What to check, each a column below:
 974
 975- DB integrity, connectivity, release assets, LFS: =restore-drill=
 976  prints =integrity ok=, =connectivity ok on N repositories=, =release
 977  assets ok: N=, =LFS objects ok: N=. Compare N with =gitbayd admin
 978  stats --json= on the source at the snapshot time.
 979- Secrets: =gitbayd --config /etc/gitbay/config.toml admin secrets
 980  check= opens every value.
 981- Host key: =ssh-keyscan -p 22 <drill-host>= matches the source's
 982  fingerprint.
 983- Config: =gitbayd --config /etc/gitbay/config.toml check-config=.
 984- Service: =ssh -p 22 git@<drill-host> whoami= and a =git clone= over
 985  SSH succeed.
 986
 987Time to service runs from the clean host's first root login to the
 988first successful =git clone= over SSH from it. The recovery point is
 989the time of the newest restic snapshot restored; record beside it the
 990newest issue, comment and push =restore-drill= printed, which show how
 991much activity the restore carries.
 992
 993The first drill ran on the operator's laptop rather than a provisioned
 994host, so its time to service has no provisioning in it, and it could
 995not check secrets: no copy of =secret.key= was on the machine, and
 996gitbayd refuses to start while any sealed value does not open. The
 997sealed values were cleared in the drill copy to reach service. The
 998off-host copy of the key is confirmed to exist (#305); the next drill
 999restores it with the snapshot and runs =admin secrets check= on the
1000restored copy.
1001
1002| Date | Host | Snapshot restored (UTC) | Newest issue / comment / push | Time to service | DB integrity | Connectivity | LFS | Release assets | Host key | Secrets | Notes |
1003|------+------+-------------------------+-------------------------------+-----------------+--------------+--------------+-----+----------------+----------+---------+-------|
1004| 2026-09-29 | laptop (macOS), restic from offsite | 2026-09-29 00:19:15 (ccd646cf) | 00:05:17 / 00:09:44 / 00:15:31 | 8m43s (restore 1m49s, checks 33s) | ok | ok, 69/69 | ok, 2 | ok, 529 | matches | not checked (#305) | 4.99 GiB restored; 71 sealed values cleared in the drill copy to start |
1005
1006* Upgrades
1007
1008Replace the binary, restart the unit. Migrations apply automatically and
1009are transactional; hook scripts under =<root>/hooks= are rewritten at
1010startup to point at the current binary path.
1011
1012* CI runner
1013
1014=gitbay-runner= executes builds queued by pushes and merge requests. It
1015polls over SSH with a key of scope =runner=, which reaches only the
1016runner protocol and read-only git (a runner executes arbitrary
1017repository code, so the key it holds must not do more). A runner key
1018claims builds only for the repositories it is attached to, by =repo
1019runner add= from a repository admin or an instance admin; an admin key
1020claims any. Users attach their own runners: see the Users page. For an
1021instance runner, run it as a dedicated unprivileged user on a non-admin
1022account. =admin user create --key= registers a full-scope key, so the
1023runner key is added afterwards through a bootstrap key that is then
1024removed, and attached to each repository it should build:
1025
1026#+begin_src sh
1027useradd --system --create-home --home-dir /var/lib/gitbay-runner ci-runner
1028sudo -u ci-runner ssh-keygen -t ed25519 -N "" -f /var/lib/gitbay-runner/.ssh/id_ed25519
1029ssh-keygen -t ed25519 -N "" -f /tmp/ci-bootstrap
1030gitbayd --config /etc/gitbay/config.toml admin user create ci --key /tmp/ci-bootstrap.pub
1031ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys add --scope runner < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
1032ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys remove "$(ssh-keygen -lf /tmp/ci-bootstrap.pub | awk '{print $2}')"
1033rm /tmp/ci-bootstrap /tmp/ci-bootstrap.pub
1034gitbay-runner -remote git@127.0.0.1 -workdir /var/lib/gitbay-runner/work
1035#+end_src
1036
1037#+begin_src sh
1038gitbay repo runner add krz/site < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
1039#+end_src
1040
1041=-jobs N= runs N builds at once. Claiming is one transaction that
1042selects and updates, and each build works in its own =build-<id>=
1043directory, so workers do not collide; idle polls are staggered across
1044the interval so N of them do not wake together. The drop-in's weights
1045below are per service, not per build, so raising =-jobs= divides them
1046rather than multiplying the host's load.
1047
1048=admin runners= shows which account each runner polls as, and what each
1049may claim. A runner key claims builds only for the repositories it is
1050attached to: with none attached it claims nothing, and =-repos= may only
1051narrow within them. An admin's full-scope key claims any repository —
1052that is what =-repos= was for — and still works for the protocol during
1053a rotation. A merge request head from a fork is built in the target
1054repository as untrusted: the claim carries no secrets, and only a runner
1055started with =-untrusted= takes it. Same-repository heads were built by
1056their branch push and are not built again.
1057
1058=make deploy-runner= also installs
1059=deploy/gitbay-runner.override.conf= as a systemd drop-in: =Nice=10=,
1060=CPUWeight=30=, =IOWeight=30=, so a build never starves the host's sshd,
1061the daemon or the backup timers, and =NoNewPrivileges=,
1062=ProtectSystem=full=, =ProtectKernelTunables=, =ProtectControlGroups=
1063and =RestrictSUIDSGID=, so a step cannot reach outside its workspace
1064and the runner's home. The e2e suite alone starts sixty
1065daemon instances; without the drop-in a deploy's copy over the admin
1066sshd stalled. Both deploy targets copy with =rsync --partial=, which
1067resumes a stalled transfer.
1068
1069Under =-isolation podman=, the default and what bay1 runs, each build
1070is confined to a container (see Container isolation below). Under
1071=-isolation none= steps run directly on the host as the runner's user,
1072so treat that machine as executing whatever your users push, and
1073install the toolchains your builds need on it.
1074
1075A runner claims the oldest pending build among the repositories its key
1076is attached to — for an admin key, the oldest in the instance. =-repos=
1077narrows within that set, which is what makes a runner outside the server
1078practical: one on a machine that should build a single project, or that
1079holds credentials for one deployment, stays on it.
1080
1081Oldest-first is across everything the key may claim, so a repository
1082with a deep queue holds every other repository the same runner serves;
1083bay1 measured a 15-minute average wait on a day of merge request
1084stacks from one repository. A runner attached to one repository cannot
1085be starved. That is the rule, decided in krz/gitbay#207: a runner
1086serving several repositories takes them oldest-first, and an operator
1087who wants one repository never to wait on another runs a second
1088runner attached to it alone. Nothing caps what an account queues,
1089and nothing needs to (krz/gitbay#206): a schedule tick queues nothing
1090while the job's last build is pending or running, so a repository
1091with no runner holds one row per scheduled job rather than one per
1092tick, and a build runs only on a runner its owner attaches, so a busy
1093schedule spends the owner's compute. Pushes are bounded by what an
1094account can push.
1095
1096#+begin_src sh
1097gitbay-runner -remote git@gitbay.org -repos krz/site,krz/docs \
1098  -workdir /var/lib/gitbay-runner/work
1099#+end_src
1100
1101Add =-untrusted= only with =-isolation podman=.
1102
1103gitbay.org's runner is attached to the forge's own repositories and
1104the isolation canary, nothing else, because it shares the host with
1105the forge; its unit names no =-repos=, the attachments are the
1106boundary. Any other repository builds on a runner its owner attaches.
1107
1108=-repos= narrows an admin runner; for a runner key the attachments are
1109the boundary, held by the server, and =-repos= may only name
1110repositories among them. =-untrusted= makes a runner claim merge
1111request heads from forks; the bay1 unit sets it because it isolates in
1112podman. A runner without it builds trusted commits only.
1113
1114=gitbay dashboard= and =ssh git@<host> admin runners= list every key
1115that has polled as a runner: the account, the key's fingerprint, when it
1116last polled, the repositories it may claim — its attachments for a runner
1117key, the =-repos= it asked for or =any= for an admin key — and the build
1118it holds; =admin runners remove <fingerprint>= (=forget= until the next release) drops the row for a key
1119that polled by mistake, the key itself untouched. =admin runners= also
1120heads the list with the queue: builds
1121pending now, and over the last day how many were claimed, how long they
1122waited to be claimed (average and worst), and
1123how many the reaper ended instead of a runner reporting them. A build a runner claimed and never
1124reported is failed by the scheduler's minute tick, whether or not any
1125runner is still alive: within about two minutes of its log stream ending
1126with no outcome reported — the runner reports right after closing the
1127stream, retrying for half a minute if gitbayd is unreachable — or, if no
1128stream was ever seen, at the deadline.
1129
1130Instance admin on the runner account only authorizes the claim/report
1131protocol; it grants no repo access. A build that pushes back — a pages
1132deploy, an archive publish, an automated MR branch — needs an explicit
1133grant on that repo: =repo access grant <owner/name> ci write=. Private
1134repos likewise need at least read for the clone.
1135
1136** Container isolation
1137
1138Builds run in a rootless podman container, one per job, with the
1139workspace bind mounted and nothing else: the clone happens outside with
1140the runner's key, so a step cannot read it. =-isolation none= keeps the
1141old behaviour — steps on the host as the runner's user — for an instance
1142where every repository is trusted. There is no automatic fallback: a
1143runner started with =-isolation podman= that cannot find a working
1144podman exits rather than running a build unsandboxed.
1145
1146gitbay's own jobs name =localhost/gitbay-ci:4=, built from
1147=deploy/Containerfile.ci= on the runner host. A job's image must carry
1148what its steps need: the suite drives real git, git-lfs, gpg and sshd and
1149asserts they exist before running, so the stock runner default would fail
1150it immediately. Build or rebuild it with:
1151
1152#+begin_src sh
1153ssh -p 2222 root@<host> 'cat > /tmp/Containerfile.ci' < deploy/Containerfile.ci
1154ssh -p 2222 root@<host> 'su - ci-runner -s /bin/sh -c \
1155  "podman build -t localhost/gitbay-ci:4 -f /tmp/Containerfile.ci /tmp"'
1156#+end_src
1157
1158The tag is deliberate rather than =:latest=: changing the file means
1159bumping the tag in =.gitbay/ci.yml=, so a running branch's image does not
1160change under it.
1161
1162=-image= names the image a job runs in when it declares none, and is
1163required under =-isolation podman=: there is no built-in default,
1164because an image this host does not have would fail every build. A job
1165overrides it with =image:= in =.gitbay/ci.yml=, validated as a reference
1166so a config file cannot turn it into podman arguments.
1167
1168=-cpus= and =-memory= cap one build (podman's units, e.g. =-cpus 2
1169-memory 4g=); unset means uncapped. The runner applies them itself: it
1170creates a cgroup per build under its own delegated service cgroup,
1171writes the limits there, and starts every podman process for the build
1172inside it, with podman's cgroup handling off. Podman's own =--memory=
1173and =--cpus= never applied under rootless cgroupfs, which is what a
1174system service gets (krz/gitbay#188). The unit therefore needs
1175=Delegate=yes=, which the drop-in sets; without it the runner refuses
1176to start when a limit is set, and logs that builds run unconfined when
1177none is. bay1 runs =-cpus 3 -memory 6g= per build inside =MemoryMax=6G=
1178and =CPUQuota=300%= on the unit, on a 7.7GB four-core host with no
1179swap: the memory cap is what keeps the forge alive when a build
1180allocates without bound, and it sits above the e2e suite's 5GB peak
1181rather than at a fair share. =OOMPolicy=continue= keeps systemd from
1182stopping the runner when a build is OOM-killed.
1183
1184A trusted build's home is its repository's, under
1185=<workdir>/trusted-home/<owner>/<name>=, mounted into its containers as
1186=HOME=: caches persist between trusted builds of one repository and are
1187never read by another's. An untrusted build — a merge request head from
1188a fork — gets =<workdir>/build-<id>-home=, new and empty, removed when
1189the build ends. Homes under =<workdir>/home= are from runners before
1190krz/gitbay#255, which shared them with untrusted builds; nothing reads
1191them any more, and they can be deleted.
1192
1193*Images are provisioned, never pulled by a build.* The runner passes
1194=--pull=never=. Two reasons, and the second is the better one: the
1195service runs with =RestrictSUIDSGID=yes= so podman cannot unpack a layer
1196holding a setuid file, which is nearly every distribution image; and on
1197an instance where anyone can push a =ci.yml=, =image:= would otherwise
1198mean "fetch and run anything from the internet". An operator pulls or
1199builds what is allowed and a build picks among those. A job naming an
1200image the host does not have fails with a message saying so.
1201
1202#+begin_src sh
1203su - ci-runner -s /bin/sh -c "podman pull docker.io/library/alpine:3.20"
1204su - ci-runner -s /bin/sh -c "podman images"
1205#+end_src
1206
1207Prepare a host before pointing an isolating runner at it:
1208
1209#+begin_src sh
1210ssh -p 2222 root@<host> 'sh -s' < deploy/runner-podman-setup.sh
1211make deploy-runner
1212#+end_src
1213
1214The script installs podman, delegates a subuid/subgid range to
1215=ci-runner=, checks that user namespaces are enabled rather than
1216assuming, enables lingering, and verifies rootless podman actually runs
1217as that user. It is idempotent.
1218
1219It also installs nftables. =make deploy-runner= ships
1220=deploy/gitbay-runner-egress.nft= to =/etc/gitbay-runner/egress.nft=
1221with =gitbay-runner-egress.service=, which loads it and which the
1222runner's unit requires; it checks the file with =nft -c=, reloads the
1223unit, and runs =deploy/runner-egress-check.sh= as =ci-runner= before
1224restarting the runner: =127.0.0.1:22= and the public 22 must answer,
12252222 must not. The table limits the runner's user to =127.0.0.1:22=,
1226DNS on loopback, and 22, 80 and 443 on the host's public address; the
1227Threat-Model page says why.
1228
1229That table cannot tell a build from the runner, since both run as
1230=ci-runner=. =deploy/gitbay-runner-builds.nft=, shipped as
1231=/etc/gitbay-runner/builds.nft=, matches by cgroup instead: the runner
1232starts each build under =builds/trusted= or =builds/untrusted= in its
1233service cgroup, and the table closes the host's loopback to every
1234build, limits an untrusted build to TCP 80 and 443 and DNS, and closes
1235private ranges to both (the CI page has the table). nftables resolves a
1236cgroup path to its id when the table loads, and the service cgroup is
1237new on every start, so the drop-in's =ExecStartPre= creates the two
1238cgroups, hands them to =ci-runner= and loads the table before the
1239runner starts; a table that does not load stops the start. =make
1240deploy-runner= checks the file's syntax before the restart and that the
1241table is loaded after it. If =/etc/resolv.conf= names a nameserver in a
1242private range, allow it in the file first or builds resolve nothing.
1243
1244A restart of =nftables.service= flushes both tables;
1245=systemctl reload gitbay-runner-egress= restores both.
1246
1247The egress unit's stop and the rollback below use =nft destroy=,
1248which needs nftables 1.0.8 or later; check =nft --version= on a new
1249host.
1250
1251Checking the tables on a running host, during a build (the flood test
1252below waits a minute before its first probe, for this):
1253
1254#+begin_src sh
1255nft list table inet gitbay_builds          # counters on the reject rules
1256for p in $(pgrep -u ci-runner pasta); do cat /proc/$p/cgroup; done
1257# 0::/system.slice/gitbay-runner.service/builds/trusted/build-<id>
1258#+end_src
1259
1260A pasta process anywhere else — the runner's own =runner= cgroup, a
1261user slice — means the builds table does not see that build's traffic
1262and only the first table applies. Run
1263=deploy/runner-auth-flood-test.sh= on the scratch repository (below),
1264once as a push and once with =--untrusted=. It fails if the runner was
1265locked out or if the build log lacks the lines only a working table
1266produces. The authoritative proof that pasta's sockets are in the
1267build's cgroup is the untrusted run: =169.254.1.2:22= and
1268=github.com:22= refused, all twelve logins refused, and the counters on
1269the =untrusted= chain's rejects rising. The first table lets
1270=ci-runner= reach both of those addresses.
1271
1272To take the builds table out, on the host:
1273
1274#+begin_src sh
1275sed -i '/^ExecStartPre=+.*builds/d' /etc/systemd/system/gitbay-runner.service.d/override.conf
1276rm /etc/gitbay-runner/builds.nft
1277systemctl daemon-reload
1278nft destroy table inet gitbay_builds
1279#+end_src
1280
1281The runner needs no restart. It still places builds under
1282=builds/trusted= and =builds/untrusted=, but with the file gone neither
1283a runner start nor =systemctl reload gitbay-runner-egress= loads the
1284table again, and builds keep the first table and =--no-map-gw=. A
1285runner that takes =-untrusted= or polls over loopback refuses to start
1286without build cgroups at all, since the table would match nothing. The
1287next =make deploy-runner= installs the file and the lines again.
1288
1289The drop-in sets =NoNewPrivileges=no=, without which rootless podman
1290cannot call =newuidmap= and the runner refuses to start. That is a
1291considered trade, explained in the file and in the Threat-Model; if you
1292run with =-isolation none=, set it back to =yes=.
1293
1294*Restarting the runner is safe.* On SIGTERM it stops claiming, finishes
1295the build in flight, reports it, and exits; the drop-in's
1296=TimeoutStopSec=50min= covers the longest build, and its =KillMode=mixed=
1297is what makes the signal reach the runner alone — under systemd's default
1298the build's container and the log session are signalled with it, and the
1299runner drains a build that is already dead. So =make deploy-runner=
1300waits for a running build rather than orphaning it, and a build's result
1301is retried for half a minute if gitbayd is restarting at that moment. A
1302second SIGTERM ends the runner at once, abandoning the build to the
1303reaper. The suite checks all three: =TestRunnerDrainsOnSIGTERM= signals
1304the process, =TestRunnerDropInLetsTheDrainHappen= reads the drop-in's
1305=KillMode= and =TimeoutStopSec=, and =TestRunnerDrainUnderSystemd= runs
1306the runner as a transient user unit under =systemd-run= and stops it
1307under both kill modes. That last one needs a systemd user manager, so it
1308skips in the container CI runs in; run it on a Linux host with
1309=go test ./e2e -run TestRunnerDrainUnderSystemd -v=.
1310
1311*Validate podman mode on a scratch repository before pointing the runner
1312at real ones.* Every deploy that switched the whole instance to
1313containers and failed took CI down with it. Instead: create a throwaway
1314repository the runner account can read (public, or granted read — a
1315private one is "not found" to the runner and the build stays pending),
1316give it one job that names the CI image, attach the runner's key to it,
1317and deploy the runner with =-repos= naming only that repository. The
1318production unit, with its real hardening, then claims nothing else;
1319other repositories' builds queue until =-repos= is removed again, which
1320is a pause, not an outage.
1321
1322#+begin_src sh
1323# on a machine with an admin gitbay identity (root on the host has none),
1324# with the runner's public key copied from the host:
1325gitbay repo create cmc/runner-scratch   # then push a .gitbay/ci.yml naming the image
1326scp -P 2222 root@<host>:/var/lib/gitbay-runner/.ssh/id_ed25519.pub runner.pub
1327gitbay repo runner add cmc/runner-scratch < runner.pub
1328# on the host:
1329sed -i 's#^ExecStart=/usr/local/bin/gitbay-runner #&-repos cmc/runner-scratch #' /etc/systemd/system/gitbay-runner.service.d/override.conf
1330systemctl daemon-reload && systemctl restart gitbay-runner
1331# back on the admin machine:
1332gitbay build log cmc/runner-scratch 1   # green: remove -repos, redeploy, delete the scratch repository
1333#+end_src
1334
1335*Do not deploy an isolating runner to a host that has not been
1336prepared.* The runner is specified to refuse to start without a working
1337podman rather than fall back to running builds unsandboxed — a fallback
1338that silently drops isolation is worse than a stopped runner, because
1339nothing surfaces it. On an unprepared host that refusal stops every
1340build on the instance.
1341
1342The service drop-in carries =Delegate=yes= for rootless cgroup
1343management and =ReadWritePaths= for podman's store under
1344=/var/lib/gitbay-runner=, which =ProtectSystem=full= would otherwise
1345make read-only. Those paths are prefixed =-= so they are ignored when
1346absent: the drop-in installs on unprepared hosts too, and a unit that
1347refused to start would stop every build.
1348=gitbay-runner-prune.timer= prunes unused images weekly, as the runner's
1349user: rootless storage belongs to that user, and root's prune would not
1350see it. An unpruned image store on a 40GB host is a slow outage.
1351Images labelled =org.gitbay.keep=true= are skipped, since a locally
1352built =localhost/= image cannot be pulled back; =deploy/Containerfile.ci=
1353sets it.
1354
1355* LFS storage
1356
1357Objects live content-addressed under =[lfs] root= (default
1358=<server.root>/lfs=); =[lfs] max_object_bytes= caps a single object
1359(512MB default). Storage sits behind a small interface — an
1360S3-compatible backend is a drop-in with the server proxying, and
1361presigned URLs a later optimization. LFS objects do not travel with
1362push mirrors (mirrors move git refs only), and gc does not yet collect
1363orphaned objects.
1364
1365* Pages
1366
1367=[pages] domain = "example.site"= serves public repos' =pages= branches
1368on =<owner>.<domain>=. DNS needs a wildcard record =*.<domain>= to the
1369server; ACME issues per-subdomain certificates on demand (only for
1370owners that exist). The domain must not be the site host or a parent of
1371it — pages content runs its own scripts and must stay off the forge's
1372origin.
1373
1374Users with repo admin claim custom domains with =repo domain add=.
1375Claims activate only after a DNS TXT challenge proves control of the
1376domain (=repo domain verify=, audit-logged); pending claims serve
1377nothing, get no certificates, and expire after 7 days. ACME issues
1378certificates only for verified hosts, so stray DNS pointed at the
1379server gets nothing.
1380
1381* Security
1382
1383The [[Threat-Model]] file is the reference for what the forge
1384trusts and refuses to do. Operational checklist:
1385
1386- *Software checks.* =deploy/audit.sh= runs =go vet=, =govulncheck=
1387  (the module list is deliberately short — review it on each release),
1388  and a short fuzz pass over every attacker-facing parser (pkt-line,
1389  commit, SSHSIG armor, OpenPGP key, SSH tokenizer). Run it before
1390  tagging a release. CI's own =vuln= job runs =govulncheck= nightly
1391  against main rather than per push, because =@latest= scans today's
1392  advisory database and an advisory lands without anyone pushing;
1393  =build trigger krz/gitbay vuln= runs it on demand. Repositories can
1394  also opt into the dependency advisory check (=repo deps enable=),
1395  the push-time secret scan (on by default as =warn=), and the
1396  scheduled code scan (=repo security enable=, see [security]).
1397- *Web responses* carry a scripts-forbidden CSP, =X-Frame-Options:
1398  DENY=, =nosniff=, =no-referrer=, and HSTS when TLS is on — no
1399  configuration needed.
1400- *Host sandboxing.* The systemd unit in =deploy/cloud-init.yaml= runs
1401  gitbayd unprivileged with =ProtectSystem=strict=, =PrivateDevices=,
1402  =LockPersonality=, =MemoryDenyWriteExecute=,
1403  =SystemCallFilter=@system-service=, and =RestrictAddressFamilies= to
1404  INET/INET6/UNIX. It keeps =CAP_NET_BIND_SERVICE= only, to bind 22/80/443.
1405- *OS patches* apply via =unattended-upgrades= (security origins,
1406  auto-reboot 04:30 if required).
1407- *Admin sshd (2222)* is throttled by =MaxStartups=/=MaxAuthTries= and
1408  watched by =fail2ban=; gitbayd's own port 22 is throttled by
1409  =limits.ssh_auth_rate= (auth failures per IP per minute), and every
1410  account's writes by =limits.write_rate=.
1411- *Monitoring.* =gitbay-monitor.timer= writes a reading hourly to
1412journald and, when =/etc/gitbay/monitor.url= exists, posts it to that
1413webhook: disk, service, the daemon's own =/healthz= answer, certificate
1414expiry, and the age of the newest full backup and database snapshot.
1415It exits non-zero on an alert so the unit shows in =systemctl
1416--failed=: a stopped service, =/healthz= not answering =ok=, disk ≥ 85%,
1417a certificate under 21 days, a full backup over 25 hours old, or a
1418database snapshot over 2 hours old.
1419
1420=GET /healthz= is unauthenticated and cache-free: whether the database
1421answers and which commit serves, 503 when it does not.
1422- *Database.* =gitbay.db= and its WAL live under =/var/lib/gitbay= (mode
1423  0750, owned by =gitbay=). The nightly archive plus provider snapshots
1424  are the recovery path; for tighter RPO, add continuous replication
1425  (litestream) against the same file — it coexists with the WAL.
1426
1427* Odds and ends
1428
1429- deleting a fork marks MRs sourced from it =source_gone=; their diffs
1430  remain viewable and mergeable because the target repo owns the
1431  objects.
1432- =refs/merge-requests/*= is server-owned and unpushable by clients;
1433  only =admin mr prune= removes one (see Maintenance).
1434- audit-relevant activity (issue/MR lifecycle, imports, pushes) lands in
1435  the =events= table, which also feeds webhooks.
1436- the daemon idles under 10MB RSS; the smallest VPS tier is adequate.