Add token-based authentication for receiver
All checks were successful
ci / build (push) Successful in 28s

This commit is contained in:
Martin McCaffery 2026-02-11 13:58:42 +01:00
parent 042ce77ddc
commit d0dd209bc9
Signed by: martin.mccaffery
GPG key ID: 7C4D0F375BCEE533
12 changed files with 705 additions and 61 deletions

View file

@ -31,6 +31,7 @@ func main() {
logFormat := flag.String("log-format", defaultLogFormat, "Output format: json, text")
topN := flag.Int("top", defaultTopN, "Number of top processes to include")
pushEndpoint := flag.String("push-endpoint", "", "HTTP endpoint to push metrics to (e.g., http://localhost:8080/api/v1/metrics)")
pushToken := flag.String("push-token", os.Getenv("COLLECTOR_PUSH_TOKEN"), "Bearer token for push endpoint authentication (or set COLLECTOR_PUSH_TOKEN)")
flag.Parse()
// Setup structured logging for application logs
@ -61,7 +62,7 @@ func main() {
// Setup push client if endpoint is configured
if *pushEndpoint != "" {
pushClient := summary.NewPushClient(*pushEndpoint)
pushClient := summary.NewPushClient(*pushEndpoint, *pushToken)
c.SetPushClient(pushClient)
execCtx := pushClient.ExecutionContext()
appLogger.Info("push client configured",

View file

@ -23,6 +23,7 @@ func main() {
addr := flag.String("addr", defaultAddr, "HTTP listen address")
dbPath := flag.String("db", defaultDBPath, "SQLite database path")
readToken := flag.String("read-token", os.Getenv("RECEIVER_READ_TOKEN"), "Pre-shared token for read endpoints (or set RECEIVER_READ_TOKEN)")
hmacKey := flag.String("hmac-key", os.Getenv("RECEIVER_HMAC_KEY"), "Secret key for push token generation/validation (or set RECEIVER_HMAC_KEY)")
flag.Parse()
logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
@ -36,7 +37,7 @@ func main() {
}
defer func() { _ = store.Close() }()
handler := receiver.NewHandler(store, logger, *readToken)
handler := receiver.NewHandler(store, logger, *readToken, *hmacKey)
mux := http.NewServeMux()
handler.RegisterRoutes(mux)