Skip to content

Commit b807fa3

Browse files
feat: Add Phase 1/Layer 1 hardening for LLM-Shield agents
HARDENING REQUIREMENTS IMPLEMENTED: - Mandatory startup validation (env vars, Ruvector health check) - Agent identity standardization (source_agent, domain, phase, layer) - Performance boundaries (MAX_TOKENS=800, MAX_LATENCY_MS=1500, MAX_CALLS_PER_RUN=2) - Read-only in-memory caching (TTL 30-60s) - Minimal observability (agent_started, decision_event_emitted, agent_abort) - Contract assertions (Ruvector required, ≥1 DecisionEvent per run) NEW FILES: - agents/lib/* - Shared infrastructure modules - agents/HARDENING.md - Complete documentation and checklist DEPLOYMENT: - Secrets via Google Secret Manager (no inline secrets) - Startup failures crash container (intentional) - Service deployed to Cloud Run: llm-shield-dev Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent 31c6f3e commit b807fa3

File tree

13 files changed

+2057
-136
lines changed

13 files changed

+2057
-136
lines changed

agents/Dockerfile

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
# ============================================================================
2-
# LLM-Shield Unified Service - Cloud Run Dockerfile
2+
# LLM-Shield Unified Service - Cloud Run Dockerfile (HARDENED)
33
# ============================================================================
44
# Builds the unified LLM-Shield service containing all 9 agents.
55
# Optimized for Google Cloud Run deployment.
66
#
7+
# Phase 1 / Layer 1 - Foundational Tooling
8+
#
9+
# HARDENING REQUIREMENTS:
10+
# - Ruvector is REQUIRED (service will crash if unavailable)
11+
# - All secrets must be provided via environment variables
12+
# - Startup validation runs before service starts
13+
# - Non-root user for security
14+
# - Minimal logging (agent_started, decision_event_emitted, agent_abort)
15+
#
716
# Build: docker build -t llm-shield-service:latest -f Dockerfile .
817
# Run: docker run -p 8080:8080 --env-file .env llm-shield-service:latest
918
# ============================================================================
1019

1120
FROM node:20-slim
1221

22+
# Build argument for version
23+
ARG SERVICE_VERSION=1.0.0
24+
1325
WORKDIR /app
1426

1527
# Install build dependencies (needed for native modules)
@@ -29,6 +41,10 @@ RUN npm install
2941
WORKDIR /app/contracts
3042
RUN npm run build || echo "contracts build completed"
3143

44+
# Build lib module (shared infrastructure for hardening)
45+
WORKDIR /app/lib
46+
RUN npm install && npm run build || echo "lib build completed"
47+
3248
# Build each agent
3349
WORKDIR /app/prompt-injection-detection
3450
RUN npm install && npm run build || echo "prompt-injection build completed"
@@ -57,7 +73,7 @@ RUN npm install && npm run build || echo "model-abuse build completed"
5773
WORKDIR /app/credential-exposure-detection
5874
RUN npm install && npm run build || echo "credential-exposure build completed"
5975

60-
# Build service
76+
# Build service (with hardened startup validation)
6177
WORKDIR /app/service
6278
RUN npm install && npm run build || echo "service build completed"
6379

@@ -71,26 +87,61 @@ RUN groupadd -r llmshield && useradd -r -g llmshield llmshield && \
7187
# Switch to non-root user
7288
USER llmshield
7389

74-
# Environment defaults
90+
# ============================================================================
91+
# MANDATORY ENVIRONMENT VARIABLES (Phase 1 / Layer 1)
92+
# ============================================================================
93+
# These MUST be provided at runtime via Cloud Run secrets or environment:
94+
#
95+
# REQUIRED (from Google Secret Manager):
96+
# RUVECTOR_SERVICE_URL - Ruvector service endpoint
97+
# RUVECTOR_API_KEY - Ruvector API authentication key
98+
#
99+
# REQUIRED (set in cloudbuild.yaml):
100+
# AGENT_NAME - Agent name identifier
101+
# AGENT_DOMAIN - Agent domain (e.g., security)
102+
# AGENT_PHASE - Must be "phase1"
103+
# AGENT_LAYER - Must be "layer1"
104+
#
105+
# OPTIONAL:
106+
# TELEMETRY_ENDPOINT - Telemetry service endpoint
107+
# ============================================================================
108+
109+
# Environment defaults (non-sensitive)
75110
ENV NODE_ENV=production
76111
ENV PORT=8080
77112
ENV HOST=0.0.0.0
78113
ENV SERVICE_NAME=llm-shield
79-
ENV SERVICE_VERSION=1.0.0
114+
ENV SERVICE_VERSION=${SERVICE_VERSION}
115+
116+
# Agent identity defaults (should be overridden at deploy time)
117+
ENV AGENT_NAME=llm-shield
118+
ENV AGENT_DOMAIN=security
119+
ENV AGENT_PHASE=phase1
120+
ENV AGENT_LAYER=layer1
80121

81122
# Expose port
82123
EXPOSE 8080
83124

84-
# Health check
85-
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
86-
CMD node -e "require('http').get('http://localhost:8080/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
125+
# Health check (checks both service health AND Ruvector connectivity)
126+
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
127+
CMD node -e "require('http').get('http://localhost:8080/health', (r) => { let d=''; r.on('data',c=>d+=c); r.on('end',()=>{const j=JSON.parse(d); process.exit(j.status==='healthy'?0:1)}) })"
87128

88129
# Start the service
130+
# NOTE: Service will crash immediately if:
131+
# - RUVECTOR_SERVICE_URL is not set
132+
# - RUVECTOR_API_KEY is not set
133+
# - AGENT_NAME is not set
134+
# - AGENT_DOMAIN is not set
135+
# - AGENT_PHASE is not "phase1"
136+
# - AGENT_LAYER is not "layer1"
137+
# - Ruvector health check fails
89138
CMD ["node", "service/dist/index.js"]
90139

91140
# ============================================================================
92141
# Metadata
93142
# ============================================================================
94143
LABEL maintainer="LLM-Shield Team"
95-
LABEL description="LLM-Shield Unified Security Service - All 9 Detection Agents"
96-
LABEL version="1.0.0"
144+
LABEL description="LLM-Shield Unified Security Service - All 9 Detection Agents (HARDENED)"
145+
LABEL version="${SERVICE_VERSION}"
146+
LABEL phase="phase1"
147+
LABEL layer="layer1"

0 commit comments

Comments
 (0)