Skip to content
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

Remove leading slash in Windows path #3304

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

TinaMor
Copy link
Contributor

@TinaMor TinaMor commented Aug 13, 2024

PR Description

This PR resolves #2966

Background

On Windows, the LogURIGenerator() function in containerd/containerd fails when it checks if the logURI path is absolute. This is due to the leading slash in the parsed logURI, which causes the check to fail and results in an error, ultimately leading to the command's failure.

The logURI parameter is a binary path formatted as a URI, for example:

"binary:///C:/Program Files/nerdctl.exe?_NERDCTL_INTERNAL_LOGGING=C%3A%5CProgramData%5Cnerdctl%5C052055e3"

When parsed with url.Parse(logURI), the resulting u.Path is:

"/C:/Program Files/nerdctl.exe"

The leading slash is incorrect for Windows paths and causes issues when the path is later checked for being absolute.

Solution

To resolve this issue, the leading slash must be removed from the u.Path before the absolute path check is performed. This ensures the path is correctly recognized as an absolute path on Windows systems.

Additional tasks

Remove Windows check in TestRunWithTtyAndDetached. 'json-file' logging for Windows implemented by PR #1468 .

func TestRunWithTtyAndDetached(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("json-file log driver is not yet implemented on Windows")
}

@TinaMor TinaMor marked this pull request as draft August 13, 2024 13:56
@TinaMor
Copy link
Contributor Author

TinaMor commented Aug 13, 2024

Waiting for the changes from Set stderr to empty string when using terminal on Windows to be available in the latest Containerd v2 release.

@TinaMor TinaMor changed the title Fix Windows Path Handling in LogURIGenerator() Remove leading slash in Windows path Aug 13, 2024
@apostasie
Copy link
Contributor

Hey @TinaMor

2.0.0 rc4 just dropped and we moved nerdctl (and testing env) to it.

Curious if the change in containerd got in?

@TinaMor TinaMor marked this pull request as ready for review September 6, 2024 14:45
@AkihiroSuda AkihiroSuda added the platform/Windows/Non-WSL2 Microsoft Windows (non-WSL2) label Sep 8, 2024
ioCreator = cio.TerminalBinaryIO(u.Path, map[string]string{
parsedPath := u.Path
// For Windows, remove the leading slash
if (runtime.GOOS == "windows") && (strings.HasPrefix(parsedPath, "/")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right place to remove the extra slash?

From the report "binary:///C:/Program Files/nerdctl.exe?_NERDCTL_INTERNAL_LOGGING=C%3A%5CProgramData%5Cnerdctl%5C052055e3" it seems it has 3 slashes in front of the file path: binary:///

Where is that generated and why does it have three slashes?

Copy link
Contributor Author

@TinaMor TinaMor Sep 10, 2024

Choose a reason for hiding this comment

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

The path is prefixed with "/" in containerd/containerd LogURIGenerator(). See the comment in LogURIGenerator().

Copy link
Contributor

Choose a reason for hiding this comment

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

ah interesting, it is expected that url.parse returns /c:/path golang/go@844b625

This actually feels like a bug in cio.TerminalBinaryIO when it is checking abs path logic but I there might be some nuance that I am missing.

Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Sep 18, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 2a388a7 into containerd:main Sep 18, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/Windows/Non-WSL2 Microsoft Windows (non-WSL2)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running a Windows container with --detach and --tty results in "nerdctl.exe must be absolute" error message
5 participants