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 · 13d 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.

forge/session/session_test.go +50

@@ -4,6 +4,7 @@ import (
4 4 "crypto/ed25519"
5 5 "crypto/rand"
6 6 "errors"
7 "os"
7 8 "path/filepath"
8 9 "strings"
9 10 "testing"
@@ -39,6 +40,7 @@ func newFixture(t *testing.T) *fixture {
39 40 f := &fixture{ident: ident, store: store, now: time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)}
40 41 store.Now = func() time.Time { return f.now }
41 42 store.AuditPath = filepath.Join(filepath.Dir(path), "audit.log")
43 ident.AuditPath = store.AuditPath
42 44 return f
43 45 }
44 46
@@ -322,3 +324,51 @@ func TestCreateRejectsAnotherAccountsPasskey(t *testing.T) {
322 324 t.Fatalf("created a session for somebody else's passkey: %v", err)
323 325 }
324 326 }
327
328 // A session is a credential. Issuing one that cannot be recorded would create a
329 // login nobody can account for, so the login fails instead.
330 func TestCreateFailsWhenTheLogCannotBeWritten(t *testing.T) {
331 t.Parallel()
332 f := newFixture(t)
333 alice := f.account(t, "alice")
334 dir := t.TempDir()
335 blocker := filepath.Join(dir, "blocked")
336 if err := os.WriteFile(blocker, []byte("x"), 0o600); err != nil {
337 t.Fatal(err)
338 }
339 f.store.AuditPath = filepath.Join(blocker, "audit.log")
340 if _, err := f.store.Create(alice.Name, nil, "agent"); err == nil {
341 t.Fatal("Create succeeded with an unwritable audit log")
342 }
343 list, err := f.store.List(alice.Name)
344 if err != nil {
345 t.Fatal(err)
346 }
347 if len(list) != 0 {
348 t.Fatalf("a session was issued anyway: %d row(s)", len(list))
349 }
350 }
351
352 // Revoking a compromised session is exactly the action an attacker would want to
353 // keep out of the log, so it does not happen unless it is written.
354 func TestRevokeFailsWhenTheLogCannotBeWritten(t *testing.T) {
355 t.Parallel()
356 f := newFixture(t)
357 alice := f.account(t, "alice")
358 sess, err := f.store.Create(alice.Name, nil, "agent")
359 if err != nil {
360 t.Fatal(err)
361 }
362 dir := t.TempDir()
363 blocker := filepath.Join(dir, "blocked")
364 if err := os.WriteFile(blocker, []byte("x"), 0o600); err != nil {
365 t.Fatal(err)
366 }
367 f.store.AuditPath = filepath.Join(blocker, "audit.log")
368 if err := f.store.Revoke(sess.Token); err == nil {
369 t.Fatal("Revoke succeeded with an unwritable audit log")
370 }
371 if _, err := f.store.Lookup(sess.Token); err != nil {
372 t.Fatalf("the session was revoked anyway: %v", err)
373 }
374 }