Introduction
Deploying machine learning models to production goes beyond accuracy and latency—it requires a strong focus on security.
A deployed model interacts with live data, APIs, and automated pipelines. Each layer introduces potential attack vectors.
Securing model deployments means ensuring confidentiality, integrity, and availability across:
- Infrastructure (VMs, Kubernetes, network)
- Container environments (Docker, images)
- APIs (FastAPI, Flask)
- CI/CD pipelines
- Secrets and credentials
A “working” model isn’t enough — it must be secure, monitored, and resilient.
Threat Landscape
| Threat | Description | Example | Mitigation |
|---|---|---|---|
| Model Theft | Model weights stolen via excessive API calls | Inference extraction attack | Add rate limiting, authentication |
| Data Leakage | Sensitive data in logs or traces | Debug log contains PII | Mask logs, enforce DLP |
| Container Escape | Host access from inside container | Privileged pod | Use runAsNonRoot, AppArmor |
| Dependency Exploits | Vulnerable packages | Outdated Flask version | Scan with Trivy or Snyk |
| CI/CD Injection | Pipeline variable leak | Malicious merge request | Protected env vars, code reviews |
| Unsecured API | No auth or HTTPS | Open /predict endpoint |
JWT/mTLS enforcement |
Threat Modeling Steps
- Identify assets: model, data, API, pipelines
- Classify threats (STRIDE method)
- Prioritize by impact × likelihood
- Apply mitigations per layer
- Continuously monitor & audit
Security is a continuous process, not a one-time configuration.
Infrastructure Hardening
Network Isolation (Kubernetes)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: restrict-model-access
namespace: model-prod
spec:
podSelector:
matchLabels:
app: model-api
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
access: allowed
egress:
- to:
- namespaceSelector:
matchLabels:
env: monitoring
For bare-metal:
sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw allow from 10.1.0.0/22 to any port 8000 proto tcp
Kernel and SSH Hardening
cat