@@ -725,7 +725,7 @@ For more information, see [remote clusters/Cluster-API](#remote-clusterscluster-
725725# ## Decryption
726726
727727` .spec.decryption` is an optional field to specify the configuration to decrypt
728- Secrets that are a part of the Kustomization.
728+ Secrets, ConfigMaps and patches that are a part of the Kustomization.
729729
730730Since Secrets are either plain text or `base64` encoded, it's unsafe to store
731731them in plain text in a public or private Git repository. In order to store
@@ -734,9 +734,11 @@ encrypt your Kubernetes Secret data with [age](https://age-encryption.org/v1/)
734734and/or [OpenPGP](https://www.openpgp.org) keys, or with provider implementations
735735like Azure Key Vault, GCP KMS or Hashicorp Vault.
736736
737- **Note:** You should encrypt only the `data/stringData` section of the Kubernetes
738- Secret, encrypting the `metadata`, `kind` or `apiVersion` fields is not supported.
739- An easy way to do this is by appending `--encrypted-regex '^(data|stringData)$'`
737+ Also, you may want to encrypt some parts of resources as well. In order to do that,
738+ you may encrypt patches as well.
739+
740+ **Note:** You must leave `metadata`, `kind` or `apiVersion` in plain text.
741+ An easy way to do this is to limit encrypted keys by appending `--encrypted-regex '^(data|stringData)$'`
740742to your `sops --encrypt` command.
741743
742744It has two fields :
@@ -788,6 +790,86 @@ data:
788790 sops.vault-token: <BASE64>
789791` ` `
790792
793+ # ### Important case: SOPS decryption encrypted_regex conflict
794+
795+ If your resource is encrypted it will be decrypted right before apply, but it may happen, that
796+ your patches will bring fields that match SOPS' encrypted_regex expression and SOPS will fail
797+ during the decryption. Let's say we have a simple resource.
798+
799+ ` ` ` yaml
800+ apiVersion: v1
801+ kind: Pod
802+ metadata:
803+ name: pod
804+ spec:
805+ containers:
806+ - name: main
807+ image: nginx:stable-alpine
808+ env:
809+ - name: ENC[AES256_GCM,data:...
810+ value: ENC[AES256_GCM,data:...
811+ resources:
812+ limits:
813+ memory: 50Mi
814+ cpu: 50m
815+ sops:
816+ ...
817+ encrypted_regex: ^env$ # There it is
818+ ...
819+ ` ` `
820+
821+ This Pod has every env list encrypted since we have `encrypted_regex` set during SOPS encryption.
822+ But next we have a patch like this.
823+
824+ ` ` ` yaml
825+ apiVersion: v1
826+ kind: Pod
827+ metadata:
828+ name: pod
829+ spec:
830+ containers:
831+ - name: patched
832+ image: nginx:stable-alpine
833+ env:
834+ - name: MainEnvValueIsEncrypted
835+ value: but this one is not
836+ ` ` `
837+
838+ And as a result you will have.
839+
840+ ` ` ` yaml
841+ apiVersion: v1
842+ kind: Pod
843+ metadata:
844+ name: pod
845+ spec:
846+ containers:
847+ - name: main
848+ image: nginx:stable-alpine
849+ env:
850+ - name: ENC[AES256_GCM,data:...
851+ value: ENC[AES256_GCM,data:...
852+ resources:
853+ limits:
854+ memory: 50Mi
855+ cpu: 50m
856+ - name: patched
857+ image: nginx:stable-alpine
858+ env:
859+ - name: MainEnvValueIsEncrypted
860+ value: but this one is not
861+ sops:
862+ ...
863+ encrypted_regex: ^env$ # There it is
864+ ...
865+ ` ` `
866+
867+ At this point, Flux will call SOPS to decrypt the file and SOPS will try to decrypt
868+ all `env` keys, but container `patched` has this list in a plain text. That is where SOPS fails.
869+
870+ **Solution**: move all your secrets to patches and your resource will not require a
871+ decryption at the end, since patches are decrypted before.
872+
791873# ### age Secret entry
792874
793875To specify an age private key in a Kubernetes Secret, suffix the key of the
0 commit comments