kustomize-controller: Unable to decrypt a secret via SOPS
With the recent upgrade to kustomize controller to v1.5.0 I’m facing the following issue during reconciliation:
Warning BuildFailed 2m40s kustomize-controller decryption failed for 'foo-token': failed to decrypt and format 'default/foo-token' Secret data: error decrypting sops tree: Error walking tree: Could not decrypt value: Input string glagent-xxx does not match sops' data format
I have a secret resource which is set to empty string in the base layer, and there is a patch that contains actual secret data. Both of them are encrypted using SOPS (and AWS KMS key, but I think that’s irrelevant here). To my surprise kustomize controller shows the secret value itself (in the logs!), and that’s probably the hint as well why it fails. I suspect kustomize is trying to decrypt the secret twice, so on the second attempt SOPS obviously complains that the passed in value doesn’t match the regex it expects.
I confirmed that my GitOps repo sucessfully reconciles with kustomize controller v1.4.0, and does not with v1.5.0. I believe the cullprit is here, but I’m lacking background knowledge and local setup to confirm though.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
I do not consider the case as valid, since mixing encrypted data from different files is not a way to go.
@kamialie I would do it this way
Also, update your
.sops.yamlto manage*.sops.env, so your token files will be encrypted. That should work.We are already addressing this part here: https://github.com/fluxcd/kustomize-controller/pull/1372
Hi @kamialie I’m investigating this bug right now, can you please share more details of how your config is structured? Possibly the exact thing except for the actual secret values of course. Much appreciated! 🙏
Also pinging @vlasov-y, your two PRs #1283 and #1286 seem to be the only ones touching decryption in the change log for kustomize-controller v1.5.0, if you could please shed some light here 🙏
Going through code I guess the assumption at the moment is that base layer is not encrypted, while the patch is. The latest version of the controller would basically simply decrypt earlier. The reason I encounter the error is probably due to base layer containing SOPS metadata, so controller thinks it needs to decrypt that source file, where patch (with already decrypted data) has been applied to. If my assumptions are correct, I can see how I can immediately fix the issue by just removing SOPS metadata from base layer, since encrypting empty string barely serves any purpose, but I can see how this can still not work for everyone. For instance, what if I simply want to rotate a shared secret across environments: my current value would be in the base layer (to avoid duplication), and I’m introducing new value in dev environment.