|
| 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. |
0 commit comments