Skip to content

fix(api): require INGESTION_API_KEY on the app image before any team exists - #3760

Open
andrewdunndev wants to merge 1 commit into
ClickHouse:mainfrom
andrewdunndev:ai/ingestion-key-enforce-before-team
Open

andrewdunndev wants to merge 1 commit into
ClickHouse:mainfrom
andrewdunndev:ai/ingestion-key-enforce-before-team

Conversation

@andrewdunndev

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #3633, which merged before this fix reached its branch.

With ENABLE_INGESTION_API_KEY=true and no team created yet, the preset key is the only key, so the otlp/hyperdx receiver is attached. Authentication follows teams[0]?.collectorAuthenticationEnforced, though, and that is undefined when there is no team. The receiver then accepts data without authentication. Before #3633, the app image opened no receiver in that state.

  • No team, flag set: authentication is now enforced with the preset key.
  • A team exists: the team's own setting still decides, as before.
  • All-in-one and dev: unchanged.

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-key and ENABLE_INGESTION_API_KEY=true on the API.

  • On main: the OpAMP config attaches otlp/hyperdx with no auth and no bearertokenauth/hyperdx extension.
  • On this branch: both protocols carry the bearertokenauth/hyperdx authenticator with the preset key's variants. The new test in opampController.test.ts covers this case.

How to test on Vercel preview

N/A, non-UI change.

References

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.
@andrewdunndev
andrewdunndev requested a review from a team as a code owner November 22, 2026 02:41
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 71a04bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

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

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

@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', () => {

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.

🟡 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);

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.

🟡 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

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The change is a correct, narrowly-scoped security fix: nullish coalescing preserves an existing team's explicit false, and the new fallback fires only when teams is empty, so it strictly shrinks the window where the otlp/hyperdx receiver opened without authentication. Multiple reviewers independently confirmed no new regression and clean type resolution (boolean).

🟡 P2 — recommended

  • packages/api/src/opamp/controllers/__tests__/opampController.test.ts:202 — the new happy-path test asserts enforcement, but the negative arms of the new branch are untested; the nearest existing empty-key test uses a non-empty team, so the teams.length === 0 arm is never exercised on its false side.
    • Fix: Add a no-team test with ENABLE_INGESTION_API_KEY=true and an empty INGESTION_API_KEY asserting no bearertokenauth/hyperdx extension and no otlp/hyperdx attachment, plus a test with a team whose collectorAuthenticationEnforced is false confirming nullish coalescing keeps enforcement off.
    • testing, correctness, security, maintainability, adversarial
  • packages/api/src/opamp/controllers/opampController.ts:200 — pre-existing and out of scope for this PR: once a team exists with collectorAuthenticationEnforced=false, an opted-in preset INGESTION_API_KEY is still pushed into apiKeys so the receiver attaches, but ?? short-circuits on the defined false and no auth extension is wired, so the preset key accepts unauthenticated ingestion; the fix intentionally covers only the no-team window.
    • Fix: As a follow-up, consider enforcing an opted-in preset key independently of team presence so an operator-set ingestion key is always authenticated, then file the residual as a separate issue.
    • adversarial, security, correctness
🔵 P3 nitpicks (1)
  • packages/api/src/opamp/controllers/opampController.ts:202 — the config.ENABLE_INGESTION_API_KEY && !!config.INGESTION_API_KEY predicate now appears both here and in the apiKeys push block above, so the two sites can drift.
    • Fix: Extract a single const ingestionKeyActive = config.ENABLE_INGESTION_API_KEY && !!config.INGESTION_API_KEY; near the top of buildOtelCollectorConfig and reuse it in both places.

Reviewers (9): correctness, security, adversarial, testing, maintainability, kieran-typescript, project-standards, previous-comments, learnings-researcher.

Testing gaps:

  • No coverage for no-team + ENABLE_INGESTION_API_KEY=true + empty key asserting the receiver stays detached.
  • No coverage asserting a team with collectorAuthenticationEnforced=false is not overridden to enforced when the preset key is opted in.
  • No coverage for the zero-team → first-team-created transition confirming auth remains attached across the boundary.

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

This branch has not been deployed

No deployments
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.

1 participant