Chapter 6. Creating a secret for a generic or GitHub webhook
Chapter 6. Creating a secret for a generic or GitHub webhook You can create a secret that you can use with a generic or GitHub webhook to trigger application builds in a Git repository. Depending on the type of Git hosting platform that you use for your application code, the JWS Operator provides a genericWebhookSecret parameter and a githubWebhookSecret parameter that you can use to specify the secret in the custom resource file for a web application. Procedure Create an encoded secret string: Create a file named, for example, secret.txt . In the secret.txt file, enter the secret string in plain text. For example: To encode the string, enter the following command: The preceding command displays the encoded string. For example: Create a secret.yaml file that defines an object of kind Secret . For example: In the preceding example, jws-secret is the name of the secret and cXdlcnR5Cg== is the encoded secret string. To create the secret, enter the following command: The preceding command displays a message to confirm that the secret is created. For example: Verification Get the URL for the webhook: The preceding command generates the webhook URL in the following format: Create a minimal JSON file named, for example, payload.json : To send a request to the webhook, enter the following curl command: In the preceding example, payload.json is the name of the minimal JSON file you have created. Replace <host> , <port> , <namespace> , and <name> in the URL string with values that are appropriate for your environment. Replace <secret> with the name of the secret you have created for the webhook. The preceding command generates the following type of webhook response in JSON format: Additional resources Webhook Triggers JWS Operator CRD parameters
qwerty base64 secret.txt cXdlcnR5Cg== kind: Secret apiVersion: v1 metadata: name: jws-secret data: WebHookSecretKey: cXdlcnR5Cg== create -f secret.yaml secret/jws-secret created describe BuildConfig | grep webhooks https:// <host>:<port> /apis/build.openshift.io/v1/namespaces/ <namespace> /buildconfigs/ <name> /webhooks/ <secret> /generic {} curl -H "X-GitHub-Event: push" -H "Content-Type: application/json" -k -X POST --data-binary @payload.json https:// <host>:<port> /apis/build.openshift.io/v1/namespaces/ <namespace> /buildconfigs/ <name> /webhooks/ <secret> /generic {"kind":"Build","apiVersion":"build.openshift.io/v1","metadata":{"name":"test-2","namespace":"jfc","selfLink":"/apis/build.openshift.io/v1/namespaces/jfc/buildconfigs/test-2/instantiate","uid":"a72dd529-edc6-4e1c-898e-7c0dbbea176e","resourceVersion":"846159","creationTimestamp":"2020-10-30T12:29:30Z","labels":{"application":"test","buildconfig":"test","openshift.io/build-config.name":"test","openshift.io/build.start-policy":"Serial"},"annotations":{"openshift.io/build-config.name":"test","openshift.io/build.number":"2"},"ownerReferences":[{"apiVersion":"build.openshift.io/v1","kind":"BuildConfig","name":"test","uid":"1f78fa3f-2f3b-421b-9f49-192184cc2280","controller":true}],"managedFields":[{"manager":"openshift-apiserver","operation":"Update","apiVersion":"build.openshift.io/v1","time":"2020-10-30T12:29:30Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:openshift.io/build-config.name":{},"f:openshift.io/build.number":{}},"f:labels":{".":{},"f:application":{},"f:buildconfig":{},"f:openshift.io/build-config.name":{},"f:openshift.io/build.start-policy":{}},"f:ownerReferences":{".":{},"k:{\"uid\":\"1f78fa3f-2f3b-421b-9f49-192184cc2280\"}":{".":{},"f:apiVersion":{},"f:controller":{},"f:kind":{},"f:name":{},"f:uid":{}}}},"f:spec":{"f:output":{"f:to":{".":{},"f:kind":{},"f:name":{}}},"f:serviceAccount":{},"f:source":{"f:contextDir":{},"f:git":{".":{},"f:ref":{},"f:uri":{}},"f:type":{}},"f:strategy":{"f:sourceStrategy":{".":{},"f:env":{},"f:forcePull":{},"f:from":{".":{},"f:kind":{},"f:name":{}},"f:pullSecret":{".":{},"f:name":{}}},"f:type":{}},"f:triggeredBy":{}},"f:status":{"f:conditions":{".":{},"k:{\"type\":\"New\"}":{".":{},"f:lastTransitionTime":{},"f:lastUpdateTime":{},"f:status":{},"f:type":{}}},"f:config":{".":{},"f:kind":{},"f:name":{},"f:namespace":{}},"f:phase":{}}}}]},"spec":{"serviceAccount":"builder","source":{"type":"Git","git":{"uri":"https://github.com/jfclere/demo-webapp.git","ref":"master"},"contextDir":"/"},"strategy":{"type":"Source","sourceStrategy":{"from":{"kind":"DockerImage","name":"image-registry.openshift-image-registry.svc:5000/jfc/jboss-webserver54-tomcat9-openshift@sha256:75dcdf81011e113b8c8d0a40af32dc705851243baa13b68352706154174319e7"},"pullSecret":{"name":"builder-dockercfg-rvbh8"},"env":[{"name":"MAVEN_MIRROR_URL"},{"name":"ARTIFACT_DIR"}],"forcePull":true}},"output":{"to":{"kind":"ImageStreamTag","name":"test:latest"}},"resources":{},"postCommit":{},"nodeSelector":null,"triggeredBy":[{"message":"Generic WebHook","genericWebHook":{"secret":"\u003csecret\u003e"}}]},"status":{"phase":"New","config":{"kind":"BuildConfig","namespace":"jfc","name":"test"},"output":{},"conditions":[{"type":"New","status":"True","lastUpdateTime":"2020-10-30T12:29:30Z","lastTransitionTime":"2020-10-30T12:29:30Z"}]}} { "kind": "Status", "apiVersion": "v1", "metadata": { }, "status": "Success", "message": "no git information found in payload, ignoring and continuing with build", "code": 200 }