Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Make the audit log one shape that a privileged change cannot skip

b1499c729a026cfda32d8a90374b3b8391ca0090 · Keenan Nemetz · 12d ago · parent d74d4de8

Make the audit log one shape that a privileged change cannot skip

Every writer used to format its own line and open its own file, so
data/audit.log held six different column layouts and a write that failed
changed nothing. A log that can be bypassed by a full disk, or by a key
comment containing a tab, is not the security promise the docs make.

internal/audit is now the only writer: one line per action, always
timestamp, action, actor, subject, detail. Every field is escaped and
capped at 4 KiB, so a key comment, an LFS lock path, a repository name or
an admin argument cannot add a column or a record. One write per line
under O_APPEND keeps the web, the SSH server and each hook process from
interleaving, and secure.OpenAppend keeps the file at 0600 including on an
upgrade from 0644.

Privileged changes now fail closed, and they are recorded before they
happen, so a failed write means the change did not occur:

  - roster, key and instance-role changes (inside the transaction)
  - access-rule changes, and a repository deletion, which records before
    removing content and forgets the rules only afterwards
  - session creation and revocation
  - a forced LFS unlock
  - an admin command over SSH, which reports audit_unavailable
  - a push that overrides a lock, an approval, a release or history

Ordinary pushes and web actions are reported instead: their changes are
already durable in git, so a write failure is logged at error level (or on
the pusher's terminal from post-receive) rather than making a working push
look rejected.

Opening an instance now checks the log is a regular file at 0600 owned by
the service account and appendable, and refuses to start otherwise. There
is no setting that disables the log or returns it to best effort.

Regression tests cover field injection through key comments, lock paths,
admin argv and repository names; 0600 on create and on upgrade; an
unwritable sink failing an ACL change, an account change, a session, a
forced unlock, an admin command and a push override while leaving the
underlying state unchanged; concurrent appends keeping whole lines; and
startup refusing a symlinked log.

server/admin_test.go +31

@@ -259,3 +259,34 @@ func TestAdminCLIForwardsToRemote(t *testing.T) {
259 259 t.Fatalf("alice's keys did not land: %+v, %v", a, err)
260 260 }
261 261 }
262
263 // An administrative change that cannot be recorded is not made. The log is the
264 // only history of the roster, so a successful command with no line is the one
265 // outcome the CLI must never report.
266 func TestRemoteAdminRefusesWhenTheAuditLogIsUnwritable(t *testing.T) {
267 t.Parallel()
268 f := newFixture(t)
269 if _, err := f.srv.Identity.SetAdmin("keenan", true, "test"); err != nil {
270 t.Fatal(err)
271 }
272 // A directory where the log should be: opening it for append fails, which is
273 // also what a read-only data filesystem looks like.
274 logPath := f.cfg.AuditLog()
275 if err := os.RemoveAll(logPath); err != nil {
276 t.Fatal(err)
277 }
278 if err := os.Mkdir(logPath, 0o700); err != nil {
279 t.Fatal(err)
280 }
281
282 out, errOut, err := f.adminSSH(f.keyPath, nil, "account", "create", "eve", "--no-key")
283 if err == nil {
284 t.Fatalf("an unrecorded admin change succeeded: %s%s", out, errOut)
285 }
286 if !strings.Contains(out+errOut, "audit log could not be written") {
287 t.Fatalf("the refusal did not say why:\nstdout: %s\nstderr: %s", out, errOut)
288 }
289 if a, err := f.srv.Identity.Find("eve"); err == nil && a != nil {
290 t.Fatalf("the account was created anyway: %+v", a)
291 }
292 }