2022-01-11 09:36:39 +00:00
## Generic Webhook
External Secrets Operator can integrate with simple web apis by specifying the endpoint
### Example
2024-11-13 17:36:33 +00:00
First, create a SecretStore with a webhook backend. We'll use a static user/password `test` :
2022-01-11 09:36:39 +00:00
```yaml
2022-01-14 21:45:04 +00:00
{% raw %}
2022-03-09 17:02:32 +00:00
apiVersion: external-secrets.io/v1beta1
2022-01-11 09:36:39 +00:00
kind: SecretStore
metadata:
name: webhook-backend
spec:
provider:
webhook:
url: "http://httpbin.org/get?parameter={{ .remoteRef.key }}"
result:
jsonPath: "$.args.parameter"
headers:
Content-Type: application/json
Authorization: Basic {{ print .auth.username ":" .auth.password | b64enc }}
secrets:
- name: auth
secretRef:
name: webhook-credentials
2022-01-14 21:45:04 +00:00
{%- endraw %}
2022-01-11 09:36:39 +00:00
---
apiVersion: v1
kind: Secret
metadata:
name: webhook-credentials
data:
username: dGVzdA== # "test"
password: dGVzdA== # "test"
```
NB: This is obviously not practical because it just returns the key as the result, but it shows how it works
2022-02-03 11:39:46 +00:00
**NOTE:** In case of a `ClusterSecretStore` , Be sure to provide `namespace` in all `secrets` references with the namespaces where the secrets reside.
2022-01-11 09:36:39 +00:00
Now create an ExternalSecret that uses the above SecretStore:
```yaml
2022-03-09 17:02:32 +00:00
apiVersion: external-secrets.io/v1beta1
2022-01-11 09:36:39 +00:00
kind: ExternalSecret
metadata:
name: webhook-example
spec:
refreshInterval: "15s"
secretStoreRef:
name: webhook-backend
kind: SecretStore
target:
name: example-sync
data:
- secretKey: foobar
remoteRef:
key: secret
---
# will create a secret with:
kind: Secret
metadata:
name: example-sync
data:
foobar: c2VjcmV0
```
#### Limitations
Webhook does not support authorization, other than what can be sent by generating http headers
2023-02-27 22:14:53 +00:00
!!! note
If a webhook endpoint for a given `ExternalSecret` returns a 404 status code, the secret is considered to have been deleted. This will trigger the `deletionPolicy` set on the `ExternalSecret` .
2022-01-11 09:36:39 +00:00
### Templating
Generic WebHook provider uses the templating engine to generate the API call. It can be used in the url, headers, body and result.jsonPath fields.
The provider inserts the secret to be retrieved in the object named `remoteRef` .
In addition, secrets can be added as named objects, for example to use in authorization headers.
Each secret has a `name` property which determines the name of the object in the templating engine.
### All Parameters
```yaml
2022-03-09 17:02:32 +00:00
apiVersion: external-secrets.io/v1beta1
2022-01-11 09:36:39 +00:00
kind: ClusterSecretStore
metadata:
name: statervault
spec:
provider:
webhook:
# Url to call. Use templating engine to fill in the request parameters
url: < url >
# http method, defaults to GET
method: < method >
# Timeout in duration (1s, 1m, etc)
timeout: 1s
result:
# [jsonPath ](https://jsonpath.com ) syntax, which also can be templated
jsonPath: < jsonPath >
# Map of headers, can be templated
headers:
< Header-Name > : < header contents >
# Body to sent as request, can be templated (optional)
body: < body >
# List of secrets to expose to the templating engine
secrets:
# Use this name to refer to this secret in templating, above
- name: < name >
secretRef:
2022-02-03 11:39:46 +00:00
namespace: < namespace > # Only used in ClusterSecretStores
2022-01-11 09:36:39 +00:00
name: < name >
# Add CAs here for the TLS handshake
caBundle: < base64 encoded cabundle >
caProvider:
2024-04-19 11:39:14 +00:00
type: Secret or ConfigMap
2022-01-11 09:36:39 +00:00
name: < name of secret or configmap >
2022-02-03 11:39:46 +00:00
namespace: < namespace > # Only used in ClusterSecretStores
2022-01-11 09:36:39 +00:00
key: < key inside secret >
```
2024-02-17 09:49:31 +00:00
### Webhook as generators
2024-11-13 17:36:33 +00:00
You can also leverage webhooks as generators, following the same syntax. The only difference is that the webhook generator needs its source secrets to be labeled, as opposed to webhook secretstores. Please see the [generator-webhook ](../api/generator/webhook.md ) documentation for more information.