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

dockerConfigFile.GetCredentialsStore.Store faulty symlink resolution behavior #3413

Open
apostasie opened this issue Sep 4, 2024 · 5 comments

Comments

@apostasie
Copy link
Contributor

apostasie commented Sep 4, 2024

Description

When DOCKER_CONFIG points to a directory that does contain a relative, dangling config.json symlink, Docker credentials store will (apparently) wrongly resolve the link to the current working directory.

This can be reproduced with the following:

mkdir -p /tmp/foo
ln -s doesnotexist /tmp/foo/config.json
cd ~
DOCKER_CONFIG=/tmp/foo nerdctl login
cat ~/doesnotexist
ln -s /tmp/foo

This does suggest there is a bug in moby/docker somewhere where readlink is used to resolve against pwd instead of the parent dir (/tmp/foo).

In turn, if, for some reason, the file cannot be created in the current working directory (for example if it is readonly), this will error in a very baffling way with a very confusing message:

rename /tmp/TestBrokenCredentialsStore705218110/008/docker-config2430087685/config.json2911426040 doesnotexist: invalid cross-device link

First spotted in #3293 (review) although at the time I was unable to diagnose it.

While this is very likely a docker bug, we need to fix these tests to deal with that.

Steps to reproduce the issue

No response

Describe the results you received and expected

na

What version of nerdctl are you using?

main

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

None

Host information

No response

@apostasie apostasie added the kind/unconfirmed-bug-claim Unconfirmed bug claim label Sep 4, 2024
apostasie added a commit to apostasie/nerdctl that referenced this issue Sep 4, 2024
As described in containerd#3413 there seems to be a fault
in docker credentials store that makes relative symlinks resolve to pwd instead of where they are.
This in turn will break our test if the current working directory is read-only (typical with Lima).
This changeset does Chdir to the parent temp directory so we can workaround that problem.

Signed-off-by: apostasie <[email protected]>
@apostasie
Copy link
Contributor Author

This ticket is both about making sure our tests work (fixed by the linked PR), but we could keep it around as "external" for now as well - or if somebody wants to, we might further diagnose it and report it to moby.

apostasie added a commit to apostasie/nerdctl that referenced this issue Sep 4, 2024
As described in containerd#3413 there seems to be a fault
in docker credentials store that makes relative symlinks resolve to pwd instead of where they are.
This in turn will break our test if the current working directory is read-only (typical with Lima).
This changeset does Chdir to the parent temp directory so we can workaround that problem.

Signed-off-by: apostasie <[email protected]>
@apostasie
Copy link
Contributor Author

apostasie commented Sep 5, 2024

@apostasie
Copy link
Contributor Author

@thaJeztah you might want to fix this ^.

Readlink does not resolve the path for you, and by the time you write it, it will be relative to cwd.

You might consider using instead filepath.EvalSymlinks (on the full path) - but then, this will error if the target does not exist, so, you have to account for that as well... maybe just os.WriteFile("") the file to ensure it exists... will work in some cases...

But then... you do MkdirAll before resolving the links (https://github.com/docker/cli/blob/master/cli/config/configfile/file.go#L144-L147), so... you will fail mkdir-ing where the link(s) actually resolve...

I certainly appreciate that an atomic write is the right thing to do, but in that case, you just cannot get away with it with just readlink...

This is not exactly trivial...

Let me know if I am missing something and/or if there is a simpler way to deal with this in go...

@AkihiroSuda AkihiroSuda added kind/external and removed kind/unconfirmed-bug-claim Unconfirmed bug claim labels Sep 5, 2024
@thaJeztah
Copy link
Member

@apostasie thanks! Yes, looks like a tricky one. Could you open a ticket for this in docker/cli ?

@apostasie
Copy link
Contributor Author

@apostasie thanks! Yes, looks like a tricky one. Could you open a ticket for this in docker/cli ?

Sure, will do eventually - it might take me some time though (busy with here), so feel free to carry it if you do have bandwidth now.

Thanks @thaJeztah !

@apostasie apostasie changed the title dockerConfigFile.GetCredentialsStore.Store likely faulty symlink behavior dockerConfigFile.GetCredentialsStore.Store faulty symlink resolution behavior Sep 10, 2024
apostasie added a commit to apostasie/nerdctl that referenced this issue Sep 10, 2024
As described in containerd#3413 there seems to be a fault
in docker credentials store that makes relative symlinks resolve to pwd instead of where they are.
This in turn will break our test if the current working directory is read-only (typical with Lima).
This changeset does Chdir to the parent temp directory so we can workaround that problem.

Signed-off-by: apostasie <[email protected]>
apostasie added a commit to apostasie/nerdctl that referenced this issue Sep 17, 2024
As described in containerd#3413 there seems to be a fault
in docker credentials store that makes relative symlinks resolve to pwd instead of where they are.
This in turn will break our test if the current working directory is read-only (typical with Lima).
This changeset does Chdir to the parent temp directory so we can workaround that problem.

Signed-off-by: apostasie <[email protected]>
apostasie added a commit to apostasie/nerdctl that referenced this issue Sep 23, 2024
As described in containerd#3413 there seems to be a fault
in docker credentials store that makes relative symlinks resolve to pwd instead of where they are.
This in turn will break our test if the current working directory is read-only (typical with Lima).
This changeset does Chdir to the parent temp directory so we can workaround that problem.

Signed-off-by: apostasie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants