Repository navigation
Conversation
IrvingMg
left a comment
There was a problem hiding this comment.
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.
|
Hi @IrvingMg, Thanks for your review. I updated the PR with new changes trying to address your remarks. Regards, |
There was a problem hiding this comment.
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
skipPathfunction to exclude symlinks from being skipped (allowing them to be processed) - Added symlink handling in
writeFileToTarto read symlink targets, detect if they point outside the source directory, and properly set the tar header linkname - Added
isSymlinkTargetOutsideOfDirfunction 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.
|
Hi @dollierp, thanks for the changes. There’s one more Copilot comment, could you take a look? |
|
Hi @IrvingMg, I updated the PR to make Copilot happy. Let me know if something else is missing. Regards. |
IrvingMg
left a comment
There was a problem hiding this comment.
Thanks again for the changes. I left a couple more comments.
|
Hi @IrvingMg, I tried to address your latest remarks and updated the PR. Regards, |
IrvingMg
left a comment
There was a problem hiding this comment.
Thanks for the update, looks good overall. Just a few final comments from my side.
|
Hi @IrvingMg, I've tried to incorporate your latest feedback and have updated the pull request. Regards, |
IrvingMg
left a comment
There was a problem hiding this comment.
Thanks for the changes! Overall /lgtm
@shipwright-io/approvers PTAL, this PR has been open for a while.
|
/lgtm |
|
Hi @adambkaplan, I squashed the commits into a single one and improved its message to match the guidelines. Regards, |
|
/lgtm Failed e2e test appears to be a flake. Re-running (which will gate merge until it passes). |
|
@adambkaplan Could we retry the E2E job so that we can merge this PR? |
|
/retest |
|
/test all |
|
@sayan-biswas: No presubmit jobs available for shipwright-io/cli@main DetailsIn response to this:
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. |
|
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>
|
Rebased |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: adambkaplan, IrvingMg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| // outside the source directory. | ||
| var absSrc, absTarget string | ||
|
|
||
| if absSrc, err = filepath.Abs(t.src); err != nil { |
There was a problem hiding this comment.
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).
| return fmt.Errorf("symlink %q points outside the source directory %q (target: %q)", relPath, absSrc, target) | ||
| } | ||
|
|
||
| header.Linkname = target |
There was a problem hiding this comment.
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:
| 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) |
|
|
||
| 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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| 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} |
There was a problem hiding this comment.
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:
| t := &Tar{src: src, ioStreams: ioStreams} | |
| if realSrc, err := filepath.EvalSymlinks(src); err == nil { | |
| src = realSrc | |
| } | |
| t := &Tar{src: src, ioStreams: ioStreams} |
| 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 |
There was a problem hiding this comment.
Nothing reads this field now that the warning became an error. It could be removed, along with the new NewTar argument.
|
@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. |
|
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. |
|
PR needs rebase. DetailsInstructions 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. |
|
Thanks @dollierp for the confirmation. I will created a new PR based on yours. |
Changes
Don't skip symlinks during local source upload
/kind bug
Submitter Checklist
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes