BossaBox

This is the playbook for engineering-playbook

Secret management with GitOps

GitOps projects have git repositories in the center that are considered a source of truth for managing both infrastructure and application. This infrastructure and application will require secured access to other resources of the system through secrets. Committing clear-text secrets into git repositories is unacceptable even if the repositories are private to your team and organization. Teams need a secure way to handle secrets when using GitOps.

There are many ways to manage secrets with GitOps and at high level can be categorized into:

  1. Encrypted secrets in git repositories
  2. Reference to secrets stored in the external key vault

TLDR: Referencing secrets in an external key vault is the recommended approach. It is easier to orchestrate secret rotation and more scalable with multiple clusters and/or teams.

Encrypted secrets in git repositories

In this approach, Developers manually encrypt secrets using a public key, and the key can only be decrypted by the custom Kubernetes controller running in the target cluster. Some popular tools for his approach are Bitnami Sealed Secrets, Mozilla SOPS

All the secret encryption tools share the following:

Bitnami Sealed Secrets

Sealed Secrets use asymmetric encryption to encrypt secrets. A Kubernetes controller generates a key-pair (private-public) and stores the private key in the cluster’s etcd database as a Kubernetes secret. Developers use Kubeseal CLI to seal secrets before committing to the git repo.

Some of the key points of using Sealed Secrets are:

Mozilla SOPS

SOPS: Secrets OPerationS is an encryption tool that supports YAML, JSON, ENV, INI, and BINARY formats and encrypts with AWS KMS, GCP KMS, Azure Key Vault, age, and PGP and is not just limited to Kubernetes. It supports integration with some common key management systems including Azure Key Vault, where one or more key management system is used to store the encryption key for encrypting secrets and not the actual secrets.

Some of the key points of using SOPS are:

This approach relies on a key management system like Azure Key Vault to hold the secrets and the git manifest in the repositories has reference to the key vault secrets. Developers do not perform any cryptographic operations with files in repositories. Kubernetes operators running in the target cluster are responsible for pulling the secrets from the key vault and making them available either as Kubernetes secrets or secrets volume mounted to the pod.

All the below tools share the following:

For secret rotation ideas, see Secrets Rotation on Environment Variables and Mounted Secrets

For how to authenticate private container registries with a service principal see: Authenticated Private Container Registry

Azure Key Vault Provider for Secrets Store CSI Driver

Azure Key Vault Provider (AKVP) for Kubernetes secret store CSI Driver allows you to get secret contents stored in an Azure Key Vault instance and use the Secrets Store CSI driver interface to mount them into Kubernetes pods. Mounts secrets/keys/certs to pod using a CSI Inline volume.

Azure Key Vault Provider for Secrets Store CSI Driver install guide.

CSI driver will need access to Azure Key Vault either through a service principal or managed identity (recommended). To make this access secure you can leverage Azure AD Workload Identity(recommended) or AAD Pod Identity. Please note AAD pod identity will soon be replaced by workload identity.

Product Group Links provided for AKVP with SSCSID:

  1. Differences between ESO / SSCSID (GitHub Issue)
  2. Secrets Management on K8S talk here (Native Secrets, Vault.io, and ESO vs. SSCSID)

Advantages:

Disadvantages:

External Secrets Operator with Azure Key Vault

The External Secrets Operator (ESO) is an open-sourced Kubernetes operator that can read secrets from external secret stores (e.g., Azure Key Vault) and sync those into Kubernetes Secrets. In contrast to the CSI Driver, the ESO controller creates the secrets on the cluster as K8s secrets, instead of mounting them as volumes to pods.

Docs on using ESO Azure Key vault provider here.

ESO will need access to Azure Key Vault either through the use of a service principal or managed identity (via Azure AD Workload Identity(recommended) or AAD Pod Identity).

Advantages:

Disadvantages:

Appendix

Authenticated Private Container Registry

An option on how to authenticate private container registries (e.g., ACR):

  1. Use a dockerconfigjson Kubernetes Secret on Pod-Level with ImagePullSecret (This can be also defined on namespace-level)