DagrA guide to binary formats, and to Dagrdraft

13 Chapter thirteen

A log that proves its own history

An audit log records who did what. Sooner or later someone asks whether the log itself can be believed: was a line changed, or removed, after it was written? This chapter puts the last two together, the signature of chapter 11 and the stream of chapter 12, and is as much about what cannot be proved as about what can.

Why one signature is not enough

Chapter 11 signed a token: one small piece of data, finished before it was signed. A log is never finished, and that breaks the obvious ideas.

What has to be signed is the stream itself: these bytes, in this order, with nothing missing between them. And it has to be done as the log grows.

Records about the records

The answer is to put, between the events, records of another kind that say something about the bytes before them. Dagr calls them meta records. A sink declares them in a list of their own:

AuditLog = DataSink("AuditLog",
    node_types=[
        Node("Event", fields=[
            "ts"      >> t.u64 >> required,
            "actor"   >> t.utf8 >> required,
            "action"  >> t.ref("Action") >> required,
            "target"  >> t.utf8,
            "details" >> t.utf8,
        ]),
        Enum("Action", ["login", "logout", "read", "write", "delete", "grant", "revoke"]),
    ],
    meta_types=[
        Node("Checkpoint", fields=[...]),
        Node("Seal", fields=[...]),
    ],
    doubly_linked=True,
)

This is all Dagr itself contributes, and it is little on purpose.

Checkpoints

Every few events the writer adds a checkpoint. A checkpoint says: "the stretch of the stream that ends right here, and began so many bytes back, had this hash", and signs that statement.

Build a log below. Then choose a checkpoint to see which records it vouches for.

kind of record, and field tagslengthsnumberstexthashes and signaturesthe length again, for reading from the end

The seal

Tick "close the log with a seal". A seal is one last record: how many records and bytes came before it, a hash of all of them, the last checkpoint's signature, and a signature over those. It says something no checkpoint can say: this is the end.

Try to change the past

Here is a finished log and a verifier. The verifier knows two things that it did not get from the log: the key, and which log this is supposed to be. Change the log and see what it says.

    vouched fornothing vouches for itwhere the verifier refusedfaded: not looked at

    What no log can prove about itself

    Now untick both boxes, so that the log is still open, and press "cut the log off after its first checkpoint". The verifier accepts what is left. It is right to: what is left is a correct log that happens to be shorter. Every signature in it points backwards, at bytes that existed when it was made. Nothing in a log can vouch for what was written after it.

    It also does not help against the one who holds the key. A log signed by its writer shows that nobody else changed it. And nothing here hides anything: the events are as readable as before.

    What it costs

    Next to the usual ways

    What these panels are.

    Try it

    1. In the first panel, set "each covering the last 1 periods". Choose the second checkpoint. Which records does it vouch for, and what now connects it to the first?
    2. Add events one at a time and watch for the moment a checkpoint appears. How many events can be unconfirmed at most?
    3. In the second panel, change a byte of event 2. Which checkpoint notices, and what would have happened had the log ended before that checkpoint was written?
    4. Delete event 4. The verifier complains about a count and never gets to a signature. Why is it good that the cheap check comes first?
    5. With the log sealed and the verifier told nothing, find every attack that still succeeds. What do they have in common?
    6. You archive last month's log. Which box describes the verifier you should use for it, and how does that verifier know?

    What comes next

    Chapter 14 goes back to a single value and asks where exactly its bytes sit in memory. Some code, the kind that processes many numbers at once on a processor or a graphics card, insists on data at particular addresses. It is about alignment.