<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://lordeassan.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://lordeassan.github.io/" rel="alternate" type="text/html" hreflang="en" /><updated>2026-11-04T15:49:07+00:00</updated><id>https://lordeassan.github.io/feed.xml</id><title type="html">Alessandro Bragetti</title><subtitle>Alessandro Bragetti — SAP BTP &amp; Full Stack Developer (SAP CAP, Node.js, SAPUI5/Fiori, OData, SAP Integration Suite). Also exploring AI engineering and cybersecurity.</subtitle><author><name>Alessandro Bragetti</name></author><entry><title type="html">Building Secure ML Pipelines: A Practical Guide</title><link href="https://lordeassan.github.io/blog/2026/02/15/building-secure-ml-pipelines/" rel="alternate" type="text/html" title="Building Secure ML Pipelines: A Practical Guide" /><published>2026-02-15T00:00:00+00:00</published><updated>2026-02-15T00:00:00+00:00</updated><id>https://lordeassan.github.io/blog/2026/02/15/building-secure-ml-pipelines</id><content type="html" xml:base="https://lordeassan.github.io/blog/2026/02/15/building-secure-ml-pipelines/"><![CDATA[<p>Modern ML systems process sensitive data, make critical decisions, and often run in environments with broad network access. Yet security is frequently treated as an afterthought — bolted on after the model is trained and deployed.</p>

<p>This post outlines a practical approach to building ML pipelines that are <strong>secure by design</strong>.</p>

<h2 id="the-threat-landscape">The Threat Landscape</h2>

<p>Machine learning pipelines introduce unique attack surfaces:</p>

<ul>
  <li><strong>Data poisoning</strong> — adversarial manipulation of training data</li>
  <li><strong>Model extraction</strong> — stealing model weights via API inference</li>
  <li><strong>Supply chain attacks</strong> — compromised dependencies in training frameworks</li>
  <li><strong>Inference manipulation</strong> — crafted inputs designed to exploit model behavior</li>
</ul>

<p>Understanding these threats is the first step toward building resilient systems.</p>

<h2 id="principles-for-secure-ml">Principles for Secure ML</h2>

<h3 id="1-validate-everything">1. Validate Everything</h3>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Schema validation on incoming training data
</span><span class="kn">from</span> <span class="n">pydantic</span> <span class="kn">import</span> <span class="n">BaseModel</span><span class="p">,</span> <span class="n">validator</span>

<span class="k">class</span> <span class="nc">TrainingRecord</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span>
    <span class="n">feature_a</span><span class="p">:</span> <span class="nb">float</span>
    <span class="n">feature_b</span><span class="p">:</span> <span class="nb">float</span>
    <span class="n">label</span><span class="p">:</span> <span class="nb">int</span>

    <span class="nd">@validator</span><span class="p">(</span><span class="sh">'</span><span class="s">label</span><span class="sh">'</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">label_must_be_valid</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">v</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">raise</span> <span class="nc">ValueError</span><span class="p">(</span><span class="sh">'</span><span class="s">Invalid label</span><span class="sh">'</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">v</span>
</code></pre></div></div>

<p>Every input — training data, configuration, model artifacts — should be validated against a strict schema before processing.</p>

<h3 id="2-isolate-the-pipeline">2. Isolate the Pipeline</h3>

<p>Run training and inference in <strong>sandboxed environments</strong> with minimal permissions:</p>

<ul>
  <li>Use container isolation (rootless containers preferred)</li>
  <li>Apply network policies — training jobs shouldn’t reach the internet</li>
  <li>Implement least-privilege IAM roles</li>
</ul>

<h3 id="3-sign-and-verify-artifacts">3. Sign and Verify Artifacts</h3>

<p>Model files are code. Treat them accordingly:</p>

<ul>
  <li>Hash and sign model artifacts after training</li>
  <li>Verify signatures before deployment</li>
  <li>Maintain an immutable artifact registry</li>
</ul>

<h3 id="4-monitor-drift-and-anomalies">4. Monitor Drift and Anomalies</h3>

<p>Deploy monitoring that catches both data drift and adversarial patterns:</p>

<ul>
  <li>Statistical tests on input distributions</li>
  <li>Anomaly detection on prediction confidence scores</li>
  <li>Rate limiting and abuse detection on inference endpoints</li>
</ul>

<h2 id="architecture-overview">Architecture Overview</h2>

<p>A secure ML pipeline typically follows this flow:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[Data Ingestion] → [Validation] → [Sandboxed Training]
       ↓                                    ↓
  [Audit Log]                    [Signed Model Artifact]
                                          ↓
                              [Staged Deployment]
                                          ↓
                              [Monitored Inference]
</code></pre></div></div>

<p>Each stage has its own security controls, logging, and rollback mechanisms.</p>

<h2 id="takeaways">Takeaways</h2>

<p>Building secure ML systems isn’t about adding layers of complexity — it’s about making security a <strong>first-class concern</strong> in your engineering process. Start with threat modeling, validate inputs, isolate workloads, and monitor everything.</p>

<p>The cost of security debt in ML systems is high. The cost of building it in from day one is surprisingly low.</p>

<hr />

<p><em>This is the first post in a series on secure AI engineering. Next up: adversarial robustness testing for production models.</em></p>]]></content><author><name>AI_SEC</name></author><category term="ai" /><category term="security" /><category term="engineering" /><summary type="html"><![CDATA[How to design machine learning pipelines with security built in from day one — threat modeling, data validation, and deployment hardening.]]></summary></entry><entry><title type="html">Adversarial Robustness: What Your Model Doesn’t Know Can Hurt It</title><link href="https://lordeassan.github.io/blog/2025/12/08/adversarial-robustness/" rel="alternate" type="text/html" title="Adversarial Robustness: What Your Model Doesn’t Know Can Hurt It" /><published>2025-12-08T00:00:00+00:00</published><updated>2025-12-08T00:00:00+00:00</updated><id>https://lordeassan.github.io/blog/2025/12/08/adversarial-robustness</id><content type="html" xml:base="https://lordeassan.github.io/blog/2025/12/08/adversarial-robustness/"><![CDATA[<p>Machine learning models are surprisingly fragile. A carefully crafted perturbation — invisible to humans — can cause a state-of-the-art classifier to fail with high confidence. This isn’t a theoretical concern; it’s a practical attack vector that’s been demonstrated against self-driving cars, medical imaging systems, and content moderation pipelines.</p>

<h2 id="the-problem-space">The Problem Space</h2>

<p>Adversarial examples exploit the gap between how models <em>learn</em> and how we <em>expect</em> them to behave. A model trained to classify images sees statistical patterns in pixel distributions. An adversary can manipulate those distributions at the sub-pixel level:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Fast Gradient Sign Method (FGSM) — Goodfellow et al., 2014
</span><span class="k">def</span> <span class="nf">fgsm_attack</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">image</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">epsilon</span><span class="o">=</span><span class="mf">0.03</span><span class="p">):</span>
    <span class="n">image</span><span class="p">.</span><span class="n">requires_grad</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="n">output</span> <span class="o">=</span> <span class="nf">model</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
    <span class="n">loss</span> <span class="o">=</span> <span class="n">F</span><span class="p">.</span><span class="nf">cross_entropy</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
    <span class="n">model</span><span class="p">.</span><span class="nf">zero_grad</span><span class="p">()</span>
    <span class="n">loss</span><span class="p">.</span><span class="nf">backward</span><span class="p">()</span>
    
    <span class="c1"># Perturb in the direction of the gradient
</span>    <span class="n">perturbation</span> <span class="o">=</span> <span class="n">epsilon</span> <span class="o">*</span> <span class="n">image</span><span class="p">.</span><span class="n">grad</span><span class="p">.</span><span class="n">data</span><span class="p">.</span><span class="nf">sign</span><span class="p">()</span>
    <span class="n">adversarial_image</span> <span class="o">=</span> <span class="n">image</span> <span class="o">+</span> <span class="n">perturbation</span>
    <span class="k">return</span> <span class="n">torch</span><span class="p">.</span><span class="nf">clamp</span><span class="p">(</span><span class="n">adversarial_image</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">epsilon</code> value controls the perturbation magnitude. At ε = 0.03, the change is invisible to the human eye — but it can drop model accuracy from 95% to below 10%.</p>

<h2 id="defense-strategies">Defense Strategies</h2>

<p>There’s no silver bullet, but several techniques significantly improve robustness:</p>

<p><strong>Adversarial Training</strong> — The most effective approach. Train on adversarial examples generated during each epoch. Computationally expensive (3-10x training cost) but provides empirical robustness.</p>

<p><strong>Input Preprocessing</strong> — Apply transformations (JPEG compression, spatial smoothing, bit-depth reduction) before inference. Breaks some perturbation patterns but can degrade clean accuracy.</p>

<p><strong>Certified Defenses</strong> — Mathematical guarantees of robustness within an ε-ball. Randomized smoothing is the leading approach for L2 perturbations. More principled than empirical defenses.</p>

<p><strong>Ensemble Methods</strong> — Use multiple diverse models and aggregate predictions. Adversarial examples that fool one model often don’t transfer to architecturally different ones.</p>

<h2 id="a-practical-robustness-pipeline">A Practical Robustness Pipeline</h2>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌────────────────┐
│  Training Data  │
└───────┬────────┘
        │
        ▼
┌────────────────┐     ┌──────────────────┐
│  Standard       │────▶│  Adversarial     │
│  Training       │     │  Example Gen     │
└───────┬────────┘     └───────┬──────────┘
        │                       │
        ▼                       ▼
┌────────────────┐     ┌──────────────────┐
│  Adversarial    │◀────│  Augmented       │
│  Training       │     │  Dataset         │
└───────┬────────┘     └──────────────────┘
        │
        ▼
┌────────────────┐
│  Robustness     │
│  Evaluation     │
│  (PGD, AutoAtk) │
└───────┬────────┘
        │
        ▼
┌────────────────┐
│  Deploy with    │
│  Monitoring     │
└────────────────┘
</code></pre></div></div>

<h2 id="key-takeaways">Key Takeaways</h2>

<ol>
  <li><strong>Test adversarially</strong> — Include PGD and AutoAttack in your eval suite</li>
  <li><strong>Budget for robustness</strong> — Adversarial training costs 3-10x more compute</li>
  <li><strong>Monitor in production</strong> — Detect distribution shift and adversarial inputs</li>
  <li><strong>Defense in depth</strong> — Combine adversarial training with input validation</li>
  <li><strong>Accept the tradeoff</strong> — Robust models often sacrifice 1-3% clean accuracy</li>
</ol>

<p>The field is evolving rapidly. What’s clear is that robustness isn’t optional — it’s a security requirement for any ML system operating in adversarial environments.</p>]]></content><author><name>Alessandro Bragetti</name></author><category term="ai" /><category term="security" /><category term="adversarial-ml" /><summary type="html"><![CDATA[Exploring adversarial attacks on ML models, defense strategies, and why robustness testing should be part of every ML pipeline.]]></summary></entry></feed>