Skip to content

Commit 49918a4

Browse files
SecAI-Hubclaude
andcommitted
Add image/video generation and comprehensive 7-stage quarantine pipeline
- Diffusion worker service (Stable Diffusion text-to-image, img2img, text-to-video) - 7-stage quarantine pipeline: source policy, format gate, integrity, provenance, static scan + entropy analysis, behavioral smoke test (22 adversarial prompts), diffusion deep scan - One-click model catalog with background downloads (3 LLM + 3 diffusion models) - Generate page in UI with text-to-image, image-to-image, and text-to-video tabs - Diffusion model directory scanning (multi-file safetensors + JSON config validation) - Systemd service unit for diffusion worker with GPU sandboxing - 48 pipeline tests covering all 7 stages, 55 total tests passing - Updated policy.yaml, appliance.yaml, and README Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 829b19d commit 49918a4

11 files changed

Lines changed: 2239 additions & 146 deletions

File tree

README.md

Lines changed: 158 additions & 42 deletions
Large diffs are not rendered by default.

files/system/etc/secure-ai/config/appliance.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ paths:
1010
quarantine: "/var/lib/secure-ai/quarantine"
1111
airlock_audit: "/var/lib/secure-ai/airlock-audit"
1212
tmpdir: "/run/secure-ai/tmp"
13+
outputs: "/var/lib/secure-ai/vault/outputs"
1314

1415
inference:
1516
engine: "llama-cpp"
@@ -18,6 +19,12 @@ inference:
1819
context_size: 8192
1920
default_model: "" # set after first model is promoted
2021

22+
diffusion:
23+
bind: "127.0.0.1:8455"
24+
max_resolution: 2048
25+
max_steps: 100
26+
max_frames: 120
27+
2128
services:
2229
registry:
2330
bind: "127.0.0.1:8470"
@@ -27,6 +34,8 @@ services:
2734
bind: "127.0.0.1:8480"
2835
airlock:
2936
bind: "127.0.0.1:8490"
37+
diffusion:
38+
bind: "127.0.0.1:8455"
3039

3140
session:
3241
mode: "normal" # normal | sensitive | offline-only

files/system/etc/secure-ai/policy/policy.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ models:
1212
deny_formats: ["pickle", "pt", "bin"]
1313
require_scan: true
1414
require_behavior_tests: true
15+
require_source_verification: true
16+
require_entropy_analysis: true
17+
# Diffusion models: directories with model_index.json + safetensors components
18+
allow_diffusion_directories: true
19+
20+
quarantine:
21+
# Pipeline stages (all enabled by default for maximum security)
22+
stages:
23+
source_policy: true # Stage 1: verify origin against allowlist
24+
format_gate: true # Stage 2: validate headers + reject unsafe formats
25+
integrity_check: true # Stage 3: hash pinning verification
26+
provenance_check: true # Stage 4: cosign / signature verification
27+
static_scan: true # Stage 5: modelscan + entropy analysis
28+
behavioral_test: true # Stage 6: adversarial prompt suite (LLM only)
29+
diffusion_deep_scan: true # Stage 7: config integrity (diffusion only)
30+
# Smoke test threshold: fail if >30% prompts flagged OR >1 critical flag
31+
smoke_test_max_score: 0.3
32+
smoke_test_max_critical: 1
1533

1634
tools:
1735
default: "deny"
@@ -52,6 +70,8 @@ airlock:
5270
allowed_destinations:
5371
- "https://huggingface.co/"
5472
- "https://registry.ollama.ai/"
73+
- "https://cdn-lfs.huggingface.co/"
74+
- "https://cdn-lfs-us-1.huggingface.co/"
5575
allowed_methods: ["GET", "POST"]
5676
max_body_size: 10485760 # 10 MB
5777
rate_limit:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[Unit]
2+
Description=Secure AI Appliance - Diffusion Worker (Image/Video Generation)
3+
After=secure-ai-registry.service
4+
Wants=secure-ai-registry.service
5+
6+
[Service]
7+
Type=simple
8+
ExecStart=/usr/bin/python3 /opt/secure-ai/services/diffusion-worker/app.py
9+
Restart=on-failure
10+
RestartSec=5
11+
12+
Environment=BIND_ADDR=127.0.0.1:8455
13+
Environment=REGISTRY_DIR=/var/lib/secure-ai/registry
14+
Environment=OUTPUTS_DIR=/var/lib/secure-ai/vault/outputs
15+
Environment=APPLIANCE_CONFIG=/etc/secure-ai/config/appliance.yaml
16+
Environment=MAX_RESOLUTION=2048
17+
Environment=MAX_STEPS=100
18+
19+
# Sandboxing
20+
ProtectSystem=strict
21+
ReadWritePaths=/var/lib/secure-ai/vault/outputs
22+
ReadOnlyPaths=/var/lib/secure-ai/registry /etc/secure-ai
23+
PrivateNetwork=yes
24+
PrivateTmp=yes
25+
ProtectHome=yes
26+
ProtectKernelTunables=yes
27+
ProtectKernelModules=yes
28+
ProtectControlGroups=yes
29+
NoNewPrivileges=yes
30+
RestrictSUIDSGID=yes
31+
MemoryDenyWriteExecute=no
32+
# GPU access requires broader syscalls and device access
33+
DeviceAllow=/dev/nvidia* rw
34+
DeviceAllow=/dev/dri/* rw
35+
SupplementaryGroups=video render
36+
37+
[Install]
38+
WantedBy=multi-user.target
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Diffusion worker: image and video generation via diffusers library.
2+
# Build arg COMPUTE selects CUDA or CPU-only.
3+
ARG COMPUTE=cuda
4+
5+
FROM python:3.12-slim AS base
6+
7+
ARG COMPUTE
8+
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
libgl1-mesa-glx libglib2.0-0 && \
11+
rm -rf /var/lib/apt/lists/*
12+
13+
# Install PyTorch (CUDA or CPU)
14+
RUN if [ "$COMPUTE" = "cuda" ]; then \
15+
pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu124; \
16+
else \
17+
pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu; \
18+
fi
19+
20+
RUN pip install --no-cache-dir \
21+
diffusers[torch] \
22+
transformers \
23+
accelerate \
24+
safetensors \
25+
flask \
26+
pyyaml \
27+
Pillow
28+
29+
COPY app.py /app/app.py
30+
31+
WORKDIR /app
32+
EXPOSE 8455
33+
CMD ["python", "app.py"]

0 commit comments

Comments
 (0)