.gitbay/wiki/Admin.org

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

622 lines · 30816 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
 21#+end_src
 22
 23=deploy/= in the source tree has a cloud-init file, a hardened systemd
 24unit, and a nightly backup timer. Run as the unprivileged =gitbay= user;
 25the unit's =AmbientCapabilities=CAP_NET_BIND_SERVICE= covers ports
 2622/80/443 without root.
 27
 28** The SSH port decision
 29
 30- =ssh.mode = "embedded"= (default): gitbayd itself listens, normally on
 31  22 — move the host's admin sshd to another port. Remotes read
 32  =git@host:owner/repo= with no port gymnastics.
 33- =ssh.mode = "system"=: the host sshd owns 22 and invokes gitbayd via
 34  =AuthorizedKeysCommand=:
 35  #+begin_example
 36  AuthorizedKeysCommand /usr/local/bin/gitbayd --config /etc/gitbay/config.toml authorized-keys %t %k
 37  AuthorizedKeysCommandUser gitbay
 38  #+end_example
 39  sshd requires that binary to be root-owned and not group/world
 40  writable. Unknown keys fail authentication inside sshd, so system mode
 41  requires =registration.mode = "closed"= (check-config enforces this).
 42
 43* Configuration reference
 44
 45=/etc/gitbay/config.toml=. =check-config= validates and names every
 46contradiction; =--no-host-checks= skips port/path probes.
 47=gitbayd admin config show= prints the configuration in effect as TOML,
 48every default filled in and =smtp_pass= redacted. A file that fails
 49validation still prints, followed by the contradiction.
 50
 51** [server]
 52- =root= (default =/var/lib/gitbay=) — repositories, database, host
 53  keys, ACME cache all live here.
 54- =site_url= (required) — canonical =https://host=; drives ACME, clone
 55  URLs, mail links.
 56- =source_repo= (optional, =owner/name=) — the repository this instance
 57  develops itself in. Startup warns when the running build's commit is
 58  not on that repository's default branch, which is how a binary built
 59  from an unmerged branch stops being invisible. Leave it unset unless
 60  the instance hosts its own source.
 61
 62** [ssh]
 63- =mode= — =embedded= | =system= (above).
 64- =port= (22) — embedded listener port.
 65- =host_keys= — list of private key paths; empty generates an ed25519
 66  key at =<root>/ssh/host_ed25519=.
 67
 68** [http]
 69- =addr= (=:443=), =tls= — =acme= | =files= | =off=.
 70- =acme=: certificates via TLS-ALPN-01 on the HTTPS port, cached at
 71  =<root>/acme=; =acme_email= for the CA account; =acme_http_addr=
 72  (=:80=, ="off"= to disable) adds HTTP-01 and an https redirect —
 73  failing to bind it is a warning, not fatal. Requires an =https://=
 74  site_url with a public DNS name.
 75- =files=: =cert_file= + =key_file=.
 76- =off=: plain HTTP — development, or behind a TLS-terminating proxy.
 77
 78=trusted_proxies= lists the addresses or CIDRs of reverse proxies in
 79front of the daemon. A request from one of them is attributed, for API
 80rate limiting, to the last =X-Forwarded-For= hop that is not itself a
 81trusted proxy; from anyone else the header is ignored. Empty, the
 82default, is right when gitbayd terminates TLS itself.
 83
 84** [web]
 85- =mode= — =view_only= (default) | =accounts=. In view_only the mutating
 86  web routes are never registered; in accounts, browser sessions are
 87  minted over SSH (=web login=), and users with write access can create
 88  repos, comment, and make simple file edits (which commit unsigned,
 89  honestly). =password_auth= is reserved and currently rejected.
 90
 91** [registration]
 92- =mode= — =closed= (default) | =invite= | =open=. invite/open require
 93  [mail]. See the user guide for the flows.
 94
 95- =pending_expiry= (empty, never) — a duration such as ="168h"=; a
 96  self-registered account still unverified after that long is removed,
 97  hourly and at start, audited as =pending.expired=.
 98
 99** [mail]
100- =smtp_host= (host:port, 587 assumed), =from=, optional =smtp_user= /
101  =smtp_pass=. STARTTLS when offered. Required for invite/open
102  registration and self-service =email add=; in closed mode you may omit
103  it entirely and assert addresses by hand (below).
104
105** [api]
106- =enabled= (false) — the JSON API surface; see [[API]]. Off
107  means no credential-bearing HTTP endpoint exists at all.
108
109** [webhooks]
110- =allow_local= (false) — permit webhook targets on loopback/private
111  addresses. Leave off unless you know why you need it (SSRF).
112
113** [limits]
114- =clone_timeout= (3600s) — cap on =repo import= fetches.
115- =max_blob_bytes= (100MB) — cap on raw file serving over the web.
116- =max_asset_bytes= (512MB) — cap per uploaded release asset.
117- =max_repos_per_user= (0, unlimited) — repositories an account may own
118  directly; =repo create=, =fork= and =import= refuse past it.
119  Organizations are not capped.
120- =max_bytes_per_user= (0, unlimited) — disk the account's own
121  repositories may take; a push may be no larger than what is left.
122- =max_pack_bytes=, =ssh_auth_rate= — reserved, not yet enforced.
123
124** [git_daemon]
125- =enabled= (false), =port= (9418) — the anonymous =git://= listener.
126  Serves only public repositories that additionally ran
127  =repo settings git-daemon <repo> on=.
128
129** [mirrors]
130- =pull_interval_minutes= (15) — how often pull mirrors fetch their
131  upstream. Push mirrors sync shortly after each local ref update.
132  Mirror URLs pass the same SSRF rules as webhook targets.
133
134** [go_import]
135Vanity Go module paths, one per line: ="host/module" = "owner/repo"=.
136Requests with =?go-get=1= at or under the module path answer with the
137go-import meta tag pointing at the repository's HTTPS clone URL, so
138=go install host/module/cmd/...@latest= resolves. The repository should
139be public (the module path itself confirms it exists).
140
141* Users, email, invites
142
143Every =gitbayd admin= subcommand except =backup=, =gc= and the one-shot
144backfills is a wrapper that dispatches the registry command of the same
145name as the host: an admin context with no account behind it, so its
146audit rows carry no actor and =source: host=. The same commands run in an
147instance admin's SSH session (=ssh git@<host> admin ...=) and write the
148same rows with the key fingerprint as source. One implementation, two
149credentials.
150
151#+begin_src sh
152gitbayd admin user create alice --key alice.pub --email a@example.org --verified [--admin]
153gitbayd admin email verify alice a@example.org   # admin assertion, no SMTP needed
154gitbayd admin invite --email b@example.org       # mails a code; prints it if no SMTP
155#+end_src
156
157"Verified" means SMTP-confirmed or host-admin-asserted; the database
158records which. Verified emails are what make commit signatures
159meaningful — an unverified address never produces a =verified= badge.
160
161* Audit and account control
162
163The audit log is the security feed (events are the product feed): every
164successful mutating command with its argv and source credential (SSH key
165fingerprint or API), registrations, admin actions, force-pushes, and
166auth failures/throttling. Secrets never appear — they travel on stdin,
167never in argv.
168
169#+begin_src sh
170gitbayd admin audit [--actor u|-] [--action prefix] [--since 24h|7d|date] [--limit n] [--json]
171ssh git@<host> audit ...             # the same, from an admin session (SSH only)
172ssh git@<host> admin user list [--state active|pending|disabled|admin]
173ssh git@<host> admin user show <name>   # keys, emails, orgs, tokens, sessions
174ssh git@<host> admin user limits <name> [--repos n|default] [--bytes n|default]   # per-account caps
175ssh git@<host> admin user promote <name>   # grant instance admin
176ssh git@<host> admin user demote <name>    # remove it; the last admin is refused
177gitbayd admin user promote <name>    # host-local: recovery when no admin key is reachable
178gitbayd admin user disable <name>    # suspend: SSH, web, API all refused;
179gitbayd admin user enable <name>     #   sessions dropped, nothing deleted
180gitbayd admin user delete <name> --yes  # only for accounts anchoring nothing:
181                                     #   refused (with each blocker named) while
182                                     #   the account owns repos, authored
183                                     #   issues/MRs/comments/reviews, or is an
184                                     #   org's only admin
185#+end_src
186
187=--actor= takes a username, or =-= for rows with no actor: host commands
188and auth failures. =--action= is a prefix, so =cmd repo= catches every
189repository command and =admin= every host or admin-session action.
190=--since= is a duration back from now (=30m=, =24h=, =7d=) or a date.
191
192=admin user list= pages by username (=--limit=, =--cursor=) and carries
193each account's state and =last_seen=, the newest use of any of its SSH
194keys or API tokens. =admin user show= adds the keys with their last use,
195each address with how it was verified, PGP keys, org roles, the owned
196repository count, API token names, and live browser sessions. Both are
197SSH-only and refused to non-admins, like =audit=.
198
199Promotion needs an active account: a pending or disabled one is refused.
200Demotion is refused when it would leave no admin, over SSH and on the
201host alike, so the host-local =promote= is the way back in when the only
202admin key is lost.
203
204Instance admin carries no right on anyone's repository: policy does not
205consult it, and a private repository still answers not-found to an
206admin. Moderation goes through explicit overrides that skip the access
207check and write their own audit row:
208
209#+begin_src sh
210ssh git@<host> admin repo list [--owner o] [--visibility public|private]  # size, last push
211ssh git@<host> admin repo archive|unarchive <owner/name>
212ssh git@<host> admin repo visibility <owner/name> public|private
213ssh git@<host> admin repo delete <owner/name> --yes
214#+end_src
215
216Each lands in the audit log as =admin repo.<action>= naming the
217repository, on top of the =cmd= row every mutating command gets.
218
219=limits.ssh_auth_rate= (10) throttles per-IP authentication *failures*
220per minute — successful auths never count and clear the slate.
221=limits.max_pack_bytes= is enforced as =receive.maxInputSize= on every
222push.
223
224=limits.write_rate= (60) bounds *mutating commands per account per
225minute*. It is counted in the dispatcher, so SSH, the JSON API and the
226web spend one budget and a caller cannot refresh it by changing surface;
227=limits.api_rate= stays in front of it, bounding a network source rather
228than an account. A command is one token whatever it writes, so a bundle
229import costs one and only a loop of separate commands spends the budget.
230Read-only commands, the runner protocol (a build streams its log in many
231small writes) and the host CLI are exempt. Refusals exit 4 and say when
232to retry. A negative value turns the limit off; it matters most with
233=registration = "open"=, where every write also queues notification mail
234and webhook deliveries.
235
236* Queues
237
238Every background worker keeps a backlog and a failure state. An instance
239admin reads them all in one place:
240
241#+begin_src sh
242gitbay dashboard --json | jq .queues   # webhooks, mail, mirrors, builds, deps
243#+end_src
244
245Per worker: pending, retrying (pending with a failed attempt) and
246dead-lettered counts with the oldest pending age, and the retrying or
247failed rows themselves, capped at twenty each. Builds list what is
248running and then what is pending, each since when, so a build no runner
249is scoped to claim is visible here rather than only in its repository;
250mirrors list the ones whose last sync failed;
251dependency checks list the ones whose last check errored. Non-admins get
252no =queues= key at all.
253
254In accounts mode the same read renders at =/admin=, linked from the rail
255for admins. Anyone else gets a 404 there.
256
257A dead-lettered mail is logged as =notification dead-lettered mail=<id>=,
258with the address redacted out of the relay's error. The id is the queue
259row: find it in the Mail table on =/admin=, or in =dashboard --json=,
260where the recipient and the unredacted error are. That is deliberate —
261see the Threat-Model page.
262
263* Maintenance
264
265#+begin_src sh
266gitbayd admin stats [--json]         # counts, database size, per-repo disk
267ssh git@<host> admin stats [--json]  # the same, from an admin session
268gitbayd admin gc [--repo owner/name] # git gc: repack and prune; per-repo sizes
269gitbayd admin gc --aggressive        # thorough repack; slow, rarely needed
270gitbayd admin gc --lfs               # also drop LFS objects no pointer names (older than a day)
271#+end_src
272
273=deploy/cloud-init.yaml= ships a =gitbay-gc.timer= that runs =admin gc=
274weekly (Sunday 07:00 UTC). Imported repositories keep whatever pack
275layout the source sent, so a first manual =admin gc= after a bulk
276import is worthwhile.
277
278* Backup and restore
279
280#+begin_src sh
281gitbayd admin backup --out /var/backups/gitbay/backup.tar.gz
282gitbayd admin backup --verify /var/backups/gitbay/backup.tar.gz   # read it back
283#+end_src
284
285One archive: a consistent SQLite snapshot (taken *before* the
286repositories are read, so the database never references objects the
287archive missed), every repository, and the SSH host keys. Excluded:
288hook socket, regenerated hook scripts, WAL files. Safe to run against a
289live daemon.
290
291=--verify= reads an archive back: the snapshot must pass SQLite's
292integrity check, and every repository the snapshot names must be in the
293archive. A database-only archive is checked for integrity and says so.
294Exit is non-zero on damage or a missing repository.
295
296Restore: extract into an empty directory, point =server.root= at it,
297start gitbayd. Host keys are preserved, so clients keep their
298known_hosts entries; hooks regenerate at startup.
299
300** Schedule and recovery point
301
302Two timers, because the two halves of the data have different exposure.
303
304- =gitbay-backup.timer=, nightly. The full archive above, last 7 kept.
305- =gitbay-db-backup.timer=, hourly. =admin backup --db-only=, which
306  writes the SQLite snapshot alone, last 48 kept. A few MB against the
307  full archive's hundreds, which is what makes the frequency affordable.
308
309The split follows what a loss would actually cost. Repositories are git,
310so a mirror or any clone is a second copy; the database is the only copy
311of issues, merge requests, comments and review state. So the recovery
312point is about an hour for the data that exists nowhere else, and a day
313for the data that does.
314
315Continuous replication (litestream and similar) was considered and not
316adopted. It would take the database's recovery point to seconds, but the
317repositories would still be on the nightly archive, so a restore could
318produce a database referencing commits the repository backup does not
319have. Consistency between the two halves is worth more here than latency
320on one of them. Revisit if repository replication becomes continuous
321too.
322
323* Upgrades
324
325Replace the binary, restart the unit. Migrations apply automatically and
326are transactional; hook scripts under =<root>/hooks= are rewritten at
327startup to point at the current binary path.
328
329* CI runner
330
331=gitbay-runner= executes builds queued by pushes and merge requests. It
332polls over SSH with a key added by =keys add --scope runner=, which
333reaches only the runner protocol and read-only git (a runner executes
334arbitrary repository code, so the key it holds must not do more), then
335clones, runs the steps, streams the log back and resolves the commit
336status. Run it as a dedicated unprivileged user on a non-admin account.
337=admin user create --key= registers a full-scope key, so the runner key
338is added afterwards through a bootstrap key that is then removed:
339
340#+begin_src sh
341useradd --system --create-home --home-dir /var/lib/gitbay-runner ci-runner
342sudo -u ci-runner ssh-keygen -t ed25519 -N "" -f /var/lib/gitbay-runner/.ssh/id_ed25519
343ssh-keygen -t ed25519 -N "" -f /tmp/ci-bootstrap
344gitbayd --config /etc/gitbay/config.toml admin user create ci --key /tmp/ci-bootstrap.pub
345ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys add --scope runner < /var/lib/gitbay-runner/.ssh/id_ed25519.pub
346ssh -i /tmp/ci-bootstrap git@127.0.0.1 keys remove "$(ssh-keygen -lf /tmp/ci-bootstrap.pub | awk '{print $2}')"
347rm /tmp/ci-bootstrap /tmp/ci-bootstrap.pub
348gitbay-runner -remote git@127.0.0.1 -workdir /var/lib/gitbay-runner/work
349#+end_src
350
351=-jobs N= runs N builds at once. Claiming is one transaction that
352selects and updates, and each build works in its own =build-<id>=
353directory, so workers do not collide; idle polls are staggered across
354the interval so N of them do not wake together. The drop-in's weights
355below are per service, not per build, so raising =-jobs= divides them
356rather than multiplying the host's load.
357
358=admin runners= shows which account each runner polls as, and what each
359is scoped to. A runner with no scope claims builds for *any*
360repository, which on an instance with open registration means running a
361stranger's steps; scope one with =-repos owner/name=. An admin key
362still works for the protocol during a rotation. A merge request head
363from a fork is built in the target repository as untrusted: the claim
364carries no secrets. Same-repository heads were built by their branch
365push and are not built again.
366
367=make deploy-runner= also installs
368=deploy/gitbay-runner.override.conf= as a systemd drop-in: =Nice=10=,
369=CPUWeight=30=, =IOWeight=30=, so a build never starves the host's sshd,
370the daemon or the backup timers, and =NoNewPrivileges=,
371=ProtectSystem=full=, =ProtectKernelTunables=, =ProtectControlGroups=
372and =RestrictSUIDSGID=, so a step cannot reach outside its workspace
373and the runner's home. The e2e suite alone starts sixty
374daemon instances; without the drop-in a deploy's copy over the admin
375sshd stalled. Both deploy targets copy with =rsync --partial=, which
376resumes a stalled transfer.
377
378v1 runs steps directly on the host — no containers — so treat the
379runner machine as executing whatever your users push. Install the
380toolchains your builds need on it.
381
382A runner claims the oldest pending build in the queue, whichever
383repository it belongs to. =-repos= narrows that to named repositories,
384which is what makes a runner outside the server practical — one on a
385machine that should build a single project, or that holds credentials for
386one deployment, no longer picks up a build belonging to someone else. With
387open registration that someone need not be anyone you know.
388
389#+begin_src sh
390gitbay-runner -remote git@gitbay.org -repos krz/site,krz/docs \
391  -workdir /var/lib/gitbay-runner/work
392#+end_src
393
394gitbay.org's runner is scoped: it builds the forge's own repositories
395and the isolation canary, nothing else, because it shares the host with
396the forge. A =.gitbay/ci.yml= in another repository there queues builds
397no runner claims. Whether that changes is krz/gitbay#184.
398
399Naming no repositories is the old behaviour and stays the right choice for
400the runner on the server itself. The scoping is what the runner asks for,
401not an ACL the server holds over it: a runner account is admin by
402necessity, so the boundary is you choosing how to start it.
403
404=gitbay dashboard= and =ssh git@<host> admin runners= list every account
405that has polled as a runner: when it last polled, the =-repos= scope it
406asked for, and the build it holds. A build a runner claimed and never
407reported is failed by the scheduler's minute tick, whether or not any
408runner is still alive: within about two minutes of its log stream ending
409with no outcome reported — the runner reports right after closing the
410stream, retrying for half a minute if gitbayd is unreachable — or, if no
411stream was ever seen, at the deadline.
412
413Instance admin on the runner account only authorizes the claim/report
414protocol; it grants no repo access. A build that pushes back — a pages
415deploy, an archive publish, an automated MR branch — needs an explicit
416grant on that repo: =repo access grant <owner/name> ci write=. Private
417repos likewise need at least read for the clone.
418
419** Container isolation
420
421Builds run in a rootless podman container, one per job, with the
422workspace bind mounted and nothing else: the clone happens outside with
423the runner's key, so a step cannot read it. =-isolation none= keeps the
424old behaviour — steps on the host as the runner's user — for an instance
425where every repository is trusted. There is no automatic fallback: a
426runner started with =-isolation podman= that cannot find a working
427podman exits rather than running a build unsandboxed.
428
429gitbay's own jobs name =localhost/gitbay-ci:1=, built from
430=deploy/Containerfile.ci= on the runner host. A job's image must carry
431what its steps need: the suite drives real git, git-lfs, gpg and sshd and
432asserts they exist before running, so the stock runner default would fail
433it immediately. Build or rebuild it with:
434
435#+begin_src sh
436ssh -p 2222 root@<host> 'cat > /tmp/Containerfile.ci' < deploy/Containerfile.ci
437ssh -p 2222 root@<host> 'su - ci-runner -s /bin/sh -c \
438  "podman build -t localhost/gitbay-ci:1 -f /tmp/Containerfile.ci /tmp"'
439#+end_src
440
441The tag is deliberate rather than =:latest=: changing the file means
442bumping the tag in =.gitbay/ci.yml=, so a running branch's image does not
443change under it.
444
445=-image= names the image a job runs in when it declares none, and is
446required under =-isolation podman=: there is no built-in default,
447because an image this host does not have would fail every build. A job
448overrides it with =image:= in =.gitbay/ci.yml=, validated as a reference
449so a config file cannot turn it into podman arguments.
450
451=-cpus= and =-memory= cap one build's container (podman's own units,
452e.g. =-cpus 2 -memory 4g=); unset means uncapped. They only take effect
453where podman can create a cgroup for the container. Under rootless
454podman with the cgroupfs manager, which is what a system service gets,
455it cannot: the container runs inside the service's own cgroup and both
456flags are accepted and ignored (krz/gitbay#188). Cap the unit instead.
457bay1's drop-in sets =MemoryMax=6G= and =CPUQuota=300%= on a 7.7GB
458four-core host with no swap: the memory cap is what keeps the forge
459alive when a build allocates without bound, and it sits above the e2e
460suite's 5GB peak rather than at a fair share. =OOMPolicy=continue= keeps
461systemd from stopping the runner when a build is OOM-killed.
462
463Each repository gets its own build home under the runner's workdir,
464mounted into its containers as =HOME=. Caches persist between builds of
465one repository and are never read by another's.
466
467*Images are provisioned, never pulled by a build.* The runner passes
468=--pull=never=. Two reasons, and the second is the better one: the
469service runs with =RestrictSUIDSGID=yes= so podman cannot unpack a layer
470holding a setuid file, which is nearly every distribution image; and on
471an instance where anyone can push a =ci.yml=, =image:= would otherwise
472mean "fetch and run anything from the internet". An operator pulls or
473builds what is allowed and a build picks among those. A job naming an
474image the host does not have fails with a message saying so.
475
476#+begin_src sh
477su - ci-runner -s /bin/sh -c "podman pull docker.io/library/alpine:3.20"
478su - ci-runner -s /bin/sh -c "podman images"
479#+end_src
480
481Prepare a host before pointing an isolating runner at it:
482
483#+begin_src sh
484ssh -p 2222 root@<host> 'sh -s' < deploy/runner-podman-setup.sh
485make deploy-runner
486#+end_src
487
488The script installs podman, delegates a subuid/subgid range to
489=ci-runner=, checks that user namespaces are enabled rather than
490assuming, enables lingering, and verifies rootless podman actually runs
491as that user. It is idempotent.
492
493The drop-in sets =NoNewPrivileges=no=, without which rootless podman
494cannot call =newuidmap= and the runner refuses to start. That is a
495considered trade, explained in the file and in the Threat-Model; if you
496run with =-isolation none=, set it back to =yes=.
497
498*Restarting the runner is safe.* On SIGTERM it stops claiming, finishes
499the build in flight, reports it, and exits; the drop-in's
500=TimeoutStopSec=50min= covers the longest build, and its =KillMode=mixed=
501is what makes the signal reach the runner alone — under systemd's default
502the build's container and the log session are signalled with it, and the
503runner drains a build that is already dead. So =make deploy-runner=
504waits for a running build rather than orphaning it, and a build's result
505is retried for half a minute if gitbayd is restarting at that moment. A
506second SIGTERM ends the runner at once, abandoning the build to the
507reaper.
508
509*Validate podman mode on a scratch repository before pointing the runner
510at real ones.* Every deploy that switched the whole instance to
511containers and failed took CI down with it. Instead: create a throwaway
512repository the runner account can read (public, or granted read — a
513private one is "not found" to the runner and the build stays pending),
514give it one job that names the CI image, and deploy the runner with
515=-repos= naming only that repository. The production unit, with its real
516hardening, then claims nothing else; other repositories' builds queue
517until =-repos= is switched back, which is a pause, not an outage.
518
519#+begin_src sh
520gitbay repo create cmc/ci-smoke          # then push a .gitbay/ci.yml naming the image
521sed -i 's#-repos krz/gitbay #-repos cmc/ci-smoke #' /etc/systemd/system/gitbay-runner.service.d/override.conf
522systemctl daemon-reload && systemctl restart gitbay-runner
523gitbay build log cmc/ci-smoke 1         # green: switch -repos back, redeploy
524#+end_src
525
526*Do not deploy an isolating runner to a host that has not been
527prepared.* The runner is specified to refuse to start without a working
528podman rather than fall back to running builds unsandboxed — a fallback
529that silently drops isolation is worse than a stopped runner, because
530nothing surfaces it. On an unprepared host that refusal stops every
531build on the instance.
532
533The service drop-in carries =Delegate=yes= for rootless cgroup
534management and =ReadWritePaths= for podman's store under
535=/var/lib/gitbay-runner=, which =ProtectSystem=full= would otherwise
536make read-only. Those paths are prefixed =-= so they are ignored when
537absent: the drop-in installs on unprepared hosts too, and a unit that
538refused to start would stop every build.
539The nightly canary on =cmc/ci-smoke= only runs if the runner's =-repos=
540names that repository too; a scoped runner claims nothing else.
541=gitbay-runner-prune.timer= prunes unused images weekly, as the runner's
542user: rootless storage belongs to that user, and root's prune would not
543see it. An unpruned image store on a 40GB host is a slow outage.
544
545* LFS storage
546
547Objects live content-addressed under =[lfs] root= (default
548=<server.root>/lfs=); =[lfs] max_object_bytes= caps a single object
549(512MB default). Storage sits behind a small interface — an
550S3-compatible backend is a drop-in with the server proxying, and
551presigned URLs a later optimization. LFS objects do not travel with
552push mirrors (mirrors move git refs only), and gc does not yet collect
553orphaned objects.
554
555* Pages
556
557=[pages] domain = "example.site"= serves public repos' =pages= branches
558on =<owner>.<domain>=. DNS needs a wildcard record =*.<domain>= to the
559server; ACME issues per-subdomain certificates on demand (only for
560owners that exist). The domain must not be the site host or a parent of
561it — pages content runs its own scripts and must stay off the forge's
562origin.
563
564Users with repo admin claim custom domains with =repo domain add=.
565Claims activate only after a DNS TXT challenge proves control of the
566domain (=repo domain verify=, audit-logged); pending claims serve
567nothing, get no certificates, and expire after 7 days. ACME issues
568certificates only for verified hosts, so stray DNS pointed at the
569server gets nothing.
570
571* Security
572
573The [[Threat-Model]] file is the reference for what the forge
574trusts and refuses to do. Operational checklist:
575
576- *Software checks.* =deploy/audit.sh= runs =go vet=, =govulncheck=
577  (the module list is deliberately short — review it on each release),
578  and a short fuzz pass over every attacker-facing parser (pkt-line,
579  commit, SSHSIG armor, OpenPGP key, SSH tokenizer). Run it before
580  tagging a release. CI's own =vuln= job runs =govulncheck= nightly
581  against main rather than per push, because =@latest= scans today's
582  advisory database and an advisory lands without anyone pushing;
583  =build trigger krz/gitbay vuln= runs it on demand.
584- *Web responses* carry a scripts-forbidden CSP, =X-Frame-Options:
585  DENY=, =nosniff=, =no-referrer=, and HSTS when TLS is on — no
586  configuration needed.
587- *Host sandboxing.* The systemd unit in =deploy/cloud-init.yaml= runs
588  gitbayd unprivileged with =ProtectSystem=strict=, =PrivateDevices=,
589  =LockPersonality=, =MemoryDenyWriteExecute=,
590  =SystemCallFilter=@system-service=, and =RestrictAddressFamilies= to
591  INET/INET6/UNIX. It keeps =CAP_NET_BIND_SERVICE= only, to bind 22/80/443.
592- *OS patches* apply via =unattended-upgrades= (security origins,
593  auto-reboot 04:30 if required).
594- *Admin sshd (2222)* is throttled by =MaxStartups=/=MaxAuthTries= and
595  watched by =fail2ban=; gitbayd's own port 22 is throttled by
596  =limits.ssh_auth_rate= (auth failures per IP per minute), and every
597  account's writes by =limits.write_rate=.
598- *Monitoring.* =gitbay-monitor.timer= writes a reading hourly to
599journald and, when =/etc/gitbay/monitor.url= exists, posts it to that
600webhook: disk, service, the daemon's own =/healthz= answer, certificate
601expiry, and the age of the newest full backup and database snapshot.
602It exits non-zero on an alert so the unit shows in =systemctl
603--failed=: a stopped service, =/healthz= not answering =ok=, disk ≥ 85%,
604a certificate under 21 days, a full backup over 25 hours old, or a
605database snapshot over 2 hours old.
606
607=GET /healthz= is unauthenticated and cache-free: whether the database
608answers and which commit serves, 503 when it does not.
609- *Database.* =gitbay.db= and its WAL live under =/var/lib/gitbay= (mode
610  0750, owned by =gitbay=). The nightly archive plus provider snapshots
611  are the recovery path; for tighter RPO, add continuous replication
612  (litestream) against the same file — it coexists with the WAL.
613
614* Odds and ends
615
616- deleting a fork marks MRs sourced from it =source_gone=; their diffs
617  remain viewable and mergeable because the target repo owns the
618  objects.
619- =refs/merge-requests/*= is server-owned and unpushable by clients.
620- audit-relevant activity (issue/MR lifecycle, imports, pushes) lands in
621  the =events= table, which also feeds webhooks.
622- the daemon idles under 10MB RSS; the smallest VPS tier is adequate.