Skip to main content

⬅️ Back to README

🚀 Deployment: Infrastructure & Resiliency

For visual diagrams of Air-Gapped and VPC setups, refer to the Deployment Topologies guide.

1. Service Mesh Native Interface

  • Implementation Details: Integrates gracefully into Kubernetes Service Meshes (like Istio/Linkerd) natively without secondary sidecar bottlenecks, providing seamless inbound/outbound interception to maintain your LLM Security Posture Management (LLM SPM).
  • Relevant Flags: Not explicitly flagged (relies on standard HOST/PORT socket configuration).

2. Zero-Overhead OpenTelemetry Tracing

  • Implementation Details: Lightweight OpenTelemetry (OTel) Tracing handles W3C traceparent distributed tracing propagation via a dedicated asynchronous background thread. Provides full observability to Jaeger or Datadog with strictly zero latency overhead to the active HTTP streaming loop.
  • Relevant Flags:

3. Service Mesh Native gRPC ext_proc Integration

  • Implementation Details: Implements Envoy's External Processing filter (envoy.service.ext_proc.v3.ExternalProcessor). Achieves Zero HTTP network hops by streaming buffers directly over UDS (Unix Domain Sockets).
  • Relevant Flags:

4. Traffic Engineering & Resiliency

  • Implementation Details:
    • Redis evalsha Token-Bucket Rate Limiter: Pre-loaded Lua scripts handle high-throughput rate limiting (6000 RPM / 200 Burst). Linked to ENABLE_RATE_LIMITING, RATE_LIMIT_RPM, and RATE_LIMIT_BURST.
    • Kubernetes 25s SIGTERM Connection Draining: Ensures active SSE streams finish transmission during pod termination before tearing down the socket. Linked to DRAIN_TIMEOUT_SECONDS.
    • Upstream Key Overriding: Strips client keys and injects internal load-balanced provider API keys dynamically. Linked to OVERRIDE_CLIENT_AUTH.

5. Zero-Dependency Kubernetes Mutating Webhook

  • Implementation Details: Intercepts Pod deployment manifests directly via a standalone Mutating Webhook to seamlessly inject the LLM-Shield sidecar container and mTLS certificates, requiring zero external dependencies.
  • Relevant Flags: N/A (Handled via Kubernetes MutatingAdmissionWebhook manifests).

6. Deep Component Health Probes and Prometheus Alert Rules

  • Implementation Details: Provides granular /healthz, /livez, and /readyz probes covering Redis connectivity and Vault mTLS states. Integrates directly with Prometheus Alertmanager via pre-packaged alert rules.
  • Relevant Flags: METRICS_BEARER_TOKEN.

7. ⚙️ Complete 12-Factor Environment Configuration (pydantic-settings)

100% compliant with 12-factor app standards. All upstream target routing, keys, thresholds, and pool sizes are managed via validated pydantic-settings:

Hierarchical Policy-as-Code (RBAC)

DevOps teams can now mount a policies.yaml file to dynamically map virtual_key_id client identities to distinct security roles. The proxy features a zero-downtime hot-reloading mechanism that continuously polls the file (defaulting to every 5 seconds) and applies modifications immediately without dropping active Server-Sent Event (SSE) streams. Unknown identifiers strictly enforce a Zero-Trust FAIL_CLOSED default.

Universal Dynamic Override Engine: DevOps teams are no longer limited to basic security toggles; they can now dynamically override any of the 30+ .env properties (like MAX_PAYLOAD_SIZE_BYTES or RATE_LIMIT_RPM) natively per virtual_key_id inside policies.yaml. This is powered by an ASGI-native contextvars.ContextVar architecture to achieve strictly isolated, O(1) thread-safe tenant configurations without global state leakage.

View the Complete Policy-as-Code Guide & Templates 📜: For detailed Role-Based Access Control (RBAC) templates, feature support matrices, and FAQs.

Core Configuration Flags

Environment VariableTypeDefaultDescription
HOSTstr0.0.0.0Socket host to bind
PORTint8000Socket port to bind
WORKERSint1Number of worker processes
LOG_LEVELstrINFOStandard log verbosity level
UPSTREAM_BASE_URLstrhttps://api.openai.comTarget upstream LLM provider base URL
OPENAI_API_KEYstrNoneCentralized enterprise OpenAI API key
GEMINI_API_KEYstrNoneCentralized Google Gemini API key
ANTHROPIC_API_KEYstrNoneCentralized Anthropic API key
DEEPSEEK_API_KEYstrNoneCentralized DeepSeek API key
VALID_VIRTUAL_KEYSstr""Comma-separated list of authorized client virtual keys
ALLOW_CLIENT_UPSTREAM_OVERRIDEboolFalseAllow clients to override upstream URL via header
REDIS_URLstrNoneRedis connection URL for distributed vault state
SESSION_TTL_SECONDSint3600Rolling TTL in seconds for session vault states
MAX_SESSION_VAULTSint10000Maximum in-memory LRU session vault capacity
ENABLE_SYNTHETIC_SWAPPINGboolTrueEnables realistic synthetic entity replacement
ENABLE_TIER2_ENTROPYboolTrueEnables Tier 2 Shannon Entropy detection
SHANNON_ENTROPY_THRESHOLDfloat4.5Minimum information entropy threshold
SHANNON_MIN_LENGTHint16Minimum token length to analyze for Shannon entropy
ENABLE_TIER3_ONNX_NERboolFalseEnables Tier 3 ONNX Runtime contextual NER
ONNX_MODEL_PATHstrNonePath to quantized ONNX BERT-NER model weights
CUSTOM_REGEX_PATHstrNonePath to custom_regex.yaml containing BYOR rules
HTTP_TIMEOUT_SECONDSfloat120.0Upstream HTTP request timeout in seconds
HTTP_MAX_KEEPALIVE_CONNECTIONSint10000Maximum keep-alive connections in HTTP pool
MAX_PAYLOAD_SIZE_BYTESint10485760Maximum allowed request body size
MAX_SSE_LINE_LENGTHint1048576Maximum allowed SSE line size (1MB)
METRICS_BEARER_TOKENstrNoneBearer token protecting the /metrics endpoint

Advanced Feature Flags (Compliance, Security, and Engineering)

Feature / SystemEnvironment VariableDefaultDescription
In-Band Stateless SyntheticSHIELD_DEFAULT_MASKING_MODESYNTHETICSet to STATELESS_CRYPTO to enable AES-256-GCM masking.
In-Band Stateless SyntheticSHIELD_ENCRYPTION_KEYNone256-bit AES-GCM encryption key for stateless masking.
Audit, Forensics & LegalAUDIT_LOG_FORMATSTANDARDSet to RFC6902_DIFF for RFC 6902 Differential Audit Logging.
Audit, Forensics & LegalFIPS_STRICT_MODETrueStrict fail-closed validation for FIPS 140-3 KAT tests.
Agent Circuit BreakerENABLE_AGENT_BREAKERTrueEnable Composite Agent Loop Circuit Breaker.
Agent Circuit BreakerAGENT_BREAKER_THRESHOLD3Consecutive duplicate turns before tripping the circuit breaker.
Agent Identity EnforcerAGENT_IDENTITY_ENFORCER"off"Agent Identity Enforcer mode ("off", "lenient", "strict").
Leak ForensicsENABLE_WATERMARKINGFalseEnable Dynamic Canary Watermarking & Steganography.
Leak ForensicsSHIELD_WATERMARK_SECRETNoneSecret for HMAC-SHA256 watermarking.
OTel & TracingTELEMETRY_ENABLEDFalseEnable W3C traceparent distributed telemetry & WORM-Compliant Merkle Logging.
OTel & TracingTELEMETRY_ENDPOINT_URLNoneTarget webhook endpoint URL for audit telemetry.
OTel & TracingANONYMOUS_USAGE_TRACKINGTrueEnable anonymous, opt-out volumetric telemetry.
TripwireENABLE_CANARY_TRIPWIREFalseEnable deterministic prompt-extraction tripwire.
TripwireCANARY_TOKENNoneCryptographic canary string, auto-generated if unset.
Blast Radius LimitsENABLE_BLAST_RADIUS_LIMITSFalseEnable Entity-Weighted Blast Radius Limits.
Blast Radius LimitsBLAST_RADIUS_BURST_CAPACITY100Maximum bucket size for PII entity exfiltration limit.
Blast Radius LimitsBLAST_RADIUS_REPLENISH_RATE_PER_MIN10Tokens added back per minute to the bucket.
FinOps MeteringENABLE_FINOPS_METERINGTrueEnable token metering and FinOps telemetry.
gRPC ext_proc MeshENABLE_EXT_PROCTrueEnable Envoy ext_proc gRPC hook.
gRPC ext_proc MeshEXT_PROC_SOCK_PATH/var/run/llm-shield/ext_proc.sockPath to the ext_proc UDS socket.
Policy-as-Code (RBAC)POLICIES_FILE_PATHpolicies.yamlPath to the hierarchical RBAC YAML policy definitions.
Policy-as-Code (RBAC)POLICIES_RELOAD_INTERVAL_SECONDS5File modification polling interval for zero-downtime hot-reloads.
Fail-Safe PolicySHIELD_FAILURE_MODEFAIL_CLOSEDEnforces Zero-Trust default (O(1) in-memory mapping FAIL_CLOSED).
Anthropic AdapterDEFAULT_UPSTREAM_PROVIDERopenaiSet to anthropic for native OpenAI-to-Anthropic request transformation.
Anthropic AdapterANTHROPIC_API_VERSION2023-06-01Anthropic API version header for SSE stream normalization.
Traffic EngineeringENABLE_RATE_LIMITINGFalseEnable distributed Redis evalsha Token Bucket rate limiter.
Traffic EngineeringRATE_LIMIT_RPM6000Requests per minute per virtual key (6000 RPM).
Traffic EngineeringRATE_LIMIT_BURST200Maximum burst size for rate limiter (200 Burst).
Traffic EngineeringDRAIN_TIMEOUT_SECONDS25Kubernetes 25s SIGTERM connection draining.
Traffic EngineeringOVERRIDE_CLIENT_AUTHFalseStrip client auth and inject UPSTREAM_API_KEY.
Resiliency & FailoverENABLE_RETRY_FAILOVERTrueEnable upstream retry and explicit failover logic.
Resiliency & FailoverMAX_RETRIES3Maximum transient retry attempts.
Resiliency & FailoverFALLBACK_BASE_URLNoneGlobal fallback provider URL.
Resiliency & FailoverFALLBACK_API_KEYNoneFallback provider API key.
Vault Secrets & mTLSENABLE_VAULT_SECRETSFalseEnable HashiCorp Vault dynamic secrets.
Vault Secrets & mTLSVAULT_ADDRNoneVault server address.
Vault Secrets & mTLSVAULT_AUTH_METHODTOKENNative HashiCorp Vault Auth (AppRole / KUBERNETES / TOKEN).
Vault Secrets & mTLSVAULT_TOKEN / VAULT_ROLE_IDNoneDirect Vault Token or AppRole Role ID.
Vault Secrets & mTLSVAULT_REFRESH_INTERVAL_SECONDS300Non-blocking TTL cache refresh interval.
Vault Secrets & mTLSENABLE_MTLSFalseEnable mutual TLS X.509 transport.
Vault Secrets & mTLSSSL_CLIENT_CERT_PATHNonePath to mTLS client certificate.
TLS/SSL (Inbound)TLS_CERT_FILENoneServer public certificate.
TLS/SSL (Inbound)TLS_KEY_FILENoneServer private key.
TLS/SSL (Inbound mTLS)CLIENT_CA_FILENoneCA bundle for verifying incoming clients.
TLS/SSL (Outbound)CA_BUNDLE_FILENoneCA bundle for verifying upstream LLM API gateways.
TLS/SSL (Outbound)INSECURE_SKIP_VERIFYFalseBypass upstream certificate verification.
TLS/SSL (Outbound mTLS)OUTBOUND_CLIENT_CERTNoneClient certificate for proxy outbound mTLS.
TLS/SSL (Outbound mTLS)OUTBOUND_CLIENT_KEYNoneClient key for proxy outbound mTLS.

[!WARNING] Zero-Trust Default (SHIELD_FAILURE_MODE): The proxy is hardcoded to default to FAIL_CLOSED. This ensures that if the engine faults, a Redis connection drops, or a policy cannot be resolved, the connection is instantly severed to prevent PII egress. If you must set SHIELD_FAILURE_MODE=FAIL_OPEN for local development or a POC, be aware that PII may leak if the engine encounters an error. Never use FAIL_OPEN in production.

8. 🔐 TLS and mTLS Deployment (Docker/Kubernetes)

When deploying LLM-Shield-Proxy in production, you should mount TLS certificates securely. In Kubernetes, use Secrets mounted as volumes.

Example Docker Compose with TLS:

services:
llm-shield:
image: llm-shield-proxy:latest
ports:
- "8443:8000"
volumes:
- ./certs:/etc/ssl/llm-shield:ro
environment:
- TLS_CERT_FILE=/etc/ssl/llm-shield/server.crt
- TLS_KEY_FILE=/etc/ssl/llm-shield/server.key
- CLIENT_CA_FILE=/etc/ssl/llm-shield/client-ca.pem
- CA_BUNDLE_FILE=/etc/ssl/llm-shield/upstream-ca.pem
- OUTBOUND_CLIENT_CERT=/etc/ssl/llm-shield/proxy-client.crt
- OUTBOUND_CLIENT_KEY=/etc/ssl/llm-shield/proxy-client.key

This configuration secures the listener with HTTPS, mandates inbound mTLS (CLIENT_CA_FILE), and enables outbound mTLS towards the upstream provider.