Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spiceai/spiceai/llms.txt
Use this file to discover all available pages before exploring further.
Authentication
Spice.ai provides flexible authentication mechanisms to secure access to your data and AI endpoints. Authentication can be configured to protect HTTP, Flight SQL, and gRPC APIs.Authentication Methods
API Key Authentication
API key authentication is the primary method for securing Spice runtime endpoints. API keys can be configured with different permission levels:- Read-Only (
:ro): Allows queries but prevents data modification - Read-Write (
:rw): Allows both queries and data modification operations
Configuration
Configure API key authentication in yourspicepod.yaml:
Key Format
API keys follow the format:<key-value>:<permission>
- If no permission suffix is provided, the key defaults to read-only (
:ro) - Use
:rwsuffix for read-write permissions - Use
:rosuffix to explicitly mark as read-only
Using API Keys
HTTP Requests
Include the API key in theX-API-Key header:
Flight SQL
API keys are used during the handshake phase and for subsequent requests:Session-Based Authentication
After initial authentication with an API key, Flight SQL clients receive a session token that can be used for subsequent requests. The runtime automatically manages session validation and tracks which API key was used to create each session. Session workflow:- Client authenticates with API key during handshake
- Runtime returns a session ID as the Bearer token
- Client uses session ID for all subsequent requests
- Runtime validates session and applies original API key’s permissions
Authentication Architecture
Endpoint Protection
Spice provides separate authentication for different protocol endpoints:- HTTP Auth: Protects REST API endpoints (
/v1/sql,/v1/query, etc.) - Flight Basic Auth: Protects Arrow Flight SQL connections
- gRPC Auth: Protects gRPC service endpoints
Anonymous Access
When authentication is not configured, Spice allows anonymous access with ananonymous principal. This is useful for development but should be disabled in production.
Security Best Practices
1. Use Secrets Management
Always reference API keys from secure secret stores:2. Principle of Least Privilege
Use read-only keys (:ro) by default. Only grant read-write (:rw) access when necessary:
3. Rotate Keys Regularly
Implement a key rotation policy:- Generate new keys in your secret store
- Update the secret store values
- Restart Spice runtime to pick up new keys
- Invalidate old keys
4. Use TLS for Production
Always combine authentication with TLS encryption in production environments:5. Constant-Time Comparison
Spice uses constant-time comparison for API key validation to prevent timing attacks. This is automatically applied to all API key comparisons.6. Key Redaction
API keys are automatically redacted in:- Log output
- Error messages
- Debug traces
[REDACTED] in all logging to prevent accidental exposure.
Authentication for Data Sources
In addition to runtime authentication, you can configure authentication for individual data sources using secrets:Monitoring Authentication
Spice logs authentication attempts at appropriate levels:- Failed authentication attempts
- Authentication rate by key
- Session creation and expiration