From d56f6478251081ee0d51cd185987ece8552f55f9 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 20 Feb 2023 13:57:15 +0100 Subject: [PATCH] pkg/auth: add `NoWriteBack` option Add an option to not write back the credentials to the authfile or any credential helper. The `/auth` compat endpoint of Podman is currently not using this code here which ultimately led to normalization errors surfacing in containers/podman/issues/17571. The new option allows the endpoint to use this function without writing back the credentials. Signed-off-by: Valentin Rothberg --- pkg/auth/auth.go | 18 +++++++++--------- pkg/auth/cli.go | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 826baf93e..5cec04916 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -160,16 +160,16 @@ func Login(ctx context.Context, systemContext *types.SystemContext, opts *LoginO } if err = docker.CheckAuth(ctx, systemContext, username, password, registry); err == nil { - // Write the new credentials to the authfile - desc, err := config.SetCredentials(systemContext, key, username, password) - if err != nil { - return err - } - if opts.Verbose { - fmt.Fprintln(opts.Stdout, "Used: ", desc) + if !opts.NoWriteBack { + // Write the new credentials to the authfile + desc, err := config.SetCredentials(systemContext, key, username, password) + if err != nil { + return err + } + if opts.Verbose { + fmt.Fprintln(opts.Stdout, "Used: ", desc) + } } - } - if err == nil { fmt.Fprintln(opts.Stdout, "Login Succeeded!") return nil } diff --git a/pkg/auth/cli.go b/pkg/auth/cli.go index 7266bf48b..26727f35c 100644 --- a/pkg/auth/cli.go +++ b/pkg/auth/cli.go @@ -26,6 +26,7 @@ type LoginOptions struct { Stdin io.Reader // set to os.Stdin Stdout io.Writer // set to os.Stdout AcceptUnspecifiedRegistry bool // set to true if allows login with unspecified registry + NoWriteBack bool // set to true to not write the credentials to the authfile/cred helpers } // LogoutOptions represents the results for flags in logout