Repository navigation
Conversation
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
So, I am not convinced we should add direct HTTP delivery here, or that the transport belongs in toolhive-core. We already accept an io.Writer in NewAuditLogger, and ToolHive supports file output as well as stdout. The new functionality here is the webhook and fan-out, rather than support for non-stdout audit logs. My concern is what happens when delivery fails. This is synchronous, best-effort HTTP with no buffering or retry, and when used through our current slog logger, the errors returned by the writer are discarded. We could lose the remote record without reporting that failure, while a slow endpoint can block the logging path for the configured timeout. That does not give us the audit-delivery guarantees I would want. I would much rather have a bounded local handoff to another process or sidecar, with backpressure, or publish to a message queue with explicit delivery guarantees. A memory-backed file alone would not provide that: we need to define when the write is acknowledged and what happens if the consumer stops or crashes. A blocking pipe/socket can provide backpressure; durable delivery needs an acknowledgement after persistence or a durable spool. I would keep core focused on the event schema and emission contract, including making audit failures observable, and let a dedicated component own remote delivery and credentials. We can revisit shared transport code if multiple consumers actually need the same implementation. Can we step back from the HTTP sink and agree on the consumer requirement and delivery guarantees first? What needs to be true before we consider an audit record accepted: buffered locally, persisted locally, or acknowledged by a broker? |
|
Also, a few statements in the description and code comments need correcting:
And the stdout default only preserves behavior for consumers that already use stdout. Replacing an existing file writer with NewWriter(Config{}) would change its destination. |
JAORMX
left a comment
There was a problem hiding this comment.
Requesting changes pending agreement on the delivery contract and where this functionality belongs. I do not want us to merge the direct HTTP sink as proposed.
We already support arbitrary writers in core and file output in ToolHive. Before adding another transport to core, we need a concrete consumer requirement and an agreed failure policy. My preference is a bounded local handoff to a dedicated delivery process, or a message queue with explicit acknowledgement and durability guarantees.
There is also a concrete failure-handling problem with the intended slog integration: errors returned by this writer are discarded by slog.Logger. Failed remote delivery would not be surfaced through the existing audit emission API. We need an observable failure path and defined backpressure/acknowledgement semantics before relying on this for audit delivery.
Please also address the inaccuracies called out in my earlier comments: platform-wide stdout-only behavior, missing-URL validation at construction, and the unconditional stdout-delivery claim.
Discussion: #326 (comment)
Corrections: #326 (comment)
|
Thanks for reviewing @JAORMX 🙏 I'm marking it as draft since haven't had time to go through this in depth, the main thing is trying to standardize the audit logs which there are different implementations/approaches, so trying to standardize it here in toolhive-core to be re-usable across components |
Summary
Adds
audit/sink, a small package that builds theio.WriteCloseran audit*slog.Loggerwrites to. It fans each JSON audit line out to any combination of stdout and an HTTP webhook, so a component that owns its audit logger can ship events to a SIEM without an external log shipper.sink.NewWriter(Config)returns a fan-out writer. An emptyConfigis stdout-only, so adopting the package changes nothing until a sink is configured.io.MultiWriter, which stops at the first failing writer. A flaky HTTP endpoint therefore never costs the stdout record.It sits beside
audit.AuditEventandaudit.NewAuditEvent, which it is meant to carry, and adds no dependencies.Why here
Several Stacklok components emit
audit.AuditEventand each hardcodesos.Stdoutfor the logger. A shared sink avoids each of them growing its own forwarder. A Kafka sink was left out on purpose to avoid a new dependency in this module; theEntrytype leaves room to add one later.Verification
task lint(golangci-lint, go vet): 0 issuestask license-check: cleango test -race -cover ./audit/sink/: pass, 90.7% coverageNotes for reviewers
CLAUDE.md asks to discuss new packages first. This one was requested explicitly as part of Stacklok's audit standardization work, so please flag if
audit/sinkis the wrong home.🤖 Generated with Claude Code