Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Moving a college to zero trust in stages

After this lesson: I can plan a staged move to zero trust and write the alerts that show it is working.

65 min lesson9 commandsWireGuard lab: build a VPN tunnel between two sites in your browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

By 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

WordWhat it means
Report modelogging what a rule would refuse, and refusing nothing
Enforce moderefusing what the rules do not allow
Staged rolloutswitching on one part at a time
Break-glass accountan emergency login kept for when access fails
Alerta message that asks a person to look
Baselinewhat normal looks like, measured first

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

One 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

StageWhat changesWhat to logAlert on
1 Inventorynothing; flows and apps listedevery connection to each appnothing yet
2 Proxy, reportthe proxy logs would-denyevery decision and its reasonnothing; read the week
3 Proxy, enforcerefusals are realevery decisionforged tokens, refusal bursts
4 Device checksposture joins the decisionthe device in each decisionone device at two addresses
5 Walls and mTLSnftables and certificatesdrop counters, refused handshakesany drop at db, certificates near expiry
6 Retire flat VPNthe VPN reaches the proxy onlywho still uses the old pathany use of the old path

The cells students fill in are left blank in this preview.

Try it: ready to enforce?

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Start the campus with fresh tokens

Command
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.tok

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write a morning of traffic, part 1

Command
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.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write a morning of traffic, part 2

Command
printf '%s\n' 'for token, path in MORNING[sys.argv[1]]:' '    print(ask(token, path), token or "no token", path)' >> ~/zt/traffic.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the alert rules, part 1

Command
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.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the alert rules, part 2

Command
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.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A morning in report mode

Command
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 printer

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Read what enforcing would refuse

Command
cd ~/zt && python3 alerts.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A 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

Command
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 printer

Shown 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

Command
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]*')"; done

Shown 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 "-".

Code: python
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

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.