From 8d2086f5e9e18aec0db393b323443e4d5beb766d Mon Sep 17 00:00:00 2001 From: Yoofi Quansah Date: Mon, 25 Sep 2023 08:33:32 -0500 Subject: [PATCH 1/4] feat: Add webhook templates documentation --- configuration/observability.mdx | 41 +++++++++++++++++++++++++++++++++ configuration/overview.mdx | 1 + 2 files changed, 42 insertions(+) diff --git a/configuration/observability.mdx b/configuration/observability.mdx index edaaf09..64cbc41 100644 --- a/configuration/observability.mdx +++ b/configuration/observability.mdx @@ -145,3 +145,44 @@ X-Forwarded-Proto: https You also have the ability to provide a signing secret for requests to your webhook. If you specify a signing secret, you will receive a request with the `X-Flipt-Webhook-Signature` header populated. The value in the header is the request body HMAC sha256 signed with the signing secret you specified. On the webhook server, you can validate the signature by using the same signing secret. It is _strongly recommended_ that you do this to prevent requests to your webhook server that are from invalid origins. + +#### Webhook Templates + +Starting from [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0), you can specify configuration for Flipt to send Webhooks to a URL with the Audit event properties you can template in the body of the request. + +A sample configuration can look something like this: + +```yaml +audit: + sinks: + webhook: + enabled: true + templates: + - url: https://example.com + headers: + Content-Type: application/json + Authorization: Bearer this-is-a-seret-token + body: | + { + "type": {{ .Type }}, + "action": {{ .Action }} + } +``` + +This configuration tells Flipt to send a `POST` request when events need to be emitted to the URL `https://example.com` with the HTTP headers, `Content-Type` and `Authorization`, and the body which is a Go template that will be executed when an event comes in. The event structure looks like this: + +```go +type Event struct { + Version string `json:"version"` + Type Type `json:"type"` + Action Action `json:"action"` + + Metadata Metadata `json:"metadata"` + + Payload interface{} `json:"payload"` + + Timestamp string `json:"timestamp"` +} +``` + +and is located [here](https://github.com/flipt-io/flipt/blob/v1.28.0/internal/server/audit/audit.go#L51-L61) in code. So any of these values in the structure are fair game for however you want to construct your HTTP body template. \ No newline at end of file diff --git a/configuration/overview.mdx b/configuration/overview.mdx index 6ed54d2..7de1dd5 100644 --- a/configuration/overview.mdx +++ b/configuration/overview.mdx @@ -248,6 +248,7 @@ These properties are as follows: | audit.sinks.webhook.url | URL to send audit events to | | v1.27.0 | | audit.sinks.webhook.signing_secret | Signing secret to use for verification of origin on webhook server | | v1.27.0 | | audit.sinks.webhook.max_backoff_duration | Max exponential backoff duration for sending webhook upon failure | 15s | v1.27.0 | +| audit.sinks.webhook.templates[] | List of webhook templates for Flipt to send audit events to | | v1.28.0 | ### Tracing From e16639a42c9c11ba7a86db35c8ded1b5d871c02b Mon Sep 17 00:00:00 2001 From: yquansah Date: Mon, 25 Sep 2023 13:37:21 +0000 Subject: [PATCH 2/4] chore: format code --- configuration/observability.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration/observability.mdx b/configuration/observability.mdx index 64cbc41..12c6bc9 100644 --- a/configuration/observability.mdx +++ b/configuration/observability.mdx @@ -185,4 +185,4 @@ type Event struct { } ``` -and is located [here](https://github.com/flipt-io/flipt/blob/v1.28.0/internal/server/audit/audit.go#L51-L61) in code. So any of these values in the structure are fair game for however you want to construct your HTTP body template. \ No newline at end of file +and is located [here](https://github.com/flipt-io/flipt/blob/v1.28.0/internal/server/audit/audit.go#L51-L61) in code. So any of these values in the structure are fair game for however you want to construct your HTTP body template. From a8f3b80aa4f5cad696ae6fe5619a6d18bd1131fa Mon Sep 17 00:00:00 2001 From: Yoofi Quansah Date: Mon, 25 Sep 2023 12:39:29 -0500 Subject: [PATCH 3/4] chore: address comments from PR --- configuration/observability.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configuration/observability.mdx b/configuration/observability.mdx index 64cbc41..55a957d 100644 --- a/configuration/observability.mdx +++ b/configuration/observability.mdx @@ -148,7 +148,7 @@ The value in the header is the request body HMAC sha256 signed with the signing #### Webhook Templates -Starting from [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0), you can specify configuration for Flipt to send Webhooks to a URL with the Audit event properties you can template in the body of the request. +Starting from [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0), you can specify a template for the body of an Audit Event Webhook request. A sample configuration can look something like this: @@ -185,4 +185,4 @@ type Event struct { } ``` -and is located [here](https://github.com/flipt-io/flipt/blob/v1.28.0/internal/server/audit/audit.go#L51-L61) in code. So any of these values in the structure are fair game for however you want to construct your HTTP body template. \ No newline at end of file +Any of the values that are [exposed](https://github.com/flipt-io/flipt/blob/v1.28.0/internal/server/audit/audit.go#L51-L61) by Flipt are fair game for inclusion in your HTTP body template. \ No newline at end of file From 216705f4ceb28afead1fd3a2a4eb9217653a5651 Mon Sep 17 00:00:00 2001 From: Yoofi Quansah Date: Wed, 27 Sep 2023 07:52:37 -0500 Subject: [PATCH 4/4] chore: add link for Go Template --- configuration/observability.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration/observability.mdx b/configuration/observability.mdx index 64386c7..c7d48fa 100644 --- a/configuration/observability.mdx +++ b/configuration/observability.mdx @@ -169,7 +169,7 @@ audit: } ``` -This configuration tells Flipt to send a `POST` request when events need to be emitted to the URL `https://example.com` with the HTTP headers, `Content-Type` and `Authorization`, and the body which is a Go template that will be executed when an event comes in. The event structure looks like this: +This configuration tells Flipt to send a `POST` request when events need to be emitted to the URL `https://example.com` with the HTTP headers, `Content-Type` and `Authorization`, and the body which is a [Go template](https://pkg.go.dev/text/template) that will be executed when an event comes in. The event structure looks like this: ```go type Event struct {