Repository navigation
fix(api): require INGESTION_API_KEY on the app image before any team exists - #3760
andrewdunndev wants to merge 1 commit into
Conversation
With ENABLE_INGESTION_API_KEY set and no team yet, the preset key made the otlp/hyperdx receiver attach, but authentication followed teams[0], which is absent, so the receiver accepted unauthenticated data.
🦋 Changeset detectedLatest commit: 71a04bb The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@andrewdunndev is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
| expect(tokens).toEqual(bearerTokenVariants(['k1', 'ingest-key'])); | ||
| }); | ||
|
|
||
| it('enforces INGESTION_API_KEY before any team exists when ENABLE_INGESTION_API_KEY is set', () => { |
There was a problem hiding this comment.
🟡 P2 — New no-team test skips the Datadog receiver and never checks that the auth extension is enabled
The fix also changes the Datadog receiver. With ENABLE_DATADOG_RECEIVER set, the bearertokenauth/datadog block at opampController.ts:426 reads the same collectorAuthenticationEnforced, so with no team that receiver now requires the preset key in DD-API-KEY. No test covers this. Separately, the new test checks the tokens and the receiver auth fields but not service.extensions. If the service.extensions = ['bearertokenauth/hyperdx'] assignment were removed, the collector would reject the config and the test would still pass. Add expect(cfg.service.extensions).toContain('bearertokenauth/hyperdx'), plus a ENABLE_DATADOG_RECEIVER + no-team case that asserts bearertokenauth/datadog has tokens ['ingest-key'].
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| teams[0]?.collectorAuthenticationEnforced ?? | ||
| (teams.length === 0 && | ||
| config.ENABLE_INGESTION_API_KEY && | ||
| !!config.INGESTION_API_KEY); |
There was a problem hiding this comment.
🟡 P2 — !!config.INGESTION_API_KEY in the fallback can never change the result
With no team, apiKeys only gets an entry when INGESTION_API_KEY is set (line 193). Auth is only attached inside if (apiKeys.length > 0) (line 353) and the Datadog guard (line 426), so an empty key never reaches either. Drop the clause and keep teams.length === 0 && config.ENABLE_INGESTION_API_KEY.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3 2 posted as inline comment(s) on the changed lines. Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. The change is a correct, narrowly-scoped security fix: nullish coalescing preserves an existing team's explicit 🟡 P2 — recommended
🔵 P3 nitpicks (1)
Reviewers (9): correctness, security, adversarial, testing, maintainability, kieran-typescript, project-standards, previous-comments, learnings-researcher. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Summary
Follow-up to #3633, which merged before this fix reached its branch.
With
ENABLE_INGESTION_API_KEY=trueand no team created yet, the preset key is the only key, so theotlp/hyperdxreceiver is attached. Authentication followsteams[0]?.collectorAuthenticationEnforced, though, and that isundefinedwhen there is no team. The receiver then accepts data without authentication. Before #3633, the app image opened no receiver in that state.The deep review on #3633 raised this.
How to reproduce
Starting point: the app image with the standalone collector in OpAMP supervisor mode, a fresh database with no team, and
INGESTION_API_KEY=preset-keyandENABLE_INGESTION_API_KEY=trueon the API.main: the OpAMP config attachesotlp/hyperdxwith noauthand nobearertokenauth/hyperdxextension.bearertokenauth/hyperdxauthenticator with the preset key's variants. The new test inopampController.test.tscovers this case.How to test on Vercel preview
N/A, non-UI change.
References