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. Updated tektoncd/pipeline to v0.6.0 pipeline Factored out execute trigger & run it as goroutine
- Loading branch information
Showing
296 changed files
with
158,635 additions
and
356 deletions.
There are no files selected for viewing
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
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,47 @@ | ||
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 name used to configure webhook | ||
- name: Github-Secret-Key | ||
description: Secret key used to configured webhook | ||
steps: | ||
- name: validate | ||
image: python:alpine | ||
command: ["/bin/sh"] | ||
args: | ||
- -ce | ||
- | | ||
set -e | ||
cat <<EOF | python | ||
import hashlib, os, hmac | ||
secret = bytes(os.environ.get('GithubSecret'), 'utf-8') | ||
payload = bytes("$(inputs.params.Payload)",'utf-8') | ||
signature = "$(inputs.params.X-Hub-Signature)" | ||
expected = hmac.new(secret, payload, hashlib.sha1).hexdigest() | ||
if expected is not None: | ||
if not isinstance(expected, str): | ||
expected = str(expected) | ||
sig_parts = signature.split("=", 1) | ||
if not isinstance(sig_parts[1], str): | ||
sig_parts1 = str(sig_parts[1]) | ||
else: | ||
sig_parts1 = sig_parts[1] | ||
if len(sig_parts) > 1 and sig_parts[0] == "sha1" and hmac.compare_digest(sig_parts1, expected): | ||
exit(0) | ||
exit(1) | ||
EOF | ||
env: | ||
- name: GithubSecret | ||
valueFrom: | ||
secretKeyRef: | ||
name: $(inputs.params.Github-Secret) | ||
key: $(inputs.params.Github-Secret-Key) |
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
Oops, something went wrong.