Skip to content

Commit 827f24e

Browse files
authored
feat: Support basic auth and bearer auth login to registry (#3310)
Signed-off-by: Tosone <[email protected]>
1 parent 8ac891f commit 827f24e

21 files changed

+74
-0
lines changed

cmd/cosign/cli/options/registry.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type RegistryOptions struct {
4444
KubernetesKeychain bool
4545
RefOpts ReferenceOptions
4646
Keychain Keychain
47+
AuthConfig authn.AuthConfig
4748

4849
// RegistryClientOpts allows overriding the result of GetRegistryClientOpts.
4950
RegistryClientOpts []remote.Option
@@ -62,6 +63,15 @@ func (o *RegistryOptions) AddFlags(cmd *cobra.Command) {
6263
cmd.Flags().BoolVar(&o.KubernetesKeychain, "k8s-keychain", false,
6364
"whether to use the kubernetes keychain instead of the default keychain (supports workload identity).")
6465

66+
cmd.Flags().StringVar(&o.AuthConfig.Username, "registry-username", "",
67+
"registry basic auth username")
68+
69+
cmd.Flags().StringVar(&o.AuthConfig.Password, "registry-password", "",
70+
"registry basic auth password")
71+
72+
cmd.Flags().StringVar(&o.AuthConfig.RegistryToken, "registry-token", "",
73+
"registry bearer auth token")
74+
6575
o.RefOpts.AddFlags(cmd)
6676
}
6777

@@ -113,6 +123,10 @@ func (o *RegistryOptions) GetRegistryClientOpts(ctx context.Context) []remote.Op
113123
github.Keychain,
114124
)
115125
opts = append(opts, remote.WithAuthFromKeychain(kc))
126+
case o.AuthConfig.Username != "" && o.AuthConfig.Password != "":
127+
opts = append(opts, remote.WithAuth(&authn.Basic{Username: o.AuthConfig.Username, Password: o.AuthConfig.Password}))
128+
case o.AuthConfig.RegistryToken != "":
129+
opts = append(opts, remote.WithAuth(&authn.Bearer{Token: o.AuthConfig.RegistryToken}))
116130
default:
117131
opts = append(opts, remote.WithAuthFromKeychain(authn.DefaultKeychain))
118132
}

doc/cosign_attach_attestation.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_attach_sbom.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_attach_signature.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_attest.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_clean.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_copy.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_dockerfile_verify.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_download_attestation.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_download_sbom.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)