Overview
The Reloader listens to AWS SQS messages to determine when to trigger secret rotations. The overall process is as follows:- Secrets Stored in AWS Secrets Manager: Your secrets are stored and managed in AWS Secrets Manager.
- EventBridge Configuration: AWS EventBridge is configured to publish events related to secret changes to an SQS queue.
- Reloader Listener: The Reloader listens to the SQS queue for events and annotates the corresponding Kubernetes ExternalSecrets to trigger reconciliation and synchronization of the secret values.
Prerequisites
- An AWS account with permissions to manage Secrets Manager, SQS, and EventBridge.
- Kubernetes cluster with Reloader installed.
- AWS IAM roles and permissions set up for authentication (either via credentials or IRSA).
- If you’re targetting an
ExternalSecretdestination, external-secrets operator needs to be installed
The following terraform code
contains a recipe for everything needed within AWS using service account keys.
If you plan to use static authentication credentials (access key ID and secret access key), we recommend using a local
kind cluster for a quick onboarding experience. If you intend to use service accounts with IRSA enabled, you’ll need an EKS cluster with an associated OIDC provider.Step 1: Configure AWS SQS Queue
Create an AWS SQS queue that will receive events from AWS Secrets Manager via EventBridge.Create an SQS Queue
- Sign in to the AWS Management Console and navigate to SQS.
- Click on Create queue.
- Choose the queue type (Standard or FIFO) based on your requirements.
- Configure the queue settings as needed.
- Note down the Queue URL; you will need it later.
Step 2: Configure AWS EventBridge Rule
Set up an EventBridge rule to forward events from AWS Secrets Manager to your SQS queue.Create an EventBridge Rule
- Navigate to EventBridge in the AWS Management Console.
- Click on Rules in the sidebar, then Create rule.
- Enter a Name and Description for your rule.
- Under Define pattern, select Event pattern.
- Choose AWS events or EventBridge partner events.
- In Event source, select AWS services.
- In AWS service, select Secrets Manager.
- In Event type, select AWS API Call via CloudTrail.
Specify Event Pattern
Under Event pattern, specify the events you want to capture.Configure Target
- Under Select targets, choose SQS queue.
- Select the SQS queue you created earlier.
- Configure any additional settings as needed.
- Click Create to save the rule.
Step 3: Configure Reloader
Update your Reloader configuration to connect to the SQS queue.Authentication
The Reloader needs to authenticate with AWS to access the SQS queue. You can use either AWS credentials stored in Kubernetes Secrets or a Kubernetes ServiceAccount configured with IRSA.1. Using AWS Credentials from a Kubernetes Secret
authMethod:credentialssecretRef: References to Kubernetes Secrets containing AWS credentials:accessKeyIDSecretRef: Reference to the AWS Access Key ID.secretAccessKeySecretRef: Reference to the AWS Secret Access Key.sessionTokenSecretRef: (Optional) Reference to the AWS session token for temporary credentials.
Example
2. Using a Kubernetes ServiceAccount
If the listener is configured with theserviceAccount auth method, then IAM Roles for Service Accounts (IRSA) needs to be set up. IRSA allows you to associate an AWS IAM role with a Kubernetes ServiceAccount, enabling the pod to access AWS resources securely using OpenID Connect (OIDC).
Brief Overview of IRSA and OIDC
- IRSA: Integrates Kubernetes ServiceAccounts with AWS IAM roles. This allows pods running in Kubernetes to assume IAM roles and access AWS resources without managing AWS credentials manually.
- OIDC: An identity layer on top of the OAuth 2.0 protocol, used by IRSA to authenticate Kubernetes ServiceAccounts with AWS IAM.
Example Configuration
Step 4: Update IAM Permissions
Ensure that the IAM role associated with your authentication method has the necessary permissions to:- Receive messages from the SQS queue.
Step 5: Deploy the Reloader
Apply the Reloader configuration to your Kubernetes cluster:Processing SQS Messages
When a secret is updated in AWS Secrets Manager, an event is sent to the SQS queue via EventBridge. The Reloader listens to the queue, processes the messages, and annotates the corresponding Kubernetes ExternalSecrets to trigger a reconciliation.Default AWS SQS Message Schema
eventName and requestParameters.secretId fields in the message payload to identify which secret has changed.
Additional Configuration Options
maxNumberOfMessages: (Optional) The maximum number of messages to retrieve from the SQS queue in a single request. Adjust based on your application’s throughput requirements.waitTimeSeconds: (Optional) The duration (in seconds) to wait for messages if the queue is empty. Increasing this value can reduce the number of empty responses when polling.visibilityTimeout: (Optional) The duration (in seconds) that a received message is hidden from other consumers. Set this value based on how long it takes to process a message.