helm-secrets

repository·main·Indexed 24 days ago

https://github.com/jkroepke/helm-secrets

A Helm plugin for decrypting encrypted Helm value files on the fly. It supports sops for Git-stored secrets and vals for referencing cloud-native secret managers like AWS SSM, Azure KeyVault, and HashiCorp Vault. Features include a protocol handler (secrets://) for ArgoCD integration, a plugin command wrapper, and the ability to evaluate secret references directly inside Helm templates using the --evaluate-templates flag.

Tokens
13K
Snippets
35
Records
72
Agent score
83%

What's inside helm-secrets

  1. Supported Secret Backends

    main

    The helm-secrets plugin supports multiple backends for managing and decrypting secrets. Currently, the supported backends are:

    • sops: For encrypting/decrypting value files (often used with Git).
    • vals: For evaluating expressions and referencing cloud-native secret managers (like AWS Secrets Manager or Azure KeyVault) inside Helm templates.
  2. Configure private key access in Argo CD

    main

    When using private key encryption (GPG or age), the argocd-repo-server must have access to the private keys to decrypt files.

    There are three primary patterns for providing keys:

    1. Mount via Kubernetes Secret Volume: Mount a K8s secret containing your .asc or .txt keys as a volume to the argocd-repo-server. Use the secrets+gpg-import:// or secrets+age-import:// schemes.
    2. Fetch via Kubernetes Secret directly: Use the secrets+gpg-import-kubernetes:// or secrets+age-import-kubernetes:// schemes to reference a secret in a specific namespace.
    3. Environment Variables: Use HELM_SECRETS_LOAD_GPG_KEYS (for GPG) or SOPS_AGE_KEY_FILE (for age) to point to the key file path.
  3. Decrypt secrets via downloader plugin

    main

    You can use helm-secrets as a Helm downloader plugin to decrypt value files directly via the -f flag using the secrets:// protocol. This allows you to reference local files or remote files (e.g., from Git) that need decryption before being processed by Helm.

    Supported URI formats include:

    • secrets://<uri to file>
    • secrets://git+<git-url>@<path>?ref=<branch/tag>
  4. Set up Cloud Integration with vals

    main

    To fetch secrets dynamically from cloud services (AWS, Azure, GCP, etc.), helm-secrets uses the vals backend.

    Prerequisites

    • helm-secrets version 3.9.x or higher (version 4.1+ is required for literal values).
    • The vals binary must be installed.

    Installation

    1. Download the vals binary from the official GitHub releases.
    2. Place the binary in your PATH (e.g., /usr/local/bin/).
    3. Alternatively, specify the path to the binary using the HELM_SECRETS_VALS_PATH environment variable.
  5. Use the helm secrets wrapper for on-the-fly decryption

    main

    The helm secrets command acts as a wrapper for standard Helm commands (e.g., install, upgrade, rollback, diff). When you use the wrapper, any files passed via the -f or --values flags that are encrypted will be decrypted on-the-fly before the Helm command executes.

    Key Behaviors:

    • Automatic Cleanup: Decrypted temporary files (suffixed with .dec by default) are automatically removed after the Helm command finishes, even if the command fails.
    • Optimization: If a decrypted file (e.g., secrets.yaml.dec) already exists and is newer than the encrypted secrets.yaml, the wrapper will use the existing .dec file instead of re-decrypting.
    • Compatibility: Works with helm-diff by calling helm secrets diff ....
    AWS_PROFILE=sandbox helm secrets upgrade \
      helloworld \
      stable/java-app \
      --install \
      --timeout 600 \
      --wait \
      --kube-context=sandbox \
      --namespace=projectx \
      -f helm_vars/projectx/sandbox/us-east-1/java-app/helloworld/secrets.yaml \
      -f helm_vars/projectx/sandbox/us-east-1/java-app/helloworld/values.yaml
  6. Decrypt secrets via plugin command

    main

    You can use the helm secrets command to wrap the entire helm execution. This method is useful for general usage but can be slower when dealing with multiple value files because it wraps the whole command.

    To use it, replace helm with helm secrets in your standard Helm commands.

    helm secrets upgrade name . -f secrets.yaml
  7. Method 3: Use environment variables for GPG or age keys

    main

    You can rely on existing environment variables or pre-seeded agents on the argocd-repo-server.

    • For GPG: Use HELM_SECRETS_LOAD_GPG_KEYS to provide the path to the GPG key, or ensure a GPG agent is running.
    • For age: Use SOPS_AGE_KEY_FILE to provide the path to the age key file.

    In your Application spec, you simply reference the encrypted file using the standard secrets:// prefix:

    valueFiles:
      - secrets://secrets.yaml
  8. Fetch remote values from Git

    main

    By using the helm-git plugin, helm-secrets can fetch secrets from Git repositories. Use the secrets://git+https:// prefix followed by the repository URL and optional parameters for path, reference, or sparse checkout.

    helm template -f secrets://git+https://<provider.com>/<path/to/repo>[@path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]]
  9. Integrate helm-secrets with Argo CD

    main

    You can use helm-secrets in Argo CD by utilizing the downloader plugin syntax within an Argo CD Application resource. This allows Argo CD to decrypt encrypted value files during the Helm template generation process.

    Important Constraints:

    • You can only encrypt value files. Encrypted manifests or templates are not supported.
    • It is recommended to use age encryption over gpg if possible.
    • In shared environments, ensure users cannot read files outside their own directory.

    Prerequisites:

    • Argo CD versions: 2.3.0+, 2.2.6+, or 2.1.11+ (Note: 2.1.9, 2.1.10, 2.2.4, and 2.2.5 are incompatible).
    • helm-secrets version 3.9.x or higher.
    • For age encryption: helm-secrets 3.10.0+ and sops 3.7.0+.
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    spec:
      source:
        helm:
          valueFiles:
            - secrets+gpg-import:///helm-secrets-private-keys/key.asc?secrets.yaml
          fileParameters:
            - name: config
              path: secrets://secrets.yaml
  10. Fetch remote values from HTTP

    main

    If curl or wget is available on your system, helm-secrets can fetch value files from remote HTTP/HTTPS locations using the secrets:// protocol prefix.

    helm template -f secrets://https://raw.githubusercontent.com/jkroepke/helm-secrets/main/examples/sops/secrets.yaml