forked from tektoncd/triggers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable TriggerBindings to validate requests
This PR resolves the issue tektoncd#45. It assumes that a task has been defined which can validate requests. That task will receive header and payload as params. Before the creation of resources, task will be called alongwith serviceaccount which has github-secret used to create webhook. Assumption: 1. Task is defined in such a way that it can use headers and payload received as params. 2. Apart from serviceaccount, payload and headers, task doesn't need anything else. 3. Task gives us non zero exit if validation failed. A sample task and main.go is provided.
- Loading branch information
Showing
9 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
|
||
signature := os.Getenv("X-Hub-Signature") | ||
if len(signature) == 0 { | ||
log.Println("Err securing endpoint: no signature") | ||
os.Exit(1) | ||
} | ||
|
||
secret := os.Getenv("Secret") | ||
if len(secret) == 0 { | ||
log.Println("Err securing endpoint: no secret") | ||
os.Exit(1) | ||
} | ||
|
||
payload := os.Getenv("Payload") | ||
if len(payload) == 0 { | ||
log.Println("Err securing endpoint: no payload") | ||
os.Exit(1) | ||
} | ||
|
||
mac := hmac.New(sha1.New, []byte(secret)) | ||
_, _ = mac.Write([]byte(payload)) | ||
expectedMAC := hex.EncodeToString(mac.Sum(nil)) | ||
|
||
if !hmac.Equal([]byte(signature[5:]), []byte(expectedMAC)) { | ||
log.Println("Err securing endpoint: signature doesn't match") | ||
os.Exit(1) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: validate-webhook | ||
spec: | ||
inputs: | ||
params: | ||
- name: Payload | ||
description: Payload of Event Received | ||
- name: X-Hub-Signature | ||
description: Hash of the Request Received | ||
- name: Github-Secret | ||
description: Secret used to configure webhook | ||
steps: | ||
- name: validate | ||
image: quay.io/khrm/trigger-validate | ||
command: ["/validate-webhook"] | ||
env: | ||
- name: Payload | ||
value: $(inputs.params.Payload) | ||
- name: X-Hub-Signature | ||
value: $(inputs.params.X-Hub-Signature) | ||
- name: Github-Secret | ||
valueFrom: | ||
secretKeyRef: | ||
name: github | ||
key: github-secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Validate Webhook Tekton Task | ||
The validate webhook task configures provides a task to validate an incoming event to the addressable endpoint. | ||
Task receives request headers and payload as Params. Sample Task provided for github. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters