Skip to content

Commit 18767ed

Browse files
authored
docs(webhook): add documentation for webhook feature (#1207)
Signed-off-by: Christopher Coco <[email protected]>
1 parent 7ef756e commit 18767ed

File tree

5 files changed

+428
-4
lines changed

5 files changed

+428
-4
lines changed

cmd/webhook.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"syscall"
1212
"text/template"
13-
"time"
1413

1514
"github.com/argoproj-labs/argocd-image-updater/pkg/argocd"
1615
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
@@ -169,8 +168,6 @@ Supported registries:
169168
webhookCmd.Flags().BoolVar(&cfg.ClientOpts.Insecure, "argocd-insecure", env.GetBoolVal("ARGOCD_INSECURE", false), "(INSECURE) ignore invalid TLS certs for ArgoCD server")
170169
webhookCmd.Flags().BoolVar(&cfg.ClientOpts.Plaintext, "argocd-plaintext", env.GetBoolVal("ARGOCD_PLAINTEXT", false), "(INSECURE) connect without TLS to ArgoCD server")
171170
webhookCmd.Flags().StringVar(&cfg.ClientOpts.AuthToken, "argocd-auth-token", "", "use token for authenticating to ArgoCD (unsafe - consider setting ARGOCD_TOKEN env var instead)")
172-
webhookCmd.Flags().BoolVar(&cfg.DryRun, "dry-run", false, "run in dry-run mode. If set to true, do not perform any changes")
173-
webhookCmd.Flags().DurationVar(&cfg.CheckInterval, "interval", env.GetDurationVal("IMAGE_UPDATER_INTERVAL", 2*time.Minute), "interval for how often to check for updates")
174171
webhookCmd.Flags().StringVar(&cfg.LogLevel, "loglevel", env.GetStringVal("IMAGE_UPDATER_LOGLEVEL", "info"), "set the loglevel to one of trace|debug|info|warn|error")
175172
webhookCmd.Flags().StringVar(&kubeConfig, "kubeconfig", "", "full path to kubernetes client configuration, i.e. ~/.kube/config")
176173
webhookCmd.Flags().StringVar(&cfg.RegistriesConf, "registries-conf-path", defaultRegistriesConfPath, "path to registries configuration file")

docs/configuration/webhook.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Webhook Configuration
2+
3+
Image Updater can be configured to respond to webhook notifications from
4+
various container registries.
5+
6+
Currently Supported Registries:
7+
8+
- Docker Hub
9+
- GitHub Container Registry
10+
- Harbor
11+
- Quay
12+
13+
Using webhooks can help reduce some of the stress that is put on the
14+
container registries and where you are running Image Updater by reducing the
15+
need to poll.
16+
17+
## Enabling the Webhook Server
18+
19+
There are two ways to enable the webhook server. You can either use it with
20+
polling still enabled through the `run` command or just have the webhook
21+
server running through the webhook command.
22+
23+
### Enabling with `run` Command
24+
Below is the command for running the webhook server with polling through the `
25+
run` command. The `--enable-webhook` flag is all that is required. The
26+
default port of the webhook server in this method is `8082`.
27+
```
28+
argocd-image-updater run --enable-webhook --webhook-port [PORT]
29+
```
30+
31+
### Enabling with `webhook` Command
32+
You can also run the webhook server without polling. See below for the
33+
command for this. The default port for this method is `8080`.
34+
```
35+
argocd-image-updater webhook --webhook-port [PORT]
36+
```
37+
38+
### Altering Manifests to Use Webhook
39+
If you are running Image Updater within your cluster, to enable the webhook
40+
you will need to alter the manifests of the application. What you need to
41+
edit depends on what command you plan to use.
42+
43+
If you want to use the webhook with polling through the `run` command you
44+
need to edit the `argocd-image-updater-config` ConfigMap with the following data:
45+
```yaml
46+
data:
47+
# enable the webhook server
48+
webhook.enable: true
49+
# (OPTIONAL) set the port for the webhook server
50+
webhook.port: <Value between 0 - 65535>
51+
```
52+
53+
If you plan to use the webhook command for the server then the `argocd-image-
54+
updater` Deployment must be updated. Adjustments to the `argocd-image-updater-config`
55+
ConfigMap are optional.
56+
```yaml
57+
# argocd-image-updater Deployment, container args need to be changed to webhook
58+
spec:
59+
template:
60+
spec:
61+
containers:
62+
- args:
63+
- webhook
64+
---
65+
# (OPTIONAL) argocd-image-updater-config ConfigMap, edit to change the webhook server port
66+
data:
67+
webhook.port: <Value between 0 - 65535>
68+
```
69+
70+
## Endpoints
71+
The webhook server contains two endpoints, `webhook` and `healthz`.
72+
73+
The `webhook` endpoint is used to receive and process webhook notifications.
74+
75+
The `healthz` endpoint acts has a health endpoint to check to see if the server is alive.
76+
77+
## Setting Up a Webhook Notification
78+
79+
To set up a webhook notification, refer to your container registries
80+
documentation on how to do that. Documentation for the supported registries
81+
can be found here:
82+
83+
- [Docker Hub](https://docs.docker.com/docker-hub/repos/manage/webhooks/)
84+
- [GitHub Container Registry](https://docs.github.com/en/webhooks/webhook-events-and-payloads)
85+
- [Harbor](https://goharbor.io/docs/1.10/working-with-projects/project-configuration/configure-webhooks/)
86+
- [Quay](https://docs.quay.io/guides/notifications.html)
87+
88+
For the URL that you set for the webhook, your link should go as the following:
89+
```
90+
https://app1.example.com/webhook?type=<YOUR_REGISTRY_TYPE>
91+
# Value of `type` for each supported container registry
92+
# Docker = docker.io
93+
# GitHub Container Registry = ghcr.io
94+
# Harbor = harbor
95+
# Quay = quay.io
96+
```
97+
98+
## Secrets
99+
100+
To help secure the webhook server you can apply a secret that is used to
101+
validate the incoming notification. The secrets can be set by editing the
102+
`argocd-image-updater-secret` secret.
103+
104+
```yaml
105+
stringData:
106+
webhook.docker-secret: <YOUR_SECRET>
107+
webhook.ghcr-secret: <YOUR_SECRET>
108+
webhook.harbor-secret: <YOUR_SECRET>
109+
webhook.quay-secret: <YOUR_SECRET>
110+
```
111+
112+
You also need to configure the webhook notification to use the secret based
113+
on the methods below. See below for the two ways and which of the supported registries use that.
114+
115+
### Registries With Preexisting Support For Secrets
116+
117+
There are container registries that have built in secrets support. How you
118+
apply the secret will vary depending on the registry so follow the
119+
instructions linked in the documentation for that registry.
120+
121+
Supported Registries That Use This:
122+
123+
- GitHub Container Registry
124+
- Harbor
125+
126+
### Parameter Secrets
127+
128+
Because some container registries do not support secrets, there is a method
129+
included to have secrets for registries. This is through the query parameters
130+
in the URL of the webhook. This is not the most secure method and is there
131+
for a small extra layer.
132+
133+
!!!warning
134+
This is not the most secure method, it is just here for a small extra layer.
135+
**Do not use a secret that is shared with other critical services for this method!**
136+
137+
It can be applied to the URL as below:
138+
```
139+
https://app1.example.com/webhook?type=<YOUR_REGISTRY_TYPE>&secret=<YOUR_SECRET>
140+
```
141+
142+
Supported Registries That Use This:
143+
144+
- Docker Hub
145+
- Quay
146+
147+
Also be aware that if the container registry has a built-in secrets method you will
148+
not be able to use this method.
149+
150+
## Exposing the Server
151+
152+
To expose the webhook server we have provided a service and ingress to get
153+
started. These manifests are not applied with `install.yaml` so you will need
154+
to apply them yourself.
155+
156+
They are located in the `manifets/base/networking` directory.
157+
158+
## Environment Variables
159+
160+
The flags for both the `run` and `webhook` CLI commands can also be set via
161+
environment variables. Below is the list of which variables correspond to which flag.
162+
163+
|Environment Variable|Corresponding Flag|
164+
|--------|--------|
165+
|`ENABLE_WEBHOOK`|`--enable-webhook`|
166+
|`WEBHOOK_PORT`|`--webhook-port`|
167+
|`DOCKER_WEBHOOK_SECRET` |`--docker-webhook-secret`|
168+
|`GHCR_WEBHOOK_SECRET` |`--gchr-webhook-secret`|
169+
|`HARBOR_WEBHOOK_SECRET` |`--harbor-webhook-secret`|
170+
|`QUAY_WEBHOOK_SECRET` |`--quay-webhook-secret`|
171+
172+
## Adding Support For Other Registries
173+
174+
If the container registry that you use is not supported yet, feel free to
175+
implement a handler for it. You can find examples on how the other handlers
176+
are implemented in the `pkg/webhook` directory. If you intend to open a PR for
177+
your handler to be added please update this documentation page to include the
178+
information about yours with the others.
179+
180+
## Example Payloads
181+
182+
Below is a list of links for finding example payloads for each of the container
183+
registries supported.
184+
185+
- [Docker Hub](https://docs.docker.com/docker-hub/repos/manage/webhooks/#example-webhook-payload)
186+
- [GitHub Container Registry](https://docs.github.com/en/webhooks/webhook-events-and-payloads#example-webhook-delivery)
187+
- [Harbor](https://goharbor.io/docs/1.10/working-with-projects/project-configuration/configure-webhooks/)
188+
(View JSON Payload Format Section)
189+
- [Quay](https://docs.quay.io/guides/notifications.html)
190+
(View Repository Push Section)
191+
192+
## Troubleshooting
193+
194+
This section will cover some potential errors that may arise when sending
195+
notifications to the webhook server. Errors are propagated through the response body.
196+
197+
**Failed to process webhook/webhook event: <SOME_ERROR>**
198+
199+
If you are consistently seeing this error then there may be something wrong
200+
with the handler for that registry or there could be a problem with something
201+
else. If this continuously occurs please open an issue with the error information.
202+
203+
**no handler available for this webhook**
204+
205+
Make sure you included the `type` query parameter for the type of webhook
206+
handler and ensure that it is correct.
207+
208+
**Missing/incorrect webhook secret**
209+
210+
If you are seeing this message make sure that you have secrets configured
211+
properly in your container registry whether it is through their service
212+
or the query parameters.

docs/install/cmd/run.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ for images can only be specified from an environment variable.
8383
If this flag is set, Argo CD Image Updater won't actually perform any changes
8484
to workloads it found in need for upgrade.
8585

86+
**--docker-webhook-secret *secret***
87+
88+
Secret for validating Docker Hub webhooks.
89+
90+
**--enable-webhook *enabled***
91+
92+
Enable webhook server for receiving registry events.
93+
94+
**--ghcr-webhook-secret *secret***
95+
96+
Secret for validating GitHub container registry webhooks.
97+
8698
**--git-commit-email *email***
8799

88100
E-Mail address to use for Git commits (default "[email protected]")
@@ -115,6 +127,10 @@ Username to use for Git commits (default "argocd-image-updater")
115127

116128
Can also be set using the *GIT_COMMIT_USER* environment variable.
117129

130+
**--harbor-webhook-secret *secret***
131+
132+
Secret for validating Harbor webhooks
133+
118134
**--health-port *port***
119135

120136
Specifies the local port to bind the health server to. The health server is
@@ -190,6 +206,10 @@ port to start the metrics server on, 0 to disable (default 8081)
190206
A shortcut for specifying `--interval 0 --health-port 0`. If given,
191207
Argo CD Image Updater will exit after the first update cycle.
192208

209+
**--quay-webhook-secret *secret***
210+
211+
Secret for validating Quay webhooks.
212+
193213
**--registries-conf-path *path***
194214

195215
Load the registry configuration from file at *path*. Defaults to the path
@@ -201,4 +221,8 @@ default configuration should be used instead, specify the empty string, i.e.
201221

202222
whether to perform a cache warm-up on startup (default true)
203223

204-
[label selector syntax]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
224+
**--webhook-port *port***
225+
226+
Port to listen on for webhook events (default 8082)
227+
228+
[label selector syntax]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors

0 commit comments

Comments
 (0)