From 71a04bbbf797dec4c480a97ed64afdd396e94f9e Mon Sep 17 00:00:00 2001 From: Andrew Dunn Date: Sat, 21 Nov 2026 10:04:11 -0500 Subject: [PATCH] fix(api): enforce the preset ingestion key before any team exists 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/ingestion-key-enforce-before-team.md | 8 ++++++++ .../__tests__/opampController.test.ts | 17 +++++++++++++++++ .../src/opamp/controllers/opampController.ts | 7 ++++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .changeset/ingestion-key-enforce-before-team.md diff --git a/.changeset/ingestion-key-enforce-before-team.md b/.changeset/ingestion-key-enforce-before-team.md new file mode 100644 index 0000000000..2204816c21 --- /dev/null +++ b/.changeset/ingestion-key-enforce-before-team.md @@ -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. diff --git a/packages/api/src/opamp/controllers/__tests__/opampController.test.ts b/packages/api/src/opamp/controllers/__tests__/opampController.test.ts index bedfda5dc1..c6cba524dd 100644 --- a/packages/api/src/opamp/controllers/__tests__/opampController.test.ts +++ b/packages/api/src/opamp/controllers/__tests__/opampController.test.ts @@ -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', () => { + 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; diff --git a/packages/api/src/opamp/controllers/opampController.ts b/packages/api/src/opamp/controllers/opampController.ts index 24d6d87f48..9ddad7b0e0 100644 --- a/packages/api/src/opamp/controllers/opampController.ts +++ b/packages/api/src/opamp/controllers/opampController.ts @@ -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); const otelCollectorConfig: CollectorConfig = { extensions: {},