checkId: check.security.apikey plugin: stellaops.doctor.security severity: warn tags: [security, apikey, authentication]

API Key Security

What It Checks

Validates API key configuration and security practices. The check only runs when an API key configuration section exists (ApiKey, Authentication:ApiKey, or Security:ApiKey). It inspects:

SettingThreshold/ConditionIssue
MinLengthLess than 32 charactersKey too short (escalates to fail if < 16)
AllowInQueryStringtrueKeys in query strings get logged in access logs
HeaderNameEquals AuthorizationConflicts with other auth schemes
RateLimitPerKeyfalse or not setCompromised key could abuse the API without limits
RotationDaysNot setNo rotation policy configured
RotationDaysGreater than 365Rotation period is very long

If API key authentication is explicitly disabled (Enabled: false), the check reports an informational result and exits.

Why It Matters

API keys are the primary authentication mechanism for service-to-service communication and CI/CD integrations. Short keys can be brute-forced. Keys passed in query strings are recorded in web server access logs, proxy logs, and browser history, creating exposure vectors. Without per-key rate limiting, a compromised key allows unlimited API abuse. Without rotation, a leaked key remains valid indefinitely.

Common Causes

How to Fix

Docker Compose

Set API key security configuration in environment variables:

environment:
  ApiKey__MinLength: "32"
  ApiKey__AllowInQueryString: "false"
  ApiKey__HeaderName: "X-API-Key"
  ApiKey__RateLimitPerKey: "true"
  ApiKey__RotationDays: "90"

Bare Metal / systemd

Edit appsettings.json:

{
  "ApiKey": {
    "Enabled": true,
    "MinLength": 32,
    "HeaderName": "X-API-Key",
    "AllowInQueryString": false,
    "RateLimitPerKey": true,
    "RotationDays": 90
  }
}

Kubernetes / Helm

Set in Helm values:

apiKey:
  minLength: 32
  headerName: "X-API-Key"
  allowInQueryString: false
  rateLimitPerKey: true
  rotationDays: 90

Verification

stella doctor run --check check.security.apikey