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
1120FROM node:20-slim
1221
22+ # Build argument for version
23+ ARG SERVICE_VERSION=1.0.0
24+
1325WORKDIR /app
1426
1527# Install build dependencies (needed for native modules)
@@ -29,6 +41,10 @@ RUN npm install
2941WORKDIR /app/contracts
3042RUN 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
3349WORKDIR /app/prompt-injection-detection
3450RUN 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"
5773WORKDIR /app/credential-exposure-detection
5874RUN npm install && npm run build || echo "credential-exposure build completed"
5975
60- # Build service
76+ # Build service (with hardened startup validation)
6177WORKDIR /app/service
6278RUN 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
7288USER 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)
75110ENV NODE_ENV=production
76111ENV PORT=8080
77112ENV HOST=0.0.0.0
78113ENV 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
82123EXPOSE 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
89138CMD ["node" , "service/dist/index.js" ]
90139
91140# ============================================================================
92141# Metadata
93142# ============================================================================
94143LABEL 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