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.

server/web/comment_writes.go +7−7

@@ -256,7 +256,7 @@ func (w *Web) addComment(rw http.ResponseWriter, r *http.Request, load topicLoad
256 256 w.fail(rw, r, http.StatusBadRequest, "cannot add the comment: "+err.Error(), t.view)
257 257 return
258 258 }
259 w.finishComment(rw, r, ctx, t, t.auditAdd, ctx.Repo.Name+" "+t.id+" "+c.ID, t.afterAdd(c))
259 w.finishComment(rw, r, ctx, t, t.auditAdd, ctx.Repo.Name, t.id+" "+c.ID, t.afterAdd(c))
260 260 }
261 261
262 262 // editComment rewrites one comment. Only its author, or an admin repairing a
@@ -290,7 +290,7 @@ func (w *Web) editComment(rw http.ResponseWriter, r *http.Request, load topicLoa
290 290 return
291 291 }
292 292 w.finishComment(rw, r, ctx, t, t.auditEdit,
293 commentAuditDetail(ctx.Repo.Name, t.id, commentID, c.Author, ctx.Name),
293 ctx.Repo.Name, commentAuditDetail(t.id, commentID, c.Author, ctx.Name),
294 294 t.afterComment(commentID))
295 295 }
296 296
@@ -320,15 +320,15 @@ func (w *Web) deleteComment(rw http.ResponseWriter, r *http.Request, load topicL
320 320 return
321 321 }
322 322 w.finishComment(rw, r, ctx, t, t.auditRemove,
323 commentAuditDetail(ctx.Repo.Name, t.id, commentID, c.Author, ctx.Name),
323 ctx.Repo.Name, commentAuditDetail(t.id, commentID, c.Author, ctx.Name),
324 324 t.afterComment(commentID))
325 325 }
326 326
327 327 // commentAuditDetail is the audit line for a comment write. An admin acting on
328 328 // somebody else's comment is recorded as an override, which is the case a reader
329 329 // of the log is looking for.
330 func commentAuditDetail(repo, topicID, commentID, author, actor string) string {
331 detail := repo + " " + topicID + " " + commentID
330 func commentAuditDetail(topicID, commentID, author, actor string) string {
331 detail := topicID + " " + commentID
332 332 if actor != author {
333 333 detail += " (author " + author + ", admin override)"
334 334 }
@@ -338,8 +338,8 @@ func commentAuditDetail(repo, topicID, commentID, author, actor string) string {
338 338 // finishComment closes a successful comment write: it records the action, checks
339 339 // the metadata tree, and answers — the re-rendered section for HTMX, a redirect for
340 340 // a plain form post.
341 func (w *Web) finishComment(rw http.ResponseWriter, r *http.Request, ctx *writeContext, t *commentTopic, action, detail, next string) {
342 w.audit(action, ctx.Name, detail)
341 func (w *Web) finishComment(rw http.ResponseWriter, r *http.Request, ctx *writeContext, t *commentTopic, action, subject, detail, next string) {
342 w.audit(action, ctx.Name, subject, detail)
343 343 if problems := t.validate(); len(problems) > 0 {
344 344 w.Logger("web: comment write left the metadata tree invalid: %v", problems)
345 345 }