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.

forge/instance_test.go +56−1

@@ -62,7 +62,7 @@ func TestInitOpenAndRepoLifecycle(t *testing.T) {
62 62 t.Fatalf("index did not follow the rename: %v", err)
63 63 }
64 64
65 if err := inst.DeleteRepo("renamed"); err != nil {
65 if err := inst.DeleteRepo("renamed", "keenan"); err != nil {
66 66 t.Fatalf("delete: %v", err)
67 67 }
68 68 if _, err := inst.Repos.Open("renamed"); !os.IsNotExist(err) {
@@ -72,3 +72,58 @@ func TestInitOpenAndRepoLifecycle(t *testing.T) {
72 72 t.Fatal("index row survived delete")
73 73 }
74 74 }
75
76 // An instance that cannot write its audit log refuses to start. Discovering that
77 // during an incident is too late: every privileged change it served would have
78 // been unrecorded.
79 func TestOpenRefusesAnUnwritableAuditLog(t *testing.T) {
80 t.Parallel()
81 dir := t.TempDir()
82 root, err := Init(dir)
83 if err != nil {
84 t.Fatalf("init: %v", err)
85 }
86 cfg, err := config.Load(filepath.Join(root, "vole.toml"))
87 if err != nil {
88 t.Fatal(err)
89 }
90 if err := os.RemoveAll(cfg.AuditLog()); err != nil {
91 t.Fatal(err)
92 }
93 if err := os.Mkdir(cfg.AuditLog(), 0o700); err != nil {
94 t.Fatal(err)
95 }
96 if inst, err := Open(cfg, "vole"); err == nil {
97 inst.Close()
98 t.Fatal("an instance opened with a directory in place of its audit log")
99 }
100 }
101
102 // A symlink lets somebody outside the service point the log at /dev/null, which
103 // is the same as not having one.
104 func TestOpenRefusesASymlinkedAuditLog(t *testing.T) {
105 t.Parallel()
106 dir := t.TempDir()
107 root, err := Init(dir)
108 if err != nil {
109 t.Fatalf("init: %v", err)
110 }
111 cfg, err := config.Load(filepath.Join(root, "vole.toml"))
112 if err != nil {
113 t.Fatal(err)
114 }
115 if err := os.RemoveAll(cfg.AuditLog()); err != nil {
116 t.Fatal(err)
117 }
118 target := filepath.Join(dir, "elsewhere.log")
119 if err := os.WriteFile(target, nil, 0o600); err != nil {
120 t.Fatal(err)
121 }
122 if err := os.Symlink(target, cfg.AuditLog()); err != nil {
123 t.Fatal(err)
124 }
125 if inst, err := Open(cfg, "vole"); err == nil {
126 inst.Close()
127 t.Fatal("an instance opened with a symlinked audit log")
128 }
129 }