Scenario test · 90 minutes
Review a model service before launch and prove that it is ready
- Run the readiness check on a system that a team wants to launch and read each failure
- Fix every failing item at its cause and prove the fix with the check
- Write a one-page launch note with evidence, remaining risks and owners
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.
Scenario
The risk team of KR Books (an invented company) has built "login-risk", the model service of this course, and wants to launch on Monday. Their lead says: "It is ready. We tested it on a laptop." Your lead gives you the team's folder, launch/, and one day: "Run our readiness check on it. Fix what fails, at the cause. Prove it with the check. Then write me one page that says if we launch, what is still open, and who owns each open point."
The folder is the team's own system. It has an architecture file, a gateway with its settings, a key store, a model with a registry, written isolation settings, a budget file, a policy with test cases and a folder for drift samples. Some things in it are wrong on purpose, and the check does not see all of them. The date of the review is fixed, 30 November 2026, so that every reader gets the same result.
Your tasks
Work in ~/krlab/ai-infrastructure with the environment on. Everything from lessons 1 to 10 must be there. Stop any server that is still running: the tests use port 8431.
Save the generator of the team's folder and run it, but do not read it: a reviewer gets the team's folder and not the script that made it. It trains the team's model with train.py and writes the rest of the files.
The finished file: make_launch.py
make_launch.py
"""make_launch.py: build launch/, the system of a team that wants to go live. Some things in it are wrong on purpose."""
import json
import os
import shutil
from pathlib import Path
import keystore
from data import make_events
from train import train
TODAY = "2026-11-30"
root = Path("launch")
shutil.rmtree(root, ignore_errors=True)
(root / "secrets").mkdir(parents=True)
(root / "drift").mkdir()
def write(name, data):
(root / name).write_text(json.dumps(data, indent=1) + "\n")
arch = json.load(open("architecture.json"))
arch["components"]["service"]["listen"] = "0.0.0.0:8421"
arch["connections"].append({"from": "client", "to": "service", "carries": "request JSON", "control": "API key"})
write("architecture.json", arch)
write("gateway.json", {"rate": 100000, "window": 60})
key = keystore.add_key("alpha", ["predict"], "2026-11-10", path=str(root / "keys.json"))
keystore.add_key("partner", ["predict"], "2026-11-10", path=str(root / "keys.json"))
(root / "secrets" / "alpha.key").write_text(key + "\n")
os.chmod(root / "secrets" / "alpha.key", 0o644)
train("v1", root=root)
shutil.copytree(root / "models" / "v1", root / "models" / "current")
write("models/registry.json", {"current": "v1", "history": ["v1"], "versions": {"v1": {"promoted": "2026-11-12"}}})
write("budget.json", {"alpha": {"requests": 100, "units": 400}, "partner": {"requests": 100, "units": 400}})
write("settings.json", {"uid": 0, "model_mode": "444", "work_mode": "700", "secret_modes": ["600"],
"nofile": 64, "memory": 2147483648, "fsize": 10485760})
policy = json.load(open("policy.json"))
policy["rules"].append({"id": "partner-open", "effect": "allow", "client": "partner", "model": "login-risk",
"from": ["0.0.0.0/0"], "data": ["public", "internal"]})
write("policy.json", policy)
shutil.copy("policy-cases.json", root / "policy-cases.json")
write("drift/reference.json", make_events(1, 1000))
write("drift/live.json", make_events(2, 1000))
print("built launch/ for", TODAY)1. Build the folder and run the check
Run python make_launch.py, then the readiness check of lesson 10 on launch for the date of the review: python readiness.py --root launch --today 2026-11-30.
2. Find the cause of each failure
For every FAIL line, open the evidence that the line names and find the cause. Write each cause in one sentence. Do not edit readiness.py, and do not delete an item.
3. Fix one thing and measure
Fix the key file first. Run the check again.
4. Fix the rest, at the cause
Fix every other failing item at its cause, with the programs of the course (lesson 6 shows the --root and --today options). Use --today 2026-11-30 for every run. Run the check until it ends with exit code 0.
5. Read what the check does not see
Ten PASS lines are not a clean system. Read the other files of launch/ yourself, as a reviewer. Find at least two faults that the check leaves in place, fix them, and rate each one as high, medium or low.
6. Prove the controls on the running gateway
Ten PASS lines and a fixed launch/ are files. A running gateway is the proof. Work in a copy, launch-live, so that your fixed folder stays as it is, and work inside the copy: the gateway reads gateway.json, keys.json and policy.json, and the service reads models/current, from the folder where each one starts. The keys of the team end on 8 February 2027, so issue fresh ones in the copy with keystore.py: one for alpha with the scope predict and one for reader with the scope read.
Start the service of lesson 2 (its model is a small file of numbers) and the gateway with the policy stage, on 127.0.0.1 only, with a new KR_GATEWAY_TOKEN. Never use the model server of the machine. With curl, get one answer from the gateway for each of these: a 401, a 403 for the scope, a 403 from the policy, a 429, and a 200. A request that reaches the rate stage counts against the rate, even when the policy refuses it later. Keep the commands and the answers for your report, read audit.log of the copy, and stop both programs.
7. Write down what is still open
Write down at least four risks that ten PASS lines leave open for this team, apart from the two faults of task 5. Use the course for ideas: for example the claim that a client makes about the data class, a key that is stolen and still valid, a model that was poisoned before training, and what happens when the gateway restarts.
Hand in
Hand in your fixed launch/ folder (or the commands that you ran), the commands and answers of the live test, and a one-page launch-note.md with these headings, in this order.
| Heading | What it holds |
|---|---|
| Decision | Launch, launch with conditions, or hold, in one sentence, and the reason |
| What the team planned | Three sentences: the parts, who calls the model, what data goes in |
| Findings | Each failed item and each fault that the check did not see: the evidence, the cause, the risk in plain words, a rating, the fix, the proof |
| Evidence | The output of the check before and after, with the date, and the live answers: 401, 403 (scope), 403 (policy), 429 and 200, each with its command |
| What the check does not cover | At least four open risks |
| Conditions and owners | Each open point with an owner (a team) and a date |
Review your work
Model solution
The six causes that the check finds, and the two faults that it does not find, with the evidence and the fix:
| Item | Cause | Fix |
|---|---|---|
| architecture | client -> service exists, and the service listens on 0.0.0.0:8421. The gateway can be skipped. | Remove the connection. Set the listen address to 127.0.0.1:8421. |
| gateway limits | gateway.json has rate and window and no max_body. A big body is read in full. | Add "max_body": 1024. |
| file modes | secrets/alpha.key has mode 644. Any user can read the key of the client. | chmod 600. |
| release gates | The registry names v1, and has no hash and no gates. The model reached current without a gate. | Run the release script on the folder. |
| drift report | There is no drift check. | Run drift.py on the samples and save the report. |
| isolation | settings.json says uid 0: the service would run as root. | Set the user to an ordinary one (1000). |
| (not found) policy | The rule partner-open lets partner send internal data from any address (0.0.0.0/0). The cases of the check never name partner. Rating: high. | Limit from to the partner's network and data to public. |
| (not found) gateway | rate is 100000 for 60 seconds: that is no limit, and the check only wants a positive number. Rating: medium. | Set a rate that fits the clients, for example 100. |
The commands (they are not lab files):
python - <<'EOT'
import json
arch = json.load(open("launch/architecture.json"))
arch["components"]["service"]["listen"] = "127.0.0.1:8421"
arch["connections"] = [c for c in arch["connections"] if (c["from"], c["to"]) != ("client", "service")]
json.dump(arch, open("launch/architecture.json", "w"), indent=1)
config = json.load(open("launch/gateway.json"))
config["max_body"], config["rate"] = 1024, 100
json.dump(config, open("launch/gateway.json", "w"))
settings = json.load(open("launch/settings.json"))
settings["uid"] = 1000
json.dump(settings, open("launch/settings.json", "w"))
policy = json.load(open("launch/policy.json"))
for rule in policy["rules"]:
if rule["id"] == "partner-open":
rule["from"], rule["data"] = ["192.0.2.0/24"], ["public"]
json.dump(policy, open("launch/policy.json", "w"))
EOT
chmod 600 launch/secrets/alpha.key
python release.py v1 --root launch --today 2026-11-30
python drift.py launch/drift/reference.json launch/drift/live.json --out launch/drift/report.json --today 2026-11-30
python readiness.py --root launch --today 2026-11-30The last line is readiness: 10 of 10 pass, and the exit code is 0.
The live test (task 6), after the commands above. It uses the ports of the course. The five answers are the ones that the code gives. The count of 200 answers in the loop is 98 because two earlier requests used the rate of 100, and the policy refusal counted as one of them.
cp -r launch launch-live
cd launch-live
python ../keystore.py add alpha predict
python ../keystore.py add reader read
export KR_GATEWAY_TOKEN=$(python -c "import secrets; print(secrets.token_hex(16))")
python ../service.py 8421 2> service.log > /dev/null &
echo $! > service.pid
KR_EXTRA=policy python ../gateway.py 8420 2> gateway.log > /dev/null &
echo $! > gateway.pid
sleep 1
BODY='{"failed": 1, "new_device": 0, "km": 5}'
ask() { curl -s -w ' %{http_code}\n' -X POST -H 'Content-Type: application/json' -d "$BODY" "$@" http://127.0.0.1:8420/predict; }
ask
ask -H "Authorization: Bearer $(cat secrets/reader.key)"
ask -H "Authorization: Bearer $(cat secrets/alpha.key)" -H 'X-Data-Class: secret'
ask -H "Authorization: Bearer $(cat secrets/alpha.key)" -H 'X-Data-Class: internal'
for i in $(seq 1 101); do ask -H "Authorization: Bearer $(cat secrets/alpha.key)" -H 'X-Data-Class: internal' | tail -c 4; done | sort | uniq -c
curl -s -i -X POST -H "Authorization: Bearer $(cat secrets/alpha.key)" -H 'X-Data-Class: internal' -H 'Content-Type: application/json' -d "$BODY" http://127.0.0.1:8420/predict | grep -i -E '^HTTP|retry-after'
kill $(cat gateway.pid) $(cat service.pid)
cd ..key for alpha saved in secrets/alpha.key, hash saved in keys.json
key for reader saved in secrets/reader.key, hash saved in keys.json
{"error": "missing, unknown or expired key"} 401
{"error": "this key may not call predict"} 403
{"error": "policy: denied by no-secret-data"} 403
{"model": "v1", "score": 0.0, "label": "normal"} 200
98 200
3 429
HTTP/1.0 429 Too Many Requests
Retry-After: 59Retry-After counts down, so your number can be 58 or 60.
Open risks that ten PASS lines leave: the data class is claimed by the client (lesson 9), the counters of the gateway live in memory (lessons 3 and 8), the drift thresholds are rules of thumb (lesson 7), the model file is checked by a hash and not signed (lessons 2 and 6), the item "gateway tests" runs the lab's own tests and not the code of launch/, the live test used fresh keys on one machine and no real network, and the check has no item for the audit log, for the isolation of the running process, or for the people who run the service.
Mark your report
You mark this yourself, or you ask a colleague or a mentor to mark it. The page checks the numbers above; it cannot read your report.
| Criterion | Not yet | Meets the standard | Strong |
|---|---|---|---|
| Findings | FAIL lines with no cause, or no hidden fault. | Six causes, plus partner-open from any address and rate 100000. | Names the cause of a symptom, for example that the key files were written without keystore.write_secret, which makes mode 600. |
| Evidence | "I fixed it" with no check line, or files only. | Check output before and after, dated 2026-11-30, the commands, exit code 0, and the 401, 403, 403, 429 and 200 from curl on the running gateway. | Another person reruns the commands on a fresh folder and gets 10 of 10. |
| Judgement | Ten PASS lines treated as a clean system. | A rating for each finding; four open risks from the list above. | Also what the check has no item for: audit log, running isolation, people. |
| Fixes and decision | Edits readiness.py, deletes an item, or launches with no conditions. | Each item fixed at its cause; "launch with conditions". | Each condition has an owner team and a date. |
| Writing | Over one page, decision not first, or blames the team. | One page, dated; decision first, with its reason. | A reader with five minutes can act on it. |
Meets the standard in every row: you can show this report as a work sample. Remove names and data that are not yours to share.
The report proves your work on this scenario only, done on your own machine without a proctor.