Monday morning, and nobody can sign in
A college switched every rule on at once over a weekend. On Monday the exam board could not reach the grades, and the rules were all turned off by lunch.
A move to zero trust goes in stages, and each stage is measured first.
The one rule
Warning
Everything in this module happens on the lab machine that is your own. Sending attack traffic at a live college network needs the owner's written permission. In the UK, without it, it can break the Computer Misuse Act 1990.
Quick check: the rule
Have a go
Quick check: the rule
3 questionsBy the end of this lesson
Note
I can plan a staged move to zero trust and write the alerts that show it is working.
Key words
| Word | What it means |
|---|---|
| Report mode | logging what a rule would refuse, and refusing nothing |
| Enforce mode | refusing what the rules do not allow |
| Staged rollout | switching on one part at a time |
| Break-glass account | an emergency login kept for when access fails |
| Alert | a message that asks a person to look |
| Baseline | what normal looks like, measured first |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
3 questionsOne stage at a time, measured first
Start with what exists: list every app and every flow, then put the proxy in front in report mode.
Read a week of would-deny lines and fix what is legitimate. Then enforce one app, then add device checks, walls and mutual TLS. The flat VPN goes last.
A plan for the college
| Stage | What changes | What to log | Alert on |
|---|---|---|---|
| 1 Inventory | nothing; flows and apps listed | every connection to each app | nothing yet |
| 2 Proxy, report | the proxy logs would-deny | every decision and its reason | nothing; read the week |
| 3 Proxy, enforce | refusals are real | every decision | forged tokens, refusal bursts |
| 4 Device checks | posture joins the decision | the device in each decision | one device at two addresses |
| 5 Walls and mTLS | nftables and certificates | drop counters, refused handshakes | any drop at db, certificates near expiry |
| 6 Retire flat VPN | the VPN reaches the proxy only | who still uses the old path | any use of the old path |
The cells students fill in are left blank in this preview.
Try it: ready to enforce?
week = [("amy", "allow"), ("ben", "would-deny"), ("dina", "allow"), ("ben", "would-deny"),
("amy", "allow"), ("eli", "would-deny")]
broken = sorted({user for user, decision in week if decision == "would-deny"})
print("enforcing today would lock out:", broken)
print("ready to enforce:", not broken)
# Give eli the access he needs by changing his entry to "allow". Is it ready now?
Make a free account to save your work and track your progress.
Check
Have a go
Check
3 questionsStart the campus with fresh tokens
cd ~/zt && zt up; zt start db db python3 db.py && zt start grades-tls grades python3 tlsapp.py && python3 idp.py issue amy -1 && mv amy.tok old.tok && python3 idp.py issue amy && python3 idp.py issue ben && python3 idp.py issue carla && python3 forge.py ben.tokShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write a morning of traffic, part 1
mkdir -p ~/zt && printf '%s\n' '"""traffic.py laptop | printer: a morning of requests to the proxy, as the people on that node make them."""' 'import sys' 'import urllib.error' 'import urllib.request' '' 'MORNING = {' ' "laptop": [("amy.tok", "/grades")] * 3 + [("carla.tok", "/admin/export"), ("ben.tok", "/grades"),' ' ("old.tok", "/grades")],' ' "printer": [(None, "/grades")] + [("forged.tok", "/admin/export")] * 3 + [("amy.tok", "/grades")],' '}' '' '' 'def ask(token, path):' ' request = urllib.request.Request("http://10.30.0.5:8000" + path)' ' if token:' ' request.add_header("Authorization", "Bearer " + open(token).read().strip())' ' request.add_header("X-Posture", open("laptop.posture").read().strip())' ' try:' ' with urllib.request.urlopen(request, timeout=5) as answer:' ' return answer.status' ' except urllib.error.HTTPError as refused:' ' return refused.code' '' '' > ~/zt/traffic.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write a morning of traffic, part 2
printf '%s\n' 'for token, path in MORNING[sys.argv[1]]:' ' print(ask(token, path), token or "no token", path)' >> ~/zt/traffic.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the alert rules, part 1
mkdir -p ~/zt && printf '%s\n' '"""alerts.py [LOG]: read the decisions of the proxy and print what the security team should look at."""' 'import collections' 'import json' 'import sys' '' 'records = [json.loads(line) for line in open(sys.argv[1] if len(sys.argv) > 1 else "logs/proxy.log")' ' if line.startswith("{")]' 'refused = collections.Counter(r["reason"] for r in records if not r["decision"] == "allow")' 'for reason, count in sorted(refused.items()):' ' print(f"refused or would refuse: {reason} x{count}")' 'forged = collections.Counter(r["client"] for r in records if r["reason"] == "bad signature")' 'for client, count in sorted(forged.items()):' ' print("ALERT", count, "forged tokens from", client)' 'for r in records:' ' if r["path"] == "/admin/export" and r["decision"] == "allow":' ' print("ALERT admin export by", r["user"], "from", r["client"])' 'places = collections.defaultdict(set)' 'for r in records:' ' if not r["device"] == "-":' > ~/zt/alerts.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the alert rules, part 2
printf '%s\n' ' places[r["device"]].add(r["client"])' 'for device, clients in sorted(places.items()):' ' if len(clients) > 1:' ' print("ALERT device", device, "used from", len(clients), "addresses:", " ".join(sorted(clients)))' 'by_client = collections.defaultdict(list)' 'for r in records:' ' if not r["decision"] == "allow":' ' by_client[r["client"]].append(r["time"])' 'for client, times in sorted(by_client.items()):' ' if any(times[i + 2] - times[i] <= 60 for i in range(len(times) - 2)):' ' print("ALERT", len(times), "refusals from", client, "with three inside a minute")' >> ~/zt/alerts.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
A morning in report mode
cd ~/zt && rm -f logs/proxy.log && zt start proxy proxy python3 proxy.py --posture --mtls --report && sudo ip netns exec zt-laptop python3 devagent.py report laptop && zt laptop python3 traffic.py laptop; zt printer python3 traffic.py printerShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read what enforcing would refuse
cd ~/zt && python3 alerts.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsA common mistake
Warning
Many people think zero trust is a product to switch on in one go. It is a set of checks added one at a time. Each is measured in report mode first, with a break-glass account kept in case access fails.
Keep the week's log and enforce
cd ~/zt && mv logs/proxy.log logs/report-week.log && zt start proxy proxy python3 proxy.py --posture --mtls && sudo ip netns exec zt-laptop python3 devagent.py report laptop && zt laptop python3 traffic.py laptop; zt printer python3 traffic.py printerShown here, not run. Press Start lab to type it into your own lab’s terminal.
The fix, and how it is seen
The fix is the plan: each stage switched on only when its would-deny lines are understood. The proof is in what is refused now, and in the alerts that keep running.
Send the proxy's decisions, the drop counters and the refused handshakes to one place, and alert on them every day.
Run the alerts on the enforced morning
cd ~/zt && python3 alerts.py && for n in grades db; do echo "$n drops: $(sudo ip netns exec zt-$n nft list chain inet zt input | grep -o 'packets [0-9]*')"; doneShown here, not run. Press Start lab to type it into your own lab’s terminal.
Assignment: is this app ready to enforce?
Decide from a report week whether an app is ready to enforce.
would_break(records) returns {(user, path): count} for every would-deny by a known user (not "-"). ready(records, minimum=5) is True when at least minimum requests were allowed and nothing would break. shared_devices(records) returns the sorted devices seen from more than one client address, ignoring "-".
def would_break(records):
# records: the proxy's decisions, [{"user": "ben", "path": "/grades", "decision": "would-deny"}, ...]
# Return {(user, path): count} for every would-deny by a known user (not "-").
return {}
def ready(records, minimum=5):
# True when at least minimum requests were allowed and nothing known would break.
return False
def shared_devices(records):
# The sorted device names seen from more than one client address. Ignore "-".
return []
Make a free account to save your work and track your progress.
Exit quiz
Have a go