Skip to content
Merged
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,24 @@ 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', () => {
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
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',
});
expect(cfg.service.extensions).toContain('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 Expand Up @@ -249,6 +267,24 @@ describe('opampController', () => {
expect(cfg.service.pipelines['logs/in'].receivers).toContain('datadog');
});

it('requires INGESTION_API_KEY on the datadog receiver before any team exists when ENABLE_INGESTION_API_KEY is set', () => {
configState.ENABLE_DATADOG_RECEIVER = true;
configState.ENABLE_INGESTION_API_KEY = true;
configState.INGESTION_API_KEY = 'ingest-key';

const cfg = buildOtelCollectorConfig([]);

expect(cfg.extensions['bearertokenauth/datadog']).toEqual({
header: 'DD-API-KEY',
scheme: '',
tokens: ['ingest-key'],
});
expect(cfg.receivers.datadog?.auth).toEqual({
authenticator: 'bearertokenauth/datadog',
});
expect(cfg.service.extensions).toContain('bearertokenauth/datadog');
});

it('leaves the datadog receiver unauthenticated when no team API keys exist', () => {
configState.ENABLE_DATADOG_RECEIVER = true;

Expand Down
5 changes: 4 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,11 @@ 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);

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