Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-1.14] fix(crank/xpkg): push properly retrieve upbound credentials #5381

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/crank/xpkg/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/logging"

"github.com/crossplane/crossplane/internal/xpkg"
"github.com/crossplane/crossplane/internal/xpkg/upbound"
"github.com/crossplane/crossplane/internal/xpkg/upbound/credhelper"
)

Expand Down Expand Up @@ -65,6 +66,9 @@ type pushCmd struct {
// Flags. Keep sorted alphabetically.
PackageFiles []string `short:"f" type:"existingfile" placeholder:"PATH" help:"A comma-separated list of xpkg files to push."`

// Common Upbound API configuration.
upbound.Flags `embed:""`

// Internal state. These aren't part of the user-exposed CLI structure.
fs afero.Fs
}
Expand Down Expand Up @@ -93,6 +97,11 @@ func (c *pushCmd) AfterApply() error {

// Run runs the push cmd.
func (c *pushCmd) Run(logger logging.Logger) error { //nolint:gocyclo // This feels easier to read as-is.
upCtx, err := upbound.NewFromFlags(c.Flags, upbound.AllowMissingProfile())
if err != nil {
return err
}

tag, err := name.NewTag(c.Package, name.WithDefaultRegistry(DefaultRegistry))
if err != nil {
return errors.Wrapf(err, errFmtNewTag, c.Package)
Expand All @@ -114,7 +123,11 @@ func (c *pushCmd) Run(logger logging.Logger) error { //nolint:gocyclo // This fe
}

kc := authn.NewMultiKeychain(
authn.NewKeychainFromHelper(credhelper.New()),
authn.NewKeychainFromHelper(credhelper.New(
credhelper.WithLogger(logger),
credhelper.WithProfile(upCtx.ProfileName),
credhelper.WithDomain(upCtx.Domain.Hostname()),
)),
authn.DefaultKeychain,
)

Expand Down
4 changes: 4 additions & 0 deletions internal/xpkg/upbound/credhelper/credhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ func (h *Helper) List() (map[string]string, error) {
// Get gets credentials for the supplied server.
func (h *Helper) Get(serverURL string) (string, string, error) {
if !strings.Contains(serverURL, h.domain) {
h.log.Debug("Supplied server URL is not supported by this credentials helper", "serverURL", serverURL, "domain", h.domain)
return "", "", errors.New(errUnsupportedDomain)
}
h.log.Debug("Getting credentials for server", "serverURL", serverURL)
if err := h.src.Initialize(); err != nil {
return "", "", errors.Wrap(err, errInitializeSource)
}
Expand All @@ -124,11 +126,13 @@ func (h *Helper) Get(serverURL string) (string, string, error) {
}
var p config.Profile
if h.profile == "" {
h.log.Debug("No profile specified, using default profile")
_, p, err = conf.GetDefaultUpboundProfile()
if err != nil {
return "", "", errors.Wrap(err, errGetDefaultProfile)
}
} else {
h.log.Debug("Using specified profile", "profile", h.profile)
p, err = conf.GetUpboundProfile(h.profile)
if err != nil {
return "", "", errors.Wrap(err, errGetProfile)
Expand Down