-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remote,build: ignore if .containerignore
or .dockerignore
is a symlink outside of buildContext
#16315
remote,build: ignore if .containerignore
or .dockerignore
is a symlink outside of buildContext
#16315
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: flouthoc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
61be56a
to
f933c67
Compare
Can you just use securejoin "github.com/cyphar/filepath-securejoin"? I think this will throw an error if .dockerignore or .containerignore point at a link outside of the root path. That way I could have a link within the context dir. |
@rhatdan I think SecureJoin does not throws error if link is outside the root path, it just resolves the symlink and concats with the However it works correctly if symlink is inside the Following is the diff which i tried diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index aabc7290d..63d354ad1 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -27,6 +27,7 @@ import (
"github.com/containers/storage/pkg/ioutils"
"github.com/docker/go-units"
"github.com/hashicorp/go-multierror"
+ securejoin "github.com/cyphar/filepath-securejoin"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
)
@@ -754,16 +755,16 @@ func errIfSymlink(path string) error {
}
func parseDockerignore(root string) ([]string, error) {
- path := filepath.Join(root, ".containerignore")
- err := errIfSymlink(path)
+ path, err := securejoin.SecureJoin(root, ".containerignore")
+ //err := errIfSymlink(path)
if err != nil {
return nil, err
}
ignore, err := os.ReadFile(path)
if err != nil {
var dockerIgnoreErr error
- path = filepath.Join(root, ".dockerignore")
- symlinkErr := errIfSymlink(path)
+ path, symlinkErr := securejoin.SecureJoin(root, ".dockerignore")
+ //symlinkErr := errIfSymlink(path)
if symlinkErr != nil {
return nil, symlinkErr
} |
f933c67
to
679a961
Compare
@rhatdan even though secure-join is not working as expected but I have modified function to |
But wouldn't securejoin work ok since when you attempt to open the path, it would fail with file does not exist? If I set .containerignore->/etc/shadow; don't you get an error like |
@rhatdan I think It does not fails cause |
OK |
@rhatdan They were flakes CI is green now. |
.containerignore
or .dockerignore
is a symlink.containerignore
or .dockerignore
is a symlink outside of buildContext
@containers/podman-maintainers PTAL |
679a961
to
45ab896
Compare
17a6bd0
to
f9ae030
Compare
I tried out f9ae0309e4213bc9094054bde0249c17bd681736
case 1: The directory /etc/testdir exists
case 2: The directory /etc/testdir does not exist
about the Podman version
|
@eriksjolund That was one of the reason to mask this error #16315 (comment) , I think we should mask this error. |
f9ae030
to
1718f7b
Compare
@eriksjolund Try again plz. |
1718f7b
to
4b242b2
Compare
@flouthoc I'm not able to do that right now but I could check during the weekend. I'm also a bit curious to investigate if there is any way to combine github.com/cyphar/filepath-securejoin with some additional checks in parseDockerIgnore(). Another thing: I think it would be more secure to use the resolved path resolvedPath
when reading the file. The symlinks might have changed after the check (TOCTOU). |
I think it would be good to aim for docker buildkit compatibility (i.e. running It looks like docker resolves a .dockerignore symlink as if the build context directory is the root of the file system.
|
@flouthoc with your new commit 4b242b2 the error message became
instead of the previous result from #16315 (comment)
About using github.com/cyphar/filepath-securejoinfrom #16315 (comment)
One alternative could be to use filepath-securejoin and at the same time introduce new a command-line option for allowing .dockerignore to be a symlink. A side-note regarding Buildkit: At first sight it seems that filepath-securejoin behaves in the same way as Buildkit regarding following symlinks. That conclusion is just drawn from the two Buildkit tests in About using filepath.EvalSymlinks(path)@flouthoc 4b242b2 (that is using |
6e8431c
to
d2d9c30
Compare
d2d9c30
to
bcdd860
Compare
I think this should become green now. |
@flouthoc are bud tests failing or are they flakes? |
Drop support for remote use-cases when `.containerignore` or `.dockerignore` is a symlink pointing to arbitrary location on host. Signed-off-by: Aditya R <[email protected]>
bcdd860
to
70e8f62
Compare
I think last test is a flake. |
@containers/podman-maintainers PTAL |
@eriksjolund PTAL |
@vrothberg @mheon PTAL |
@giuseppe @flouthoc @vrothberg PTAL |
(feedback from reading the code) It looks like the resulting |
@eriksjolund Yes this is expected and keeping the original behavior but if it needs to be changed I think it should be part of a new issue. The original issue is also fixed at buildah end here so this PR only makes sure that we dont tar up symlink from |
SGTM Yesterday I tried out local (i.e. non-remote) Podman and got different results when using either .dockerignore or the filename Dockerfile.dockerignore If the file If I repeat the experiment but use the filename .dockerignore instead of the filename Dockerfile.dockerignore, in other words
local podman will not use I think restricting local podman would be good but the scope for this PR is the remote case. |
How is 'an arbitrary location outside the build context' defined? A symlink that resolves to a path outside the build context? |
Does the issue resolved in podman 4.4.2? Thanks! |
@flouthoc @eriksjolund is this ready to merge? |
LGTM |
/lgtm |
/cherrypick v4.4.1-rhel |
@lsm5: new pull request created: #20901 In 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/test-infra repository. |
Drop support for remote use-cases when
.containerignore
or.dockerignore
is a symlink pointing to arbitrary location on host.