build/diff: strip SOPS metadata from non-Secret resources - #5869
build/diff: strip SOPS metadata from non-Secret resources#5869SebTardif wants to merge 3 commits into
Conversation
Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca> Assisted-by: GitHub Copilot/GPT-5.3-Codex
There was a problem hiding this comment.
Pull request overview
This PR improves flux build kustomization and flux diff kustomization compatibility with SOPS-encrypted non-Secret manifests by stripping the top-level .sops metadata block from non-Secret resources in CLI build output, preventing server-side apply dry-run schema validation errors on CRDs.
Changes:
- Extend
maskSopsDatato clear top-level.sopsfor non-Secret resources when SOPS metadata is detected. - Add unit tests covering
.sopsstripping for non-Secret resources. - Add CLI build/create kustomization golden tests and new testdata fixtures for SOPS scenarios.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/build/build.go | Adds .sops stripping for non-Secret resources during masking. |
| internal/build/build_test.go | Adds unit coverage for .sops stripping behavior on non-Secret resources. |
| cmd/flux/build_kustomization_test.go | Adds integration-style golden tests for building SOPS-decorated HelmRelease/ConfigMap. |
| cmd/flux/create_kustomization_test.go | Adds golden coverage for create kustomization decryption flags output. |
| cmd/flux/testdata/create_kustomization/with-sops-decryption.yaml | New golden YAML for create-kustomization decryption flags. |
| cmd/flux/testdata/build-kustomization/sops-helmrelease/* | New kustomization + HelmRelease SOPS fixture. |
| cmd/flux/testdata/build-kustomization/sops-helmrelease-result.yaml | New golden output verifying .sops is stripped from HelmRelease. |
| cmd/flux/testdata/build-kustomization/sops-configmap/* | New kustomization + ConfigMap SOPS fixture. |
| cmd/flux/testdata/build-kustomization/sops-configmap-result.yaml | New golden output verifying .sops is stripped from ConfigMap. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca> Assisted-by: GitHub Copilot/GPT-5.3-Codex
|
Hmmmm encrypting non-Secret resources is so bad... |
|
@matheuscscp > Hmmmm encrypting non-Secret resources is so bad... I worked in many projects were the credentials are showing up in git and logs. I want to make it easy to avoid that. Ending up with credentials hidden inside Kubernetes that is not in a secret and that nobody has practical access, is something my projects accept totally. |
|
I'm OK with this change if we put it behind an opt-in flag like |
Add --strip-sops-metadata flags to build and diff kustomization\ncommands and plumb the option into the build engine.\n\nKeep top-level .sops removal for non-Secret resources disabled by\ndefault, while preserving secret masking behavior.\n\nUpdate unit tests to cover both opt-in strip and default behavior, and\nupdate command tests that assert stripped output. Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca> Assisted-by: GitHub Copilot/GPT-5.3-Codex
|
Implemented follow-up in ce8d638:
Also verified the two Copilot findings are handled:
|
Summary
This PR makes
flux build kustomizationandflux diff kustomizationsafer and more compatible with SOPS-encrypted non-Secret manifests (e.g.HelmRelease,ConfigMap) by stripping top-level.sopsmetadata from non-Secret resources in CLI build output.Why
When
.sopsmetadata is left in non-Secret resources, server-side apply dry-run can fail with schema validation errors on CRDs (e.g..sops: field not declared in schema).Changes
maskSopsDataininternal/build/build.goto clear top-level.sopsfor non-Secret resources when detected.Secretresources.ENC[...]ciphertext values (no decryption performed in CLI build step).internal/build/build_test.go.cmd/flux/build_kustomization_test.goandcmd/flux/testdata/build-kustomization/*.flux create kustomizationdecryption golden coverage incmd/flux/create_kustomization_test.go.Validation
make fmt vetmake testRelated context: #4075