Lesson 16 · 50 minutes
Build a compliance evidence pack and check it with one command
- Assemble the records of the course into one evidence pack
- Check the pack with one command that runs every checker and the cross-checks
- Find planted faults in a copy of the pack and repair them
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.
Scenario
The auditor of the school network comes to Brindle Books in January. Jonas has asked for "the pack" a week before: every record that shows how the company runs its security, in one folder. Carys knows that each file passed its own checker on the day it was written. She does not know whether the files still agree with each other. A risk may name an asset that is gone, or a control may point at evidence that nobody sealed. You write the one command that answers this, and you prove that it notices a broken pack.
Recall
Lesson 15: which inputs does the review checker require, and what makes a person top management?
Five inputs: previous actions, metrics, audit, incidents and risks, each with a summary and an existing file. Top management is a person who approves a policy in the register, and the chair must be one of them.
Lesson 6: which three things does the verify command of evidence.py report?
A sealed file that is gone, a file that changed after it was sealed, and a file that was collected more than 90 days ago. It also reports a row with no source or no collector.
The idea
An evidence pack is the set of records that shows, for one organisation and one date, that its management system exists and runs. You built every part in lessons 1 to 15. The pack check does two things. First it runs the checker of each lesson: each of your programs has a function problems that returns a list, so the pack check imports the modules and calls them. Second it adds cross-checks: facts that two files must agree on. Each file can be perfect alone while the set is broken.
A later course, "AI governance for engineers", applies the same method to AI systems. New here: the links between security records, listed in the table.
| Part | Files | Lesson | Cross-check |
|---|---|---|---|
| Policy set | policies/ | 1 | |
| Clause map | isms_map.csv | 2 | Every record of the map is on file |
| Scope and assets | scope.md, assets.csv | 3 | |
| Risk register | risks.csv | 4 | Each risk names an asset of the inventory |
| Applicability | soa.csv | 5 | Each evidence file is sealed in the manifest |
| Evidence | evidence/ | 6 | |
| Access review | hr.csv, accounts.csv, role_rights.csv, access_decisions.csv | 7 | |
| Changes | changes.csv, exceptions.csv | 8 | Each exception names a document of the register |
| Suppliers | suppliers.csv, responsibility.csv | 9 | Each asset is in the inventory, each control of ours is in the statement |
| Continuity | bia.csv, restore_test.json | 10 | |
| Audit findings | findings.csv | 11 | Each finding names a control of the statement |
| Framework mapping | mapping.csv | 12 | |
| Competence | competence_needs.csv, competence.csv | 14 | Each person with an enabled account has a record. Each reading names a document of the register |
| Management review | management_review.json, review_actions.csv | 15 | Each overdue corrective action is named by an action of the review |
The metrics report of lesson 13 is in the pack too: the clause map lists it, so the first cross-check fails if it is missing.
- risks.csv → assets.csv: each risk names an asset
- suppliers.csv → assets.csv: each supplier names its assets
- findings.csv → soa.csv: each finding names a control
- soa.csv → MANIFEST.csv: each evidence file is sealed
- exceptions.csv → index.csv: each exception names a document
Two cross-checks are new in this lesson, because the pack now holds the people and the review.
- accounts.csv → competence.csv: each account holder has a record
- findings.csv → review_actions.csv: each overdue finding has an action
The check proves that the pack is complete and consistent. It does not prove that the company is secure, or that a control is good enough. Those are judgements, and the scenario test asks you to make them.
Worked example
Work in ~/krlab/security-governance. The pack is the lab folder itself. If you built the lab with kr-lab.sh, run python3 evidence.py collect and python3 metrics.py . first: they make the folder evidence and the file report.md, which the zip cannot hold.
1. Seal the evidence again
In lesson 6, four files of the evidence plan were not on file, and lesson 14 added competence.csv. All are on file now. Seal again, so that the manifest covers all eleven, then verify.
python3 evidence.py seal
python3 evidence.py verifysealed 11 files on 2026-11-21
problems: 02. Write the pack check
run builds a dictionary from the name of each part to a small function that checks it. A lambda with no argument is a function to call later, and the loop calls each one inside try, so that a missing file becomes a problem of its part and does not stop the run. error.filename is the path that Python could not open. The helper ids returns the values of one column as a set. The helper refs is the cross-check: every value in a column of one file must be in a set of known values. unaware and unlisted are the two new cross-checks. The first lists people who have an enabled account and no record. The second lists overdue findings that no action of the review names.
check_pack.py
"""check_pack.py: run every check of the course on one folder, the evidence pack.
python3 check_pack.py [FOLDER] (the folder defaults to the current one)
The exit code is 1 when anything fails.
"""
import sys
from pathlib import Path
import access_review
import assets_check
import change_check
import competence_check
import continuity
import evidence
import findings_check
import isms_check
import mapping_check
import policy_check
import review_check
import risks
import soa_check
import supplier_check
from grc import load
def run(folder):
f = Path(folder)
def ids(name, column):
return {r[column] for r in load(f / name)}
def refs(name, column, known, what):
return [f"{name}: {value} is not {what}" for r in load(f / name) for value in r[column].split()
if value not in known]
def unaware():
known = ids("competence.csv", "person")
return [f"accounts.csv: {p} has an enabled account and no awareness record"
for p in sorted({a["person"] for a in load(f / "accounts.csv") if a["enabled"] == "yes"} - known - {""})]
def unlisted():
named = ids("review_actions.csv", "ref")
return [f"findings.csv: {x['id']} is overdue, and no action of the review names it"
for x in findings_check.overdue(f / "findings.csv") if x["id"] not in named]
parts = {
"policy set": lambda: policy_check.problems(f / "policies"),
"clause map": lambda: isms_check.problems(f / "isms_map.csv", f, strict=True),
"scope and assets": lambda: assets_check.problems(f / "assets.csv", f / "scope.md"),
"risk register": lambda: risks.problems(f / "risks.csv")
+ refs("risks.csv", "asset", ids("assets.csv", "id"), "an asset of the inventory"),
"applicability": lambda: soa_check.problems(f / "soa.csv", f / "risks.csv")
+ refs("soa.csv", "evidence", ids("evidence/MANIFEST.csv", "file"), "sealed in the manifest"),
"evidence": lambda: evidence.problems(f),
"access review": lambda: access_review.problems(f),
"changes": lambda: change_check.problems(f / "changes.csv", f / "exceptions.csv")
+ refs("exceptions.csv", "policy", ids("policies/index.csv", "id"), "a document of the register"),
"suppliers": lambda: supplier_check.problems(f / "suppliers.csv", f / "responsibility.csv")
+ refs("suppliers.csv", "assets", ids("assets.csv", "id"), "an asset of the inventory")
+ refs("responsibility.csv", "our_control", ids("soa.csv", "control"), "a control of the statement"),
"continuity": lambda: continuity.bia_problems(f / "bia.csv")
+ continuity.problems(f / "restore_test.json", f / "bia.csv"),
"audit findings": lambda: findings_check.problems(f / "findings.csv")
+ refs("findings.csv", "control", ids("soa.csv", "control"), "a control of the statement"),
"framework mapping": lambda: mapping_check.problems(f / "mapping.csv", f / "soa.csv"),
"competence": lambda: competence_check.problems(f / "competence_needs.csv", f / "competence.csv", f / "hr.csv",
f / "policies" / "index.csv")
+ refs("competence_needs.csv", "document", ids("policies/index.csv", "id"), "a document of the register")
+ unaware(),
"management review": lambda: review_check.problems(f / "management_review.json", f / "review_actions.csv",
f / "policies" / "index.csv") + unlisted(),
}
results = []
for name, check in parts.items():
try:
results.append((name, check()))
except FileNotFoundError as error:
results.append((name, [f"missing file: {Path(error.filename).name}"]))
return results
if __name__ == "__main__":
total = 0
for name, found in run(sys.argv[1] if len(sys.argv) > 1 else "."):
print(f"{name:<19}{'ok' if not found else str(len(found)) + ' problem(s)'}")
for line in found:
print(" ", line)
total += len(found)
print(f"pack: {total} problem(s)")
sys.exit(1 if total else 0)3. Run it
python3 check_pack.py
echo "exit code $?"policy set ok
clause map ok
scope and assets ok
risk register ok
applicability ok
evidence ok
access review ok
changes ok
suppliers ok
continuity ok
audit findings ok
framework mapping ok
competence ok
management review ok
pack: 0 problem(s)
exit code 0Fourteen parts, no problem, exit code 0. If your run shows a problem, read its line: it names the part and the file. The usual cause is a file that differs from the lesson that printed it.
4. Save the drill script
To test the check you need a broken pack, and you should not break your own. drill.py copies the pack into the folder drill. With the word plant it also changes seven places in the copy. It is a lab file, and its list of faults is the exercise, so it is in a collapsed block: save it without reading it, or take it from the zip, and read it after the Your turn. shutil.copytree copies a folder with everything in it, and shutil.rmtree removes one.
The finished file: drill.py
drill.py
"""drill.py: copy the evidence pack into drill/, and plant faults in the copy. A lab file of the course.
python3 drill.py copy a clean copy of the pack in drill/
python3 drill.py plant a clean copy with seven faults
Do not edit this file. Repair the files in drill/.
"""
import shutil
import sys
from pathlib import Path
FILES = ["isms_map.csv", "scope.md", "assets.csv", "risks.csv", "soa.csv", "evidence_plan.csv", "hr.csv",
"accounts.csv", "role_rights.csv", "access_decisions.csv", "changes.csv", "exceptions.csv",
"suppliers.csv", "responsibility.csv", "bia.csv", "restore_test.json", "findings.csv", "mapping.csv",
"report.md", "competence_needs.csv", "competence.csv", "management_review.json", "review_actions.csv"]
FAULTS = [
("risks.csv", "1,5,Efe,2026-10-02", "1,5,,"),
("exceptions.csv", "2026-09-01,2027-02-28", "2026-09-01,2026-11-01"),
("access_decisions.csv", "ines,shop-admin,leaver,remove,Greta,2026-11-21,\n", ""),
("evidence/backup.log", "FAILED disk full", "OK files=409"),
("findings.csv", "Dev,2027-01-15,open", "Dev,2026-11-15,open"),
("soa.csv", "evidence/patch-state.csv", "evidence/patch-report.csv"),
("suppliers.csv", "PayNorth,Card payment service,A5,high,security breach_notice audit", "PayNorth,Card payment service,A5,high,security breach_notice"),
]
missing = [name for name in FILES + ["policies", "evidence"] if not Path(name).exists()]
if missing:
sys.exit(f"missing: {' '.join(missing)}. Run python3 evidence.py collect and python3 metrics.py . first")
out = Path("drill")
if out.exists():
shutil.rmtree(out)
out.mkdir()
for name in FILES:
shutil.copy(name, out / name)
for folder in ("policies", "evidence"):
shutil.copytree(folder, out / folder)
if sys.argv[1] == "plant":
for name, old, new in FAULTS:
text = (out / name).read_text()
if old not in text:
sys.exit(f"{name} differs from the file that its lesson printed: save it again")
(out / name).write_text(text.replace(old, new))
print(f"drill/ is ready ({sys.argv[1]})")5. Break a copy by hand
Make a clean copy, then lose the restore test record and name an asset that does not exist.
python3 drill.py copy
rm drill/restore_test.json
sed -i '/^R6/s/,A6,/,A66,/' drill/risks.csv
python3 check_pack.py drill | grep -v " ok$"
echo "exit code $?"drill/ is ready (copy)
clause map 1 problem(s)
Restore test record: not on file: restore_test.json
risk register 1 problem(s)
risks.csv: A66 is not an asset of the inventory
evidence 1 problem(s)
restore_test.json: sealed, but the file is gone
continuity 1 problem(s)
missing file: restore_test.json
pack: 4 problem(s)
exit code 0grep -v " ok$" hides the parts that are fine. One missing file causes problems in four parts: the clause map lists the record, the statement of applicability names it as evidence, the manifest sealed it, and the continuity part needs it. That is what a cross-check is for: the pack tells you everything that depended on the file. The exit code shown is again the one of the last command in the pipe.
Your turn
Run python3 drill.py plant. It makes a fresh copy of your pack in drill and plants seven faults. There are no steps: run the pack check on drill, read each problem, and repair the files in drill until the check exits with 0. Three files changed after sealing. Two of them are records that you repair and seal again. For the third, sealing again is not the honest repair. Answer the questions from the first run, before your repairs.
Then write one line for each fault: what was wrong, and who at Brindle Books must act. For the evidence file, say why "seal it again" is the wrong repair.
Check yourself
Every file passes its own checker. Why can the pack still be broken?
The files refer to each other: a risk names an asset, a control names evidence, an exception names a policy, a finding names a control. A checker of one file cannot see whether the thing it points at exists. The cross-checks test those links.
The backup log in the drill folder was edited after sealing. Why is sealing it again the wrong repair?
A new seal would make the check pass and hide the fact that evidence was changed. The honest path is to find out who changed it and why, to collect the log again from the system, and to record what happened. An auditor who learns that evidence was edited and resealed will doubt the whole pack.
The pack check exits with 0. Which three things has it not shown?
That the controls are enough for the risks, that the scores and decisions are wise, and that the records are true. It has shown that the pack is complete, consistent and fresh on one date. People judge the rest: the risk owners, the internal auditor and the management review.
Why does the pack check turn a missing file into a problem of one part and not stop?
A reader wants the whole picture in one run. If the program stopped at the first missing file, you would repair it, run again, and meet the next one. With every part reported, one run gives the full work list, and the exit code is still 1.
Field notes
- Run the pack check on a schedule and on every change to the pack, for example in the build job of the repository that holds it. A pack that is checked only before an audit is repaired in panic.
- Give the auditor read access to the pack and the manifest, and let them run the check themselves. Evidence that the audited team presents by hand is weaker than evidence that the auditor draws.
- Keep the pack small enough to read. Every file in it needs an owner and a date, and a file that nobody owns goes stale and fails the check for everybody.
- The fixed date of this course makes the answers equal for every reader. In production the check uses the real date, so a pack that was clean in June fails in October with no edit: reviews, evidence and acceptances age. That is the check doing its job.
- A clean pack is the start of an audit. The auditor will pick a risk and walk it through the files, as lesson 5 showed, and then ask a person to show the control on the live system.