
- You have a Git repository checked out (example:
bb-app-source) and are on theinfrastructurebranch. - A SOPS public key file exists in the repository at
sops/sops-gpg.pub. - Flux is installed and configured to apply resources from the repository.
- Prepare the Secret YAML in plaintext.
- Import the SOPS public (PGP) key into your GPG keyring.
- Install SOPS on your developer machine.
- Encrypt the secret with SOPS (PGP backend).
- Push the encrypted manifest and give Flux the SOPS private key so it can decrypt.
- Reconcile Flux and verify the Secret is applied decrypted in the cluster.
1) Plaintext Secret (before encryption)
Create a simple Secret usingstringData so values are easy to read before encryption:
database/secret-mysql.yaml.
2) Import the public PGP key into GPG
On the developer machine, verify and import the public key that ships with the repository:3) Install SOPS on your machine
Install the SOPS CLI. Example (Linux binary download for sops v3.7.3):4) Encrypt the Secret using the developer’s public key (SOPS + PGP)
Encrypt only the secret data keys (data or stringData) so metadata remains human-readable. Use the PGP fingerprint you imported:
--encrypted-regexcontrols which keys are encrypted (here:dataandstringData).--in-placereplaces the file with the encrypted version.
Never commit private keys to the public repository. Only the public key (
sops-gpg.pub) belongs in the repo. The private key must be handled securely (see the next section for how to provide it to Flux).5) Commit & push the encrypted file; what Flux will do by default
Commit and push the encrypted secret file to your Git repository. Flux will fetch the manifest and apply it as-is. Without extra configuration Flux will apply the encrypted value literally, so the Secret in Kubernetes will contain the SOPS-encrypted string (not the usable plaintext). You can confirm the applied Secret content (it will show the encrypted string after decoding from base64):6) Provide the SOPS private key to Flux and configure Kustomization decryption
An administrator creates a Kubernetes Secret in theflux-system namespace that contains the SOPS/GPG private key. Example command (performed by an admin):
./database to include a decryption block. Key parts of the Kustomization:
- The Flux secret
sops-gpgmust exist in theflux-systemnamespace and include the private key file content under the key name expected by Flux (for PGP, this is typically the raw private key file). - After adding
decryption, Flux will attempt to decrypt any SOPS-encrypted files in that path before applying them.
Ensure the Flux secret (
sops-gpg) contains the SOPS/GPG private key and is created in the flux-system namespace — Flux requires that private key to decrypt SOPS-encrypted manifests.7) Reconcile Flux and verify the Secret is applied decrypted
Trigger a manual reconcile (optional — Flux will reconcile automatically based oninterval):
Summary, options and best practices
- Mozilla SOPS supports multiple encryption backends: PGP, AWS KMS, GCP KMS, Azure Key Vault, HashiCorp Vault, age, and others. Use the backend that matches your organizational key management policies.
- In GitOps workflows with Flux, store only encrypted secrets in Git. To let Flux apply decrypted values, configure the Kustomization
decryptionblock and provide the decryption key/secret to Flux. - If you omit the Kustomization decryption configuration, Flux will apply the encrypted Secret object as stored in Git — the cluster will hold the encrypted string.
- Secure the SOPS private key carefully. Prefer storing it in a restricted admin-controlled location and only create the Flux secret in
flux-systemwhen necessary.
- Mozilla SOPS project: https://github.com/mozilla/sops
- Flux docs — Kustomization decryption: https://fluxcd.io/docs/components/kustomize/kustomization/#decryption
- GPG documentation: https://gnupg.org/documentation/