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.
server/web/audit_test.go +86
| @@ -0,0 +1,86 @@ | |||
| 1 | package web | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "os" | ||
| 6 | "path/filepath" | ||
| 7 | "strings" | ||
| 8 | "testing" | ||
| 9 | |||
| 10 | "github.com/rodent-software/vole/forge/config" | ||
| 11 | ) | ||
| 12 | |||
| 13 | // auditWeb returns a Web whose only wired parts are the ones the audit log | ||
| 14 | // needs: a data directory and a collector for the server log. | ||
| 15 | func auditWeb(t *testing.T) (*Web, *[]string) { | ||
| 16 | t.Helper() | ||
| 17 | cfg, err := config.Load("") | ||
| 18 | if err != nil { | ||
| 19 | t.Fatal(err) | ||
| 20 | } | ||
| 21 | cfg.DataDir = t.TempDir() | ||
| 22 | var lines []string | ||
| 23 | w := &Web{Cfg: cfg} | ||
| 24 | w.Logger = func(format string, args ...any) { lines = append(lines, fmt.Sprintf(format, args...)) } | ||
| 25 | return w, &lines | ||
| 26 | } | ||
| 27 | |||
| 28 | func TestAuditWritesOneRecordInFiveColumns(t *testing.T) { | ||
| 29 | w, lines := auditWeb(t) | ||
| 30 | w.audit("web.repo.delete", "keenan", "demo", "") | ||
| 31 | if len(*lines) != 0 { | ||
| 32 | t.Fatalf("a successful write logged an error: %v", *lines) | ||
| 33 | } | ||
| 34 | raw, err := os.ReadFile(w.Cfg.AuditLog()) | ||
| 35 | if err != nil { | ||
| 36 | t.Fatal(err) | ||
| 37 | } | ||
| 38 | cols := strings.Split(strings.TrimSuffix(string(raw), "\n"), "\t") | ||
| 39 | if len(cols) != 5 { | ||
| 40 | t.Fatalf("got %d columns, want 5: %q", len(cols), raw) | ||
| 41 | } | ||
| 42 | if cols[1] != "web.repo.delete" || cols[2] != "keenan" || cols[3] != "demo" || cols[4] != "" { | ||
| 43 | t.Fatalf("record = %q", raw) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | // A repository name, a branch name and a commit message reach this code straight | ||
| 48 | // from a form. None of them may forge a column or a second record. | ||
| 49 | func TestAuditEscapesInjectedFields(t *testing.T) { | ||
| 50 | w, _ := auditWeb(t) | ||
| 51 | evil := "demo\tadmin\troot\n2026-01-01T00:00:00Z\tweb.admin.acl\troot" | ||
| 52 | w.audit("web.issue.create", evil, evil, evil) | ||
| 53 | raw, err := os.ReadFile(w.Cfg.AuditLog()) | ||
| 54 | if err != nil { | ||
| 55 | t.Fatal(err) | ||
| 56 | } | ||
| 57 | if n := strings.Count(string(raw), "\n"); n != 1 { | ||
| 58 | t.Fatalf("injected field wrote %d lines: %q", n, raw) | ||
| 59 | } | ||
| 60 | if n := len(strings.Split(strings.TrimSuffix(string(raw), "\n"), "\t")); n != 5 { | ||
| 61 | t.Fatalf("injected field wrote %d columns: %q", n, raw) | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | // The web cannot undo an action it has already taken, so a log that cannot be | ||
| 66 | // written has to be loud. It must never look like success to an operator. | ||
| 67 | func TestAuditReportsWriteFailure(t *testing.T) { | ||
| 68 | w, lines := auditWeb(t) | ||
| 69 | blocker := filepath.Join(t.TempDir(), "blocked") | ||
| 70 | if err := os.WriteFile(blocker, []byte("x"), 0o600); err != nil { | ||
| 71 | t.Fatal(err) | ||
| 72 | } | ||
| 73 | if err := os.RemoveAll(w.Cfg.AuditLog()); err != nil { | ||
| 74 | t.Fatal(err) | ||
| 75 | } | ||
| 76 | if err := os.Symlink(filepath.Join(blocker, "audit.log"), w.Cfg.AuditLog()); err != nil { | ||
| 77 | t.Fatalf("symlink in place of the log: %v", err) | ||
| 78 | } | ||
| 79 | w.audit("web.repo.delete", "keenan", "demo", "") | ||
| 80 | if len(*lines) != 1 || !strings.Contains((*lines)[0], "audit log write failed") { | ||
| 81 | t.Fatalf("the failure was not reported: %v", *lines) | ||
| 82 | } | ||
| 83 | if !strings.Contains((*lines)[0], "web.repo.delete") { | ||
| 84 | t.Fatalf("the failure does not name the action: %v", *lines) | ||
| 85 | } | ||
| 86 | } | ||