Merge pull request #6256 from thaJeztah/28.x_backport_remove_prompt_privilege_func

[28.x backport] cli/command: remove interactive login prompt from docker push/pull, deprecate RegistryAuthenticationPrivilegedFunc
This commit is contained in:
Sebastiaan van Stijn 2025-08-14 14:43:15 +02:00 committed by GitHub
commit eceff3dbc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 10 additions and 31 deletions

View File

@ -74,8 +74,6 @@ Image index won't be pushed, meaning that other manifests, including attestation
} }
// runPush performs a push against the engine based on the specified options. // runPush performs a push against the engine based on the specified options.
//
//nolint:gocyclo // ignore cyclomatic complexity 17 of func `runPush` is high (> 16) for now.
func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error { func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error {
var platform *ocispec.Platform var platform *ocispec.Platform
out := tui.NewOutput(dockerCli.Out()) out := tui.NewOutput(dockerCli.Out())
@ -115,14 +113,10 @@ To push the complete multi-platform image, remove the --platform flag.
if err != nil { if err != nil {
return err return err
} }
var requestPrivilege registrytypes.RequestAuthConfig
if dockerCli.In().IsTerminal() {
requestPrivilege = command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push")
}
options := image.PushOptions{ options := image.PushOptions{
All: opts.all, All: opts.all,
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege, PrivilegeFunc: nil,
Platform: platform, Platform: platform,
} }

View File

@ -149,13 +149,9 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru
if err != nil { if err != nil {
return err return err
} }
var requestPrivilege registrytypes.RequestAuthConfig
if cli.In().IsTerminal() {
requestPrivilege = command.RegistryAuthenticationPrivilegedFunc(cli, imgRefAndAuth.RepoInfo().Index, "pull")
}
responseBody, err := cli.Client().ImagePull(ctx, reference.FamiliarString(imgRefAndAuth.Reference()), image.PullOptions{ responseBody, err := cli.Client().ImagePull(ctx, reference.FamiliarString(imgRefAndAuth.Reference()), image.PullOptions{
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege, PrivilegeFunc: nil,
All: opts.all, All: opts.all,
Platform: opts.platform, Platform: opts.platform,
}) })

View File

@ -56,7 +56,7 @@ func newInstallCommand(dockerCli command.Cli) *cobra.Command {
return cmd return cmd
} }
func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOptions, cmdName string) (types.PluginInstallOptions, error) { func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOptions) (types.PluginInstallOptions, error) {
// Names with both tag and digest will be treated by the daemon // Names with both tag and digest will be treated by the daemon
// as a pull by digest with a local name for the tag // as a pull by digest with a local name for the tag
// (if no local name is provided). // (if no local name is provided).
@ -90,18 +90,13 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
return types.PluginInstallOptions{}, err return types.PluginInstallOptions{}, err
} }
var requestPrivilege registrytypes.RequestAuthConfig
if dockerCli.In().IsTerminal() {
requestPrivilege = command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, cmdName)
}
options := types.PluginInstallOptions{ options := types.PluginInstallOptions{
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
RemoteRef: remote, RemoteRef: remote,
Disabled: opts.disable, Disabled: opts.disable,
AcceptAllPermissions: opts.grantPerms, AcceptAllPermissions: opts.grantPerms,
AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.remote), AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.remote),
PrivilegeFunc: requestPrivilege, PrivilegeFunc: nil,
Args: opts.args, Args: opts.args,
} }
return options, nil return options, nil
@ -120,7 +115,7 @@ func runInstall(ctx context.Context, dockerCLI command.Cli, opts pluginOptions)
localName = reference.FamiliarString(reference.TagNameOnly(aref)) localName = reference.FamiliarString(reference.TagNameOnly(aref))
} }
options, err := buildPullConfig(ctx, dockerCLI, opts, "plugin install") options, err := buildPullConfig(ctx, dockerCLI, opts)
if err != nil { if err != nil {
return err return err
} }

View File

@ -73,7 +73,7 @@ func runUpgrade(ctx context.Context, dockerCLI command.Cli, opts pluginOptions)
} }
} }
options, err := buildPullConfig(ctx, dockerCLI, opts, "plugin upgrade") options, err := buildPullConfig(ctx, dockerCLI, opts)
if err != nil { if err != nil {
return err return err
} }

View File

@ -36,6 +36,8 @@ const authConfigKey = "https://index.docker.io/v1/"
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info // RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
// for the given command to prompt the user for username and password. // for the given command to prompt the user for username and password.
//
// Deprecated: this function is no longer used and will be removed in the next release.
func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) registrytypes.RequestAuthConfig { func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) registrytypes.RequestAuthConfig {
configKey := getAuthConfigKey(index.Name) configKey := getAuthConfigKey(index.Name)
isDefaultRegistry := configKey == authConfigKey || index.Official isDefaultRegistry := configKey == authConfigKey || index.Official

View File

@ -63,13 +63,9 @@ func runSearch(ctx context.Context, dockerCli command.Cli, options searchOptions
return err return err
} }
var requestPrivilege registrytypes.RequestAuthConfig
if dockerCli.In().IsTerminal() {
requestPrivilege = command.RegistryAuthenticationPrivilegedFunc(dockerCli, indexInfo, "search")
}
results, err := dockerCli.Client().ImageSearch(ctx, options.term, registrytypes.SearchOptions{ results, err := dockerCli.Client().ImageSearch(ctx, options.term, registrytypes.SearchOptions{
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege, PrivilegeFunc: nil,
Filters: options.filter.Value(), Filters: options.filter.Value(),
Limit: options.limit, Limit: options.limit,
}) })

View File

@ -82,10 +82,6 @@ func runSignImage(ctx context.Context, dockerCLI command.Cli, options signOption
return trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), err) return trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), err)
} }
} }
var requestPrivilege registrytypes.RequestAuthConfig
if dockerCLI.In().IsTerminal() {
requestPrivilege = command.RegistryAuthenticationPrivilegedFunc(dockerCLI, imgRefAndAuth.RepoInfo().Index, "push")
}
target, err := createTarget(notaryRepo, imgRefAndAuth.Tag()) target, err := createTarget(notaryRepo, imgRefAndAuth.Tag())
if err != nil || options.local { if err != nil || options.local {
switch err := err.(type) { switch err := err.(type) {
@ -104,7 +100,7 @@ func runSignImage(ctx context.Context, dockerCLI command.Cli, options signOption
} }
responseBody, err := dockerCLI.Client().ImagePush(ctx, reference.FamiliarString(imgRefAndAuth.Reference()), imagetypes.PushOptions{ responseBody, err := dockerCLI.Client().ImagePush(ctx, reference.FamiliarString(imgRefAndAuth.Reference()), imagetypes.PushOptions{
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege, PrivilegeFunc: nil,
}) })
if err != nil { if err != nil {
return err return err