# AI Guard — Muro de Anonimización Perimetral (Zero-Knowledge Proxy)

> **Corre en la infraestructura del cliente. El SaaS jamás ve datos en texto plano.**

Este directorio contiene los artefactos de despliegue del proxy perimetral que
las instituciones financieras instalan en su propia infraestructura para
garantizar que ninguna PII, tarjeta, CLABE, RFC o CURP cruce la frontera hacia
AI Guard LATAM.

## Contenido

```
.
├── docker-compose.yml            # Despliegue local con Docker
├── Dockerfile                    # Imagen del proxy (non-root, distroless-like)
├── proxy/
│   ├── main.py                   # FastAPI thin-proxy con la capa ZK
│   └── requirements.txt
├── k8s/                          # Manifiestos Kubernetes (EKS / AKS / GKE)
│   ├── 00-namespace.yaml
│   ├── 10-configmap.yaml
│   ├── 20-secret.yaml
│   ├── 30-redis.yaml             # Redis RAM-only (emptyDir medium=Memory)
│   ├── 40-perimeter-wall.yaml    # Deployment + Service + HPA + PDB
│   ├── 50-networkpolicy.yaml     # Default-deny + reglas explícitas
│   └── kustomization.yaml
├── WHITEPAPER.md                 # Whitepaper técnico oficial (LFPDPPP/CNBV/T-MEC)
└── README.md
```

## Despliegue local (Docker Compose)

```bash
export AIGUARD_API_KEY=gov_live_xxxxxxxxxxxxxxxx
export AIGUARD_REDACTION_SALT=$(openssl rand -hex 32)
export REDIS_PASSWORD=$(openssl rand -hex 24)

docker compose up -d
curl http://localhost:8443/healthz
```

## Despliegue en cluster (Kubernetes)

```bash
# 1. Crear el secret con valores reales (nunca commitees credenciales)
kubectl create namespace aiguard-perimeter
kubectl create secret generic perimeter-wall-secrets \
  --namespace aiguard-perimeter \
  --from-literal=AIGUARD_API_KEY=gov_live_xxxxxxxxxxxxxxxx \
  --from-literal=AIGUARD_REDACTION_SALT=$(openssl rand -hex 32) \
  --from-literal=REDIS_PASSWORD=$(openssl rand -hex 24)

# 2. Aplicar el resto con kustomize
kubectl apply -k k8s/

# 3. Verificar
kubectl -n aiguard-perimeter get pods,svc,hpa
kubectl -n aiguard-perimeter port-forward svc/perimeter-wall 8443:443
curl -k https://localhost:8443/healthz
```

## Uso desde las apps internas del banco

```python
import httpx
async with httpx.AsyncClient(base_url="http://perimeter-wall.aiguard-perimeter.svc") as c:
    r = await c.post("/proxy/evaluate", json={
        "text": "Cliente Juan Pérez con tarjeta 4111 1111 1111 1111 pagó MX$50,000",
        "session_id": "chat-9821",
        "stage": "INPUT",
        "model_id": "chatbot-atencion",
    })
    print(r.json())
```

## Panel local de auditoría (CISO)

```bash
curl http://localhost:8443/audit/summary          # KPIs agregados
curl http://localhost:8443/audit/verify-chain     # integridad hash-chain
curl http://localhost:8443/audit/export > log.json  # export completo tamper-evident
```

## Whitepaper técnico

Ver [`WHITEPAPER.md`](./WHITEPAPER.md) — documento formal para CTOs, CISOs y
auditores externos que demuestra el cumplimiento con LFPDPPP, CNBV, T-MEC e
ISO 27001.
