Skip to content

Don't skip symlinks during local source upload - #355

Open
dollierp wants to merge 1 commit into
shipwright-io:mainfrom
dollierp:symlinks
Open

dollierp wants to merge 1 commit into
shipwright-io:mainfrom
dollierp:symlinks

Conversation

@dollierp

@dollierp dollierp commented Nov 6, 2025 •

Copy link
Copy Markdown

Changes

Don't skip symlinks during local source upload

/kind bug

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Content from symlinks is included during local source upload

@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 6, 2025
@openshift-ci openshift-ci Bot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 6, 2025

@IrvingMg IrvingMg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

Overall, LGTM. I left a couple of comments. It would also be nice to have unit tests for at least basic cases, as the changes are related to the core functionality of the upload command.

Comment thread pkg/shp/streamer/tar.go Resolved
Comment thread pkg/shp/streamer/util.go Resolved
Copilot AI review requested due to automatic review settings April 6, 2026 13:28
@dollierp

dollierp commented Apr 6, 2026

Copy link
Copy Markdown
Author

Hi @IrvingMg,

Thanks for your review.

I updated the PR with new changes trying to address your remarks.

Regards,

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where symlinks were being skipped during local source uploads. Previously, the tar helper would skip any file that wasn't a regular file (including symlinks, directories, and other special file types). The changes now allow symlinks to be included in the tar archive while still skipping unsupported file types.

Changes:

  • Modified skipPath function to exclude symlinks from being skipped (allowing them to be processed)
  • Added symlink handling in writeFileToTar to read symlink targets, detect if they point outside the source directory, and properly set the tar header linkname
  • Added isSymlinkTargetOutsideOfDir function to check if symlink targets escape the source directory and warn appropriately
  • Updated test to verify that symlinks are captured in the tar archive
  • Fixed documentation from "buildrun" to "build" command references

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/shp/streamer/tar.go Modified skipPath condition to allow symlinks through filtering
pkg/shp/streamer/util.go Added symlink handling logic with safety check for targets pointing outside source directory
pkg/shp/streamer/tar_test.go Enhanced test to verify symlinks are included in tar output
pkg/shp/cmd/build/upload.go Fixed documentation typo from "buildrun" to "build"
docs/shp_build_upload.md Updated documentation examples to match corrected command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/shp/streamer/util.go Resolved
@dollierp
dollierp requested a review from IrvingMg April 6, 2026 13:37
@IrvingMg

IrvingMg commented Apr 8, 2026

Copy link
Copy Markdown
Member

Hi @dollierp, thanks for the changes.

There’s one more Copilot comment, could you take a look?

@dollierp

dollierp commented Apr 8, 2026 •

Copy link
Copy Markdown
Author

Hi @IrvingMg,

I updated the PR to make Copilot happy.

Let me know if something else is missing.

Regards.

@IrvingMg IrvingMg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks again for the changes. I left a couple more comments.

Comment thread pkg/shp/streamer/util.go Resolved
Comment thread test/symlink/symlink_inside_tree Resolved
@pull-request-size pull-request-size Bot 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 Apr 9, 2026
@dollierp
dollierp requested a review from Copilot April 9, 2026 18:06
@dollierp

dollierp commented Apr 9, 2026

Copy link
Copy Markdown
Author

Hi @IrvingMg,

I tried to address your latest remarks and updated the PR.

Regards,

@dollierp
dollierp requested a review from IrvingMg April 9, 2026 19:03

@IrvingMg IrvingMg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update, looks good overall. Just a few final comments from my side.

Comment thread pkg/shp/streamer/util.go Resolved
Comment thread pkg/shp/streamer/tar_test.go Resolved
Comment thread pkg/shp/streamer/tar_test.go Resolved
Comment thread pkg/shp/streamer/tar_test.go Resolved
@dollierp

Copy link
Copy Markdown
Author

Hi @IrvingMg,

I've tried to incorporate your latest feedback and have updated the pull request.

Regards,

@dollierp
dollierp requested a review from IrvingMg April 11, 2026 08:48

@IrvingMg IrvingMg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the changes! Overall /lgtm

@shipwright-io/approvers PTAL, this PR has been open for a while.

@IrvingMg

Copy link
Copy Markdown
Member

/lgtm

@dollierp

Copy link
Copy Markdown
Author

Hi @adambkaplan,

I squashed the commits into a single one and improved its message to match the guidelines.

Regards,

@adambkaplan

Copy link
Copy Markdown
Member

/lgtm

Failed e2e test appears to be a flake. Re-running (which will gate merge until it passes).

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 23, 2026
@IrvingMg

Copy link
Copy Markdown
Member

@adambkaplan Could we retry the E2E job so that we can merge this PR?

@shipwright-io shipwright-io deleted a comment from openshift-ci Bot Jun 3, 2026
@sayan-biswas

Copy link
Copy Markdown
Contributor

/retest

@shipwright-io shipwright-io deleted a comment from openshift-ci Bot Jun 3, 2026
@sayan-biswas

Copy link
Copy Markdown
Contributor

/test all

@openshift-ci

openshift-ci Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@sayan-biswas: No presubmit jobs available for shipwright-io/cli@main

Details

In response to this:

/test all

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.

@IrvingMg IrvingMg closed this Aug 22, 2026
@github-project-automation github-project-automation Bot moved this to Done in Issues Aug 22, 2026
@IrvingMg IrvingMg reopened this Aug 22, 2026
@openshift-ci openshift-ci Bot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2026
@IrvingMg

Copy link
Copy Markdown
Member

Closing and reopening the PR to retrigger the checks.

Until now, the `shp build upload <build-name> /path` command would
silently discard symbolic links when walking through a local source
directory.

This is not backward compatible with the `oc start-build <build-name>
--from-dir=/path` command which supports symbolic links.

This change adds support for symbolic links to Shipwright cli to match
the legacy OpenShift build commands.

To prevent the type of vulnerability described by CWE-61 [1], an additional
security measure is implemented: an error is raised upon detecting a
symbolic link that points to a file outside the provided directory.

[1]: https://cwe.mitre.org/data/definitions/61.html

Signed-off-by: Denis Ollier <dollierp@redhat.com>
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2026
@IrvingMg

Copy link
Copy Markdown
Member

Rebased

@IrvingMg

Copy link
Copy Markdown
Member

/lgtm
/approve

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2026
@openshift-ci

openshift-ci Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adambkaplan, IrvingMg
Once this PR has been reviewed and has the lgtm label, please assign qu1queee for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Comment thread pkg/shp/streamer/util.go
// outside the source directory.
var absSrc, absTarget string

if absSrc, err = filepath.Abs(t.src); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The link target is resolved with EvalSymlinks on line 90, but the source folder is not. If the source path goes through a symlink, the two paths never match, and every link inside the folder looks outside.

On macOS /tmp is a symlink to /private/tmp. So shp build upload b /tmp/app fails with symlink "app/l-up" points outside the source directory, even though the link is ../keep.txt. I saw this on OpenShift and on kind. Resolving the source once in NewTar fixes it (see the comment on tar.go line 69).

Comment thread pkg/shp/streamer/util.go
return fmt.Errorf("symlink %q points outside the source directory %q (target: %q)", relPath, absSrc, target)
}

header.Linkname = target

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

An absolute link to a file inside the folder keeps the local path, for example /Users/me/app/keep.txt. That path doesn't exist in the build pod, so the link is broken there. I checked this in a build. A relative link fixes it:

Suggested change
header.Linkname = target
if filepath.IsAbs(target) {
realDir, err := filepath.EvalSymlinks(filepath.Dir(fpath))
if err != nil {
return err
}
realTarget, err := filepath.EvalSymlinks(target)
if err != nil {
realTarget = filepath.Clean(target)
}
if target, err = filepath.Rel(realDir, realTarget); err != nil {
return err
}
}
header.Linkname = filepath.ToSlash(target)

Comment thread pkg/shp/streamer/util.go

if outside, _ := isSymlinkTargetOutsideOfDir(absSrc, absTarget); outside {
relPath, _ := filepath.Rel(t.src, fpath)
return fmt.Errorf("symlink %q points outside the source directory %q (target: %q)", relPath, absSrc, target)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The error shows the link's own target, not where it ends up. In a Python venv, .venv/bin/python points to python3.14, which then points outside the folder. The message says (target: "python3.14"), which looks like it's inside. Showing the resolved path would make the cause clear.

This also affects many Python projects. Python 3.13 and later write .venv/.gitignore, so projects often leave .venv/ out of their top .gitignore. shp reads only the top file. Before this PR these uploads passed without the python links. Now they fail. A line in the release note would help.

if err := os.Remove(symlink); err != nil {
t.Fatalf("Failed to cleanup test symlink %q: %v", symlink, err)
}
if err := os.Symlink("../path/inside/source/tree", symlink); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This link points at nothing, so EvalSymlinks fails and the check falls back to comparing plain paths. That's why the test misses the problem on util.go line 44.

A link to a real file inside a t.TempDir() folder fails on macOS today, because the temp folder is under /var, which is a symlink. It would also keep the test from writing into the repo's test/ folder.

Comment thread pkg/shp/streamer/tar.go
func NewTar(src string) (*Tar, error) {
t := &Tar{src: src}
func NewTar(src string, ioStreams *genericclioptions.IOStreams) (*Tar, error) {
t := &Tar{src: src, ioStreams: ioStreams}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This fixes the problem on util.go line 44. It also fixes the case where the source folder is itself a symlink, which now fails with symlink "." points outside:

Suggested change
t := &Tar{src: src, ioStreams: ioStreams}
if realSrc, err := filepath.EvalSymlinks(src); err == nil {
src = realSrc
}
t := &Tar{src: src, ioStreams: ioStreams}

Comment thread pkg/shp/streamer/tar.go
gitIgnore *ignore.GitIgnore // matcher for git ignored files
src string // base directory
gitIgnore *ignore.GitIgnore // matcher for git ignored files
ioStreams *genericclioptions.IOStreams // io streams for user-facing output

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing reads this field now that the warning became an error. It could be removed, along with the new NewTar argument.

@psrvere

psrvere commented Sep 29, 2026

Copy link
Copy Markdown

@dollierp - I also need this feature in a downstream project. Please see the feedback and let me know if you still are pursuing this PR.

@dollierp

Copy link
Copy Markdown
Author

Hello @psrvere,

It's been almost a year since I opened this PR, and I've moved on to other projects since then.

Feel free to take over.

Thank you.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 30, 2026
@openshift-ci

openshift-ci Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

PR needs rebase.

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.

@psrvere

psrvere commented Sep 30, 2026

Copy link
Copy Markdown

Thanks @dollierp for the confirmation. I will created a new PR based on yours.

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

Labels

kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants