Skip to content

Enforce stack info for cloud commands#5833

Open
codebien wants to merge 16 commits intomasterfrom
5651-make-stack-required
Open

Enforce stack info for cloud commands#5833
codebien wants to merge 16 commits intomasterfrom
5651-make-stack-required

Conversation

@codebien
Copy link
Copy Markdown
Contributor

@codebien codebien commented Apr 10, 2026

Closes #5651

What?

This PR makes Stack mandatory value for all cloud commands (k6 cloud run, k6 cloud upload, k6 cloud run --local-execution), completing the deprecation warning introduced in #5420.

Note about differences from the original proposal

The original issue (#5650) proposed making stack input consistent across all input methods — accepting slug, full URL, or numeric ID interchangeably in all contexts. This PR does not fully unify the input formats: K6_CLOUD_STACK_ID and the stackID script option still accept a numeric ID only, while k6 cloud login --stack accepts a slug or full URL. Full input-format unification is left for a following dedicated work (probably after v2 release).

Note about implementation details

  • k6 cloud login now requires both token and stack — passing -t without --stack (or vice versa) fails with an explicit error. The previous behavior of accepting a token-only login and falling back to v1 token validation has been removed.
  • Token masking in --show output: the stored token is now partially masked to avoid accidental credential exposure.
  • Interactive login no longer offers None as a valid nor default stack option — both fields are required.
  • Removed the v1 token-only validation path (/v1/validate-token). All authentication now goes through the v6 API (/cloud/v6/auth), which validates both token and stack together.

@codebien codebien self-assigned this Apr 10, 2026
@codebien codebien added cloud breaking change for PRs that need to be mentioned in the breaking changes section of the release notes labels Apr 10, 2026
@codebien codebien force-pushed the 5651-make-stack-required branch from 26feb10 to bb5cb4a Compare April 10, 2026 19:16
@codebien codebien added this to the v2.0.0 milestone Apr 10, 2026
@codebien codebien temporarily deployed to azure-trusted-signing April 10, 2026 19:22 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 10, 2026 19:24 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 16:07 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 16:14 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 16:16 — with GitHub Actions Inactive
@codebien codebien force-pushed the 5651-make-stack-required branch from 9554623 to ae67d6d Compare April 14, 2026 16:21
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 16:27 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 16:29 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 19:45 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 14, 2026 19:47 — with GitHub Actions Inactive
@codebien codebien force-pushed the 5651-make-stack-required branch from 4878029 to 367ec92 Compare April 15, 2026 10:03
@codebien codebien temporarily deployed to azure-trusted-signing April 15, 2026 10:08 — with GitHub Actions Inactive
@codebien codebien temporarily deployed to azure-trusted-signing April 15, 2026 10:10 — with GitHub Actions Inactive
@codebien codebien marked this pull request as ready for review April 15, 2026 11:31
@codebien codebien requested a review from a team as a code owner April 15, 2026 11:31
@codebien codebien requested review from inancgumus and mstoykov and removed request for a team April 15, 2026 11:31
mstoykov
mstoykov previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM!

On second pass through that it seems that the print only happens on show, so I guess it was already verified , so you can ignore it.

Comment thread internal/cmd/cloud_login.go
@codebien codebien force-pushed the 5651-make-stack-required branch from 11919b8 to 78d3cfe Compare April 15, 2026 16:21
@codebien codebien temporarily deployed to azure-trusted-signing April 15, 2026 16:27 — with GitHub Actions Inactive
mstoykov
mstoykov previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Clean work 👍 Some nits only.

Comment thread internal/cmd/cloud.go
Comment on lines +34 to +49
var errUserUnauthenticated = errors.New("You must first authenticate to run tests in Grafana Cloud." +
" Run the `k6 cloud login` command providing the stack and token, or check the docs" +
" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication" +
" for additional authentication methods.")
" for additional methods.")

// checkCloudLogin verifies that both a token and a stack are configured.
// Together they represent a complete Grafana Cloud login.
func checkCloudLogin(conf cloudapi.Config) error {
if !conf.Token.Valid || conf.Token.String == "" {
return errUserUnauthenticated
}
if !conf.StackID.Valid || conf.StackID.Int64 == 0 {
return errUserUnauthenticated
}
return nil
}
Copy link
Copy Markdown
Contributor

@inancgumus inancgumus Apr 17, 2026

Choose a reason for hiding this comment

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

checkCloudLogin() collapses “missing token” and “missing stack” into the same errUserUnauthenticated, so users with only a token get only a generic authentication message. Would be nicer to return distinct errors, or at least include the specific missing piece in the message.

}

// validateInputs validates a token and a stack if provided
// tokenAuthentication validates a token and a stack
Copy link
Copy Markdown
Contributor

@inancgumus inancgumus Apr 17, 2026

Choose a reason for hiding this comment

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

Tiny nit.

Suggested change
// tokenAuthentication validates a token and a stack
// authenticateUserToken validates a token and a stack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change for PRs that need to be mentioned in the breaking changes section of the release notes cloud

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI Cloud commands: make stack info mandatory

3 participants