Skip to content

fix: normalize cloud login stack URLs with trailing slashes#6087

Open
oleiade wants to merge 7 commits into
masterfrom
fix/cloud-login-stack-trailing-slash
Open

fix: normalize cloud login stack URLs with trailing slashes#6087
oleiade wants to merge 7 commits into
masterfrom
fix/cloud-login-stack-trailing-slash

Conversation

@oleiade

@oleiade oleiade commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What?

Supersedes #5904 (original fix by @cyphercodes), which is blocked on an unsigned CLA.

Fixes #5894

Why?

Trim trailing / characters from k6 cloud login stack inputs before validating them with Grafana Cloud. A trailing slash was sent to the Cloud auth API as part of X-Stack-Url, which made an otherwise valid stack such as https://my-team.grafana.net/ fail authentication as not found.

Adds unit coverage for stack URL normalization and command coverage for login with a trailing-slash stack URL.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

closes #5904
fixes #5894

Trim trailing `/` characters from `k6 cloud login` stack inputs before
validating them with Grafana Cloud. A trailing slash was sent to the
Cloud auth API as part of `X-Stack-Url`, which made an otherwise valid
stack such as `https://my-team.grafana.net/` fail authentication as not
found.

Adds unit coverage for stack URL normalization and command coverage for
login with a trailing-slash stack URL.

Supersedes #5904 (original fix by @cyphercodes), which is blocked on an
unsigned CLA.

Fixes #5894
@oleiade oleiade requested a review from a team as a code owner June 16, 2026 09:05
@oleiade oleiade requested review from mstoykov and szkiba and removed request for a team June 16, 2026 09:05
@oleiade oleiade self-assigned this Jun 16, 2026
@oleiade oleiade added the bug label Jun 16, 2026
@oleiade oleiade added this to the v2.1.0 milestone Jun 16, 2026
@oleiade oleiade mentioned this pull request Jun 16, 2026
4 tasks
@oleiade oleiade temporarily deployed to azure-trusted-signing June 16, 2026 09:11 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing June 16, 2026 09:14 — with GitHub Actions Inactive
ankur22
ankur22 previously approved these changes Jun 16, 2026
Comment thread internal/cmd/cloud_login.go
@oleiade oleiade temporarily deployed to azure-trusted-signing June 18, 2026 11:03 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing June 18, 2026 11:05 — with GitHub Actions Inactive
Comment thread internal/cmd/cloud_login.go
Comment thread internal/cmd/cloud_login.go Outdated
oleiade and others added 2 commits June 19, 2026 10:30
Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com>
@oleiade oleiade requested review from ankur22 and mstoykov June 19, 2026 08:32
ankur22
ankur22 previously approved these changes Jun 19, 2026
@oleiade oleiade temporarily deployed to azure-trusted-signing June 19, 2026 08:37 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing June 19, 2026 08:38 — with GitHub Actions Inactive

@mstoykov mstoykov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter and some tests are failing :(

A review suggestion switched normalizeStackURL to url.Parse but returned
u.String(), which keeps the path and so preserved the very trailing
slash the function exists to strip (https://team.grafana.net/ stayed
https://team.grafana.net/). Rebuild the URL from scheme and host only,
dropping any path including one or more trailing slashes. Trim trailing
slashes on the slug branch as well, since that trim was dropped from
stripGrafanaNetSuffix.

This also corrects the misindented closing brace that failed the gofmt
lint check.
@oleiade oleiade temporarily deployed to azure-trusted-signing June 19, 2026 11:40 — with GitHub Actions Inactive
@oleiade oleiade temporarily deployed to azure-trusted-signing June 19, 2026 11:42 — with GitHub Actions Inactive
@oleiade oleiade requested a review from mstoykov June 19, 2026 12:08
@oleiade

oleiade commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Add to revert to instantiating a url again to make the tests pass. That allows cleaning up whatever else is the URL to only keep the core stack URL 🙇🏻

@oleiade oleiade requested a review from ankur22 June 19, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

k6 cloud login stack trailing /

4 participants