Lecture 26 · Security in distributed systems: resilience under attack

Distributed Systems · Lecture 26。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: CMU 15-440/640 Spring 2026, the learning outcome on resilience under attack: channel security, authentication, authorization, and the theme protection from accidental and malicious harm. Reading: Satyanarayanan 1989 on AFS security. There is no problem set on this material; the course ends here. Sources:

  • R. Needham and M. Schroeder, Using Encryption for Authentication in Large Networks of Computers (CACM 1978);
  • D. Denning and G. Sacco, Timestamps in Key Distribution Protocols (CACM 1981);
  • B. C. Neuman and T. Ts’o, Kerberos: An Authentication Service for Computer Networks (IEEE Communications 1994);
  • M. Satyanarayanan, Integrating Security in a Large Distributed System (ACM TOCS 1989), AFS;
  • J. Saltzer and M. Schroeder, The Protection of Information in Computer Systems (Proc. IEEE 1975);
  • W. Diffie and M. Hellman, New Directions in Cryptography (IEEE IT 1976);
  • D. Dolev and A. Yao, On the Security of Public Key Protocols (IEEE IT 1983);
  • M. Abadi and R. Needham, Prudent Engineering Practice for Cryptographic Protocols (IEEE TSE 1996);
  • A. Birgisson et al., Macaroons (NDSS 2014);
  • J. Kohl and B. C. Neuman, The Kerberos Network Authentication Service (V5) (RFC 1510 / 4120).

The slides are not public; this is not a transcript. This lecture is defensive: it explains the mechanisms that keep a distributed system working when the network, and some of its machines, cannot be trusted. It treats cryptography as a set of black boxes with stated promises and does not describe how to attack any system. Every number not attributed to a source comes from code/lecture26/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9); the cryptographic code there is for teaching only, never for real use. Code: code/lecture26/. Reading time: ~85 minutes, plus about five seconds to run the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. State a threat model: what an attacker on the network can and cannot do, and why the design assumes it (the Dolev–Yao model).
  2. Use the four cryptographic black boxes — a MAC, authenticated encryption, a key-derivation function, and public-key signatures and agreement — knowing what each promises and, as importantly, what it does not.
  3. Build a secure channel step by step, and explain why integrity, order and confidentiality are separate properties.
  4. Explain freshness and three ways to guarantee it — timestamps with a replay cache, monotonic counters, and nonces — with their costs.
  5. Explain authentication with a trusted key server: shared-key Needham–Schroeder, the Denning–Sacco timestamp fix, and Kerberos tickets and authenticators.
  6. Explain authorization: access-control lists against capabilities, as the two directions of the access matrix, including AFS’s directory ACLs, groups and negative rights, and how each model revokes.
  7. Define the trusted computing base and apply the principles of least privilege, complete mediation, defence in depth and fail-safe defaults.

0.2 Prerequisites and scope

  • Prerequisites:
    • Lecture 4: RPC semantics, duplicate suppression, the end-to-end argument — the same duplicates and reorderings this lecture meets again, now from a hostile network, not just a lossy one;
    • Lecture 5: AFS naming, volumes, whole-file caching (AFS’s security is a running example);
    • Lecture 7: leases and bounded time, which Kerberos tickets reuse;
    • Lecture 14: Byzantine faults — an attacker is a Byzantine participant who also controls the network;
    • Lecture 17: write-ahead logging and durable state, which freshness counters need;
    • Lecture 25 §5.7: why open peer-to-peer systems are hard to secure.
  • Scope:
    • Covered: threat models, channel security, freshness, authentication with a trusted server, authorization.
    • Treated as black boxes: the internals of block ciphers, hash functions, and the number theory behind public-key cryptography. This is a distributed-systems course, not a cryptography course.
    • Not covered: how to break ciphers or protocols; side channels and their exploitation; intrusion detection; specific vulnerabilities. Any of these belongs in a security course, taught with the care it needs.

A note on this lecture’s framing. Everything here is written from the defender’s side: how a receiver validates what arrives, how two honest parties authenticate, how a server decides what a request may do. The demos test each mechanism against the damaged or stale inputs a correct receiver must reject — as inputs to validate, not as an attacker’s playbook.

0.3 Section → code map

SectionIdeaDemo in code/lecture26/
§1threat model, the boxestoycrypto.py
§2.1–2.3building a secure channel01_channel.py, secchan.py
§2.4freshness02_freshness.py
§2.5key agreement and identity03_key_exchange.py, toycrypto.py
§3authentication: Needham–Schroeder, Kerberos04_kerberos.py, kerberos.py
§4authorization: ACLs vs capabilities05_authorization.py, authz.py
§5trusted computing base, principles(notes)

0.4 Notation

  • A, B two principals (Alice, Bob); S or KDC a trusted server; K_X a long-term key X shares with the server; K_AB a session key.
  • {m}K: message m sealed under key K (confidential and authenticated). MAC_K(m): a tag proving m came from a holder of K.
  • Na, Nb: nonces (numbers used once). T: a timestamp.
  • g, p: the generator and prime of a Diffie–Hellman group; x a secret exponent, g^x the matching public value.

1. The problem, and the tools

1.1 Every earlier lecture trusted its parts

Read back over the course. RPC (Lecture 4) assumed a reply really came from the server. GFS (Lecture 25) trusted its chunkservers; Ceph trusted its OSDs; Paxos (Lecture 20) trusted that an acceptor which promised did not lie. Even the Byzantine work (Lecture 14), which tolerated lying participants, assumed the messages between honest generals arrived unaltered. The whole course has been about surviving machines that fail. This lecture is about surviving machines and networks that are hostile: that do not merely stop, but read, change, forge and replay.

The shift matters because distribution hands an attacker the network. On one machine, the operating system mediates every access. Across a network, messages cross links, switches and routers that the system does not own. AFS’s designers put it plainly (Lecture 5): rather than trust thousands of workstations, Andrew rests its security on the integrity of a far smaller number of Vice servers, and assumes a workstation’s hardware and software may be modified in any way. Trust must be placed somewhere, deliberately, and kept small (§5).

1.2 The threat model

A security claim is meaningless without saying against whom. The standard model for network protocols is Dolev and Yao’s (1983): treat the network itself as the adversary. An attacker can observe every message, drop it, delay it, reorder it, change its bits, record it and send it again later, and inject messages of its own. What it cannot do is break the cryptography: without the right key, it cannot read a sealed message or produce a valid tag. This is a strong attacker — stronger than most real ones — and a design that holds against it holds against less.

Two things to notice. First, this is the Byzantine network from Lecture 14, made adversarial: the same lost, duplicated and reordered messages that a faulty network produces by accident, an attacker produces on purpose and at the worst moment. The defences rhyme: Lecture 4 suppressed duplicate RPCs with sequence numbers; §2.4 suppresses replayed requests the same way. Second, the model says what we protect against, not what we protect. We must still name the properties we want.

1.3 The properties

For a message on the wire:

  • Confidentiality: no one but the intended receiver learns the content.
  • Integrity: the receiver can tell whether the content was changed.
  • Authenticity: the receiver can tell who sent it.
  • Freshness: the receiver can tell this is a current message, not a replay of an old one.

For the system:

  • Authentication: establishing who a party is.
  • Authorization: deciding what an authenticated party may do.
  • Availability: the service keeps working. (Hard to guarantee against an attacker who can flood the network; this lecture says little about it, as AFS’s paper also set resource-exhaustion attacks mostly aside.)

Notice confidentiality and integrity are independent. A message can be secret but alterable, or readable but unforgeable. §2 keeps them separate on purpose.

1.4 Cryptography as black boxes

This course uses cryptographic primitives the way a programmer uses a hash table: by their interface and their guarantees, not their internals. toycrypto.py gives each a function and a one-line promise. (It is teaching code — seeded randomness, short exponents, not constant-time — and says so; never use it for anything real.)

BoxInterfacePromiseDoes NOT give you
MAC (keyed hash, HMAC)mac(k, m) -> tagnobody without k can produce a valid tag for any mconfidentiality; freshness
Authenticated encryptionseal(k, m, nonce), open_sealed(k, blob)integrity + confidentiality; open returns the message or nothingfreshness; hides length/timing
Key-derivation functionkdf(k, label) -> keyindependent keys from one secret—
Public-key signaturesign(sk, m), verify(vk, m, sig)only the holder of sk can sign; anyone with vk can checkconfidentiality
Key agreement (Diffie–Hellman)dh_keypair(), dh_shared(x, Y)two parties derive the same key over a public channelwho is at the other end

The right-hand column is the lecture. Each box does one thing; the protocol combines them and supplies what none of them gives — above all, freshness and identity, which no box knows about.

Symmetric vs public-key. A MAC and authenticated encryption use one key that both parties share (symmetric). Signatures and agreement use a key pair: a secret half and a public half (asymmetric). Symmetric operations are thousands of times faster (§2.5), but they need the two parties to already share a secret. Public-key operations do not, which is why they set up the shared key that the fast symmetric boxes then use for the session.


2. Building a secure channel

2.1 One protection at a time (demo 01)

Alice sends Bob a stream of commands over a network an attacker controls. We build Bob’s acceptance check up in four designs, each adding one protection, and test each against the inputs a real receiver must handle: a packet whose payload was altered in transit, a copy of a message already delivered, a message that arrives out of order, and a packet built locally with a guessed tag. A correct receiver takes the genuine stream and rejects every one of those.

channel designaltered payloadstale copyout-of-order copyguessed tagpayload hidden
plain (seq, payload)acceptedacceptedacceptedacceptedno
mac (payload, MAC)rejectedacceptedacceptedrejectedno
mac+seq (seq, payload, MAC over both)rejectedrejectedrejectedrejectedno
aead+seq (seq, seal(payload, nonce=seq))rejectedrejectedrejectedrejectedyes

The four rows are four lessons.

  • Plain delivers whatever arrives. No surprise.
  • A MAC gives integrity and authenticity. The receiver recomputes MAC_k(payload) and compares; an altered payload or a locally forged one fails, because only a holder of k can produce the right tag. (The comparison uses hmac.compare_digest, which takes the same time whichever byte first differs, so response timing leaks nothing.) But a MAC says only “a key-holder sent this at some point”. A perfect, unaltered copy of an earlier message still has a valid tag. The MAC receiver accepted the stale copy. A MAC is not, by itself, a secure channel.
  • A sequence number the MAC covers gives order and freshness within the stream. The receiver insists on seq = last + 1. A replayed message carries an old, smaller number; a reordered one arrives with the wrong number; both are refused. This is exactly Lecture 4’s duplicate suppression, now holding against an attacker rather than a retransmitting client, and it is what TLS does over a TCP byte stream. The verdict the demo prints — seq 3 after 6: duplicate or reorder — is the receiver treating any break in the sequence as an attack on the stream.
  • Authenticated encryption adds confidentiality. The first three designs send the payload in the clear (a MAC authenticates, it does not hide). aead+seq seals the payload, so an observer learns nothing but its length, and carries the sequence number as authenticated associated data so the order check still works.

The cost is small. A 78-byte payload became a 102-byte plain packet, 140 bytes under mac+seq (a 32-byte tag plus the sequence number), and 151 bytes under authenticated encryption (plus the nonce). Protecting and verifying one message took a few microseconds. Per-message integrity and confidentiality are nearly free; the hard parts are getting the key and guaranteeing freshness.

2.2 Why integrity usually comes before confidentiality

A beginner’s instinct is “encrypt it and it’s safe”. Two corrections.

First, encryption alone does not give integrity. Many encryption schemes let an attacker who cannot read a message still change it predictably — flip a bit of the ciphertext and a bit of the plaintext flips. Without a MAC, the receiver decrypts the altered bytes into a different message and cannot tell. This is why modern designs use authenticated encryption (encrypt and MAC, in a safe order) rather than encryption alone. toycrypto.seal is encrypt-then-MAC: encrypt, then MAC the ciphertext, and verify the MAC before decrypting, so altered bytes are rejected without ever being interpreted.

Second, integrity is often the property that matters, and confidentiality may not be needed at all. A software-update system must know a package is genuine and unmodified (integrity, authenticity); whether an eavesdropper sees which package is downloaded may not matter. A routing protocol must trust its neighbours’ messages but need not hide them. Many systems MAC without encrypting. Few should encrypt without authenticating.

2.3 Keys for different jobs

One secret should do one job. toycrypto.seal does not use the channel key k directly; it derives k_enc = kdf(k, "enc") and k_mac = kdf(k, "mac"), two keys that look unrelated to anyone without k. Reusing one key for two purposes (encrypting with the same key you MAC with, or in two protocols) is a classic source of failures: an interaction between the two uses can leak what each alone would not. The rule — derive a fresh key per purpose from a master secret — is cheap and removes a whole class of bugs. It is the same modular discipline as the rest of the course: give each concern its own, non-overlapping piece of state.

2.4 Freshness: the replay that passes every other check (demo 02)

A MAC says who; a sequence number orders a stream. But a one-shot request — “unlock the door”, “transfer €100” — has no stream around it. Authenticated and correct, a recording of it is just as authentic tomorrow. The receiver needs a way to tell fresh from old. There are three, and each pays somewhere.

Timestamps with a replay cache. The request carries the sender’s clock reading T; the receiver accepts it if |now − T| ≤ window. This needs the two clocks to be loosely synchronized (Supplement S1), and the window must cover the clock skew plus the network delay. By itself it is not enough: a copy that arrives again within the window still looks current. The demo’s timestamp-only receiver accepted 7 of 8 requests, letting a replay through. The fix is a replay cache: remember the ids of requests seen within the window and refuse a second copy. With the cache, 5 of 8 were accepted (the genuine repeats refused), and the cache held only one entry, because an id older than the window is dropped — a request that old is refused by the clock test anyway, so the cache need never grow beyond a window’s worth. This is exactly what Kerberos does.

A monotonic counter. The sender numbers its requests; the receiver accepts a counter only if it exceeds the last one accepted. No clock needed. But the “last accepted” value must be durable: the demo’s in-memory counter, after a receiver restart, accepted an old counter as new (every past request became fresh again), while the counter kept on stable storage did not. This is Lecture 4’s at-most-once sequence number and Lecture 17’s lesson together: freshness state is recovery state, and must survive a crash.

A server-issued nonce (challenge–response). The receiver hands out a fresh, unpredictable nonce; the request must quote it, and each nonce is accepted once. No clock, no durable counter — the receiver keeps only its set of outstanding nonces. The price is a round trip: the client must contact the receiver before it can make its request, so this suits an interactive handshake, not a one-way message. It is the mechanism inside Needham–Schroeder (§3).

freshness checkextra round tripneedsmain weakness
timestamp + replay cachenosynchronized clocksclock sync; a cache sized to the window
monotonic counternodurable last-value per sendera restart that loses it re-opens old requests
server-issued nonceyesnothing durablean extra round trip before the request

There is no free freshness. Every secure channel and authentication protocol in this lecture pays one of these three prices.

2.5 Agreeing on a key, and the identity gap (demo 03)

All of §2 assumed Alice and Bob already share a key. How do two parties who have never met get one?

Diffie–Hellman (1976) is the surprising answer: they can agree on a secret over a channel anyone can read. In a public group (a large prime p and a generator g), Alice picks a secret x and publishes g^x mod p; Bob picks y and publishes g^y. Each then computes g^(xy): Alice as (g^y)^x, Bob as (g^x)^y. An observer sees g^x and g^y but cannot compute g^(xy) — recovering x from g^x is the discrete-logarithm problem, believed hard for a large group. In the demo, Alice and Bob derived the same key from values sent entirely in the clear.

But — and this is the point — the key is shared with whoever sent the public value. When the demo let Alice complete the exchange with a value that was not Bob’s, the arithmetic succeeded just the same, giving Alice a key she shares with that other party. Diffie–Hellman gives secrecy from a passive observer; it says nothing about who is at the other end. An active attacker who sits in the middle, running one exchange with each side, ends up sharing a key with each and relaying between them. This “person in the middle” is not a flaw in the mathematics; it is the absence of authentication, which is a separate property that a separate mechanism must supply.

Two mechanisms close the gap:

  • Sign the public value with a long-term key the other party can verify (a certificate binds that verification key to a name). In the demo, Bob’s genuine value verified under his public key and a substituted value did not. This is how TLS authenticates a server.
  • Use a trusted server that already shares a key with each party and vouches for the session key, naming the peer. No public-key arithmetic at all. This is Needham–Schroeder and Kerberos (§3).

And the reason protocols bother to set up a shared key, rather than using public-key operations for every message, is cost. In the 2048-bit group, one modular exponentiation took about 20,000 times as long as one MAC:

operationtime (µs, real)× a MAC
Diffie–Hellman keypair~2,300~2,500
Diffie–Hellman shared secret~21,000~23,000
Schnorr sign~1,800~1,900
Schnorr verify~22,000~23,000
HMAC-SHA256~0.91

(The shared-secret and verify steps also validate the 2048-bit public value with a full-width exponentiation, which is most of their cost.) So the universal pattern: public-key or trusted-server exchange once to establish a session key, then the fast symmetric boxes of §2.1 for every message of the session. TLS, SSH, Kerberos and the rest are all built this way.


3. Authentication with a trusted server (demo 04)

3.1 The setting

Alice and Bob share no secret. Each shares a long-term key only with a trusted key-distribution centre (KDC) — in practice derived from a password (toycrypto.password_key, a deliberately slow function of the password and a per-user salt, so that a stolen value is expensive to guess against). The goal: end a short exchange with a fresh session key K_AB that each holds and each knows the other holds, without the KDC on every later message, and without Alice storing Bob’s secret or either password crossing the network.

3.2 Needham–Schroeder, shared key (1978)

The protocol that started the field:

stepmessagemeaning
1A → KDC: A, B, NaAlice asks for a key to talk to Bob, with a fresh nonce Na
2KDC → A: {Na, B, K_AB, {K_AB, A}K_B}K_Asealed for Alice; carries the session key and a ticket for Bob
3A → B: {K_AB, A}K_BAlice forwards the ticket; only Bob can open it
4B → A: {Nb}K_ABBob challenges with his own nonce
5A → B: {Nb − 1}K_ABAlice answers, proving she holds K_AB now

Why each piece is there:

  • Na (steps 1–2) ties the reply to this request. Without it, Alice could not tell a fresh reply from a replay of an old one (freshness, §2.4, by nonce).
  • The reply is sealed under K_A, so only Alice can read K_AB, and she knows it came from the KDC (only the KDC holds K_A).
  • The ticket {K_AB, A}K_B is sealed under Bob’s key, so Alice cannot read or change it; she only relays it. When Bob opens it he learns both the session key and that his peer is A.
  • Nb (steps 4–5) is Bob’s challenge: only someone holding K_AB can return Nb − 1, so Bob learns Alice is live and holds the key.

In the demo, after the run both held the same K_AB, Alice’s nonce came back in step 2, Bob learned from the ticket that his peer is Alice, and Bob saw his nonce answered. The handshake works, and no password crossed the wire.

3.3 The Denning–Sacco fix

Denning and Sacco (1981) spotted a gap, and it is a lovely lesson in reading a protocol carefully. The ticket in step 3 carries no time. It is valid from the moment it is issued for as long as the key system runs. So if that session key were ever compromised, the ticket that carries it could be presented to Bob again, long after, as if it were new — Bob has no way to tell an old ticket from a fresh one.

The fix is one field: put an issue time and lifetime in the ticket, and have Bob refuse an expired one. The demo built a dated ticket and presented it both fresh (accepted) and 700 seconds later (refused as expired). That single change — dating the ticket so its holder’s freshness can be checked — is the step from Needham–Schroeder to Kerberos. It is also a general principle (Abadi and Needham’s “prudent engineering”): every credential should say what it is for and when it expires, so that its receiver can judge it without outside knowledge.

3.4 Kerberos (demo 04)

Kerberos (MIT, 1980s; the basis of Windows domain login and a relative of AFS’s scheme) adds one idea to the dated-ticket protocol: spend the password once per login, not once per service. It splits the KDC into two roles.

  • Authentication server (AS). At login, it issues a ticket-granting ticket (TGT) for the ticket-granting server, and a key K_c,tgs, all sealed under the client’s password key. This is the only step that uses the password.
  • Ticket-granting server (TGS). For each service the client wants, it checks the TGT and issues a service ticket and a key K_c,svc, sealed under K_c,tgs (which the TGS reads from the TGT). The password is not touched again.
  • Each ticket carries {issue time, lifetime} (the Denning–Sacco fix). To use a ticket, the client sends it with a fresh authenticator {client, timestamp}K, sealed under the ticket’s key, proving it holds the key now.

In the demo, one login let the client reach three services — file, mail, print — with the password key used exactly once. A captured password is therefore exposed only at the login step, and every ticket is bounded in time.

One subtlety the demo makes concrete (§2.4 again): even with a valid, authenticated ticket, a service keeps a short replay cache. The ticket is valid for its whole lifetime, so a copy of a single authenticated request, delivered again within the clock window, would otherwise be accepted. The service took the first authenticator, refused an identical one, and took a new authenticator at a later time. Tickets carry a lifetime, authenticators carry a timestamp, and the service keeps a window-sized cache: the three freshness tools of §2.4 working together.

3.5 AFS, and public-key alternatives

AFS (Lecture 5; Satyanarayanan 1989) used a close relative of this scheme. A user logs in and Venus obtains tokens from an authentication server; Venus then establishes secure, authenticated RPC connections to file servers using those tokens, so the password need not be re-entered or stored in the clear, and tokens expire (typically after 24 hours) to bound the damage from a lost one. The authentication servers were replicated: a master that takes updates and read-only slaves, so a user can log in as long as any one is reachable (Lecture 19’s primary-backup, applied to authentication). AFS-3 later adopted Kerberos itself.

Where no trusted server is shared in advance, public-key certificates take its place: a certificate authority signs a binding of a name to a public key, and anyone holding the authority’s public key can check it. This is the web’s model (TLS). It trades the online, shared-key KDC for an offline signature and a chain of trust up to a root — a different placement of the same trust, with its own hard problems (revoking a certificate, trusting the roots).


4. Authorization: who may do what (demo 05)

Authentication tells a server who is asking. Authorization decides whether that who may do what it asks. The abstract picture is Lampson’s access matrix: a grid with one row per subject and one column per object, each cell holding the rights that subject has on that object. Nobody stores the whole matrix — it is huge and sparse — so systems store it one way or the other, and the choice shapes everything.

4.1 Access-control lists

An ACL stores the matrix by column: each object keeps the list of which subjects have which rights. This is the familiar model (Unix file permissions, AFS directory ACLs, cloud IAM policies). authz.py models AFS’s design:

  • Rights are drawn from a set — here {read, write, insert, delete, lookup, admin}.
  • A principal’s rights are the union of the entries for it and for every group it belongs to, and groups may contain groups. In the demo, a student got read and lookup from the “course” group; a TA additionally got write, insert and delete.
  • An ACL may carry negative rights — an entry that denies. Denial wins over any grant. A suspended member, denied write by a negative entry, kept only read and lookup although still in a group that grants more. AFS introduced negative rights for exactly this: fast revocation decoupled from the slower propagation of group-membership changes. You need not hunt down and edit every group; one negative entry takes effect at once.
  • AFS attaches ACLs to directories, not individual files — far less state, and a natural unit, since files in a directory usually share a policy. A file’s rights come from its directory; Unix mode bits then give a within-file refinement (“what may be done”, the ACL says “who”). In the demo, a mode-r file could be read but not written even by its owner, the mode bit removing a right the ACL had granted.

ACLs make one question a lookup and the other a scan. “Who may touch object X?” — read X’s ACL. “What may subject S touch?” — scan every object’s ACL. Revoking a right on X is a quick edit of X’s list. Delegating a right needs admin rights on X. And every server that checks an ACL must be able to reach the ACL and the group database.

4.2 Capabilities

A capability stores the matrix by row: a subject holds a set of tokens, each of which is a right to an object. Possession is permission. The model is older than ACLs (the Cambridge CAP machine, Hydra) and lives on in signed URLs, OAuth bearer tokens, cloud pre-signed links, and Kerberos tickets (a ticket is a capability for a service).

For a capability to be a right, it must be unforgeable. authz.CapabilityServer makes a token {object, rights, expiry, generation, nonce} with a MAC over all of it under the server’s secret. A holder cannot change any field — more rights, another object, a later expiry — without invalidating the MAC. In the demo, a token worked for its object and rights, was refused on another object and for a right it lacked, and a copy with a right added by hand was refused with “bad MAC”. Capabilities have two properties ACLs lack:

  • Attenuation. A holder can make a weaker token for someone else: fewer rights, a shorter life, bound to one object. The demo made a read-only token from a read-write-admin one; it worked for read, not write. It can never be widened — asking for a right the parent lacked was refused. (Macaroons, Birgisson et al. 2014, let a holder attenuate a token offline by chaining MACs, with the same one-way rule; the demo re-issues under the server for simplicity.)
  • Portability. The token travels with the request. A server checking it needs only its own secret — no per-subject state, no group database, no lookup. This is why capabilities suit distributed systems: the right moves with the message, across servers that need share only a verification key.

4.3 The two, compared

question / operationACLs (per-object list)capabilities (per-subject token)
who may touch object X?read X’s ACL (lookup)scan every subject’s tokens
what may subject S touch?scan every object’s ACLread S’s tokens (lookup)
delegate a rightadd an ACL entry (needs admin on X)hand over, or attenuate, a token
carry the right across serverseach server needs the ACL and groupsthe token travels with the request
revoke one rightedit X’s ACL — immediatehard: the token is already out

Revocation is where they most differ, and it is capabilities’ weak point. An ACL entry, removed, is gone at the next check. A capability is a bearer token, valid until it expires or the server invalidates it. The demo shows two ways to invalidate: bump the object’s generation number, which revokes every token for that object at once (valid before, refused after) — immediate but coarse; or issue short-lived tokens and wait for expiry — fine but delayed. Revoking exactly one token, immediately, needs a revocation list the server consults, which is really an ACL creeping back in. Real systems (OAuth, Kerberos) choose short lifetimes plus a revocation list for the rare urgent case. The price of not keeping a per-object list is that you cannot easily edit one.

Most real systems use both: an ACL for the durable policy on each object, capabilities (tokens, tickets) for carrying an authenticated, time-bounded right across services during a session.


5. Trust, and the principles

5.1 The trusted computing base

Every system trusts something; security engineering is deciding what, and keeping it small. The trusted computing base (TCB) is the set of components whose correctness is necessary for the security property to hold — the parts that, if subverted, defeat it. AFS’s TCB is its Vice servers, their operating systems, the authentication servers and the network between servers, plus the cryptography; explicitly not the workstations, which may be modified at will. GFS and Ceph trust their master or monitors and their storage daemons. Kerberos trusts the KDC absolutely: it holds every principal’s key, so compromising it compromises everyone.

The smaller and simpler the TCB, the more credible the security. This is Lecture 1’s modularity (Simon’s watchmakers) in a new guise: a small, well-defined trusted core, with everything else outside it and checked at the boundary.

5.2 Saltzer and Schroeder’s principles

The 1975 design principles are still the checklist:

  • Economy of mechanism: keep the design small enough to verify. (A small TCB.)
  • Fail-safe defaults: deny by default; grant explicitly. An ACL with no entry for you gives you nothing (the demo’s stranger).
  • Complete mediation: check every access, not just the first. (A cached “yes” that is never rechecked is how revocation fails.)
  • Open design: security must not depend on the mechanism being secret, only the keys. (Kerchhoffs’s principle; it is why toycrypto can be published and still be about real constructions.)
  • Separation of privilege: require more than one condition — two keys, two parties — for the most sensitive actions.
  • Least privilege: give each component the fewest rights it needs. Capabilities and attenuation (§4.2) serve this directly; so does running no user code on GFS/AFS servers.
  • Least common mechanism: minimize what is shared between users, to limit unintended channels.
  • Psychological acceptability: if the secure path is hard, people route around it. Kerberos’s single sign-on (§3.4) is this principle — one login, not one per service.

Two more the field added: defence in depth — more than one independent check, so that one failure is not fatal (GFS checked chunk versions at both the master and the chunkserver, Lecture 25 §2.7); and the end-to-end argument once more (Lecture 4) — the parties who care about a property should check it themselves, because an intermediary cannot be relied on to.

5.3 What this lecture did not cover

Security is a field, not a lecture. We treated cryptography as black boxes and said nothing about their internals or how they are attacked; nothing about side channels, timing or power analysis; nothing about denial of service beyond noting it is hard; nothing about software vulnerabilities, intrusion detection, or the operational discipline that AFS’s paper stresses is as important as the mechanisms. Those belong in a security course. What this lecture gives is the distributed-systems core: a precise threat model, the properties worth naming, and the mechanisms — channels, freshness, authentication, authorization — that let a system keep its guarantees when the network, and some of its machines, are hostile.


6. The course, in one view

Twenty-six lectures, one problem: make many computers behave like one fast, correct, available system, despite slow and unreliable communication, independent failures, and no shared clock — and now, despite hostility.

  • Communication is slow and finite (1–3, 9–10): latency floors, bandwidth, the cost of a remote call; RPC to hide it, caching, prefetching and batching to live with it.
  • Failure is partial (4, 13–19): you cannot tell a dead server from a slow one. RPC semantics and the end-to-end argument; failure models and their limits; checkpoints; transactions and write-ahead logging; two-phase commit; quorums.
  • There is no global clock or global state (7, 20–23, S1, S2): consistency protocols, logical time, consensus — Paxos and Multi-Paxos, optimistic replication, blockchains.
  • Scale changes everything (11–12, 24–26): at thousands of machines something is always broken and something is always the bottleneck. Scaling out and control loops; the programming paradigms (MapReduce, MPI, graph-parallel); large-scale storage and peer-to-peer (GFS, Ceph, DHTs); and security, because at scale you cannot trust every part.

The recurring moves: hide what you can behind an abstraction (RPC, a file system, a key-value get), but respect what you cannot (the network’s latency, partial failure, the lack of a clock, the presence of an adversary); replicate for availability and then pay in consistency; measure before you believe; and keep the trusted, coordinating core small — one master, a handful of monitors, a quorum, a KDC — while everything else is cheap, replaceable and checked at the boundary.


Summary

  • Threat model first. The Dolev–Yao attacker is the network: it reads, drops, reorders, alters, replays and injects, but cannot break the cryptography. Name what you protect against before claiming anything.
  • Cryptographic boxes with promises, and gaps. A MAC gives integrity and authenticity, not freshness or secrecy; authenticated encryption adds secrecy; signatures and Diffie–Hellman work without a shared secret but are thousands of times slower (one exponentiation ≈ 20,000 MACs) and Diffie–Hellman alone binds the key to no identity.
  • A secure channel, built up: plain → MAC (an altered or forged packet is rejected, but a replay is accepted) → MAC+sequence number (replays and reorders rejected) → authenticated encryption (payload hidden). Integrity and confidentiality are independent; integrity usually matters more, and encryption without authentication is unsafe. Overhead is tens of bytes and microseconds.
  • Freshness for one-shot requests takes timestamps + a replay cache (needs clock sync), a durable counter (a restart that loses it re-opens old requests), or a server nonce (an extra round trip). No free option.
  • Authentication via a trusted server: Needham–Schroeder gives two strangers a session key, each learning the other; the ticket’s missing timestamp (Denning–Sacco) is fixed by dating it — the step to Kerberos, where one login (one password use) reaches many services, every ticket is dated, and services keep a replay cache.
  • Authorization is the access matrix, stored by column (ACLs: “who may touch X?” is a lookup; AFS’s directory ACLs, nested groups, negative rights for fast revocation) or by row (capabilities: unforgeable, attenuable, portable tokens; “what may S touch?” is a lookup; revocation is the weak point). Most systems use both.
  • Keep the trusted computing base small, deny by default, mediate every access, and layer independent checks (Saltzer and Schroeder). Trust is placed deliberately, not assumed.

Common pitfalls

  • Claiming “secure” without a threat model: against whom, protecting what?
  • Encrypting without authenticating, so altered ciphertext decrypts to a changed message the receiver cannot detect.
  • Treating a MAC as a secure channel: it stops forgery and tampering, not replay or reordering.
  • Forgetting freshness on a one-shot request, so a recorded “transfer €100” can be sent again.
  • Keeping freshness state (a counter, a nonce set) only in memory, so a restart re-opens every old request.
  • Reusing one key for two purposes, or one nonce twice under one key.
  • Trusting a Diffie–Hellman key without authenticating the exchange (the person-in-the-middle gap).
  • A credential with no expiry (the Denning–Sacco ticket): it is valid forever.
  • Using public-key operations per message instead of to set up a session key.
  • Assuming a capability can be cleanly revoked: a bearer token is valid until it expires or everything for that object is invalidated.
  • A large or ill-defined trusted computing base, or security that depends on a mechanism staying secret rather than on keys.
  • A secure path so awkward that users route around it.

Exercises

  1. MAC or encryption? For each, say which of confidentiality, integrity, authenticity and freshness is needed, and what you would use: (a) a thermostat reporting the room temperature to a home hub; (b) a firmware update downloaded by thousands of devices from a public mirror; (c) a bank transfer request; (d) a medical record fetched over a shared network.

    Answer(a) Integrity and authenticity (a wrong or forged reading misbehaves), and freshness (an old "cold" reading must not loop the heating); confidentiality rarely matters. A MAC with a counter or timestamp. (b) Integrity and authenticity above all (a modified or fake update is the whole danger), and freshness (do not re-install a withdrawn version); confidentiality usually not needed — the mirror can be public. A **signature** over the package (so the public mirror need not be trusted) plus a version/expiry. (c) All four: confidentiality (account numbers, amounts), integrity and authenticity (no altering payee or amount, no forging), freshness (no replaying the transfer). Authenticated encryption over an authenticated, fresh channel — §2.1's `aead+seq` with the freshness of §2.4. (d) Confidentiality (privacy), integrity, authenticity, freshness. Authenticated encryption on a mutually authenticated channel; and authorization (§4) that only the treating clinician may fetch it.
  2. Why Nb? In Needham–Schroeder (steps 4–5), Bob sends Nb and expects Nb − 1 back. (a) What does step 5 prove to Bob that step 3 did not? (b) Why Nb − 1 rather than Nb? (c) If step 4 were dropped and Alice simply sent {“I am Alice”}K_AB, what would be lost?

    Answer(a) Step 3 proves only that *someone* delivered a ticket; the ticket could have been recorded and replayed. Step 5 proves that the party talking to Bob can **encrypt a fresh value under K_AB right now**, so it holds the session key and is live — a liveness/freshness check by nonce (§2.4). (b) Any transformation Bob can recognise and that an attacker could not have precomputed from a recording works; Nb − 1 differs from Nb, so a recorded {Nb}K_AB from a previous run cannot simply be echoed back. (Real designs put the nonce inside a MAC'd, structured message; "minus one" is the 1978 paper's shorthand.) (c) {"I am Alice"}K_AB carries no freshness: it could be replayed from an old session (if that session's key were known), and it is not tied to Bob's challenge. Bob would lose the proof that Alice is live and holds *this* key now.
  3. Sizing a replay cache. A service accepts timestamped requests within a ±30 s window and sees 5,000 requests per second. (a) How many entries must its replay cache hold, worst case? (b) What happens to a legitimate request that is delayed 45 s in the network? (c) If clocks can drift 10 s apart, how does the window change, and the cache?

    Answer(a) The cache need only hold requests whose timestamp is within the window of now, i.e. the last 60 s (±30 s): at most 60 × 5,000 = 300,000 entries, each a request id and a time. Older ones are dropped, because the clock test refuses them anyway. (b) It arrives with now − T ≈ 45 s > 30 s and is refused as "outside the window", even though it is genuine: the window trades replay protection against tolerance for delay, and 30 s rejects a 45 s straggler. (c) The window must cover clock skew plus delay: ±(30 + 10) = ±40 s, so the cache grows to 80 × 5,000 = 400,000 entries. Looser clocks cost both a wider replay window and a bigger cache — a reason to synchronize clocks well (Supplement S1).
  4. Dating the ticket. Denning and Sacco fixed Needham–Schroeder by timestamping the ticket. (a) What must the receiver (Bob) have for the fix to work? (b) A ticket lifetime of 8 hours vs 5 minutes: what does each trade? (c) Kerberos tickets are dated and used with a fresh authenticator. Why both, when either carries a time?

    Answer(a) A clock loosely synchronized with the issuer's, so that "now − issue time ≤ lifetime" is meaningful (Supplement S1); Kerberos depends on this. (b) 8 hours: convenient (log in once a day), but a leaked ticket or session key is usable for 8 hours. 5 minutes: a leak is useful only briefly, but the client must refresh constantly and is sensitive to clock skew (a 5-minute window with 10-minute drift rejects everything). Lifetime trades convenience and robustness-to-skew against exposure. (c) The ticket's date bounds how long the *ticket* (and its key) is valid — coarse, set when issued. The authenticator's timestamp proves the client holds the ticket's key **right now**, on *this* request, and the service's replay cache stops that one request being repeated within the window. The ticket authorizes a session; the authenticator makes each use fresh. Neither alone does both.
  5. ACL or capability? For each, choose a model and justify: (a) a shared folder in a company file server, with per-group access that admins change; (b) a “share this document via link” feature where anyone with the link may view; (c) a microservice passing a user’s authority to downstream services for one request; (d) a hospital record that must be revocable the instant a clinician leaves.

    Answer(a) **ACL**: durable, admin-managed, group-based policy attached to the folder, with easy per-group revocation — exactly AFS's directory ACLs. (b) **Capability**: the link *is* a bearer token (a signed URL); possession grants view. Attenuate it (view-only, expiring) and accept that revoking one link means expiry or invalidating that link's generation. (c) **Capability**: a token carrying the user's authority, attenuated to the least the downstream call needs (least privilege), travelling with the request across services — no shared ACL/group database needed at each hop. (d) **ACL**, because revocation must be immediate and fine-grained: remove the clinician's entry (or add a negative right) and the next check denies. A capability would stay valid until expiry unless backed by a revocation list, which is an ACL in disguise. A hybrid is common: ACL for the standing policy, short-lived capabilities within a session.
  6. Trusted computing base. (a) List the TCB of the Kerberos login in §3.4 — every component whose compromise defeats it. (b) Which single component is the most dangerous to lose, and why? (c) AFS runs no user code on its servers. Which principle is that, and how does it shrink the TCB?

    Answer(a) The KDC (both AS and TGS) and its storage of every principal's key; the KDC's operating system and machine; the cryptographic primitives and the randomness that generates keys; the client's handling of the password and tickets; and the clocks, to the extent timestamps are trusted. (b) The **KDC**: it holds every principal's long-term key, so compromising it lets the attacker impersonate anyone and read any session — a single point of total failure. This is why the KDC is hardened, isolated, and sometimes split (the AS/TGS split limits password exposure but both still trust the key database). (c) **Least privilege** (and economy of mechanism): running no user code means a server's TCB excludes every application, so a buggy or malicious application cannot subvert the file service. It keeps the trusted core to the server software itself — the same reason GFS/Ceph keep application logic off their storage nodes.
  • There is no problem set on this material, and no project uses it. The course’s projects are P1 (RPC), P2 (a caching proxy), P3 (scaling), P4 (two-phase commit); none is a security exercise. This lecture is the conceptual close of the course.
  • The AFS reading (Satyanarayanan 1989) connects back to Lecture 5: the same system, seen through its security design.

Further reading

  • R. Needham and M. Schroeder, “Using Encryption for Authentication in Large Networks of Computers”, CACM 1978.
  • D. Denning and G. Sacco, “Timestamps in Key Distribution Protocols”, CACM 1981.
  • B. C. Neuman and T. Ts’o, “Kerberos: An Authentication Service for Computer Networks”, IEEE Communications 1994; J. Kohl and B. C. Neuman, RFC 1510 / 4120.
  • M. Satyanarayanan, “Integrating Security in a Large Distributed System”, ACM TOCS 1989.
  • J. Saltzer and M. Schroeder, “The Protection of Information in Computer Systems”, Proc. IEEE 1975.
  • W. Diffie and M. Hellman, “New Directions in Cryptography”, IEEE Trans. Information Theory 1976.
  • D. Dolev and A. Yao, “On the Security of Public Key Protocols”, IEEE Trans. Information Theory 1983.
  • M. Abadi and R. Needham, “Prudent Engineering Practice for Cryptographic Protocols”, IEEE TSE 1996.
  • A. Birgisson, J. Politz, Ú. Erlingsson, A. Taly, M. Vrable and M. Lentczner, “Macaroons: Cookies with Contextual Caveats for Decentralized Authorization in the Cloud”, NDSS 2014.
  • R. Anderson, Security Engineering, 3rd ed., Wiley 2020 (chapters on protocols, access control and distributed systems).
  • J. Katz and Y. Lindell, Introduction to Modern Cryptography, 3rd ed., CRC 2020 (for the boxes’ internals, in a proper cryptography course).

Preview of the supplements

The main sequence ends here. Two supplements fill in machinery the lectures used without deriving:

  • Supplement S1 — Time, clocks and the ordering of events: physical clock synchronization (Cristian, NTP) and its error bounds; happened-before; Lamport clocks; vector clocks and concurrency detection; total-order broadcast. The timestamps of this lecture, the leases of Lectures 7 and 25, and the version vectors of Lecture 22 all rest on it.
  • Supplement S2 — Consistency models: linearizability, sequential, causal and eventual consistency, session guarantees, and the CAP trade-off stated precisely — the vocabulary behind “one-copy semantics” (Lecture 19) and the relaxed models of Lectures 22 and 25.

术语表 (Glossary, English → 中文)

English中文
threat model / adversary威胁模型 / 敌手
Dolev-Yao attackerDolev-Yao 攻击者(控制网络的敌手)
confidentiality / integrity / authenticity / freshness机密性 / 完整性 / 真实性 / 新鲜性
authentication / authorization认证(身份鉴别) / 授权
availability可用性
symmetric / asymmetric (public-key) cryptography对称 / 非对称(公钥)密码学
key / session key / long-term key密钥 / 会话密钥 / 长期密钥
message authentication code (MAC) / HMAC消息认证码 / 基于哈希的 MAC
authenticated encryption / encrypt-then-MAC认证加密 / 先加密后认证
associated data关联数据(认证但不加密)
key-derivation function (KDF)密钥派生函数
nonce / initialization vector一次性随机数 / 初始向量
salt / password-based key derivation (PBKDF2)盐值 / 基于口令的密钥派生
secure channel安全信道
sequence number / replay / reorder序列号 / 重放 / 乱序
replay cache重放缓存
monotonic counter单调计数器
challenge-response挑战-应答
Diffie-Hellman key agreementDiffie-Hellman 密钥协商
discrete logarithm problem离散对数问题
person-in-the-middle中间人
digital signature / certificate / certificate authority数字签名 / 证书 / 证书颁发机构
key-distribution centre (KDC)密钥分发中心
Needham-Schroeder protocolNeedham-Schroeder 协议
ticket / ticket-granting ticket (TGT)票据 / 票据授予票据
authentication server / ticket-granting server认证服务器 / 票据授予服务器
authenticator认证符
Kerberos / single sign-onKerberos / 单点登录
token (authentication)令牌(认证)
access matrix访问矩阵
access-control list (ACL)访问控制列表
capability能力(权能)
principal / subject / object主体(委托人) / 主体 / 客体
group / group inheritance组 / 组继承
negative rights负权限
attenuation (of a capability)能力弱化(削减)
bearer token持有者令牌
revocation / revocation list撤销 / 撤销列表
trusted computing base (TCB)可信计算基
least privilege / complete mediation / fail-safe defaults最小特权 / 完全仲裁 / 失败安全默认
defence in depth纵深防御
open design (Kerckhoffs’s principle)公开设计(柯克霍夫原则)
← 返回课程目录