# Workshop 9: AI Development and Security

> Security is not a feature you add at the end; it is a property you build in at every stage. This workshop follows the machine-learning lifecycle from data to deployment and shows where security must be engineered into the process, in the code, the pipeline, and the organization that runs it.

## Overview

Most machine-learning failures in the wild are not exotic. They come from ordinary software and operational weaknesses, an unvalidated input, an unpinned dependency with a known vulnerability, a model checkpoint loaded from an untrusted source, a secret committed to a repository, an endpoint deployed without authentication. This workshop is about closing those gaps by treating an ML system as what it is: software plus data plus models, each of which carries its own attack surface, moving through a lifecycle that has to be secured end to end.

The session builds on a simple observation from the guest lecture: the tools and knowledge to secure ML systems largely exist, yet they are frequently not applied. Practitioners optimize for getting a model to work, security is treated as someone else's field, and the result is a systematic gap between what is known and what is practiced. The workshop therefore covers both the technical substance, the ML lifecycle and how to integrate security into it (MLOps and DevSecOps), secure coding practices tailored to ML, the threats that enter through the pipeline, and a preview of deployment security, and the compliance frameworks (GDPR, HIPAA, ISO 27001, and the NIST frameworks) that increasingly make these practices mandatory rather than optional.

This is a concepts-and-practices session grounded in a guest lecture on the human side of ML security. There is no coding lab; instead, the material below is the deliverable, and it is written to be studied closely and returned to as a checklist when you build your own systems.

**Prerequisites:** Complete [Workshop 1](../Workshop01/Introduction_and_Fundamentals_in_AI.md) first. This session assumes familiarity with the basic shape of a machine-learning workflow (data, training, a deployed model that serves predictions) and draws on the threat and attack concepts introduced earlier in the program.

## Workshop Video

This session is a recorded guest lecture on AI development and security, framed around the speaker's research into why ML systems are, and are not, secured in practice. Watch the recording below, then read the material below.

<div class="video-embed">
  <iframe src="https://www.youtube.com/embed/olh_lGw0b_s" title="Workshop 9: AI Development and Security, guest lecture" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

### Guest Speaker

<div style="margin-bottom: 40px; overflow: auto;">
  <img src="../assets/images/Jaron_Mink.png" alt="Jaron Mink" align="left" width="250" height="250" style="float: left; width: 250px; height: 250px; object-fit: cover; border-radius: 50%; margin: 10px 30px 10px 0;">
  <h4 style="margin-top: 0;">Jaron Mink</h4>
  <p><strong>Arizona State University</strong> | Assistant Professor</p>
  <p>Jaron Mink is an Assistant Professor in the School of Computing and Augmented Intelligence at Arizona State University. He received his Ph.D. in Computer Science from the University of Illinois at Urbana-Champaign, and his B.Sc. (Magna Cum Laude) from the University of California, Los Angeles.</p>
  <p>Jaron investigates computer security threats and focuses on how human factors affect the security of machine learning systems. His work has appeared in top-tier venues (CHI, USENIX Security, IEEE S&P, WWW), has been covered by a variety of news outlets (New Scientist, The Transmitter, The 21st Show), and has been made into educational content (Futurum Careers). Jaron has also served as a consultant for "Partnership on AI", an NGO that fosters the responsible development of AI systems. He is an awardee of the NSF Graduate Research Fellowship Program (GRFP).</p>
</div>

## Learning Objectives

After completing this workshop, you will be able to:

- Describe the machine-learning lifecycle, data collection, feature engineering, training, evaluation, deployment, and monitoring, and identify the principal security concern that enters at each stage.
- Explain how MLOps extends software DevOps to manage data and models, and what DevSecOps adds by "shifting security left" and automating checks in the CI/CD pipeline.
- Apply secure coding practices specific to ML: input validation and sanitization, safe data handling, secrets management, and least-privilege access.
- Manage dependency and supply-chain risk with pinned versions and vulnerability scanning (for example pip-audit, Bandit, and Trivy).
- Explain why loading untrusted models is dangerous, how pickle-based formats such as `torch.load` enable arbitrary code execution, and how safer formats such as safetensors mitigate it.
- Recognize the threats that enter through the pipeline, data poisoning, model theft, adversarial examples, and lost artifact provenance, and connect them to reproducibility and integrity.
- Outline the elements of secure deployment, container hardening, authenticated and rate-limited API endpoints, and TLS, and know where the program develops them further.
- Match the major compliance frameworks (GDPR, HIPAA, ISO/IEC 27001, the NIST Cybersecurity Framework, and the NIST AI Risk Management Framework) to the ML concerns each governs.
- Explain, from the guest lecture's research, why known ML defenses are often not implemented, and why closing that gap is organizational as much as technical.

## Theoretical Background

### The Machine-Learning Lifecycle as an Attack Surface

A useful mental model, and the one the guest lecture opens with, is to draw the ML system as a pipeline and then ask where security and privacy problems can occur. In its fullest form the lifecycle runs:

**Data collection and preparation → feature engineering → training → evaluation → deployment → monitoring**, with monitoring feeding back into retraining.

Every stage is a boundary an attacker or an accident can cross. Poisoned or low-quality data enters at collection. Sensitive attributes can leak during feature engineering. Training can be non-reproducible or run on tampered data and dependencies. Evaluation can miss adversarial and edge-case behavior. Deployment exposes endpoints, containers, and model files. Monitoring can fail to notice drift, degradation, or an attack in progress. The central discipline of this workshop is to attach a concrete practice to each of those concerns rather than bolting security on at the end.

| Lifecycle stage | Principal security concern | Practice / tooling |
|---|---|---|
| Data collection & preparation | Poisoned or untrusted data; sensitive-data exposure; weak provenance | Provenance and lineage tracking; data validation; encryption at rest and in transit; access control; zero-trust and least privilege |
| Feature engineering | Leakage of sensitive attributes; unsanitized inputs | Input validation and sanitization; data minimization; remove unnecessary personal data |
| Training | Non-reproducibility; tampered data or dependencies | Pinned dependencies; log parameters, seeds, and data versions; integrity checks; isolated compute; audit logging |
| Evaluation | Blind spots to adversarial and edge behavior | Adversarial and robustness testing; fairness and backdoor checks; signed evaluation reports |
| Deployment | Vulnerable containers; exposed endpoints; unsafe model loads | Image scanning; authentication and authorization; rate limiting; TLS; safe model formats |
| Monitoring | Data drift; silent degradation; live attacks | Drift detection; security monitoring; performance and fairness monitoring; incident response |

### From DevOps to MLOps to DevSecOps

**DevOps** shortened the loop between building software and running it, code moves through build, test, deploy, monitor, and feedback, with as much of that path automated as possible. **MLOps** applies the same operational discipline to machine learning, but the object under management is larger. In software DevOps the versioned artifact is code; in MLOps it is code plus data plus trained models plus configuration, and the system's behavior is data-dependent rather than deterministic. That difference reshapes every operational concern.

| Aspect | Software DevOps | MLOps |
|---|---|---|
| Versioned artifact | Code | Code, data, models, and configuration |
| Testing | Unit and integration tests | Data validation, model tests, bias and robustness checks |
| Behavior | Deterministic | Non-deterministic, data-dependent |
| Monitoring | Error rates, latency, uptime | Model performance, data drift, fairness, plus the above |
| Rollback | Revert to a previous code version | Revert to a previous model or retrain |

**DevSecOps** is the security discipline layered onto this. Its two organizing ideas are to *shift security left*, moving security review, testing, and threat modeling to the earliest stages rather than treating them as a pre-release gate, and to *automate* those checks inside the continuous-integration and continuous-deployment (CI/CD) pipeline so that they run on every change without depending on someone remembering. In an ML pipeline that means dependency scanning and static analysis on every commit, data validation before training, adversarial and fairness tests in the evaluation stage, container image scanning before deployment, and monitoring wired into production from day one.

### Attacking the ML Pipeline

The guest lecture makes the threat model concrete by marking where attacks strike the same pipeline. Two are emblematic. **Poisoned data** is injected at the data-collection stage: by tampering with training data an attacker corrupts the model that is learned from it, potentially planting a backdoor that behaves normally until a trigger appears. **Adversarial examples** strike at deployment: a crafted input causes a trained model to produce an attacker-chosen ("hacked") prediction. Between and around these sit **model theft** (reconstructing or cloning a proprietary model through its API), **data leakage** (recovering sensitive training data from the model), and the loss of **artifact provenance** (not knowing which data, code, and parameters produced a given model, which makes both reproduction and forensic investigation impossible).

The through-line is that pipeline security is not only about defending the final model. Data poisoning is a *data-stage* failure of integrity and provenance; artifact provenance and reproducibility are *training-stage* properties; adversarial robustness is an *evaluation and deployment* property. Securing the pipeline means securing each stage's inputs, outputs, and records, so that the model you deploy is the model you built, trained on the data you trust.

### Secure Coding Practices for Machine Learning

Beneath the lifecycle sit the ordinary, unglamorous coding practices that prevent most real incidents. The following are drawn from the workshop's secure-coding reference and apply directly to ML codebases.

**Input validation and sanitization.** Never trust external input, whether it arrives through an API, a file upload, or a network interface. Before processing a file, check that it exists and is readable, that its type matches what is expected, and that its size is bounded so an oversized input cannot exhaust resources and cause a denial of service. The insecure pattern, opening and processing whatever arrives, lets an attacker supply arbitrary data that crashes the system or drives unexpected behavior; the secure pattern validates first and consistently.

**Safe data handling.** Treat data with the rigor you would apply to cryptographic keys. Encrypt sensitive data at rest and use TLS/HTTPS in transit. Apply access control on the principle of least privilege, and minimize what you collect and retain in the first place, data you never stored cannot leak. Log access to sensitive stores so there is an audit trail for monitoring and forensics, and remove or pseudonymize personal identifiers that the task does not require.

**Secrets management.** Credentials, API keys, and tokens must never be hardcoded in source, where they leak into repository history and become permanently exposed. Keep them external, in environment variables loaded from protected files or, better, in a dedicated secrets vault, and access them through secure configuration.

**Dependency and supply-chain management.** ML projects import large, fast-moving dependency trees, and each dependency is attack surface. Outdated libraries carry known vulnerabilities; compromised packages carry injected code; version drift introduces silent breakage. Pin versions with a lockfile for reproducible, controlled builds; scan regularly for known vulnerabilities with tools such as **pip-audit** (which checks Python dependencies against vulnerability advisories) and **Bandit** (static analysis for common security issues in Python); scan container images and filesystems with **Trivy**; and prune unused dependencies to shrink the surface.

**Untrusted model loads and unsafe deserialization.** This risk is specific to ML and easy to overlook. Many model formats serialize with Python's `pickle`, and `pickle` can execute arbitrary code during deserialization. Because `torch.load` is pickle-based, loading a model checkpoint downloaded from an untrusted source can run attacker-controlled code on your machine, a supply-chain vulnerability disguised as "just loading a model." The mitigation is to avoid deserializing untrusted pickles and to prefer a format that stores only tensor data and cannot execute code, such as **safetensors**. Treat a third-party checkpoint with the same suspicion as a third-party executable.

**Least privilege throughout.** Give every user, service, and process exactly the access it needs and no more, backed by a zero-trust posture that authenticates and authorizes access to data and infrastructure and continuously monitors it. This limits the blast radius when any single component is compromised.

### A Preview of Deployment Security

Deployment turns a model into a running service, and a running service has an operational attack surface. The essentials are container hardening (build minimal Docker images, scan them for vulnerabilities, run as a non-root user, and keep secrets out of the image), secure API endpoints (TLS for all traffic, authentication to establish who is calling, authorization to check they may perform the requested operation, and rate limiting to blunt abuse and brute-force probing), and monitoring wired in from the start to detect anomalies and attacks. These are introduced here so the lifecycle is complete; **Workshop 11** develops secure deployment and operation of AI systems in depth.

### Regulatory and Compliance Frameworks

Security practice does not exist in a legal vacuum. Several frameworks govern how ML systems that handle personal or sensitive data must be built and operated, and increasingly they turn good practice into a requirement.

| Framework | What it governs | Why it matters to ML |
|---|---|---|
| **GDPR** (EU General Data Protection Regulation) | Processing of EU residents' personal data | Requires lawful basis and consent, purpose limitation, data minimization, retention limits, and supports a right to explanation for automated decisions, constraining what data a model may use and demanding that decisions be explainable |
| **HIPAA** (US health-data law) | Protected Health Information (PHI) | Mandates access controls, audit controls, and encryption for any ML system touching patient data, plus agreements binding third-party processors |
| **ISO/IEC 27001** | Information Security Management Systems (ISMS) | A certifiable framework for managing security systematically, security policy, access control, cryptography, incident management, and supplier assurance, applicable to the organization running the ML system |
| **NIST Cybersecurity Framework (CSF)** | General cybersecurity risk management | Its core functions, Identify, Protect, Detect, Respond, Recover (CSF 2.0 adds a sixth, Govern), give a widely adopted structure for organizing the controls above across the ML lifecycle |
| **NIST AI Risk Management Framework (AI RMF)** | Risks specific to AI systems | Provides an AI-specific vocabulary and process (Govern, Map, Measure, Manage) for identifying and mitigating risks such as bias, robustness failures, and misuse, complementing the general-purpose CSF |

These frameworks are the bridge to the next session. **Workshop 10** takes up AI and data governance, regulations, and standards in depth, treating the legal and policy layer as a subject in its own right rather than a checklist appended to engineering.

### The Human Factor: Why Defenses Exist but Are Not Implemented

The guest lecture's distinctive contribution is empirical and human-centered: it studies not the attacks and defenses themselves but the *people* who are supposed to apply them, and it finds a consistent gap between available defenses and deployed ones. Two studies frame it. One examines how security practitioners perceive ML-based tools and finds that ML is adopted mainly *alongside* rule-based systems rather than replacing them, valued for catching novel patterns but held back by false positives and opacity, and that security is often not even a primary consideration in tool choice. The other asks why ML developers do not secure their systems, and locates the barriers at three points along the path from a developer to an active defense.

- **Exposure.** Many practitioners simply are not exposed to adversarial-ML concepts. Data privacy is broadly understood, but model security and privacy are not; some believe security is "not their field" and separate from ML. The knowledge is concentrated in specialized CS courses and is rarely demanded by project requirements, which are functionality-centered and often set by non-technical stakeholders.
- **Assessment.** Even where developers are aware, misconceptions and missing tools prevent accurate risk assessment. Threat models are frequently wrong, so vulnerabilities go unseen, and evaluation stops at accuracy and F1-scores, adversarial and edge-case testing is ad hoc when it happens at all.
- **Implementation.** Organizational structure impedes the last step. Teams are isolated along the pipeline, so responsibility for defense is diffuse, and security teams are further removed still, so the pipeline rarely benefits from their expertise.

The reference reading reaches the same conclusion from the code itself: ML researchers and practitioners continue to use insecure coding practices despite public documentation of the risks and mature, low-friction tooling, largely because they prioritize rapid experimentation and do not see themselves or their projects as targets. The lesson of the workshop is therefore double. The technical practices in the sections above are necessary, but they are not self-executing. Closing the gap between known and applied security requires organizational commitment: making security a stated project requirement, breaking the isolation between ML and security teams, and building the practices into the pipeline so that doing the secure thing is the path of least resistance.

## Hands-on Lab

This workshop has no coding notebook. It shares its recorded lab walkthrough with Workshops 5 and 10.

<div class="video-embed">
  <iframe src="https://www.youtube.com/embed/2Do8I3l5kn0" title="Workshop 9: AI Development and Security, lab walkthrough" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

## Key Takeaways

- Secure ML is built stage by stage. Map the lifecycle, data, features, training, evaluation, deployment, monitoring, and attach a concrete security practice to the concern at each stage rather than adding security at the end.
- MLOps extends DevOps to manage data and models as well as code; DevSecOps adds the security layer by shifting checks left and automating them in CI/CD.
- The pipeline is the attack surface: data poisoning enters at collection, adversarial examples at deployment, and lost provenance undermines integrity and reproducibility throughout.
- The high-value secure-coding habits are ordinary: validate all input, handle data like keys, keep secrets out of code, pin and scan dependencies, never load untrusted pickles (prefer safetensors), and apply least privilege everywhere.
- Deployment security, hardened containers, authenticated and rate-limited endpoints, TLS, and monitoring, completes the lifecycle and is developed further in Workshop 11.
- Compliance is not optional overhead: GDPR, HIPAA, ISO/IEC 27001, and the NIST CSF and AI RMF each govern part of how ML systems must be built, and they lead into Workshop 10's treatment of governance.
- The binding constraint is often human, not technical. Defenses exist but go unapplied because of gaps in exposure, assessment, and implementation; closing them is an organizational task as much as an engineering one.

## Additional Resources

- **Slide deck - Jaron Mink, AI Development and Security (PDF):** [`SecAI_Workshop09_JaronMink.pdf`](https://github.com/SecureAI-luc/SecureAI-Lab/blob/main/Workshop09/slides/SecAI_Workshop09_JaronMink.pdf) - the guest lecture deck, covering the ML pipeline as an attack surface and the human barriers to securing ML systems.
- **Slide deck - Secure Coding in Machine Learning (PDF):** [`Secure Coding in Machine Learning-1.pdf`](https://github.com/SecureAI-luc/SecureAI-Lab/blob/main/Workshop09/slides/Secure Coding in Machine Learning-1.pdf) - the companion deck on secure development and deployment practices for ML.
<!-- - **Reference notes - Secure Coding in Machine Learning:** [`secure_coding_in_machinelearning.md`](docs/secure_coding_in_machinelearning.md) — *needs to be added to `Workshop09/assets/docs/` in the SecureAI repo first, then this will resolve on both local build and GitHub.* -->
- **OWASP Top 10:** [owasp.org/www-project-top-ten](https://owasp.org/www-project-top-ten/) - the baseline catalog of web-application security risks that ML services inherit as soon as they are exposed over an API.
- **OWASP Machine Learning Security Top 10:** [mltop10.info](https://mltop10.info/) - an OWASP list of the most significant security risks specific to machine-learning systems.
- **NIST Cybersecurity Framework:** [nist.gov/cyberframework](https://www.nist.gov/cyberframework) - the Identify/Protect/Detect/Respond/Recover structure for organizing security controls.
- **NIST AI Risk Management Framework:** [nist.gov/itl/ai-risk-management-framework](https://www.nist.gov/itl/ai-risk-management-framework) - an AI-specific framework (Govern, Map, Measure, Manage) for identifying and mitigating AI risks.
- **ISO/IEC 27001:** [iso.org/standard/27001](https://www.iso.org/standard/27001) - the international standard for information-security management systems.
- **pip-audit:** [github.com/pypa/pip-audit](https://github.com/pypa/pip-audit) - scans Python dependencies for known vulnerabilities.
- **Bandit:** [bandit.readthedocs.io](https://bandit.readthedocs.io/) - static analysis for common security issues in Python code.
- **Trivy:** [trivy.dev](https://trivy.dev/) - vulnerability scanning for container images and filesystems.
- **safetensors:** [github.com/huggingface/safetensors](https://github.com/huggingface/safetensors) - a safe tensor-serialization format that stores data without executing code, unlike pickle-based checkpoints.
- **Docker:** [docs.docker.com](https://docs.docker.com/) - containerization; harden and scan images before deployment.
- **[Program Resource Library](../resources.md)** - shared papers, tools, and datasets for the full workshop series.

## Next Steps

Continue to [Workshop 10: AI and Data Governance - Regulations and Standards](../Workshop10/AI_and_Data_Govern_Regulations_and_Standards.md), which develops the legal and policy layer previewed here, turning frameworks such as GDPR and the NIST AI RMF from a checklist into a subject of study, and situating secure development inside the broader accountability that governance provides.
