Bastion is configured via environment variables and a .env.local file. All variables use the BASTION_ prefix. Settings are loaded by pydantic-settings with OS env vars taking highest priority.
# .env.local (gitignored — never commit real credentials)
BASTION_CONN="postgresql://user:pass@host:26257/bastion?sslmode=verify-full"
BASTION_API_KEY="bastion-your-api-key-here"
BASTION_MOCK=false
Core Settings
Connection
| Variable | Default | Required | Description |
|---|
| BASTION_CONN | — | Yes | CockroachDB PostgreSQL connection string (sslmode=verify-full) |
| BASTION_MOCK | false | No | Enable mock mode — no database required, in-memory storage only |
| BASTION_API_KEY | — | Prod | API key for MCP/A2A authentication. Disabled when empty. |
| BASTION_AGENT_ID | bastion-a2a | No | Agent identity for A2A server |
Embedding Pipeline
| Variable | Default | Required | Description |
|---|
| BASTION_EMBED_MODEL_ID | BAAI/bge-large-en-v1.5 | No | HuggingFace model ID for embedding generation |
| BASTION_EMBED_DIM | 1024 | No | Embedding dimensions (must match model output) |
| HF_TOKEN | — | No | HuggingFace API token for embedding API access |
| BASTION_EMBED_READ_TIMEOUT | 30 | No | Timeout (seconds) for embedding API reads |
| BASTION_EMBED_CONNECT_TIMEOUT | 10 | No | Timeout (seconds) for embedding API connections |
Server Settings
MCP Server
| Variable | Default | Required | Description |
|---|
| BASTION_MCP_API_KEYS | — | No | Comma-separated list of valid API keys (multi-key mode) |
| BASTION_TRUST_PROXY | false | No | Trust X-Forwarded-For headers (for reverse proxy deployments) |
| BASTION_MCP_OAUTH_CLIENT_ID | — | No | Pre-registered OAuth client ID for MCP auth |
| BASTION_MCP_OAUTH_CLIENT_SECRET | — | No | Pre-registered OAuth client secret |
| BASTION_MCP_OAUTH_REDIRECT_URI | — | No | OAuth redirect URI |
A2A Server
| Variable | Default | Required | Description |
|---|
| A2A_PORT | 9998 | No | A2A server listen port |
| A2A_HOST | 0.0.0.0 | No | A2A server bind address |
| A2A_URL | http://0.0.0.0:9998 | No | Public A2A URL for agent card |
| BASTION_A2A_PRIVATE_KEY | — | No | Base64-encoded Ed25519 private key for agent card signing |
| BASTION_A2A_STRICT | true | No | Strict A2A auth mode (reject unsigned cards) |
| BASTION_A2A_TRUSTED_KEYS | — | No | Comma-separated SHA-256 fingerprints of trusted keys |
| BASTION_A2A_ROLE | admin | No | Default role for single-key mode |
| BASTION_A2A_ROLES | — | No | Per-key role mapping: key1:writer,key2:reader,default:admin |
| A2A_CLEANUP_INTERVAL | 3600 | No | Seconds between task cleanup cycles |
| A2A_TASK_MAX_AGE | 86400 | No | Max age (seconds) for completed tasks before cleanup |
Bridge (MCP↔A2A)
| Variable | Default | Required | Description |
|---|
| BASTION_BRIDGE_ALLOW_LOOPBACK | false | No | Allow bridge to forward to localhost (dev mode) |
Connection Pool & Resilience
Pool Settings
| Variable | Default | Required | Description |
|---|
| BASTION_POOL_MIN_SIZE | 5 | No | Minimum idle connections in pool |
| BASTION_POOL_MAX_SIZE | 20 | No | Maximum connections in pool |
| BASTION_POOL_MAX_IDLE_SECONDS | 300 | No | Max idle time before connection is closed |
Circuit Breaker
| Variable | Default | Required | Description |
|---|
| BASTION_CIRCUIT_BREAKER_FAILURE_THRESHOLD | 5 | No | Consecutive failures before circuit opens |
| BASTION_CIRCUIT_BREAKER_RECOVERY_TIMEOUT | 30 | No | Seconds before circuit tries half-open |
| BASTION_CIRCUIT_BREAKER_SUCCESS_THRESHOLD | 2 | No | Successes in half-open to close circuit |
Retry
| Variable | Default | Required | Description |
|---|
| BASTION_RETRY_MAX_RETRIES | 5 | No | Maximum retry attempts |
| BASTION_RETRY_BASE_DELAY_MS | 10 | No | Base delay (ms) for exponential backoff |
| BASTION_RETRY_MAX_DELAY_MS | 2000 | No | Maximum delay (ms) between retries |
| BASTION_RETRY_JITTER_FACTOR | 0.5 | No | Jitter factor to prevent thundering herd |
Rate Limiter
| Variable | Default | Required | Description |
|---|
| BASTION_LIMITER_MAX_CONCURRENT | 10 | No | Max concurrent requests |
| BASTION_LIMITER_MAX_QUEUE | 100 | No | Max queued requests when at capacity |
| BASTION_LIMITER_TIMEOUT_SECONDS | 30 | No | Seconds before queued request times out |
Guard (OWASP ASI06)
| Variable | Default | Required | Description |
|---|
| BASTION_GUARD_MAX_CONTENT | 100000 | No | Max content length (chars) before block |
| BASTION_GUARD_BLOCK_SEVERITY | high | No | Minimum severity to block: low, medium, high, critical |
| BASTION_LLM_GUARD | false | No | Enable LLM-powered semantic classification (requires Groq) |
| GROQ_API_KEY | — | Conditional | Groq API key (required when BASTION_LLM_GUARD=true) |
| GROQ_MODEL | openai/gpt-oss-120b | No | Groq model for LLM guard classification |
Search & Memory
| Variable | Default | Required | Description |
|---|
| BASTION_SEARCH_DEFAULT_K | 5 | No | Default number of results for memory_search |
| BASTION_SEARCH_DEFAULT_THRESHOLD | 0.8 | No | Default similarity threshold (0-1) |
| BASTION_CACHE_DEFAULT_THRESHOLD | 0.97 | No | L1 cache promotion threshold |
| BASTION_DECAY_RATE | 0.01 | No | Cognitive decay rate for importance scores |
| BASTION_REINFORCE_BOOST | 1.0 | No | Importance boost when memory is accessed |
Encryption (KMS)
| Variable | Default | Required | Description |
|---|
| BASTION_KMS_KEY | — | No | Hex-encoded 256-bit key for local encryption |
| BASTION_KMS_KEY_FILE | — | No | Path to file containing hex-encoded key |
| BASTION_KMS_GENERATE | false | No | Auto-generate and persist a new key |
| BASTION_AWS_KMS_KEY_ARN | — | No | AWS KMS key ARN for CMEK encryption |
| BASTION_GCP_KMS_RESOURCE | — | No | GCP KMS resource name for CMEK |
| AWS_REGION | us-east-1 | No | AWS region for KMS operations |
Logging & Compliance
| Variable | Default | Required | Description |
|---|
| BASTION_LOG_LEVEL | INFO | No | Python log level: DEBUG, INFO, WARNING, ERROR, CRITICAL |
| LOG_JSON | false | No | Enable JSON structured logging |
| BASTION_COMPLIANCE_MODE | — | No | Compliance mode: e.g., 'eu_ai_act', 'soc2' |
Storage
| Variable | Default | Required | Description |
|---|
| BASTION_S3_BUCKET | bastion-memory-archives | No | S3 bucket for memory archives |
| BASTION_PROJECT_URL | https://bastion-self.vercel.app | No | Project URL for agent card |
| BASTION_DOCS_URL | https://github.com/dgboy-ai/Bastion | No | Documentation URL for agent card |
Query Limits
| Variable | Default | Required | Description |
|---|
| AUDIT_LIMIT | 100 | No | Max rows returned by memory_audit |
| ANOMALY_LIMIT | 50 | No | Max rows returned by anomaly detection |
| SEARCH_RESULT_LIMIT | 500 | No | Max rows returned by search queries |
| DBA_SLOW_QUERY_LIMIT | 10 | No | Max slow queries returned by DBA tools |
| LOCALITY_LIMIT | 10 | No | Max rows for locality analysis |
Example Configurations
Development (Mock Mode)
# Minimal config — no database needed
BASTION_MOCK=true
BASTION_API_KEY=test-key
Production (CockroachDB)
# Full production config
BASTION_CONN="postgresql://user:pass@your-cluster:26257/bastion?sslmode=verify-full"
BASTION_MOCK=false
BASTION_API_KEY="bastion-prod-api-key"
BASTION_A2A_PRIVATE_KEY="base64-encoded-ed25519-key"
BASTION_POOL_MAX_SIZE=20
BASTION_GUARD_BLOCK_SEVERITY=medium
BASTION_LOG_LEVEL=INFO
Docker
# docker-compose.yml environment section
environment:
BASTION_CONN: ${BASTION_CONN}
BASTION_API_KEY: ${BASTION_API_KEY}
BASTION_MOCK: "false"
BASTION_POOL_MAX_SIZE: "20"
Ready to deploy?
Follow the Setup Guide for step-by-step deployment.
Setup Guide →