Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions api/application/v1alpha2/application.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@
"notifications": {
"additionalProperties": {
"additionalProperties": false,
"if": {
"required": [
"signingSecretEnv"
]
},
"properties": {
"format": {
"default": "Text",
Expand All @@ -825,6 +830,14 @@
},
"type": "array"
},
"signingSecretEnv": {
"description": "Local environment-variable name containing a Standard Webhooks signing secret (whsec_ followed by base64). When set, each request carries webhook-id, webhook-timestamp and webhook-signature headers, and a send is retried at most three times within 15 seconds on a network error, 429 or 5xx. Requires format JSON. A missing or malformed secret is a warning, never a blocked operation: the command does not send that notification, and a scheduled job keeps signing with the keys its last deploy wrote. Notifications are sent concurrently, so several dead receivers still cost one 15-second bound. Expects a variable name of letters, digits and underscores, not starting with a digit.",
"examples": [
"ONEBOX_WEBHOOK_SECRET"
],
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
"type": "string"
},
"webhook": {
"description": "HTTP endpoint that receives outcome notifications.",
"examples": [
Expand All @@ -833,6 +846,16 @@
"type": "string"
}
},
"then": {
"properties": {
"format": {
"const": "JSON"
}
},
"required": [
"format"
]
},
"type": "object"
},
"description": "Named webhooks that receive selected operation and scheduled-job outcomes.",
Expand Down
22 changes: 7 additions & 15 deletions cmd/ob/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ func notifyOutcome(ctx context.Context, cfg *app.Resolved, g *globalFlags, verb,
// stable, redaction-safe outcome.
p.Status, p.Error = "fail", "operation failed; inspect trusted local diagnostics and journal evidence"
}
for _, name := range sortedNames(cfg.Notifications) {
if nerr := notify.Send(ctx, cfg.Notifications[name], p); nerr != nil {
fmt.Fprintf(os.Stderr, "warn: notify webhook %s: %v\n", name, nerr)
}
// Sent concurrently, so a verb waits for at most one send's bound however
// many webhooks are configured.
for _, failure := range notify.SendAll(ctx, cfg.Notifications, p) {
fmt.Fprintf(os.Stderr, "warn: notify webhook %s: %v\n", failure.Name, failure.Err)
}
}

Expand All @@ -294,7 +294,9 @@ func notifyOperationOutcome(ctx context.Context, cfg *app.Resolved, g *globalFla
evidenceID = result.ReleaseID
}
// The operation context is cancelled by Ctrl-C and SIGTERM. Its outcome is
// still worth sending; notify.Send has its own bounded HTTP timeout.
// still worth sending; notify.SendAll bounds itself: one 5s attempt, or for
// a signed notification at most three attempts within notify.SignedBudget,
// with every webhook sent at once.
notifyOutcome(context.WithoutCancel(ctx), cfg, g, verb, evidenceID, err)
}

Expand Down Expand Up @@ -571,16 +573,6 @@ func notificationConfig(g *globalFlags) (*app.Resolved, error) {
return spec.Resolve(g.Env)
}

// sortedNames orders map keys so repeated runs report in the same sequence.
func sortedNames[V any](m map[string]V) []string {
out := make([]string, 0, len(m))
for k := range m {
out = append(out, k)
}
sort.Strings(out)
return out
}

func renderDeployNoOp(u *ui.UI, currentRelease string) {
u.Successf("nothing to deploy — %s is current (`--redeploy` forces a fresh roll)", currentRelease)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/app/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ var schemaConstraints = []struct {
{[]string{"registries", "*", "username"}, pattern(gRegistryUser)},
{[]string{"registries", "*", "password_env"}, pattern(gEnvName)},
{[]string{"notifications", "*", "format"}, enum(eNotifyFormat)},
{[]string{"notifications", "*", "signing_secret_env"}, pattern(gEnvName)},
// Format defaults to text, so a signed notification has to say JSON.
{[]string{"notifications", "*"}, map[string]any{
"if": map[string]any{"required": []any{"signing_secret_env"}},
"then": map[string]any{
"required": []any{"format"},
"properties": map[string]any{"format": map[string]any{"const": "json"}},
},
}},
{[]string{"runtime", "env_files", "items", "file"}, pattern(gRepoPath)},
{[]string{"runtime", "env_files", "items", "provider"}, enum(eSecretProvider)},
{[]string{"runtime", "env_files", "items"}, map[string]any{"required": []any{"file"}}},
Expand Down
35 changes: 35 additions & 0 deletions internal/app/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ spec:
// event is a webhook that reads as configured and never calls.
{"notification on an unknown event", min + "notifications: {ops: {webhook: \"https://h.example.com/x\", on: [deployed]}}\n", false},
{"notification with no events", min + "notifications: {ops: {webhook: \"https://h.example.com/x\"}}\n", true},
// A signed notification authenticates the JSON body a verifier reads;
// the secret itself is never in the file, only the variable naming it.
{"signed JSON notification", min + "notifications: {ops: {webhook: \"https://h.example.com/x\", format: json, signing_secret_env: OPS_WEBHOOK_SECRET}}\n", true},
{"signed notification with the default text format", min + "notifications: {ops: {webhook: \"https://h.example.com/x\", signing_secret_env: OPS_WEBHOOK_SECRET}}\n", false},
{"signed text notification", min + "notifications: {ops: {webhook: \"https://h.example.com/x\", format: text, signing_secret_env: OPS_WEBHOOK_SECRET}}\n", false},
{"signing secret env that is not a variable name", min + "notifications: {ops: {webhook: \"https://h.example.com/x\", format: json, signing_secret_env: \"whsec_abc=\"}}\n", false},
// logging lands verbatim in the generated runtime, so an unchecked value
// fails at container create on the server, after validate/preview/plan
// all reported the project fine.
Expand Down Expand Up @@ -1065,3 +1071,32 @@ spec:
})
}
}

// The published key is signingSecretEnv, and a signed notification must say
// format: JSON because the default text body is not what a verifier reads.
func TestSignedNotificationProjectFile(t *testing.T) {
project := func(notification string) []byte {
return []byte(`apiVersion: onebox.run/v1alpha2
kind: Application
metadata:
name: shop
spec:
environments: {production: {server: root@203.0.113.10}}
workloads:
web: {image: nginx}
notifications:
facet: ` + notification + `
`)
}
spec, err := loadFixtureBytes(project(`{webhook: "https://facet.example.com/hooks/onebox", format: JSON, signingSecretEnv: FACET_WEBHOOK_SECRET}`), "ob.yml")
if err != nil {
t.Fatal(err)
}
if got := spec.Notifications["facet"].SigningSecretEnv; got != "FACET_WEBHOOK_SECRET" {
t.Fatalf("signingSecretEnv = %q", got)
}
_, err = loadFixtureBytes(project(`{webhook: "https://facet.example.com/hooks/onebox", signingSecretEnv: FACET_WEBHOOK_SECRET}`), "ob.yml")
if err == nil || !strings.Contains(err.Error(), "notifications.facet.format") || !strings.Contains(err.Error(), "format: JSON") {
t.Fatalf("error = %v, want a refusal at notifications.facet.format", err)
}
}
20 changes: 20 additions & 0 deletions internal/app/testdata/contract-verdicts.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,26 @@
"loads": false,
"code": "unknown_field"
},
{
"case": "conformance/signed JSON notification",
"loads": true,
"digest": "4722d2d66d41aa91e17ee4e3d9e56074ff6edbae82a46d6202abad3282521801"
},
{
"case": "conformance/signed notification with the default text format",
"loads": false,
"code": "project_invalid"
},
{
"case": "conformance/signed text notification",
"loads": false,
"code": "project_invalid"
},
{
"case": "conformance/signing secret env that is not a variable name",
"loads": false,
"code": "project_invalid"
},
{
"case": "conformance/status code 600",
"loads": false,
Expand Down
3 changes: 3 additions & 0 deletions internal/app/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ type Notification struct {
Webhook string `json:"webhook" description:"HTTP endpoint that receives outcome notifications." example:"https://hooks.example.com/onebox"`
On []string `json:"on,omitempty" description:"Operation outcomes that trigger this notification." default:"success, failure"`
Format string `json:"format" description:"Notification payload format." default:"text"`
// SigningSecretEnv names a variable in the operator's environment, never
// the secret itself, so the project file stays safe to commit.
SigningSecretEnv string `json:"signing_secret_env,omitempty" description:"Local environment-variable name containing a Standard Webhooks signing secret (whsec_ followed by base64). When set, each request carries webhook-id, webhook-timestamp and webhook-signature headers, and a send is retried at most three times within 15 seconds on a network error, 429 or 5xx. Requires format JSON. A missing or malformed secret is a warning, never a blocked operation: the command does not send that notification, and a scheduled job keeps signing with the keys its last deploy wrote. Notifications are sent concurrently, so several dead receivers still cost one 15-second bound." example:"ONEBOX_WEBHOOK_SECRET"`
}

type Registry struct {
Expand Down
11 changes: 11 additions & 0 deletions internal/app/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ func validateTopLevel(p *Spec) error {
return err
}
}
if err := gEnvName.checkOptional("notifications."+name+".signing_secret_env", p.Notifications[name].SigningSecretEnv); err != nil {
return err
}
// The signature covers the exact body bytes, and a receiver that
// verifies one reads the structured fields. A text body is a sentence
// for a chat channel, so signing it would authenticate nothing a
// verifier can use.
if p.Notifications[name].SigningSecretEnv != "" && p.Notifications[name].Format != "json" {
return errf("project_invalid", "notifications."+name+".format", "",
"a signed notification sends the JSON payload; set format: JSON beside signingSecretEnv")
}
}
for _, name := range sortedKeys(p.Hooks) {
// A hook key is either a lifecycle seam the engine invokes, or the name
Expand Down
Loading
Loading