Overview
The Reloader listens to Azure Event Grid events to determine when to trigger secret rotations. The overall process is as follows:- Secrets Stored in Azure Key Vault: Your secrets are stored and managed in Azure Key Vault.
- Event Grid Configuration: Azure Event Grid is configured to publish events related to secret changes to a webhook endpoint.
- Reloader Listener: The Reloader includes a webhook listener that receives events from Event Grid and annotates the corresponding Kubernetes ExternalSecrets to trigger reconciliation and synchronization of the secret values.
Prerequisites
- An Azure account with permissions to manage Key Vault, Event Grid, and create subscriptions.
- Kubernetes cluster with External Secrets Operator and Reloader installed.
- Access to create Kubernetes Services and Ingress resources.
- Domain name and TLS certificates if using HTTPS (required by Azure Event Grid).
Step 1: Configure Azure Key Vault
Ensure you have an Azure Key Vault set up with the secrets you wish to manage.- Sign in to the Azure Portal.
- Navigate to Key Vaults and select your Key Vault or create a new one.
- Add or update secrets as needed.
Step 2: Configure Reloader
Update your Reloader configuration to set up the Event Grid listener.Event Grid Listener Configuration
The Reloader needs to run a webhook listener to receive events from Azure Event Grid. The configuration for the listener is specified using theAzureEventGrid notification source type.
Configuration Spec
host: The host interface to bind the listener to. Use0.0.0.0to listen on all interfaces.port: The port on which the listener will accept connections.subscriptions: A list of subscription names. For each subscription, the listener will create a unique path to listen to events specific to that subscription.
Example Configuration
- The listener will accept events at
http://<host>:8080/my-event-subscription. - You can specify multiple subscriptions if needed.
Step 3: Expose the Webhook Listener
To allow Azure Event Grid to send events to the webhook listener, you need to expose it outside the Kubernetes cluster.Create a Kubernetes Service
Create a Service to expose the Reloader webhook listener.Configure Ingress
Use an Ingress resource to expose the service externally over HTTPS.Example Ingress Configuration
- Replace
your.domain.comwith your actual domain. - Ensure that
cert-manageris installed and configured to obtain TLS certificates. - Update annotations based on your Ingress controller and TLS setup.
DNS Configuration
- Create a DNS
Arecord pointingyour.domain.comto the external IP address of your Ingress controller.
Ensure HTTPS Access
- Verify that
https://your.domain.com/my-event-subscriptionis accessible externally. - Use tools like
curlor a web browser to test the endpoint.
Step 4: Configure Azure Event Grid Subscription
Set up Azure Event Grid to send events when secrets in Key Vault are updated.Create an Event Grid Subscription
- Navigate to your Key Vault in the Azure Portal.
- Under Events, click on + Event Subscription.
- Fill in the Name for your subscription (e.g.,
my-event-subscription). - In Event Schema, select Event Grid Schema.
- Under Event Types, select the events you want to subscribe to:
- Microsoft.KeyVault.SecretNewVersionCreated
- Microsoft.KeyVault.SecretNearExpiry (optional)
- In Endpoint Type, select Web Hook.
- For the Endpoint URL, enter
https://your.domain.com/my-event-subscription. - Optionally, configure additional settings such as filters.
- Click Create to save the subscription.
Azure Event Grid will perform a validation handshake by sending a validation event to the webhook endpoint. The Reloader listener must be running and accessible at the specified URL for validation to succeed.
Validation Handshake
- The Reloader’s webhook listener handles the validation automatically.
- If validation fails, ensure:
- The listener is running.
- The Ingress and Service are correctly configured.
- The TLS certificate is valid and trusted.
- There are no firewall or network policies blocking traffic.
Step 5: Deploy the Reloader
Apply the Reloader configuration to your Kubernetes cluster:- Replace
reloader-azure-sample.yaml,reloader-webhook-service.yaml, andreloader-azure-webhook-ingress.yamlwith the filenames of your configuration files.
Processing Event Grid Events
When a secret is updated in Azure Key Vault, an event is sent to the webhook listener via Event Grid. The Reloader processes the events and annotates the corresponding Kubernetes ExternalSecrets to trigger a reconciliation.Azure Event Grid Event Schema
eventType and data.Id fields in the event payload to identify which secret has changed.
Additional Configuration Options
-
Multiple Subscriptions: You can specify multiple subscriptions in the
subscriptionslist. Each subscription will have a unique path. -
Host and Port: Adjust the
hostandportas needed based on your deployment environment. - Ingress Annotations: Depending on your Ingress controller (e.g., NGINX, Traefik), you may need to add specific annotations to enable features like TLS termination or client IP preservation.
Enabling External Traffic
To ensure the webhook listener is accessible:- Network Policies: If using network policies, allow inbound traffic to the webhook listener.
- Firewall Rules: Configure firewalls or security groups to allow traffic from Azure Event Grid to your cluster.
- Ingress Controller: Make sure your Ingress controller is properly set up to handle external traffic.
Using Ingress Controllers
Ingress controllers manage external access to services in a Kubernetes cluster.- Install an Ingress Controller: Choose an Ingress controller compatible with your environment.
-
Configure TLS: Use
cert-managerto automatically obtain and renew TLS certificates from Let’s Encrypt. - Update DNS Records: Point your domain to the Ingress controller’s external IP.
Summary
By configuring Azure Event Grid to send events to a webhook listener and setting up the Reloader to listen to those events, you enable automatic synchronization of secret updates from Azure Key Vault to your Kubernetes cluster.Additional Resources
- Azure Key Vault Documentation
- Azure Event Grid Documentation
- Azure Event Grid Webhook Delivery
- Kubernetes Services Documentation
- Kubernetes Ingress Documentation
- Cert-Manager Documentation
- External Secrets Operator Documentation
Troubleshooting
Event Grid Subscription Validation Fails
- Check Listener Accessibility: Ensure the webhook endpoint is accessible over HTTPS from the internet.
- Verify TLS Certificate: The TLS certificate must be valid and signed by a trusted Certificate Authority.
- Inspect Logs: Check the Reloader pod logs for any errors during validation.
Events Not Being Processed
- Verify Event Subscription: Ensure the Event Grid subscription is active and events are being sent.
- Confirm Secret IDs: The
data.Idin the event must match the secret IDs in your Kubernetes ExternalSecrets. - Review Network Policies: Ensure network policies are not blocking incoming events.