Skip to content

fix: container filesystem resolves symlinks correctly#6559

Merged
tonistiigi merged 1 commit intomoby:masterfrom
jsternberg:container-fs-readlink
Mar 18, 2026
Merged

fix: container filesystem resolves symlinks correctly#6559
tonistiigi merged 1 commit intomoby:masterfrom
jsternberg:container-fs-readlink

Conversation

@jsternberg
Copy link
Copy Markdown
Collaborator

The symlink reader with the new container exec filesystem capability was
reading symlinks in an invalid way. The io/fs interface requires all
paths to be relative paths, but it was passing an absolute path to the
function which returned an error.

This was primarily affecting ReadDir which would error out if it tried
to read a directory with a symlink in it.

@jsternberg jsternberg force-pushed the container-fs-readlink branch from c1875b7 to e8d1939 Compare March 6, 2026 17:51
@jsternberg jsternberg requested a review from tonistiigi March 6, 2026 17:52
@jsternberg jsternberg force-pushed the container-fs-readlink branch 2 times, most recently from c1875b7 to 3a21bae Compare March 11, 2026 19:27
}

path, err := filepath.Rel("/", req.Path)
fpath, err := filepath.Rel("/", req.Path)
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.

Check if this should be path, or maybe path.Join("/", req.Path)[1:] is better.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to update this to another implementation that just trims the prefix. I think this is probably more complicated than it was intended. The intention was that the API was only supposed to accept absolute values. Using path.Join causes it to accept both absolute and relative paths which isn't the intention. At the same time, the current implementation accepts filepaths relative to the OS rather than only Unix filepaths which is the standard everywhere else.

It's probably better to just clean the path, check if the first character is a slash, then trim it. I'll also update the other functions to use the same utility.

@jsternberg jsternberg force-pushed the container-fs-readlink branch 2 times, most recently from e0b36ea to ebec28d Compare March 12, 2026 15:15
@jsternberg jsternberg requested a review from tonistiigi March 12, 2026 19:14
@jsternberg jsternberg force-pushed the container-fs-readlink branch from ebec28d to 494737b Compare March 16, 2026 15:38

// Resolving this symlink causes the path to escape.
// Attempt to use lstat and allow the client to perform the resolution.
fi, err = fs.Lstat(fsys, fpath)
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.

This seems like a fine fallback, but maybe we should consider LStatFile in follow-up, as it doesn't really seem to be possible to reliably differentiate between them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking about adding a NoFollowLinks to the stat request but then I'd have to implement it on the other implementation of StatFile and it didn't really seem like something that anybody would actually use right now.

The symlink reader with the new container exec filesystem capability was
reading symlinks in an invalid way. The `io/fs` interface requires all
paths to be relative paths, but it was passing an absolute path to the
function which returned an error.

This was primarily affecting `ReadDir` which would error out if it tried
to read a directory with a symlink in it.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg jsternberg force-pushed the container-fs-readlink branch from 494737b to fd45966 Compare March 17, 2026 15:25
@tonistiigi tonistiigi merged commit 89dd0ee into moby:master Mar 18, 2026
222 of 223 checks passed
@jsternberg jsternberg deleted the container-fs-readlink branch March 18, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants