Files
sam 8a3ba32c5a Feat/operator alerts (#1635)
* feat(state): durable operator alerts owned by the State Store

Alerts dedup on org+kind+subject, resolve themselves when a condition
clears, and are raised, resolved, dismissed and listed through the state
contract. Task transitions raise needs-human and failed alerts in the same
transaction; the store checks service health and prunes closed alerts.
Each raise and resolve queues a webhook delivery whose attempts are kept.

* feat(notify): deliver operator alerts to the webhook; raise config and release alerts

notify.webhook now receives raised and resolved alerts above a severity
threshold with HMAC-signed payloads, bounded retry and every attempt recorded
on the alert. archied raises model alias, provider and credential-binding
alerts from the effective configuration, an update alert from the release
channel, and a credential-rejected alert from the egress resolver. The
dashboard API lists and dismisses the caller's org's alerts.

* feat(ui): alert bell in the top bar and webhook alert settings

The bell lists the org's open alerts by severity with dismiss and a link per
alert, and refreshes from the event stream. The task settings page gains the
webhook severity threshold and signing secret. ui/dist rebuilt.
2026-10-12 03:30:46 +11:00

35 lines
993 B
Go

package webhookguard
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"strings"
)
// VerifyHMAC checks a hex SHA-256 HMAC of body, with or without a "sha256="
// prefix, case-insensitively. An empty signature never verifies.
func VerifyHMAC(body []byte, signature, secret string) bool {
if signature == "" {
return false
}
// Decode both sides to raw bytes and compare those: hex.DecodeString
// accepts either case, and comparing digests rather than their text
// keeps the comparison constant-time.
supplied, err := hex.DecodeString(strings.TrimPrefix(signature, "sha256="))
if err != nil {
return false
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(body)
return hmac.Equal(supplied, mac.Sum(nil))
}
// SignHMAC is the "sha256=" hex HMAC-SHA256 of body, the form VerifyHMAC
// accepts.
func SignHMAC(body []byte, secret string) string {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(body)
return "sha256=" + hex.EncodeToString(mac.Sum(nil))
}