Skip to content

Commit 22aeed8

Browse files
authored
Merge pull request #1526 from srburton/add-identification-apikey
Add Apikey in generic webhook
2 parents 019ccf5 + 2734e7a commit 22aeed8

6 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎CONTRIBUTORS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Committing with `git commit -s` will add the sign-off at the end of the commit m
4343
- Felix Hörsting <felix.hoersting@iteratec.com>
4444
- Matthew Cascio <cascio@cybercapsicum.com>
4545
- Patryk Miłek <patrykmilek96@gmail.com>
46+
- Renato Burton <renatoburton96@gmail.com>

‎hooks/generic-webhook/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Kubernetes: `>=v1.11.0-0`
6060
| hook.authentication.basic.passwordKey | string | `"password"` | Name of the password key in the `userSecret` secret. Use this if you already have a secret with different key / value pairs |
6161
| hook.authentication.basic.userSecret | string | `"generic-webhook-credentials"` | Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs |
6262
| hook.authentication.basic.usernameKey | string | `"username"` | Name of the username key in the `userSecret` secret. Use this if you already have a secret with different key / value pairs |
63+
| hook.authentication.apikey.userSecret | string | `"generic-webhook-credentials"` | Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs |
64+
| hook.authentication.apikey.headerName | string | `"X-api-key"` | Customize header name as per your needs |
65+
| hook.authentication.apikey.headerValue | string | `"26ea529e517748baa6d87ebfe5781475"` | Use your API key |
6366
| hook.image.repository | string | `"docker.io/securecodebox/hook-generic-webhook"` | Hook image repository |
6467
| hook.image.tag | string | defaults to the charts version | The image Tag defaults to the charts version if not defined. |
6568
| hook.labels | object | `{}` | Add Kubernetes Labels to the hook definition |

‎hooks/generic-webhook/docs/README.ArtifactHub.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Kubernetes: `>=v1.11.0-0`
6868
| hook.authentication.basic.passwordKey | string | `"password"` | Name of the password key in the `userSecret` secret. Use this if you already have a secret with different key / value pairs |
6969
| hook.authentication.basic.userSecret | string | `"generic-webhook-credentials"` | Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs |
7070
| hook.authentication.basic.usernameKey | string | `"username"` | Name of the username key in the `userSecret` secret. Use this if you already have a secret with different key / value pairs |
71+
| hook.authentication.apikey.userSecret | string | `"generic-webhook-credentials"` | Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs |
72+
| hook.authentication.apikey.headerName | string | `"X-api-key"` | Customize header name as per your needs |
73+
| hook.authentication.apikey.headerValue | string | `"26ea529e517748baa6d87ebfe5781475"` | Use your API key |
7174
| hook.image.repository | string | `"docker.io/securecodebox/hook-generic-webhook"` | Hook image repository |
7275
| hook.image.tag | string | defaults to the charts version | The image Tag defaults to the charts version if not defined. |
7376
| hook.labels | object | `{}` | Add Kubernetes Labels to the hook definition |

‎hooks/generic-webhook/hook/hook.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ async function handle({
88
webhookUrl = process.env["WEBHOOK_URL"],
99
webhookUser = process.env["WEBHOOK_USER"],
1010
webhookPassword = process.env["WEBHOOK_PASSWORD"],
11+
webhookApikey = process.env["WEBHOOK_APIKEY"],
12+
webhookApikeySecret = process.env["WEBHOOK_APIKEY_SECRET"],
1113
axios = require('axios')
1214
}) {
1315
const findings = await getFindings();
1416

1517
console.log(`Sending ${findings.length} findings to ${webhookUrl}`);
1618

17-
if (webhookUser && webhookPassword){
19+
if (webhookApikey && webhookApikeySecret){
20+
await axios.post(webhookUrl, {scan, findings }, {headers: { [webhookApikey]: webhookApikeySecret}});
21+
}else if (webhookUser && webhookPassword){
1822
await axios.post(webhookUrl, {scan, findings }, {auth: {username: webhookUser, password: webhookPassword}});
1923
}else{
2024
await axios.post(webhookUrl, {scan, findings });

‎hooks/generic-webhook/templates/webhook-hook.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ spec:
3131
name: {{ .Values.hook.authentication.basic.userSecret }}
3232
key: {{ .Values.hook.authentication.basic.passwordKey }}
3333
optional: true
34+
- name: WEBHOOK_APIKEY
35+
valueFrom:
36+
secretKeyRef:
37+
name: {{ .Values.hook.authentication.apikey.userSecret }}
38+
key: {{ .Values.hook.authentication.apikey.headerName }}
39+
optional: true
40+
- name: WEBHOOK_APIKEY_SECRET
41+
valueFrom:
42+
secretKeyRef:
43+
name: {{ .Values.hook.authentication.apikey.userSecret }}
44+
key: {{ .Values.hook.authentication.apikey.headerValue }}
45+
optional: true
3446
affinity:
3547
{{- toYaml .Values.hook.affinity | nindent 4 }}
3648
tolerations:

‎hooks/generic-webhook/values.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ hook:
3535
# hook.tolerations -- Optional tolerations settings that control how the hook job is scheduled (see: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/)
3636
tolerations: []
3737

38-
# hook.authentication -- Optional basic authentication credentials
38+
# hook.authentication -- Optional basic authentication credentials or apikey
3939
authentication:
40+
apikey:
41+
# -- Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs
42+
userSecret: generic-webhook-credentials
43+
# -- Customize header name as per your needs ex: X-Api-Key
44+
headerName: X-Example-Header
45+
headerValue: example
4046
basic:
4147
# -- Link a pre-existing generic secret with `usernameKey` and `passwordKey` key / value pairs
4248
userSecret: generic-webhook-credentials

0 commit comments

Comments
 (0)