Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/ingestion-key-enforce-before-team.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperdx/api': patch
---

fix: require `INGESTION_API_KEY` on the app image before any team exists

With `ENABLE_INGESTION_API_KEY` set and no team created yet, the collector's OTLP
receiver accepted data without authentication. It now requires the preset key.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ describe('opampController', () => {
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

configState.ENABLE_INGESTION_API_KEY = true;
configState.INGESTION_API_KEY = 'ingest-key';

const cfg = buildOtelCollectorConfig([]);

expect(cfg.extensions['bearertokenauth/hyperdx'].tokens).toEqual(
bearerTokenVariants(['ingest-key']),
);
expect(cfg.receivers['otlp/hyperdx']?.protocols.grpc.auth).toEqual({
authenticator: 'bearertokenauth/hyperdx',
});
expect(cfg.receivers['otlp/hyperdx']?.protocols.http.auth).toEqual({
authenticator: 'bearertokenauth/hyperdx',
});
});

it('adds nothing when ENABLE_INGESTION_API_KEY is set but INGESTION_API_KEY is empty', () => {
configState.ENABLE_INGESTION_API_KEY = true;

Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/opamp/controllers/opampController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ export const buildOtelCollectorConfig = (
}
}

// Before any team exists, an opted-in INGESTION_API_KEY is the only key,
// so enforce it rather than open the receiver without auth.
const collectorAuthenticationEnforced =
teams[0]?.collectorAuthenticationEnforced;
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


const otelCollectorConfig: CollectorConfig = {
extensions: {},
Expand Down
Loading