fix: copy external files referenced by kustomize transformer 'path:' into temp dir#198
Merged
Merged
Conversation
…into temp dir Kustomize transformers like PatchTransformer can reference external files via a top-level 'path:' field (as opposed to inline 'patch:'). Chartify was copying the transformer YAML to tempDir but not the files it referenced, causing kustomize to fail with security errors since the referenced files were outside its restricted root. This adds resolveTransformerFileRefs() which scans transformer YAML for top-level 'path:' fields, copies referenced files into tempDir, and rewrites the paths so kustomize can access them. Path resolution matches kustomize semantics (relative to kustomization root/CWD), with a fallback to the transformer file's directory for colocated files. Fixes #90 Signed-off-by: yxxhero <aiopsclub@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Kustomize transformers like
PatchTransformercan reference external files via a top-levelpath:field (as opposed to inlinepatch:). Chartify was copying the transformer YAML to tempDir but not the files it referenced, causing kustomize to fail with security errors since the referenced files were outside its restricted root.Fixes #90
Error before fix
Relative path:
Absolute path:
Solution
Added
resolveTransformerFileRefs()inpatch.gowhich:path:fields that reference existing filestempDir/transformer-patch-files/path:to point to the in-root copyPath resolution strategy
Kustomize resolves transformer
path:relative to the kustomization root. The newresolveTransformerPath()helper tries:Edge cases handled
path:values (e.g. JSON paths infieldSpecs) are left untouchedos.Statpath:fields are returned unchanged (no re-encoding)Test plan
kube_manifest_transformer_with_path— verifies aPatchTransformerwithpath: patch.yamlcorrectly patches the target resourcekube_manifest_transformer_alpha_plugintest still passeskube_manifest_with_patchtest still passesgo fmt,go vet,go buildall pass