Skip to content

feat(websocket): support JWT secret rotation - #43524

Merged
villebro merged 7 commits into
apache:gaq-to-gtffrom
villebro:gaq-websocket-jwt-secret-rotation
Aug 25, 2026
Merged

villebro merged 7 commits into
apache:gaq-to-gtffrom
villebro:gaq-websocket-jwt-secret-rotation

Conversation

@villebro

@villebro villebro commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Adds verify-only websocket JWT secret rotation support to the superset-websocket service. The Flask app continues minting realtime cookies with WEBSOCKET_JWT_SECRET. The Node websocket service validates against its active verifier secret (JWT_SECRET / jwtSecret) and, during rotation, an optional previous verify-only key (PREVIOUS_JWT_SECRET / previousJwtSecret). The previous key is service-local websocket config; the Flask app does not need it because it only mints new tokens with the active secret.

This also renames the Superset-side enable flag from ENABLE_WEBSOCKET to WEBSOCKET_ENABLE so the websocket config surface is consistently WEBSOCKET_* before the feature branch merges.

The frontend realtime client now treats duplicate initialization with the same websocket config as idempotent. This avoids closing and replacing an already-active socket during bootstrap, which otherwise produces noisy browser console failures even though the replacement socket succeeds.

The websocket server now emits a debug log after forwarding a message to local sockets. The log includes the outbound browser channel and socket count, but not the payload.

The async chart-data middleware also stays idle until a chart request actually returns HTTP 202. Websocket mode still keeps polling as the correctness fallback while waiting for async tasks, but it no longer performs a startup /api/v1/task/status_changes request when there is no async chart activity.

This now also fixes chained GTF task execution for async chart-data queries. Dependent tasks are enqueued immediately and wait for prerequisite tasks before claiming execution. A dependent worker can load a prerequisite as pending while another worker later commits it as success; without a forced refresh, SQLAlchemy can return the stale identity-map object forever and the dependent task never reaches the executor body. BaseDAO now supports an opt-in force_fetch query mode, and TaskDAO enables it by default because task rows are cross-worker mutable state.

Chained chart-data tasks also carry the output metadata needed by contribution-mode queries. Contribution totals normalization runs on the QueryContext before any query_cache_key is computed. The totals task publishes its actual DATA cache key in task payload; dependent contribution tasks read prerequisite payloads via TaskContext.get_dependency_payloads() and use that key to inject totals. Contribution post-processing without a synthetic totals query, such as pie-chart share calculations, remains local and does not read dependency payloads. This intentionally exposes only dependency payload dictionaries, not full task ORM objects, keeping the internal DAG API limited while still allowing tasks to pass small pieces of context forward.

One compatibility compromise remains here: serialized query payloads can carry an internal preserve_null_row_limit marker so a normalized synthetic totals query with row_limit: null rehydrates with the same cache key, while ordinary external/query-context row_limit: null values keep the previous default-limit behavior. This is not ideal API shape, but it keeps the GAQ-to-GTF bridge narrow and avoids regressions in the legacy query-context interface. The future Semantic Query based interface should represent this directly instead of inheriting this shortcoming.

The docs now spell out the Kubernetes deployment model: run superset-websocket as a horizontally scalable, stateless Deployment/Service, not a singleton. Each browser socket is owned by exactly one replica after HTTP Upgrade; Redis Pub/Sub events are broadcast to all websocket replicas, and each replica fans out only to matching sockets it owns locally. Sticky sessions are not required, and polling remains the correctness backstop for reconnects/drains.

A separate WEBSOCKET_K8S_OPERATOR_REQUIREMENTS.md captures the operator requirements for ingress, auth config, secret rotation, short-lived sockets, draining, Redis, and HPA/scaling tradeoffs.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

From the repo root:

pytest tests/unit_tests/websocket/test_channel.py tests/unit_tests/views/test_base.py tests/unit_tests/initialization/check_websocket_secret_test.py
pytest tests/unit_tests/daos/test_tasks.py tests/unit_tests/tasks/test_dependencies.py tests/unit_tests/tasks/test_manager.py tests/unit_tests/databases/dao/dao_tests.py tests/unit_tests/semantic_layers/dao_test.py
pytest tests/unit_tests/tasks/test_async_queries.py tests/unit_tests/tasks/test_dependencies.py tests/unit_tests/common/test_query_object_factory.py tests/unit_tests/common/test_query_serialization.py tests/unit_tests/common/test_query_context_processor.py tests/unit_tests/common/test_query_context_processor_timing.py
npm --prefix superset-websocket run test
npm --prefix superset-websocket run type

From superset-frontend/:

npm run test -- src/middleware/realtime.test.ts src/middleware/asyncEvent.test.ts

Also run:

pre-commit run

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot Bot added authentication Related to authentication doc Namespace | Anything related to documentation infra:webserver Infra setup and configuration related to webserver labels Aug 25, 2026
@bito-code-review

bito-code-review Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at [email protected].

@github-actions github-actions Bot added dependencies:npm and removed doc Namespace | Anything related to documentation labels Aug 25, 2026
@netlify

netlify Bot commented Aug 25, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit dc11316
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a8de61f13c688000873865d
😎 Deploy Preview https://deploy-preview-43524--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +504 to +506
const acceptedSecrets = [opts.jwtSecret, opts.previousJwtSecret].filter(
secret => secret.length > 0,
);

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.

Suggestion: Configuration loaded from JSON is not runtime-validated, so a null previousJwtSecret bypasses the optional startup check and then causes every upgrade attempt to throw when the filter accesses secret.length. Normalize non-string values to an empty secret or reject the configuration before requests are handled. [null pointer]

Severity Level: Major ⚠️
- ❌ All WebSocket upgrades fail with malformed rotation configuration.
- ❌ Realtime browser updates cannot establish socket connections.
- ⚠️ Polling remains available as the documented correctness backstop.

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-websocket/src/index.ts
**Line:** 504:506
**Comment:**
	*Null Pointer: Configuration loaded from JSON is not runtime-validated, so a null `previousJwtSecret` bypasses the optional startup check and then causes every upgrade attempt to throw when the filter accesses `secret.length`. Normalize non-string values to an empty secret or reject the configuration before requests are handled.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue regarding a potential null pointer when previousJwtSecret is null is valid. To resolve this, you should ensure the configuration is normalized to an empty string if it is null or undefined before it is used in the filter.

Here is a concise fix for the configuration loading logic:

// Ensure previousJwtSecret is a string, defaulting to an empty string if null/undefined
config.previousJwtSecret = config.previousJwtSecret || '';

I have checked the PR comments and there are no other actionable suggestions in the provided context. Would you like me to fetch all comments to validate and implement fixes for any remaining issues?

superset-websocket/src/index.ts

config.previousJwtSecret = config.previousJwtSecret || '';

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.80531% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.92%. Comparing base (5fda736) to head (8112a53).
⚠️ Report is 69 commits behind head on gaq-to-gtf.

Files with missing lines Patch % Lines
superset/common/query_context.py 84.21% 2 Missing and 1 partial ⚠️
superset/common/query_context_processor.py 66.66% 0 Missing and 1 partial ⚠️
superset/daos/semantic_layer.py 50.00% 1 Missing ⚠️
superset/initialization/__init__.py 50.00% 0 Missing and 1 partial ⚠️
superset/tasks/async_queries.py 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           gaq-to-gtf   #43524      +/-   ##
==============================================
+ Coverage       78.89%   78.92%   +0.03%     
==============================================
  Files            2884     2889       +5     
  Lines          165429   165672     +243     
  Branches        38218    38153      -65     
==============================================
+ Hits           130514   130759     +245     
- Misses          32444    32454      +10     
+ Partials         2471     2459      -12     
Flag Coverage Δ
hive 38.10% <25.25%> (+0.04%) ⬆️
mysql 57.64% <43.43%> (-0.01%) ⬇️
postgres 57.67% <43.43%> (+<0.01%) ⬆️
presto 40.03% <30.30%> (+0.05%) ⬆️
python 83.55% <92.92%> (-0.01%) ⬇️
sqlite 57.36% <43.43%> (-0.01%) ⬇️
superset-extensions-cli 90.57% <ø> (?)
unit 73.67% <91.91%> (-0.06%) ⬇️

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.

@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Failed - Technical Failure

Bito encountered technical difficulties while generating code feedback . To retry, type /review in a comment and save. If the issue persists, contact [email protected] and provide the following details:

Agent Run ID: d97a3f34-581d-45c1-97e6-e865743cb0a1

@villebro
villebro merged commit 9b7540a into apache:gaq-to-gtf Aug 25, 2026
62 of 63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

authentication Related to authentication dependencies:npm infra:webserver Infra setup and configuration related to webserver size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant