Skip to content

Extend SOPS redaction to postBuild substitutions - #1741

Open
dipti-pai wants to merge 1 commit into
fluxcd:mainfrom
dipti-pai:extend-sops-redaction-to-postbuild
Open

dipti-pai wants to merge 1 commit into
fluxcd:mainfrom
dipti-pai:extend-sops-redaction-to-postbuild

Conversation

@dipti-pai

Copy link
Copy Markdown
Member

postBuild.substituteFrom values are substituted verbatim into manifests before server-side apply. When the resulting value causes a Kubernetes API validation error that echoes the value back (e.g. a label value over the 63 byte limit), the raw error was copied unmodified into the Kustomization status conditions and events.

Load the postBuild.substituteFrom variables once per reconcile, using the same loader generator.SubstituteVariables relies on internally, and mask their values out of apply errors before they are attached to the Ready condition or emitted as an event. This extends the existing SOPS decryption error redaction (safeDecrypt) to also cover postBuild substitutions.

Assisted-by: GitHub Copilot/Claude Sonnet 5

@dipti-pai
dipti-pai force-pushed the extend-sops-redaction-to-postbuild branch from 088f579 to a107437 Compare September 11, 2026 16:54
Comment thread internal/controller/kustomization_controller.go Outdated
Karthik-Chowdary

This comment was marked as spam.

@matheuscscp

Copy link
Copy Markdown
Member

@dipti-pai Looks like the agent still implemented this in a way that the data is being loaded twice

@dipti-pai
dipti-pai force-pushed the extend-sops-redaction-to-postbuild branch from a107437 to bf0485b Compare September 14, 2026 21:07
postBuild.substituteFrom values are substituted verbatim into
manifests before server-side apply. When the resulting value causes a
Kubernetes API validation error that echoes the value back (e.g. a
label value over the 63 byte limit), the raw error was copied
unmodified into the Kustomization status conditions and events.

Register a collector via generator.ContextWithSecretVarsCollector on
the context passed to r.build(), which captures the
postBuild.substituteFrom Secret-sourced values already loaded
internally by generator.SubstituteVariables (via
generator.LoadVariables) while building manifests, and mask those
values out of apply errors before they are attached to the Ready
condition or emitted as an event. ConfigMap-sourced substituteFrom
values and inline postBuild.substitute values are intentionally
excluded from redaction, since they are not expected to hold sensitive
data. This extends the existing SOPS decryption error redaction
(safeDecrypt) to also cover postBuild substitutions, without an
additional ConfigMap/Secret fetch beyond what r.build() already
performs.

go.mod TEMPORARILY replaces github.com/fluxcd/pkg/kustomize with a
branch on github.com/dipti-pai/pkg that adds
ContextWithSecretVarsCollector
(fluxcd/pkg@main...dipti-pai:pkg:kustomize-substitute-with-vars).
This must be swapped for a tagged github.com/fluxcd/pkg/kustomize
release once that change is reviewed and merged upstream.

Signed-off-by: Dipti Pai <diptipai89@outlook.com>
Assisted-by: GitHub Copilot/Claude Sonnet 5
@dipti-pai
dipti-pai force-pushed the extend-sops-redaction-to-postbuild branch from bf0485b to 7bf79fe Compare September 14, 2026 22:30
@dipti-pai

Copy link
Copy Markdown
Member Author

@dipti-pai Looks like the agent still implemented this in a way that the data is being loaded twice

Hi @matheuscscp. Had to update pkg code to avoid the additional call to LoadVariables from kustomize-controller. The associated PR is here - fluxcd/pkg#1298 . Temporarily updated the go.mod to point to the pkg fork.

Could you take a look? Thanks.

@matheuscscp

Copy link
Copy Markdown
Member

Thanks @dipti-pai, I merged pkg 1298. I will cut a kustomize release together with all the other pkgs after pkg 1144 is also merged

@dipti-pai

Copy link
Copy Markdown
Member Author

Thanks @dipti-pai, I merged pkg 1298. I will cut a kustomize release together with all the other pkgs after pkg 1144 is also merged

Thanks @matheuscscp : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants