Merge pull request #5553 from fluxcd/backport-5551-to-release/v2.7.x

[release/v2.7.x] Fix `flux push artifact` not working with `--provider`
pull/5557/head
Matheus Pimenta 2 weeks ago committed by GitHub
commit 17dae751a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -93,7 +93,7 @@ func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
if diffArtifactArgs.provider.String() != sourcev1.GenericOCIProvider { if diffArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
logger.Actionf("logging in to registry with provider credentials") logger.Actionf("logging in to registry with provider credentials")
opt, err := loginWithProvider(ctx, url, diffArtifactArgs.provider.String()) opt, _, err := loginWithProvider(ctx, url, diffArtifactArgs.provider.String())
if err != nil { if err != nil {
return fmt.Errorf("error during login with provider: %w", err) return fmt.Errorf("error during login with provider: %w", err)
} }

@ -52,7 +52,7 @@ var listArtifactsCmd = &cobra.Command{
Long: `The list command fetches the tags and their metadata from a remote OCI repository. Long: `The list command fetches the tags and their metadata from a remote OCI repository.
The command can read the credentials from '~/.docker/config.json' but they can also be passed with --creds. It can also login to a supported provider with the --provider flag.`, The command can read the credentials from '~/.docker/config.json' but they can also be passed with --creds. It can also login to a supported provider with the --provider flag.`,
Example: ` # List the artifacts stored in an OCI repository Example: ` # List the artifacts stored in an OCI repository
flux list artifact oci://ghcr.io/org/config/app flux list artifacts oci://ghcr.io/org/config/app
`, `,
RunE: listArtifactsCmdRun, RunE: listArtifactsCmdRun,
} }
@ -85,7 +85,7 @@ func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
if listArtifactArgs.provider.String() != sourcev1.GenericOCIProvider { if listArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
logger.Actionf("logging in to registry with provider credentials") logger.Actionf("logging in to registry with provider credentials")
ociOpt, err := loginWithProvider(ctx, url, listArtifactArgs.provider.String()) ociOpt, _, err := loginWithProvider(ctx, url, listArtifactArgs.provider.String())
if err != nil { if err != nil {
return fmt.Errorf("error during login with provider: %w", err) return fmt.Errorf("error during login with provider: %w", err)
} }

@ -20,6 +20,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane" "github.com/google/go-containerregistry/pkg/crane"
"github.com/fluxcd/pkg/auth" "github.com/fluxcd/pkg/auth"
@ -28,14 +29,14 @@ import (
) )
// loginWithProvider gets a crane authentication option for the given provider and URL. // loginWithProvider gets a crane authentication option for the given provider and URL.
func loginWithProvider(ctx context.Context, url, provider string) (crane.Option, error) { func loginWithProvider(ctx context.Context, url, provider string) (crane.Option, authn.Authenticator, error) {
var opts []auth.Option var opts []auth.Option
if provider == azure.ProviderName { if provider == azure.ProviderName {
opts = append(opts, auth.WithAllowShellOut()) opts = append(opts, auth.WithAllowShellOut())
} }
authenticator, err := authutils.GetArtifactRegistryCredentials(ctx, provider, url, opts...) authenticator, err := authutils.GetArtifactRegistryCredentials(ctx, provider, url, opts...)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not login to provider %s with url %s: %w", provider, url, err) return nil, nil, fmt.Errorf("could not login to provider %s with url %s: %w", provider, url, err)
} }
return crane.WithAuth(authenticator), nil return crane.WithAuth(authenticator), authenticator, nil
} }

@ -94,7 +94,7 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
if pullArtifactArgs.provider.String() != sourcev1.GenericOCIProvider { if pullArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
logger.Actionf("logging in to registry with provider credentials") logger.Actionf("logging in to registry with provider credentials")
opt, err := loginWithProvider(ctx, url, pullArtifactArgs.provider.String()) opt, _, err := loginWithProvider(ctx, url, pullArtifactArgs.provider.String())
if err != nil { if err != nil {
return fmt.Errorf("error during login with provider: %w", err) return fmt.Errorf("error during login with provider: %w", err)
} }

@ -225,11 +225,12 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
if provider := pushArtifactArgs.provider.String(); provider != sourcev1.GenericOCIProvider { if provider := pushArtifactArgs.provider.String(); provider != sourcev1.GenericOCIProvider {
logger.Actionf("logging in to registry with provider credentials") logger.Actionf("logging in to registry with provider credentials")
authOpt, err := loginWithProvider(ctx, url, provider) var opt crane.Option
opt, authenticator, err = loginWithProvider(ctx, url, provider)
if err != nil { if err != nil {
return fmt.Errorf("error during login with provider: %w", err) return fmt.Errorf("error during login with provider: %w", err)
} }
opts = append(opts, authOpt) opts = append(opts, opt)
} }
if rootArgs.timeout != 0 { if rootArgs.timeout != 0 {

@ -82,7 +82,7 @@ func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
if tagArtifactArgs.provider.String() != sourcev1.GenericOCIProvider { if tagArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
logger.Actionf("logging in to registry with provider credentials") logger.Actionf("logging in to registry with provider credentials")
opt, err := loginWithProvider(ctx, url, tagArtifactArgs.provider.String()) opt, _, err := loginWithProvider(ctx, url, tagArtifactArgs.provider.String())
if err != nil { if err != nil {
return fmt.Errorf("error during login with provider: %w", err) return fmt.Errorf("error during login with provider: %w", err)
} }

Loading…
Cancel
Save