Skip to content

Commit 8bf27c0

Browse files
committed
proposal: webhook receiver
1 parent 4304bbe commit 8bf27c0

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/spec/v1alpha1/receivers.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Receivers
2+
3+
The `Receiver` API defines a webhook receiver that triggers
4+
a synchronization for a group of sources.
5+
6+
## Specification
7+
8+
```go
9+
type ReceiverSpec struct {
10+
// Type of webhook sender, used to determine
11+
// the validation procedure and payload deserialization.
12+
// +kubebuilder:validation:Enum=github;gitlab
13+
// +required
14+
Type string `json:"type"`
15+
16+
// A list of sources to be notified about changes.
17+
// +required
18+
Sources []corev1.TypedLocalObjectReference `json:"sources"`
19+
}
20+
```
21+
22+
Webhook sender type:
23+
24+
```go
25+
const (
26+
GitHubWebhook string = "github"
27+
GitLabWebhook string = "gitlab"
28+
)
29+
```
30+
31+
## Status
32+
33+
```go
34+
type ReceiverStatus struct {
35+
// Generated webhook URL in the format
36+
// of '/hook/sha256sum(token)'.
37+
// +required
38+
URL string `json:"url"`
39+
40+
// Generate token used to validate the payload authenticity.
41+
// +required
42+
Token string `json:"token"`
43+
}
44+
```
45+
46+
## Implementation
47+
48+
The source controller handles the webhook requests on a dedicated port. This port can be used to create
49+
a Kubernetes LoadBalancer Service or Ingress to expose the receiver endpoint outside the cluster.
50+
51+
When a `Receiver` is created, the controller generates a random token and
52+
sets the `Receiver` status token and URL in the format `/hook/sha256sum(token)`.
53+
The `ReceiverReconciler` creates an indexer for the SHA265 digest
54+
so that it can be used as a field selector.
55+
56+
When source controller receives a POST request:
57+
* extract the SHA265 digest from the URL
58+
* loads the `Receiver` using the digest field selector
59+
* extracts the signature from HTTP headers based on `spec.type`
60+
* validates the signature using `status.Token` based on `spec.type`
61+
* extract the event type from the payload
62+
* triggers a synchronization for `spec.sources` if the event type is `push`

0 commit comments

Comments
 (0)