Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service api calls with custom http headers #1478

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions content/en/docs/writing-policies/external-data-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,40 @@ To access images stored on private registries, see [using private registries](ve
For more examples of using an imageRegistry context, see the [samples page](../../policies).

The policy-level setting `failurePolicy` when set to `Ignore` additionally means that failing calls to image registries will be ignored. This allows for Pods to not be blocked if the registry is offline, useful in situations where images already exist on the nodes.

## Service API Calls with Custom HTTP Headers

Kyverno now supports including custom HTTP headers when making API calls to external services. This enhancement allows users to add extra metadata such as authentication tokens, user agents, or any other header information that may be required by the external service.

## Feature Overview

Prior to this update, API calls made by Kyverno policies did not allow the inclusion of extra HTTP headers. With this feature, you can now specify a `headers` field under the `service` configuration in an API call, making your external requests more flexible and secure.

## Example Policy Configuration

``` yaml
context:
- name: result
apiCall:
method: POST
data:
- key: foo
value: bar
- key: namespace
value: "{{ `{{ request.namespace }}` }}"
service:
url: http://my-service.svc.cluster.local/validation
headers:
- key: "UserAgent"
value: "Kyverno Policy XYZ"
- key: "Authorization"
value: "Bearer {{ MY_SECRET }}"
```

## Explanation

- **service.url**: Specifies the endpoint of the external service.
- **service.headers**: A new field that accepts an array of key-value pairs. Each pair represents a custom HTTP header to include in the API request.
- **UserAgent**: Can be used to identify the client or policy making the call.
- **Authorization**: Typically used to pass authentication tokens or credentials.
- **Variable Substitution**: You can dynamically include values (e.g., `{{ MY_SECRET }}`) in your headers using Kyverno's variable substitution mechanism.