Documentation
¶
Overview ¶
Package hookauth checks that an incoming webhook comes from its service: the presets (GitHub, GitLab, Grafana, Alertmanager, Sentry, any JSON) and their signatures or tokens, compared in constant time. The hub checks a managed webhook with it (docs/hub/sources.md «Вебхуки»); a machine checks its own, unmanaged one with the same code (internal/connectors/webhook). It knows nothing of where the secret is kept.
Index ¶
- Constants
- Variables
- func Bearer(h http.Header, secret string) bool
- func DeliveryID(h http.Header) string
- func Equal(a, b string) bool
- func Fresh(ts string, now time.Time) bool
- func Known(preset string) bool
- func PathAuth(preset, auth string) bool
- func RouteToken(secret, source string) string
- func SecretKey(preset string) string
- func Signed(secret string, body []byte, given string) bool
- func Verify(preset, auth, secret string, h http.Header, body []byte, path string, ...) bool
- func VerifyHeaders(preset, secret string, h http.Header, body []byte, now time.Time) bool
Constants ¶
const ( PresetGitHub = "github" PresetGitLab = "gitlab" PresetGrafana = "grafana" PresetAlertmanager = "alertmanager" PresetSentry = "sentry" PresetJSON = "json" )
Presets of the services it understands.
const ( AuthHeader = "header" AuthPath = "path" )
How a service proves a request is its own, for the presets that let the person choose.
const Skew = 5 * time.Minute
Skew is how far a signed timestamp may be from now (Sentry, Grafana): an older request is a replay.
Variables ¶
var Headers = []string{"Content-Type", "User-Agent", "Authorization",
"X-Hub-Signature-256", "X-GitHub-Event", "X-GitHub-Delivery",
"X-Gitlab-Token", "X-Gitlab-Event", "X-Gitlab-Event-UUID", "Idempotency-Key",
"X-Grafana-Alerting-Signature", "X-Grafana-Alerting-Signature-Timestamp",
"Sentry-Hook-Signature", "Sentry-Hook-Timestamp", "Sentry-Hook-Resource", "Request-ID",
"X-Signature-256", "X-Signature", "X-Webhook-Signature", "X-Request-Id", "X-Delivery-Id"}
Headers are what the presets read: nothing else of a request is passed on or kept.
Functions ¶
func DeliveryID ¶
DeliveryID is the service's own id of the delivery ("Header:value"), "" when it sends none.
func Equal ¶
Equal compares a given secret with the kept one in constant time; an empty one is never equal.
func Fresh ¶
Fresh says a signed timestamp (unix seconds or milliseconds) is near now; an absent one is not.
func PathAuth ¶
PathAuth says the secret is the last part of the address (a sender that cannot sign or set a header).
func RouteToken ¶
RouteToken is the secret part of a managed webhook's address (/hook/t/<source>/<token>): derived from the secret the service signs with and the source, so it changes with the secret and opens no other source. 64 hex.
func SecretKey ¶
SecretKey is the name of the field that holds the secret a preset signs with: Sentry signs with its integration's own Client Secret.
func Verify ¶
func Verify(preset, auth, secret string, h http.Header, body []byte, path string, now time.Time) bool
Verify checks a request by the secret of its preset. path is the secret the address carried ("" for none); a preset that takes the secret in the address is proved by it alone, any other refuses an address with one. Any failure is false, without saying which part was wrong.
Types ¶
This section is empty.