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.

server/integration_test.go +7−3

@@ -170,6 +170,7 @@ func newFixtureWith(t *testing.T, tweak func(*config.Config)) *fixture {
170 170 if err != nil {
171 171 t.Fatal(err)
172 172 }
173 ident.AuditPath = cfg.AuditLog()
173 174 owner, err := ident.Create("keenan", pub, "test")
174 175 if err != nil {
175 176 t.Fatal(err)
@@ -542,6 +543,9 @@ func TestRosterIsOneDatabaseFile(t *testing.T) {
542 543 t.Fatal(err)
543 544 }
544 545 defer ident.Close()
546 // This copy is only read here, but a store without a sink would refuse a
547 // mutation silently the next time a test used it to write.
548 ident.AuditPath = f.cfg.AuditLog()
545 549 if _, ok := ident.Snapshot().ByName["keenan"]; !ok {
546 550 t.Fatal("copied roster has no users")
547 551 }
@@ -1758,7 +1762,7 @@ func TestCommentEditsBelongToTheirAuthor(t *testing.T) {
1758 1762 if err != nil {
1759 1763 t.Fatal(err)
1760 1764 }
1761 if !strings.Contains(string(audit), "comment-D "+commentPath(wilburCm)) {
1765 if !strings.Contains(string(audit), "\tcomment.delete\tkeenan\tdemo\t"+commentPath(wilburCm)) {
1762 1766 t.Fatalf("the admin override was not audited:\n%s", audit)
1763 1767 }
1764 1768 }
@@ -1897,7 +1901,7 @@ func TestMetadataForcePushIsAdminOnly(t *testing.T) {
1897 1901 if err != nil {
1898 1902 t.Fatal(err)
1899 1903 }
1900 if !strings.Contains(string(audit), "force-push refs/heads/vole") {
1904 if !strings.Contains(string(audit), "\tpush.force\tkeenan\tdemo\trefs/heads/vole") {
1901 1905 t.Fatalf("force-push not audited:\n%s", audit)
1902 1906 }
1903 1907 }
@@ -2251,7 +2255,7 @@ func TestProtectedBranchRequiresApprovedRequest(t *testing.T) {
2251 2255 if err != nil {
2252 2256 t.Fatal(err)
2253 2257 }
2254 if !strings.Contains(string(audit), "merge refs/heads/main via request "+reqID) {
2258 if !strings.Contains(string(audit), "\tmerge\twilbur\tdemo\trefs/heads/main via request "+reqID) {
2255 2259 t.Fatalf("merge not audited:\n%s", audit)
2256 2260 }
2257 2261 }