Overview
The ArgoCD Vault Plugin is a custom extension for ArgoCD that securely retrieves secrets from external vaults and dynamically injects them into Kubernetes configurations. In our example, HashiCorp Vault is used to store secrets securely. The plugin then retrieves these secrets and replaces placeholders in the Kubernetes manifest with the actual secret values. HashiCorp Vault controls access to sensitive data in public or hybrid environments using secret engines. In this guide, the key-value secrets engine is enabled to store and retrieve plain text secrets. Here, thekvput command writes a secret—specifically the MYSQL-PASSWORD—to a defined path in Vault.
In Vault, sensitive values stored in plain text are referenced in Kubernetes manifests using the
stringData field rather than data. The stringData field accepts plain text without requiring Base64 encoding.Example Walkthrough
Below is a comprehensive example that illustrates the necessary commands and configuration details.Step 1: Enable the Key-Value Secrets Engine
Enable the key-value secrets engine (version 2) at a specified path:Step 2: Write a Secret to Vault
Write the secretMYSQL-PASSWORD to Vault under the path crds/mysql:
Step 3: Prepare the Kubernetes Secret Manifest Template
Review the Kubernetes secret manifest template, which includes an annotation that maps the Vault secret path to the placeholder in the manifest:Step 4: Download and Install the ArgoCD Vault Plugin
Download the ArgoCD Vault Plugin binary, set the appropriate execute permissions, and move it to the local binary directory:Step 5: Configure Vault Authentication
Create a file namedvault.env that contains the Vault configuration details. This file includes the Vault address, authentication token, and plugin-specific configuration:
Step 6: Generate the Final Kubernetes Manifest
Generate the final Kubernetes manifest with the Vault secret injected by running thegenerate command. The plugin connects to Vault using the provided configuration, retrieves the secret, and replaces the <MYSQL-PASSWORD> placeholder in the manifest:
The annotation
avp.kubernetes.io/path: "crds/data/mysql" in the manifest instructs the plugin to retrieve the secret key MYSQL-PASSWORD from the specified Vault path. Ensure your Vault configuration and paths match this specification.How It Works
- Vault Secret Storage: The key-value secrets engine in HashiCorp Vault stores the credentials.
- Plugin Authentication: The ArgoCD Vault Plugin uses the configuration provided in
vault.envto connect and authenticate with Vault. - Manifest Rendering: The plugin reads the secret from Vault and replaces the placeholder
<MYSQL-PASSWORD>in the Kubernetes manifest template. - Deployment Integration: The final manifest, with secrets properly injected, is ready for deployment on Kubernetes.