Skip to content

[release/1.5] cherry-pick: windows: Use GetFinalPathNameByHandle for ResolveSymbolicLink#5537

Merged
dmcgowan merged 1 commit intocontainerd:release/1.5from
kevpar:symlink-1.5
May 27, 2021
Merged

[release/1.5] cherry-pick: windows: Use GetFinalPathNameByHandle for ResolveSymbolicLink#5537
dmcgowan merged 1 commit intocontainerd:release/1.5from
kevpar:symlink-1.5

Conversation

@kevpar
Copy link
Copy Markdown
Member

@kevpar kevpar commented May 26, 2021

Cherry-pick of #5411 for release/1.5
Trying again since #5454 had the wrong target branch. :)

This change splits the definition of pkg/cri/os.ResolveSymbolicLink by
platform (windows/!windows), and switches to an alternate implementation
for Windows. This aims to fix the issue described in #5405.

The previous implementation which just called filepath.EvalSymlinks has
historically had issues on Windows. One of these issues we were able to
fix in Go, but EvalSymlinks's behavior is not well specified on
Windows, and there could easily be more issues in the future, so it
seems prudent to move to a separate implementation for Windows.

The new implementation uses the Windows GetFinalPathNameByHandle API,
which takes a handle to an open file or directory and some flags, and
returns the "real" name for the object. See comments in the code for
details on the implementation.

I have tested this change with a variety of mounts and everything seems
to work as expected. Functions that make incorrect assumptions on what a
Windows path can look like may have some trouble with the \?\ path
syntax. For instance EvalSymlinks fails when given a \?\UNC\ path. For
this reason, the resolvePath implementation modifies the returned path
to translate to the more common form (\?\UNC\server\share ->
\server\share).

Signed-off-by: Kevin Parsons kevpar@microsoft.com
(cherry picked from commit b0d3b35)
Signed-off-by: Kevin Parsons kevpar@microsoft.com

This change splits the definition of pkg/cri/os.ResolveSymbolicLink by
platform (windows/!windows), and switches to an alternate implementation
for Windows. This aims to fix the issue described in containerd#5405.

The previous implementation which just called filepath.EvalSymlinks has
historically had issues on Windows. One of these issues we were able to
fix in Go, but EvalSymlinks's behavior is not well specified on
Windows, and there could easily be more issues in the future, so it
seems prudent to move to a separate implementation for Windows.

The new implementation uses the Windows GetFinalPathNameByHandle API,
which takes a handle to an open file or directory and some flags, and
returns the "real" name for the object. See comments in the code for
details on the implementation.

I have tested this change with a variety of mounts and everything seems
to work as expected. Functions that make incorrect assumptions on what a
Windows path can look like may have some trouble with the \\?\ path
syntax. For instance EvalSymlinks fails when given a \\?\UNC\ path. For
this reason, the resolvePath implementation modifies the returned path
to translate to the more common form (\\?\UNC\server\share ->
\\server\share).

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
(cherry picked from commit b0d3b35)
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented May 26, 2021

Build succeeded.

Copy link
Copy Markdown
Member

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

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

LGTM

@dmcgowan dmcgowan merged commit d1119dc into containerd:release/1.5 May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants