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

Handle the redirect-url flag #1350

Merged
merged 2 commits into from
Jan 29, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ CGO_OVERRIDE?=CGO_ENABLED=0
# which build id in .goreleaser.yml to build
GORELEASER_BUILD_ID?=default

# all go files
SRC=$(shell find . -type f -name '*.go')

all: lint test build

ci: test build
Expand Down Expand Up @@ -107,7 +110,7 @@ bootstra%:
build: $(PREFIX)/$(BINNAME)
@echo "Build Complete!"

$(PREFIX)/$(BINNAME):
$(PREFIX)/$(BINNAME): $(SRC)
$Q mkdir -p $(PREFIX)
$Q $(GOOS_OVERRIDE) $(CGO_OVERRIDE) go build \
-v \
Expand Down
29 changes: 25 additions & 4 deletions utils/cautils/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@
apiEndpoint = u.String()
}

// Get the --redirect-url flag, If passed, we will use this one even if the
// API provides one.
redirectURL := ctx.String("redirect-url")
if redirectURL != "" {
if _, err := url.Parse(redirectURL); err != nil {
return err
}

Check warning on line 228 in utils/cautils/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/bootstrap.go#L224-L228

Added lines #L224 - L228 were not covered by tests
}

// Using public PKI
//nolint:gosec // Variadic URL is considered safe here for the following reasons:
// 1) The input is from the command line, rather than a web form or publicly available API.
Expand All @@ -239,8 +248,9 @@
if err := readJSON(resp.Body, &r); err != nil {
return errors.Wrap(err, "error getting authority data")
}

if r.RedirectURL == "" {
if redirectURL != "" {
r.RedirectURL = redirectURL
} else if r.RedirectURL == "" {

Check warning on line 253 in utils/cautils/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/bootstrap.go#L251-L253

Added lines #L251 - L253 were not covered by tests
r.RedirectURL = "https://smallstep.com/app/teams/sso/success"
}

Expand All @@ -257,8 +267,19 @@
return err
}
}
return bootstrap(ctx, caURL, fingerprint,
withDefaultContextValues(caHostname))

var opts = []bootstrapOption{
withDefaultContextValues(caHostname),
}

if redirectURL := ctx.String("redirect-url"); redirectURL != "" {
if _, err := url.Parse(redirectURL); err != nil {
return err
}
opts = append(opts, withRedirectURL(redirectURL))

Check warning on line 279 in utils/cautils/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/bootstrap.go#L271-L279

Added lines #L271 - L279 were not covered by tests
}

return bootstrap(ctx, caURL, fingerprint, opts...)

Check warning on line 282 in utils/cautils/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/bootstrap.go#L282

Added line #L282 was not covered by tests
}

func getHost(caURL string) (string, error) {
Expand Down