auth: static X-API-Key gate; 0.3.0#10
Merged
Merged
Conversation
Enables exposing /single and /multi through ingress while keeping the service protected by a static shared secret. /healthz stays open so k8s probes and external liveness monitors don't need to know the token. - config: new optional `api_token` (env KZ_SCORING_API_TOKEN). Empty = no auth (matches original behaviour; dev-stand and port-forward keep working without headers). - app: HTTP middleware compares X-API-Key against api_token via hmac.compare_digest. /healthz bypasses the gate. - chart: dedicated Secret rendered only when apiToken is set, mounted via envFrom; deployment stays unchanged when auth is off. - tests: 8 new cases covering healthz-open, missing header, wrong token, correct token, /multi mirror, and constant-time compare regression (61 tests total, all green). Not in scope: multi-token / per-caller quotas / rotation. If needed later, this middleware can be extended without breaking callers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional static `X-API-Key` gate so `/single` and `/multi` can be safely exposed via ingress. `/healthz` stays open for k8s probes and external liveness monitors. When `api_token` is empty the middleware is a passthrough — dev-stand and port-forward callers keep working without headers.
Wire-up
Caller shape
```
curl -H "X-API-Key: " "https://kz-scoring.cdp.beelinekz.aggregion.com/single?iin=700205302324\"
```
Test plan
Not in scope
Multi-token, per-caller quotas, rotation. Middleware can grow to handle those without breaking callers.
🤖 Generated with Claude Code