Skip to content

Reject empty OTLP API keys - #20363

Merged
James Newton-King (JamesNK) merged 2 commits into
mainfrom
fix/otlp-empty-api-key
Sep 23, 2026
Merged

James Newton-King (JamesNK) merged 2 commits into
mainfrom
fix/otlp-empty-api-key

Conversation

@JamesNK

@JamesNK James Newton-King (JamesNK) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Description

Reject empty OTLP API keys so an explicitly empty secondary key cannot authenticate a request carrying an empty x-otlp-api-key header.

This change validates that configured primary and secondary OTLP API keys are non-empty when API-key authentication is enabled. The secondary key remains optional when it is unset. The authentication handler also rejects an empty incoming header before performing either fixed-time key comparison.

The tests cover empty primary and secondary configuration, an explicit JSON null secondary key, direct handler behavior, and the OTLP HTTP endpoint response.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20363

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20363"

@github-actions

This comment has been minimized.

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

The JSON null integration test must be reconciled with .NET 10 configuration binding behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Hardens OTLP API-key authentication by rejecting empty configured keys and empty request headers.

Changes:

  • Validates non-empty primary and secondary keys while allowing an unset secondary key.
  • Rejects empty headers before fixed-time comparison.
  • Adds unit and integration coverage.
File Review
tests/​Aspire.Dashboard.Tests/​OtlpApiKeyAuthenticationHandlerTests.cs Covers handler rejection behavior.
tests/​Aspire.Dashboard.Tests/​Integration/​OtlpHttpServiceTests.cs The explicit JSON null test conflicts with .NET 10 binding behavior and will fail; update its expectation or validation logic.
tests/​Aspire.Dashboard.Tests/​DashboardOptionsTests.cs Covers API-key option validation.
src/​Aspire.Dashboard/​Configuration/​ValidateDashboardOptions.cs Validates configured OTLP API keys.
src/​Aspire.Dashboard/​Authentication/​OtlpApiKey/​OtlpApiKeyAuthenticationHandler.cs Rejects empty incoming API-key headers.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.

joperezr
Jose Perez Rodriguez (joperezr) approved these changes Sep 23, 2026 •
@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Accept a null optional secondary key while asserting that an explicitly empty key fails dashboard options validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

13 / 99 PR test projects · 2 PR jobs, from 5 changed files.

Selected PR test projects (13 / 99)

Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (2)

extension-e2e, native-dashboard-validation


How these were chosen — grouped by what changed

⚠️ 11 of the 13 selected test projects come from a single change — src/Aspire.Dashboard/Authentication/OtlpApiKey/OtlpApiKeyAuthenticationHandler.cs.

🔧 src/Aspire.Dashboard/Authentication/OtlpApiKey/OtlpApiKeyAuthenticationHandler.cs (changed source)
→ 11 via the project graph: Aspire.Dashboard.Components.Tests, Aspire.Hosting.Azure.Kubernetes.Tests (3 hops), Aspire.Hosting.Azure.Tests (2 hops), Aspire.Hosting.Blazor.Tests (2 hops), Aspire.Hosting.Dotnet.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests (2 hops), Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests (2 hops)

📦 affected project Aspire.Dashboard
→ 1 test: Aspire.Templates.Tests

🧪 tests/Aspire.Dashboard.Tests/DashboardOptionsTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Tests

🧪 tests/Aspire.Dashboard.Tests/Integration/OtlpHttpServiceTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Tests

🧪 tests/Aspire.Dashboard.Tests/OtlpApiKeyAuthenticationHandlerTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Tests

Job reasons

Job Triggered by
extension-e2e • src/Aspire.Dashboard/Authentication/OtlpApiKey/OtlpApiKeyAuthenticationHandler.cs, src/Aspire.Dashboard/Configuration/ValidateDashboardOptions.cs
• affected project Aspire.Dashboard
native-dashboard-validation affected project Aspire.Dashboard

Selection computed for commit 7adc091.

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

This security-sensitive authentication change warrants final human review.

Review effort: Balanced
Findings: None

@JamesNK
James Newton-King (JamesNK) merged commit 9987831 into main Sep 23, 2026
155 checks passed
@github-actions github-actions Bot added this to the 13.6 milestone Sep 23, 2026
aspire-repo-bot Bot added a commit to microsoft/aspire.dev that referenced this pull request Sep 23, 2026
Documents PR microsoft/aspire#20363, which rejects empty OTLP primary/secondary API keys and empty incoming x-otlp-api-key headers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1720

Generated by PR Documentation Check · copilot · auto · 38.9 AIC · ⌖ 17.1 AIC · ⊞ 18.7K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1720 targeting release/13.6.

docs_optional path: no deterministic signal fired (signal_count=0), but this matches the 'user-visible behavior change to an already-documented feature' positive trigger. The diff (OtlpApiKeyAuthenticationHandler.cs) shows the handler now rejects an empty x-otlp-api-key header before comparison, and ValidateDashboardOptions.cs adds a new validation error requiring Dashboard:Otlp:SecondaryApiKey be non-empty when set. The dashboard/configuration.mdx page already documents Dashboard:Otlp:PrimaryApiKey and Dashboard:Otlp:SecondaryApiKey, so this is an update to already-documented behavior rather than new surface. Updated the OTLP section intro sentence and the PrimaryApiKey/SecondaryApiKey option descriptions to state that empty API key values (and an empty incoming header) are rejected when API key auth mode is used.

Note

This draft PR needs human review before merging.

@JamesNK

Copy link
Copy Markdown
Member Author

/backport to release/13.6

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.6 (link to workflow run)

Jose Perez Rodriguez (joperezr) pushed a commit that referenced this pull request Sep 24, 2026
Backport of #20363 to release/13.6

/cc @JamesNK

## Customer Impact

An explicitly empty secondary OTLP API key could allow a request with an
empty `x-otlp-api-key` header to authenticate. This prevents that
unintended access while still allowing an unset optional secondary key.

## Testing

Dashboard test CI passed on Windows and Linux for this backport; Ubuntu
x64 native-AOT Dashboard validation passed. The source PR adds
configuration, authentication-handler, and OTLP HTTP endpoint coverage
for empty keys and a null optional secondary key.

## Risk

Medium. This changes OTLP authentication and startup validation:
configurations with explicitly empty keys that were previously accepted
will now fail validation; no public API changes.

## Regression?

Unknown — please confirm.

---------

Co-authored-by: James Newton-King <james@newtonking.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
David Pine (IEvangelist) pushed a commit that referenced this pull request Oct 1, 2026
Backport of #20363 to release/13.6

/cc @JamesNK

## Customer Impact

An explicitly empty secondary OTLP API key could allow a request with an
empty `x-otlp-api-key` header to authenticate. This prevents that
unintended access while still allowing an unset optional secondary key.

## Testing

Dashboard test CI passed on Windows and Linux for this backport; Ubuntu
x64 native-AOT Dashboard validation passed. The source PR adds
configuration, authentication-handler, and OTLP HTTP endpoint coverage
for empty keys and a null optional secondary key.

## Risk

Medium. This changes OTLP authentication and startup validation:
configurations with explicitly empty keys that were previously accepted
will now fail validation; no public API changes.

## Regression?

Unknown — please confirm.

---------

Co-authored-by: James Newton-King <james@newtonking.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants