DockerCLI/cli/config/credentials
Sebastiaan van Stijn 365e7a5a4e
cli/config/credentials: skip saving config-file if credentials didn't change
Before this change, the config-file was always updated, even if there
were no changes to save. This could cause issues when the config-file
already had credentials set and was read-only for the current user.

For example, on NixOS, this poses a problem because `config.json` is a
symlink to a write-protected file;

    $ readlink ~/.docker/config.json
    /home/username/.config/sops-nix/secrets/ghcr_auth

    $ readlink -f ~/.docker/config.json
    /run/user/1000/secrets.d/28/ghcr_auth

Which causes `docker login` to fail, even if no changes were to be made;

    Error saving credentials: rename /home/derek/.docker/config.json2180380217 /home/username/.config/sops-nix/secrets/ghcr_auth: invalid cross-device link

This patch updates the code to only update the config file if changes
were detected. It there's nothing to save, it skips updating the file,
as well as skips printing the warning about credentials being stored
insecurely.

With this patch applied:

    $ docker login -u yourname
    Password:

    WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/go/credential-store/

    Login Succeeded

    $ docker login -u yourname
    Password:
    Login Succeeded

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d3f6867e4d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-22 00:21:18 +02:00
..
credentials.go Remove docker api dependency from cli/config 2019-01-31 21:25:43 +00:00
default_store.go remove uses of golang.org/x/sys/execabs 2023-05-26 02:03:45 +02:00
default_store_darwin.go defaultCredentialStore: make this a function 2017-09-20 11:14:27 -06:00
default_store_linux.go config/credentials: don't run 'pass' to detect it 2018-06-29 11:38:39 -07:00
default_store_unsupported.go remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00
default_store_windows.go defaultCredentialStore: make this a function 2017-09-20 11:14:27 -06:00
file_store.go cli/config/credentials: skip saving config-file if credentials didn't change 2024-10-22 00:21:18 +02:00
file_store_test.go cli/config/credentials: ConvertToHostname: handle IP-addresses 2024-06-26 15:05:38 +02:00
native_store.go Fix setting ServerAddress property in NativeStore 2023-11-11 14:22:23 +01:00
native_store_test.go Fix setting ServerAddress property in NativeStore 2023-11-11 14:22:23 +01:00