Skip to content

fix(api-gateway): require a dev-token scope for the playground bypass [lts/v1.6] - #11579

Merged
paveltiunov merged 1 commit into
lts/v1.6from
claude/dev-token-lts-v1.6
Aug 17, 2026
Merged

paveltiunov merged 1 commit into
lts/v1.6from
claude/dev-token-lts-v1.6

Conversation

@paveltiunov

Copy link
Copy Markdown
Member

Backport of the dev-token gate to the v1.6 LTS line. Runtime half only — the control-plane half that mints the scope lives in cubejs-enterprise and has no counterpart in the LTS image.

Upstream: #11571 (merged to master).

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required — n/a, no user-facing config or API surface changes

Description of Changes Made

signedWithPlaygroundAuthSecret unlocks the runtime's developer affordances — meta members hidden by public: false / access policies, generated SQL, pre-aggregation and refresh-key debug info, request ids in errors. It was set purely from the token having verified against playgroundAuthSecret.

In Cube Cloud that secret signs every token a deployment mints, including ones handed to end users and to external BI tools, so the signature alone was never evidence that the bearer is a developer. This requires a dev-token entry in the token's scope as well:

req.signedWithPlaygroundAuthSecret =
  Boolean(internalOptions?.isPlaygroundCheckAuth) && hasDevTokenScope(req.securityContext);

The grant sits in scope alongside the runtime's other per-token grants (sql-runner, agents-config) rather than in a claim of its own.

What is unaffected

  • devMode. All six consumers of the flag on this branch are identical to master's, and every behavioural one already ORs with getEnv('devMode'), so a local cube dev server keeps full visibility. The one site reading the flag alone is the isPlayground field on Load Request logs, which correspondingly now marks only developer traffic.
  • Authentication. The scope gates what a playground-signed token may see, not whether it verifies. /cubejs-system/v1/* still accepts any playground-signed token, so service-to-service callers are unchanged.
  • Self-hosted. Nothing in this repo mints playground tokens, and birdbox sets CUBEJS_PLAYGROUND_AUTH_SECRET equal to CUBEJS_API_SECRET, so main auth wins there and the flag was already false.

Rollout ordering. This is fail-closed, so it must not ship ahead of a control plane that stamps the scope: a runtime deployed first would silently drop hidden-member visibility and generated SQL in the console. The enterprise side is already merged.

Verification

Run locally on this branch, against a from-scratch native build:

Check Result
npx tsc -p . (v1.6 toolchain, src + tests) clean
npx eslint src/gateway.ts test/auth.test.ts clean
jest dist/test/auth.test.js 29/29 passing

The five added cases pin the strictness that matters: no scope at all, a scope carrying only other grants, ['dev-token'] alone and alongside sql-runner, non-array scope shapes (Array.isArray guards before includes, so a bare string cannot match by substring), and a main-secret-signed token carrying the scope. Every pre-existing case still passes — including apiSecrets - playground secret path is unaffected and apiSecrets - coexists with playgroundAuthSecret, the two most likely to catch a semantic drift on this branch.

The gateway.ts diff is byte-identical to what merged on master, and both anchor points are structurally the same here, so this is a true backport rather than a re-implementation.

🤖 Generated with Claude Code

https://claude.ai/code/session_018rhtueaPpiVVNkvA5rWv8X


Generated by Claude Code

Backport of the dev-token gate to the v1.6 LTS line.

`signedWithPlaygroundAuthSecret` unlocks developer affordances — meta
members hidden by `public: false` / access policies, generated SQL,
pre-aggregation and refresh-key debug info, request ids — and was set
purely from the token having verified against `playgroundAuthSecret`.
In Cube Cloud that secret signs every token a deployment mints, including
ones handed to end users and to external BI tools, so the signature alone
was never evidence that the bearer is a developer. Require a `dev-token`
entry in the token's `scope` as well; the control plane adds it only for
the developer-facing console surfaces and only for users with
deployment-manage permissions.

devMode is unaffected: all six consumers of the flag on this branch are
identical to master's, and every behavioural one already ORs with
`getEnv('devMode')`, so a local `cube dev` server keeps full visibility.
Authentication is unchanged — the scope gates what a playground-signed
token may see, not whether it verifies, so `/cubejs-system/v1/*` still
accepts any playground-signed token.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018rhtueaPpiVVNkvA5rWv8X
@paveltiunov
paveltiunov requested a review from a team as a code owner August 17, 2026 17:29
@github-actions github-actions Bot added the javascript Pull requests that update Javascript code label Aug 17, 2026
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.75%. Comparing base (e77c444) to head (87457f8).
⚠️ Report is 1 commits behind head on lts/v1.6.

Files with missing lines Patch % Lines
packages/cubejs-api-gateway/src/gateway.ts 71.42% 1 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (e77c444) and HEAD (87457f8). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (e77c444) HEAD (87457f8)
cubesql 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##           lts/v1.6   #11579       +/-   ##
=============================================
- Coverage     79.17%   58.75%   -20.42%     
=============================================
  Files           481      224      -257     
  Lines         97583    17907    -79676     
  Branches       3652     3655        +3     
=============================================
- Hits          77260    10522    -66738     
+ Misses        19800     6861    -12939     
- Partials        523      524        +1     
Flag Coverage Δ
cube-backend 58.75% <71.42%> (+<0.01%) ⬆️
cubesql ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paveltiunov
paveltiunov merged commit ff7c674 into lts/v1.6 Aug 17, 2026
76 of 80 checks passed
@paveltiunov
paveltiunov deleted the claude/dev-token-lts-v1.6 branch August 17, 2026 19:03

This branch was successfully deployed

1 active deployment
Preview — 87457f81 Deployed Aug 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy