Support notifying an audit-server over unix socket (#266)

The audit-server is able to listen on a unix socket, but the client does not support http on unix socket. It's pretty simple to implement in golang, by overriding the socket dialer in a http client.

We could also depend on https://github.com/peterbourgon/unixtransport for a better-tested implementation, but I don't think it's worth the maintenance cost.

Reviewed-on: https://codeberg.org/git-pages/git-pages/pulls/266
Reviewed-by: Catherine <whitequark@whitequark.org>
This commit is contained in:
Xavier Vello
2026-10-07 22:42:15 +02:00
committed by Catherine
parent 762ff0ae65
commit d833deabf3
+16 -1
View File
@@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"os/exec"
@@ -345,6 +346,20 @@ func notifyAudit(ctx context.Context, id AuditID) {
notifyURL := config.Audit.NotifyURL.URL
notifyURL.RawQuery = id.String()
client := http.Client{}
if notifyURL.Scheme == "http+unix" {
socketPath := fmt.Sprintf("/%s/%s", notifyURL.Host, notifyURL.Path)
client.Transport = &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
var dialer net.Dialer
return dialer.DialContext(ctx, "unix", socketPath)
},
}
notifyURL.Scheme = "http"
notifyURL.Host = "localhost"
notifyURL.Path = ""
}
// See also the explanation in `AuditEventProcessor` above.
go func() {
backoff := exponential.Backoff{
@@ -353,7 +368,7 @@ func notifyAudit(ctx context.Context, id AuditID) {
Max: time.Second * 60,
}
for {
resp, err := http.Get(notifyURL.String())
resp, err := client.Get(notifyURL.String())
var body []byte
if err == nil {
body, _ = io.ReadAll(resp.Body)