OpenCyber Academy
Engineering · Chapter 41 · English
Course code: OCA-122Chapter 41: OCA-122-C041

Chapter 41 — Security architecture and engineering: system optimization

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 41 published. Map, example, EX121.

flowchart TD
  N0["Learning outcomes"]
  N1["41.1 Choosing under constraints"]
  N2["41.2 Greedy versus exhaustive"]
  N3["Lab — Greedy and exhaustive control selection"]
  N4["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4
  N4 --> EX["Worked example"]
  EX --> Q["Exercise EX121"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["41.1 Choosing under constraints"]
  N2["41.2 Greedy versus exhaustive"]
  N3["Lab — Greedy and exhaustive control selection"]
  N4["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> Q["EX121"]
[Learning outcomes]
    |
    v
[41.1 Choosing under constraints]
    |
    v
[41.2 Greedy versus exhaustive]
    |
    v
[Lab — Greedy and exhaustive control selection]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX121]

Learning outcomes

You will (1) frame control selection as an optimisation under budget; (2) compare greedy and exhaustive selection on synthetic data; (3) recognise limits of numeric optimisation in security.

41.1 Choosing under constraints

Corvia's security budget for next year cannot fund every proposed control. Sofia frames the choice as optimisation: each candidate control has a cost and an estimated risk reduction from the risk assessment in chapter 24, and the goal is to maximise total reduction within budget. This is a version of the knapsack problem from discrete mathematics. Framing the decision this way makes assumptions explicit and lets stakeholders see why one control was preferred over another, rather than relying on whoever argues loudest in a budget meeting.

41.2 Greedy versus exhaustive

Sofia compares two methods on eight synthetic candidate controls. A greedy method picks controls in order of reduction per unit cost until the budget is used. An exhaustive search tries every combination, feasible here because eight items give only 256 subsets. The lab below shows that greedy selection comes close but misses the best combination, because it fills the budget with small efficient items and leaves no room for one large, valuable control. For larger problems exhaustive search becomes impossible, and engineers use better algorithms or accept approximations knowingly.

Lab — Greedy and exhaustive control selection

# Greedy vs exhaustive control selection under budget (synthetic costs and risk reductions).
from itertools import combinations
C = {"mfa-admins": (8, 10), "egress-filter": (15, 13), "log-review": (20, 14), "hsm-keys": (50, 34),
     "edr-depots": (35, 20), "phish-training": (12, 9), "backup-offline": (25, 17), "waf": (30, 15)}
B = 100
g, cost, val = [], 0, 0
for k, (c, v) in sorted(C.items(), key=lambda kv: kv[1][1] / kv[1][0], reverse=True):
    if cost + c <= B: g.append(k); cost += c; val += v
best = max((s for r in range(len(C) + 1) for s in combinations(C, r) if sum(C[k][0] for k in s) <= B),
           key=lambda s: sum(C[k][1] for k in s))
print(f"greedy:     value {val}, cost {cost}, {sorted(g)}")
print(f"exhaustive: value {sum(C[k][1] for k in best)}, cost {sum(C[k][0] for k in best)}, {sorted(best)}")

Run with python3 lab_knapsack.py. Verified output:

greedy:     value 63, cost 80, ['backup-offline', 'egress-filter', 'log-review', 'mfa-admins', 'phish-training']
exhaustive: value 74, cost 98, ['backup-offline', 'egress-filter', 'hsm-keys', 'mfa-admins']

41.3 Limits of the numbers

Optimisation is only as good as its inputs. Risk-reduction estimates are uncertain, controls interact, so two controls may overlap rather than add, and some controls are mandatory for compliance regardless of score. Sofia runs the selection with low and high estimates and shows which controls are chosen in every scenario; those are robust choices. She presents the result as decision support, not a decision. Daniel adds that the exercise's main value is the conversation it forces about estimates, which often reveals that nobody knows how much a popular control actually reduces risk.

Worked example

Sofia frames next year's controls as a budgeted knapsack problem, shows greedy selection missing the optimum on synthetic data and identifies robust choices across estimate ranges.

Synthetic case. Controls, costs and reductions are synthetic.

Errors and limits

Additive risk reduction is unrealistic when controls overlap. Mandatory controls must be fixed before optimisation.

Exercises

Synthesis

Optimisation frames security investment clearly, but uncertain and interacting estimates make its output advice, not a verdict.

Continue studying — chapter 41 of 50

← Chapter 40 (draft) · Course chapter index · Chapter 42 (draft) →

Worked answers

EX121. The knapsack problem: maximise value within a weight, here cost, limit.

EX122. Greedy reached a reduction of 63 using 80 of the budget, while the exhaustive optimum reached 74 at cost 98 by including the large hsm-keys control.

EX123. It is chosen in every estimate scenario, from low to high.