OpenCyber Academy
Engineering · Chapter 26 · English
Course code: OCA-135Chapter 26: OCA-135-C026

Chapter 26 — AI and machine-learning security: architecture alternatives

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Lesson map

Lesson 26 published. Map, example, EX076.

flowchart TD
  N0["Learning outcomes"]
  N1["26.1 Patterns for LLM applications"]
  N2["26.2 Patterns for predictive ML services"]
  N3["26.3 Hosted versus self-hosted"]
  N4["26.4 Trade-off analysis"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5
  N5 --> EX["Worked example"]
  EX --> Q["Exercise EX076"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["26.1 Patterns for LLM applications"]
  N2["26.2 Patterns for predictive ML services"]
  N3["26.3 Hosted versus self-hosted"]
  N4["26.4 Trade-off analysis"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> Q["EX076"]
[Learning outcomes]
    |
    v
[26.1 Patterns for LLM applications]
    |
    v
[26.2 Patterns for predictive ML services]
    |
    v
[26.3 Hosted versus self-hosted]
    |
    v
[26.4 Trade-off analysis]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX076]

Learning outcomes

You will (1) compare architectural patterns for LLM applications and ML services by security properties; (2) evaluate patterns such as dual-model (privileged/quarantined), plan-then-execute, retrieval isolation and human-in-the-loop; (3) choose between hosted and self-hosted models with a threat lens; and (4) justify a choice with a trade-off table.

26.1 Patterns for LLM applications

These patterns reduce injection impact by limiting what untrusted text can influence; none removes it entirely.

26.2 Patterns for predictive ML services

Return labels rather than full probability vectors when clients do not need confidences (reduces extraction and membership-inference signal); add input validation and out-of-distribution detection; ensemble or randomise where it increases attack cost; isolate training from serving.

Each measure raises the cost of a specific attack. Returning only labels removes the fine-grained scores that extraction and membership inference rely on, as the membership lab showed with confidence outputs. Out-of-distribution detection flags inputs unlike the training data, which includes many adversarial ones. Isolating training from serving means a compromised serving host cannot alter the data the next model learns from.

26.3 Hosted versus self-hosted

Hosted models offer strong operations and fast updates but change without notice, process data outside your boundary and may restrict testing. Self-hosted models give control and reproducibility but make you responsible for patching, capacity and safety tuning. The choice is a risk decision involving data protection, testing authority and supply-chain trust.

For NRS, sending rail-maintenance documents to an outside provider may be acceptable, while sending HR reports may not; the data's classification decides as much as the model's quality. A hosted model that updates silently can also invalidate a security evaluation overnight, so contracts should state how changes are announced and whether customers may test.

26.4 Trade-off analysis

Score each alternative on residual injection impact, data exposure, utility, latency, cost and operational burden. Make the weighting explicit and get stakeholders to agree on it before scoring.

Agreeing weights first prevents the analysis from being tuned to justify a favourite. Scores need short reasons, such as 'dual model: untrusted text yields only a fixed record, so injected actions cannot reach the planner model'. Where a criterion such as latency can be measured, a measurement replaces the estimate. The result is a recommendation with its basis visible, which stakeholders can challenge on the facts rather than on preference, and which can be rescored if weights change later.

26.5 Worked example (synthetic NRS case)

For the depot-planner assistant, Sam compared single-model, dual-model and plan-then-execute. Dual-model scored best on injection impact (untrusted bulletins only produce a constrained "affected asset IDs and severity" record) but cost 30% more latency. Plan-then-execute could not handle planners' iterative questions well. The team chose dual-model for bulletin processing and single-model for free conversation without tools.

The split decision combines the strengths of both patterns. Free conversation has no tools, so injection there can at worst produce a misleading answer, and bulletins reach planning only as constrained records. The 30% latency cost falls only on bulletin processing, which runs in the background rather than while a planner waits for an answer.

26.6 Errors and limits

A pattern chosen because others use it may defend against threats the system does not face while missing those it does. A quarantined model that returns free text gives injected instructions a direct route to the privileged model, defeating the pattern's purpose. Hosted-model terms that forbid testing leave a team unable to verify its own security claims, so those terms are checked before the choice is made.

Exercises

Synthesis

Architecture choices determine how far untrusted input can reach. Dual-model, plan-then-execute, isolation and approval patterns trade latency and flexibility for bounded impact.

Continue studying — chapter 26 of 50

← Chapter 25 (draft) · Course chapter index · Chapter 27 (draft) →

Worked answers

EX076. If the quarantined model returned free text, injected instructions could pass through it into the privileged model's context. A strict schema (IDs, enumerations, numbers) carries only the needed facts.

EX077. Model extraction and confidence-based membership inference (both exploit detailed scores).

EX078. Hosted: provider's mature operations and patching; no need to secure GPU infrastructure. Self-hosted: data stays within your boundary; versions are fixed and testable under your own authority (also: no terms restricting testing).