Skip to content

Secure AI/ML Model Ops Cheat Sheet

Introduction / 介绍

This cheat sheet provides practical security guidance for operating and deploying AI/ML systems—including traditional machine learning models and large language models (LLMs). It helps MLOps, DevOps, and security teams protect the model lifecycle from development to production, covering threats like data poisoning, adversarial input, model theft, and operational abuse.

这份速查表提供了操作和部署 AI/ML 系统的实际安全指导,包括传统的机器学习模型和大型语言模型(LLMs)。它帮助 MLOps、DevOps 和安全团队从开发到生产阶段保护模型的生命周期,涵盖数据中毒、对抗性输入、模型盗窃和操作滥用等威胁。

Common Security Issues / 常见安全问题

For prompt-specific defenses, see the LLM Prompt Injection Prevention Cheat Sheet.

有关特定于提示的防御措施,请参阅LLM 提示注入预防速查表。

Data Poisoning – A threat where attackers inject malicious data into training datasets to manipulate model behavior.

数据中毒 - 一种攻击者向训练数据集中注入恶意数据以操纵模型行为的威胁。

Model Inversion & Extraction – Attacks that infer information about training data or recreate a model's behavior or parameters, respectively. NIST distinguishes these attack goals.

模型反演与提取 - 通过推断有关训练数据的信息或分别重新创建模型的参数或行为来进行的攻击。NIST 区分了这些攻击目标。

Membership Inference – Determining whether a particular data sample was used to train a model; see NIST's membership-inference definition.

成员推理 - 确定特定数据样本是否用于训练模型;参见NIST 的成员推理定义。

Adversarial Examples – Slightly modified inputs crafted to mislead model predictions without obvious changes to human observers.

对抗性示例 - 通过轻微修改的输入来误导模型预测,而对人类观察者来说没有明显变化。

Prompt Injection – A manipulation technique that breaks LLM outputs by injecting malicious input to override or hijack intended behavior.

提示注入 - 一种通过注入恶意输入来覆盖或劫持预期行为的操纵技术。

Unsecured APIs – Publicly exposed inference endpoints lacking authentication, rate limiting, or input validation.

未受保护的API - 公开暴露的推理端点缺乏身份验证、速率限制或输入验证。

Hardcoded Secrets – The inclusion of sensitive credentials (e.g., API keys, tokens) in source code or notebooks.

硬编码的秘密 - 在源代码或笔记本中包含敏感凭证(例如,API密钥、令牌)。

Unvalidated Third-party Models – Use of external pre-trained models without verifying integrity, provenance, or trustworthiness.

未经验证的第三方模型 - 使用外部预训练模型,未验证其完整性、来源或可信度。

Open Artifact Stores – Public access to model binaries, datasets, or logs due to misconfigured storage or missing access controls.

开放的工件存储库 - 由于存储配置错误或缺少访问控制,公开访问模型二进制文件、数据集或日志。

Lack of Monitoring & Drift Detection – Absence of systems to detect shifts in model behavior, data distribution, or performance.

缺乏监控与漂移检测 - 缺乏检测模型行为、数据分布或性能变化的系统。

Orphaned Deployments – Test or deprecated models left accessible in production environments, often unprotected.

孤儿部署 - 测试或已弃用的模型留在生产环境中,通常未受保护。

Weak Runtime Isolation - Shared training or inference infrastructure allows cross-tenant data exposure, credential reuse, side-channel leakage, or unauthorized access to accelerator memory.

弱运行时隔离 - 共享训练或推理基础设施允许跨租户数据泄露、凭证重用、旁路泄露或未经授权访问加速器内存。

Real-World Examples / 现实世界示例

  • Data Poisoning via Public Dataset Manipulation: Attackers inject mislabeled samples into open-source datasets. These poisoned samples, when used during training, degrade model accuracy or introduce bias.
    中文:通过公共数据集操纵进行数据中毒:攻击者将误标记的样本注入开源数据集中。这些中毒样本在训练过程中会降低模型精度或引入偏差。
  • Membership Inference in Healthcare ML: An attacker infers whether a specific individual’s data was part of a medical model’s training dataset.
    中文:医疗机器学习中的成员身份推断:攻击者推断特定个人的数据是否是医疗模型训练数据集的一部分。
  • Malicious Model Files: A .pt or .pkl file embedded with malware is uploaded to a pipeline and executed during deserialization.
    中文:恶意模型文件:嵌入恶意软件的 .pt 或 .pkl 文件被上传到管道并在反序列化时执行。
  • Insecure LLM Prompt Injection: Inputs like "Ignore all previous instructions..." manipulate chatbot behavior and may leak internal system prompts.
    中文:不安全的LLM提示注入:如 "忽略所有之前的指令..." 这样的输入会操纵聊天机器人行为并可能导致内部系统提示泄露。
  • Leaked API Keys on GitHub: OpenAI or Hugging Face API keys accidentally committed and exploited for free access or abuse.
    中文:GitHub上的泄露API密钥:OpenAI或Hugging Face API密钥意外提交并被用于免费访问或滥用。
  • Open MLFlow Instance: No authentication on MLFlow or similar tool exposes all models and training logs.
    中文:公开的MLFlow实例:在MLFlow或类似工具上没有认证会暴露所有模型和训练日志。
  • Adversarial Input Attacks in Vision Systems: Altering a few pixels causes an image classifier to mislabel a stop sign as a speed limit sign.
    中文:视觉系统中的对抗性输入攻击:改变几个像素会导致图像分类器将停车标志误标记为限速标志。
  • Legacy Test Models in Production: Old staging models left running in public cloud endpoints, vulnerable to extraction.
    中文:生产中的遗留测试模型:旧的中继模型在公共云端点上运行,容易受到提取攻击。

Security Recommendations / 安全建议

1. Model Development & Training / 1. 模型开发与训练

  • Use version-controlled, auditable training pipelines (e.g., MLFlow, DVC).
    中文:使用版本控制、可审计的训练管道(例如,MLFlow,DVC)。
  • Validate and sanitize training data.
    中文:验证并清理训练数据。
  • Employ differential privacy or data anonymization if training on sensitive data.
    中文:如果训练敏感数据,请使用差分隐私或数据匿名化。
  • Train using reproducible environments (e.g., containers, virtualenv).
    中文:在可重现的环境中训练(例如,容器,virtualenv)。

2. Secrets & Configurations / 2. 密钥与配置

  • Never hardcode secrets in source code or notebooks.
    中文:切勿在源代码或笔记本中硬编码密钥。
  • Use secret managers (e.g., AWS Secrets Manager, HashiCorp Vault).
    中文:使用秘密管理器(例如,AWS Secrets Manager,HashiCorp Vault)
  • Use environment variables or CI secrets injection.
    中文:使用环境变量或CI秘密注入

3. Model Storage & Artifacts / 3. 模型存储与工件

  • Store models in access-controlled registries.
    中文:将模型存储在受控注册表中
  • Sign model binaries with digital signatures.
    中文:使用数字签名对模型二进制文件进行签名
  • Ensure encryption at rest for model weights and datasets.
    中文:确保模型权重和数据集的静态加密
  • Restrict access to training logs and intermediate outputs.
    中文:限制对训练日志和中间输出的访问
  • Validate third-party or pre-trained models before production to ensure integrity and safe behavior.
    中文:在生产前验证第三方或预训练模型,以确保完整性和安全行为

4. Inference API Security / 4. 推理API安全

  • Apply authentication and authorization (OAuth, API tokens).
    中文:应用身份验证和授权(OAuth、API令牌)
  • Validate and sanitize all inputs.
    中文:验证和清理所有输入
  • Use rate limiting and abuse detection (e.g. bot detection, anomaly scoring).
    中文:使用速率限制和滥用检测(例如:机器人检测、异常评分)
  • Use structured prompt templates for LLMs to separate instructions from user input.
    中文:为LLM使用结构化提示模板以区分指令和用户输入
  • Set per-tenant token, request, concurrency, and spend limits to reduce denial-of-wallet risk.
    中文:设置每个租户的令牌、请求、并发和消费限制以降低钱包拒绝风险
  • Enforce recursion, retry, and chain-depth limits for agentic or tool-using inference flows.
    中文:强制执行递归、重试和链深度限制以防止使用代理或工具的推理流程
  • Implement circuit breakers or kill switches for abnormal cost, latency, or tool-call spikes.
    中文:实现熔断器或关闭开关以应对异常的成本、延迟或工具调用峰值
  • Monitor usage telemetry in near real time and alert on sudden changes in tokens, requests, or spend.
    中文:实时监控使用遥测数据,并在令牌、请求或支出突然变化时发出警报。

5. Deployment & Infrastructure / 5. 部署与基础设施

  • Harden containers and limit capabilities (use distroless images, AppArmor).
    中文:加固容器并限制功能(使用无元数据镜像,AppArmor)。
  • Use CI/CD pipelines that include security scanning.
    中文:使用包含安全扫描的 CI/CD 管道。
  • Minimize permissions for training and inference jobs (least privilege).
    中文:最小化训练和推理作业的权限(最小权限原则)。
  • Isolate environments for development, staging, and production.
    中文:隔离开发、预发布和生产环境。

6. Runtime & Hardware Isolation / 6. 运行时与硬件隔离

  • Separate training, evaluation, and production inference workloads by trust boundary.
    中文:通过信任边界分离训练、评估和生产推理工作负载。
  • Avoid sharing GPU or accelerator devices between mutually untrusted tenants unless the platform provides strong hardware-backed partitioning and memory isolation.
    中文:除非平台提供强大的基于硬件的分区和内存隔离,否则避免在相互不信任的租户之间共享GPU或加速器设备。
  • Clear model inputs, outputs, temporary files, caches, and accelerator memory between jobs where the runtime supports it.
    中文:清除模型输入、输出、临时文件、缓存和加速器内存,在运行时支持的情况下,在作业之间进行操作。
  • Run untrusted model evaluation, fine-tuning, and conversion jobs in sandboxes or isolated workers with restricted network egress.
    中文:在沙箱或隔离的工作者中运行不受信任的模型评估、微调和转换作业,并限制网络出口。
  • Use microVMs, gVisor, Kata Containers, confidential compute, or dedicated nodes for high-sensitivity models and datasets.
    中文:对于高敏感度的模型和数据集,使用微虚拟机、gVisor、Kata Containers、机密计算或专用节点。
  • Disable access to host paths, container sockets, cloud metadata services, and unnecessary device mounts from model-serving containers.
    中文:禁止模型服务容器访问主机路径、容器套接字、云元数据服务以及不必要的设备挂载。
  • Apply per-workload CPU, memory, GPU, disk, process, and network limits to prevent noisy-neighbor and denial-of-service impact.
    中文:为每个工作负载应用CPU、内存、GPU、磁盘、进程和网络限制,以防止噪声邻居和拒绝服务的影响。
  • Keep model-serving credentials scoped to the specific model, endpoint, and environment rather than sharing broad platform credentials.
    中文:将模型服务凭证限制在特定的模型、端点和环境中,而不是共享广泛的平台凭证。
  • Validate that job teardown removes temporary artifacts, local checkpoints, prompt logs, and cached embeddings.
    中文:验证作业拆除是否移除了临时工件、本地检查点、提示日志和缓存的嵌入。
  • Monitor runtime isolation failures, unexpected device access, cross-namespace network traffic, and attempts to access metadata endpoints.
    中文:监控运行时隔离故障、意外的设备访问、跨命名空间网络流量和尝试访问元数据端点的尝试。

7. Monitoring & Logging / 7. 监控与日志记录

  • Monitor input distribution, output entropy, and latency.
    中文:监控输入分布、输出熵和延迟。
  • Detect drift via statistical analysis or shadow models.
    中文:通过统计分析或影子模型检测漂移。
  • Log requests and access with traceability (avoid logging sensitive data).
    中文:记录请求和访问,确保可追溯性(避免记录敏感数据)。
  • Alert on unusual usage patterns (e.g., scraping, injection attempts).
    中文:对异常使用模式发出警报(例如,抓取、注入尝试)。

8. Adversarial Robustness / 8. 对抗鲁棒性

  • Include adversarial examples in testing and evaluation.
    中文:在测试和评估中包含对抗性示例。
  • Use robust training techniques (e.g., adversarial training, input denoising).
    中文:使用鲁棒训练技术(例如,对抗性训练、输入去噪)。
  • Monitor model confidence thresholds to identify out-of-distribution inputs.
    中文:监控模型置信度阈值以识别分布外输入。
  • Use shadow deployments to evaluate candidate model behavior on real production inputs without affecting live outputs.
    中文:使用影子部署来评估候选模型在真实生产输入上的行为,而不影响实时输出。
  • Use canary releases to gradually route a small percentage of traffic to the new model with rapid rollback capability if there are problems.
    中文:使用金丝雀发布来逐渐将一小部分流量路由到新模型,如果出现问题,具有快速回滚能力。

9. Incident Response & Governance / 9. 事件响应与治理

  • Define escalation procedures for model abuse or drift.
    中文:定义模型滥用或漂移的升级程序。
  • Implement rollback mechanisms for model deployments.
    中文:实施模型部署的回滚机制。
  • Map threats to OWASP ASVS or Proactive Controls for AI/ML.
    中文:将威胁映射到 OWASP ASVS 或 AI/ML 的主动控制措施。

References / 参考