Skip to content

Commit

Permalink
feat: Support basic auth and bearer auth login to registry (#3310)
Browse files Browse the repository at this point in the history
Signed-off-by: Tosone <[email protected]>
  • Loading branch information
tosone authored Nov 7, 2023
1 parent 8ac891f commit 827f24e
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/cosign/cli/options/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type RegistryOptions struct {
KubernetesKeychain bool
RefOpts ReferenceOptions
Keychain Keychain
AuthConfig authn.AuthConfig

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

cmd.Flags().StringVar(&o.AuthConfig.Username, "registry-username", "",
"registry basic auth username")

cmd.Flags().StringVar(&o.AuthConfig.Password, "registry-password", "",
"registry basic auth password")

cmd.Flags().StringVar(&o.AuthConfig.RegistryToken, "registry-token", "",
"registry bearer auth token")

o.RefOpts.AddFlags(cmd)
}

Expand Down Expand Up @@ -113,6 +123,10 @@ func (o *RegistryOptions) GetRegistryClientOpts(ctx context.Context) []remote.Op
github.Keychain,
)
opts = append(opts, remote.WithAuthFromKeychain(kc))
case o.AuthConfig.Username != "" && o.AuthConfig.Password != "":
opts = append(opts, remote.WithAuth(&authn.Basic{Username: o.AuthConfig.Username, Password: o.AuthConfig.Password}))
case o.AuthConfig.RegistryToken != "":
opts = append(opts, remote.WithAuth(&authn.Bearer{Token: o.AuthConfig.RegistryToken}))
default:
opts = append(opts, remote.WithAuthFromKeychain(authn.DefaultKeychain))
}
Expand Down
3 changes: 3 additions & 0 deletions doc/cosign_attach_attestation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_attach_sbom.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_attach_signature.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_attest.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_clean.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_copy.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_dockerfile_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_download_attestation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_download_sbom.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_download_signature.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_generate.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_load.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_manifest_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_sign.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_tree.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions doc/cosign_triangulate.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 827f24e

Please sign in to comment.