Authentication
The LineageBridge API supports optional API key authentication via the X-API-Key header. This lets you protect your lineage data when running the API in production or exposing it to external systems.
How It Works
sequenceDiagram
participant Client
participant API
participant Endpoint
Note over API: LINEAGE_BRIDGE_API_KEY set?
Client->>API: GET /api/v1/health
API-->>Client: 200 OK (no auth required)
Client->>API: GET /api/v1/lineage/events
API->>API: Check X-API-Key header
alt No API key provided
API-->>Client: 403 Forbidden - Missing API Key
else Invalid API key
API-->>Client: 403 Forbidden - Invalid API Key
else Valid API key
API->>Endpoint: Process request
Endpoint-->>API: Response
API-->>Client: 200 OK
end Configuration
Authentication is disabled by default. To enable it, set the LINEAGE_BRIDGE_API_KEY environment variable:
When this variable is set, all endpoints except /api/v1/health require authentication.
Why health is always open: Monitoring tools and load balancers need to check if the API is running without worrying about credentials.
Using API Keys
Pass your API key in the X-API-Key header with every request (except /health).
Tip: Store your API key in an environment variable, not in your source code:
Then reference it:
Generating Secure Keys
Use a cryptographically secure random string for production. A good API key has at least 32 bytes (64 hex characters) of entropy.
Don't use simple passwords like "password123" or predictable strings. An attacker could guess them.
Unauthenticated Endpoints
The following endpoint is always accessible without authentication:
GET /api/v1/health- Health check for monitoring
Error Responses
Missing API Key
When authentication is enabled and no API key is provided:
HTTP Status: 403 Forbidden
Invalid API Key
When an incorrect API key is provided:
HTTP Status: 403 Forbidden
Security Best Practices
- Use environment variables - Never hardcode API keys in source code
- Use HTTPS in production - Always run behind a reverse proxy (nginx, Caddy) with TLS
- Rotate keys regularly - Update keys periodically and when team members leave
- Use strong keys - Generate keys with at least 32 bytes of entropy
- Restrict network access - Use firewall rules to limit API access to trusted networks
Production Deployment
Example nginx reverse proxy configuration with TLS:
server {
listen 443 ssl http2;
server_name lineage-api.example.com;
ssl_certificate /etc/letsencrypt/live/lineage-api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/lineage-api.example.com/privkey.pem;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Example Caddy configuration:
Docker Deployment
When running in Docker, pass the API key via environment variable:
docker run -d \
-e LINEAGE_BRIDGE_API_KEY="your-secret-key-here" \
-p 8000:8000 \
lineage-bridge:latest
Or use Docker Compose:
version: '3.8'
services:
api:
image: lineage-bridge:latest
ports:
- "8000:8000"
environment:
LINEAGE_BRIDGE_API_KEY: ${LINEAGE_BRIDGE_API_KEY}
Then start with:
Testing Authentication
After enabling authentication, test that it works correctly:
What "should fail" means: You get a 403 Forbidden response. This is good! It means your API is protected.
Future Enhancements
Planned authentication features:
- OAuth2/OIDC integration
- Role-based access control (RBAC)
- API key scopes (read-only, write, admin)
- Rate limiting per key
- Key expiration and rotation
See the roadmap for more details.