Repository navigation
fix(oci): handle absolute symlinks with folders in rootfs user lookup - #13383
jasonjoo2010 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends pkg/oci/spec_opts.go symlink handling for user/group file lookups (/etc/passwd, /etc/group) so that absolute symlinks on intermediate path components (e.g., /etc -> /system/etc) are resolved, not just absolute symlinks on the leaf file.
Changes:
- Add
extractSymlinkto iteratively resolve symlinks per path component (with depth limit) and re-anchor absolute targets to the rootfs. - Extend the local FS capability interface from
ReadLinktoReadLink+Lstatto detect symlinks without relying onReadLinkerror semantics. - Expand
TestOpenUserFile_AbsoluteSymlinkwith folder-symlink and multi-level symlink cases, and update test helpers to provideLstat.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/oci/spec_opts.go | Implements iterative symlink extraction for user/group file opening, including intermediate directory symlinks. |
| pkg/oci/spec_test.go | Adds/extends tests to cover absolute symlinks on directories and multi-level absolute symlink chains; updates test FS wrapper to support Lstat. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ad0a7d4 to
c1f5601
Compare
c1f5601 to
33346e1
Compare
33346e1 to
2b52a6a
Compare
40ab8d3 to
967efad
Compare
967efad to
e28fdd5
Compare
e28fdd5 to
4939828
Compare
4939828 to
07bd401
Compare
07bd401 to
b73cfb2
Compare
b73cfb2 to
87e7489
Compare
87e7489 to
ba0ed04
Compare
ba0ed04 to
3241b6b
Compare
3241b6b to
3721649
Compare
|
Hi @dmcgowan Sorry to tag you directly. Thanks |
3721649 to
1cd257e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/oci/spec_opts.go:1845
- The doc comment for openUserFile still describes only the leaf-file absolute-symlink case, but the implementation now resolves symlinks across intermediate path components (including directory symlinks) via extractSymlink. Updating the comment will keep behavior and documentation aligned (and avoids implying this is limited to os.DirFS only).
// openUserFile attempts to open a file within the root fs.
// It handles cases where the file is an absolute symlink (e.g., NixOS /etc/passwd -> /nix/store/...),
// which triggers "path escapes from parent" errors in Go 1.24+ due to stricter os.DirFS validation.
//
Signed-off-by: Jason Joo <[email protected]>
1cd257e to
865687e
Compare
|
Close and move to #13818 |
What is the problem you're trying to solve
The
openUserFilefunction inpkg/oci/spec_opts.gofails to resolve absolute symlinks that point to directories rather than files. For example, on Android emulator images,/etcis commonly a symlink to/system/etc. When containerd tries to openetc/passwd, it only handles the case where the final file (etc/passwd) is itself a symlink(fixed in #12732), but not the case where an intermediate directory component (etc) is a symlink with absolute path.This deficiency prevents:
/etc -> /system/etcsymlink layouts fail to resolve user/group files.Describe the solution you'd like
The fix introduces an
extractSymlinkfunction that iteratively walks each path component, usesLstatto check for symlinks (instead of relying onReadLinkerror semantics), re-anchors absolute targets to the root, and enforces a depth limit of 8 to prevent circular symlink loops which is the same approach as builtinos/root.godoes. ThereadLinkerinterface is extended toreadLinkStaterto include theLstatmethod.A new test case ("absolute symlink for folder") has been added alongside the existing "absolute symlink" test to verify that directory-level symlinks (e.g.,
/etc -> /system/etc) are correctly resolved when openingetc/passwd.The test case
TestOpenUserFile_AbsoluteSymlinkis extended to include 3 more tests covering:fixed #13382