Skip to content

fix(oci): handle absolute symlinks with folders in rootfs user lookup - #13383

Closed
jasonjoo2010 wants to merge 1 commit into
containerd:mainfrom
jasonjoo2010:fix/absolute-symlink-folder
Closed

jasonjoo2010 wants to merge 1 commit into
containerd:mainfrom
jasonjoo2010:fix/absolute-symlink-folder

Conversation

@jasonjoo2010

@jasonjoo2010 jasonjoo2010 commented May 12, 2026 •

Copy link
Copy Markdown

What is the problem you're trying to solve

The openUserFile function in pkg/oci/spec_opts.go fails to resolve absolute symlinks that point to directories rather than files. For example, on Android emulator images, /etc is commonly a symlink to /system/etc. When containerd tries to open etc/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:

  • Intermediate directory symlink resolution: Container images with /etc -> /system/etc symlink layouts fail to resolve user/group files.
  • Nested symlink resolution: Any rootfs layout where intermediate path or leaf file are nested absolute symlinks is broken.

Describe the solution you'd like

The fix introduces an extractSymlink function that iteratively walks each path component, uses Lstat to check for symlinks (instead of relying on ReadLink error 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 builtin os/root.go does. The readLinker interface is extended to readLinkStater to include the Lstat method.

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 opening etc/passwd.

The test case TestOpenUserFile_AbsoluteSymlink is extended to include 3 more tests covering:

  1. Absolute symlink for folder (single-level)
  2. Multi-level absolute symlinks both for file and folders (nested symlinks)

fixed #13382

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 extractSymlink to iteratively resolve symlinks per path component (with depth limit) and re-anchor absolute targets to the rootfs.
  • Extend the local FS capability interface from ReadLink to ReadLink + Lstat to detect symlinks without relying on ReadLink error semantics.
  • Expand TestOpenUserFile_AbsoluteSymlink with folder-symlink and multi-level symlink cases, and update test helpers to provide Lstat.

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.

Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_test.go Resolved
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from ad0a7d4 to c1f5601 Compare May 12, 2026 03:48
Copilot AI review requested due to automatic review settings May 12, 2026 03:51
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from c1f5601 to 33346e1 Compare May 12, 2026 03:51
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 33346e1 to 2b52a6a Compare May 12, 2026 03:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_test.go Resolved
Copilot AI review requested due to automatic review settings May 12, 2026 03:58
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 40ab8d3 to 967efad Compare May 12, 2026 03:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread pkg/oci/spec_opts.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_opts.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread pkg/oci/spec_opts.go Resolved
Comment thread pkg/oci/spec_test.go Resolved
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 07bd401 to b73cfb2 Compare May 12, 2026 11:21
@jasonjoo2010
jasonjoo2010 requested a review from Copilot May 12, 2026 11:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread pkg/oci/spec_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 87e7489 to ba0ed04 Compare May 13, 2026 04:14
Copilot AI review requested due to automatic review settings June 19, 2026 14:00
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from ba0ed04 to 3241b6b Compare June 19, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 3241b6b to 3721649 Compare June 25, 2026 17:42
@jasonjoo2010

Copy link
Copy Markdown
Author

Hi @dmcgowan

Sorry to tag you directly.
May I ask for a review for this bug fix or could you suggest a name? We updated to v2.2 about 2 months ago but broke the internal android emulator platforms, so we had to rollback. We really need this bug fix and want to enable image volume feature which was enhanced at v2.2.

Thanks

Copilot AI review requested due to automatic review settings June 29, 2026 07:46
@jasonjoo2010
jasonjoo2010 force-pushed the fix/absolute-symlink-folder branch from 3721649 to 1cd257e Compare June 29, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
//

@jasonjoo2010

Copy link
Copy Markdown
Author

Close and move to #13818

@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Pull Request Review Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[Go 1.24] version >=v2.2 fails to create containers from images having /etc symlinked to an absolute path

3 participants