API Key Authentication
This document describes how API key authentication is handled in the Registration Backend service.
Overview
All API endpoints require authentication via API keys.
Requests must include a valid API key in the x-api-key HTTP header.
How It Works
Request Flow
- Every incoming request passes through the
authMiddlewaredefined in app/root.tsx - The middleware extracts the
x-api-keyheader from the request - The key is validated against the list of valid API keys
- If valid, the request proceeds; otherwise, an error response is returned
API Key Storage
API keys are stored in AWS Secrets Manager under the secret name
registration-backend-api-keys. The secret contains a JSON array of valid API keys:
["key-1", "key-2", "key-3"]
Key Loading & Caching
The middleware uses a two-tier approach for loading API keys:
- Environment Variable Cache: First checks
APP_API_KEYSenvironment variable - Secrets Manager Fallback: If not in env, fetches from AWS Secrets Manager
using the ARN stored in
APP_API_KEYS_SECRET_ARN - Caching: After fetching from Secrets Manager, keys are cached in
APP_API_KEYSto avoid repeated API calls
This caching happens per Lambda instance, so keys are loaded once per cold start.
Configuration
Environment Variables
| Variable | Description |
|---|---|
APP_API_KEYS |
JSON array of valid API keys (cached) |
APP_API_KEYS_SECRET_ARN |
ARN of the Secrets Manager secret |
SKIP_MIDDLEWARE_AUTH |
Set to "true" to bypass auth (dev only) |
Infrastructure (CDK)
The secret is created in cdk.mts and the Lambda function is granted read access:
const apiKeysSecret = new secretsmanager.Secret(
stack,
"RegistrationBackendApiKeys",
{
secretName: "registration-backend-api-keys",
description: "API keys for the Registration Backend application",
},
);
// Lambda is granted read access
apiKeysSecret.grantRead(remix.implementation.lambda);
Managing API Keys
Adding/Removing Keys
To manage API keys via the AWS Console:
- Open the AWS Secrets Manager Console for the environment you want to change the keys (Stage or Prod).
- Select the appropriate region for your environment (
eu-central-1) - Search for
registration-backend-api-keysand click on the secret - Click Retrieve secret value to view the current keys
- Click Edit to modify the secret
- Click Plaintext
-
Update or add an array with API keys you created:
["existing-key", "new-key-to-add"] -
Click Save
Note: API keys are stored in the shared Bitwarden bucket
PIT/Developers/Acquisition and Registration. Remember to update this location when keys are added, deleted or changed.
Note: Each consumer should have a unique API key. Do not share keys across multiple consumers or environments.
Note: Changes to the secret take effect on the next Lambda cold start. To apply changes immediately, redeploy the Lambda function.
Local Development
For local development, you can:
- Set
SKIP_MIDDLEWARE_AUTH=trueto bypass authentication entirely