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.go +27−20
| @@ -1,30 +1,37 @@ | |||
| 1 | 1 | package web | |
| 2 | 2 | ||
| 3 | // The audit log. Vole records every privileged action in the same tab-separated | ||
| 4 | // shape the SSH hook and the identity store use, so one file answers "who did | ||
| 5 | // this" whether the change arrived over SSH, from the CLI, or from a form. | ||
| 3 | // The audit log. Vole records every privileged action in one tab-separated | ||
| 4 | // shape, so one file answers "who did this" whether the change arrived over SSH, | ||
| 5 | // from the CLI, or from a form. internal/audit owns the shape and the escaping; | ||
| 6 | // this file is only the web's way in. | ||
| 6 | 7 | // | |
| 7 | // A failure to write it is not reported to the browser: the action has already | ||
| 8 | // happened, and refusing the response would not undo it. The log is an audit | ||
| 9 | // trail, not a gate. | ||
| 8 | // A write failure is reported to the server log at error level and nothing else: | ||
| 9 | // the action has already happened, and refusing the response would not undo it. | ||
| 10 | // The acts that must fail closed — account, key and ACL changes, and a repository | ||
| 11 | // deletion — are recorded before they happen by the store they go through | ||
| 12 | // (forge/identity, forge/access, forge/repo), so a request that could not be | ||
| 13 | // recorded never reaches this file's callers. | ||
| 10 | 14 | ||
| 11 | 15 | import ( | |
| 12 | "fmt" | ||
| 13 | "github.com/rodent-software/vole/internal/secure" | ||
| 14 | "strings" | ||
| 15 | "time" | ||
| 16 | "github.com/rodent-software/vole/internal/audit" | ||
| 16 | 17 | ) | |
| 17 | 18 | ||
| 18 | // audit writes the same tab-separated shape the SSH hook and identity store use. | ||
| 19 | func (w *Web) audit(action, accountID, detail string) { | ||
| 20 | if w.Cfg == nil || w.Cfg.AuditLog() == "" { | ||
| 21 | return | ||
| 19 | // audit appends one record for an action that has already been taken. A failure | ||
| 20 | // is loud, never silent, and never changes the answer the browser already earned. | ||
| 21 | func (w *Web) audit(action, actor, subject, detail string) { | ||
| 22 | path := "" | ||
| 23 | if w.Cfg != nil { | ||
| 24 | path = w.Cfg.AuditLog() | ||
| 22 | 25 | } | |
| 23 | f, err := secure.OpenAppend(w.Cfg.AuditLog()) | ||
| 24 | if err != nil { | ||
| 25 | return | ||
| 26 | if err := audit.Append(path, audit.Record{ | ||
| 27 | Action: action, | ||
| 28 | Actor: actor, | ||
| 29 | Subject: subject, | ||
| 30 | Detail: detail, | ||
| 31 | }); err != nil { | ||
| 32 | if w.Logger != nil { | ||
| 33 | w.Logger("audit log write failed: action=%s account=%s subject=%s: %v", | ||
| 34 | action, actor, subject, err) | ||
| 35 | } | ||
| 26 | 36 | } | |
| 27 | defer f.Close() | ||
| 28 | detail = strings.NewReplacer("\n", " ", "\r", " ", "\t", " ").Replace(detail) | ||
| 29 | fmt.Fprintf(f, "%s\t%s\t%s\t%s\n", time.Now().UTC().Format(time.RFC3339), action, accountID, detail) | ||
| 30 | 37 | } | |