Skip to content

Reject ambiguous resource paths with inner ".." to prevent silent misresolution#6087

Merged
k8s-ci-robot merged 5 commits intokubernetes-sigs:masterfrom
0xMH:fix/5979-malformed-resources
Mar 25, 2026
Merged

Reject ambiguous resource paths with inner ".." to prevent silent misresolution#6087
k8s-ci-robot merged 5 commits intokubernetes-sigs:masterfrom
0xMH:fix/5979-malformed-resources

Conversation

@0xMH
Copy link
Copy Markdown
Member

@0xMH 0xMH commented Mar 5, 2026

I dug into #5979 where a YAML indentation error silently causes kustomize to load resources from the wrong directory.

When a kustomization.yaml has a subtle indentation mistake:

resources:
- ../../base
 - ../../shared/prod
- m3.yaml

YAML parsing collapses the first two entries into a single string: "../../base - ../../shared/prod".

The combined string then hits filepath.Clean, which processes the segments:

  1. .. + .. -> normal, goes up two directories
  2. base - .. -> treated as a single directory name (with spaces and dash)
  3. .. -> Clean sees this and cancels the previous component (base - ..), removing it
  4. .. -> goes up one more
  5. shared/prod -> descends into final path

So Clean collapses it to ../../shared/prod. The base - .. segment gets absorbed by the .. that follows it, as if it never existed.

The root cause is that YAML merged two list entries into one string ("../../base - ../../shared/prod"), creating a path component base - .. that looks like a directory name but contains .. from the second entry. filepath.Clean then treats the subsequent .. as "go up", which eats base - .. and erases any trace of ../../base.

Since /shared/prod is a real directory, ConfirmDir passes and kustomize silently loads the wrong resources. No error is raised. This is dangerous in CI/CD environments where missing manifests can cause resources to be deleted.

Fix

I added a hasInnerDotDot check in FileLoader.New() that rejects paths containing .. after a non-.. component. These are always either a YAML artifact or a non-canonical path with a simpler equivalent (foo/../bar is just bar). No valid use case that I know of is affected.

There was a prior attempt in #5980, but it checked existence after normalization, so if the wrong directory exists the check passes.

/kind bug
/fix #5979

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 5, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @0xMH. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 5, 2026
@0xMH 0xMH force-pushed the fix/5979-malformed-resources branch from 987c662 to 2941bf1 Compare March 6, 2026 05:43
@chansuke
Copy link
Copy Markdown
Member

chansuke commented Mar 7, 2026

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 7, 2026
Comment thread api/internal/loader/fileloader.go Outdated
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@0xMH 0xMH force-pushed the fix/5979-malformed-resources branch 2 times, most recently from eb00182 to 2bbf133 Compare March 7, 2026 11:06
@0xMH
Copy link
Copy Markdown
Member Author

0xMH commented Mar 7, 2026

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 7, 2026
@koba1t
Copy link
Copy Markdown
Member

koba1t commented Mar 9, 2026

@0xMH
Could you fix lint error?

@0xMH
Copy link
Copy Markdown
Member Author

0xMH commented Mar 9, 2026

@koba1t Done!

@0xMH
Copy link
Copy Markdown
Member Author

0xMH commented Mar 12, 2026

Hi @koba1t, I think the lint errors reported in CI are all pre-existing issues in fileloader_test.go not introduced by this PR. Correct me if I'm wrong but I think that's because the PR touches this file, golangci-lint re-evaluates it against the new-from-rev baseline (c94b5d8f2) and flags old code: unchecked error returns (errcheck), unused assignments (ineffassign, staticcheck), a global variable (gochecknoglobals), and a missing http.StatusOK constant (usestdlibvars).

I'm happy to fix them in a separate commit on this PR, but wanted to flag that none of these are caused by my changes. What should we do in this situation? Would you prefer I clean them up here, or should they be addressed in a separate PR?

@koba1t
Copy link
Copy Markdown
Member

koba1t commented Mar 22, 2026

@0xMH
It's okay to add a fix commit for the linter to this PR.

@0xMH 0xMH force-pushed the fix/5979-malformed-resources branch from ec59321 to 7fd88c2 Compare March 24, 2026 21:28
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 24, 2026
@0xMH
Copy link
Copy Markdown
Member Author

0xMH commented Mar 24, 2026

@0xMH It's okay to add a fix commit for the linter to this PR.

@koba1t Perfect, Did that now.

Copy link
Copy Markdown
Member

@koba1t koba1t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 25, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 0xMH, chansuke, koba1t

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 25, 2026
@k8s-ci-robot k8s-ci-robot merged commit 29bf16c into kubernetes-sigs:master Mar 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed resources YAML entry silently resolves to wrong directory (../../shared/prod) instead of erroring

4 participants