An audit log is only useful if people believe it. A log that someone can quietly edit tells you nothing about the events you most need to check. This post explains how the KeyDog audit log is built, what each part protects against, and where the limits are.
Write the change and the record together
Every change that KeyDog makes to records goes through one function that writes the row and its audit entry in the same transaction. If the change fails, the entry is not written. If the entry cannot be written, the change is rolled back. A record can never change without a corresponding entry.
The entry stores the entity, the kind of change, the time, and the user who made it. For updates it stores the old and new values, so you can see what changed, not just that something did.
Make the database refuse edits
Application code is the easiest place to enforce a rule, and the easiest place for a bug to slip past. So the important rules live in the database as triggers:
- Audit entries cannot be updated or deleted.
- Committed key systems cannot be changed, and cannot go back to draft.
- A key's bitting history can only be removed while its system is still a draft.
If the application has a bug, or someone edits the file with a different program, the database still refuses. We test these triggers directly, not only through the screens.
Keep bittings out of the log
An audit log is read by more people than the records it describes. If it copied every bitting in full, a user who could not see bittings on screen could read them in the log. So when an entry is written, the sensitive columns are redacted. Bittings, top master keys, pinning and secret values are recorded as changed, not as their contents.
Entries written before that rule are masked when they are read. A test checks that a user without permission to view bittings cannot read them from any table, the audit log included.
Chain the rows
Triggers stop the normal software from changing history. They do not stop someone who has the passphrase and a database tool from dropping the triggers and editing rows. For that case we added a hash chain.
Each audit row stores a hash of its own content together with the hash of the row before it. Change any row and its hash no longer matches, and every row after it is wrong too. The audit screen has a Verify the chain button. It walks the log, reports whether the chain is intact, and shows the newest hash.
The newest hash is the useful part. If you write it down, or keep a copy somewhere else, you can later show that the log has not been rewritten since that point.
What the chain does not prove
Be clear about the limits, because an auditor will ask.
- It does not stop a determined editor. Someone who can edit every row can recompute the chain from the first row on. The chain makes that visible only if you have kept an earlier hash to compare against.
- It does not prove who made a change. It records the user name the program was given. Accounts with passwords and two-factor sign-in on Self Hosted and KeyDog MAX make that name more reliable, but they are not a signature.
- It does not cover the time of the change. The time is the computer's clock. Keep the clock correct.
Why this shape
We wanted a log that works on a single PC with no server, survives a restore from backup, and does not need a second system to trust. Triggers and a chain do that with one file. A remote log service would be stronger on paper, but it would make KeyDog depend on a service being up before a key could be issued.
If you are reviewing KeyDog for your own controls, the question to ask is not whether the log can ever be changed, but whether a change would be noticed. The chain is there to answer that.