Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Lesson 01 · 40 minutes

Write a policy set and check it with a program

After this lesson you can
  • Tell a policy from a standard, a procedure, a guideline and a control
  • Name the three lines model and say what an auditor asks for
  • Check a policy set for owners, approvals, review dates and required sections
Lab files of this lesson (12)

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

Brindle Books is an invented online bookshop with 14 staff. A large customer, a school network, sends a questionnaire: "Send us your information security policy, and show that it is approved and current." The managing director, Asha, finds three documents in three places, one of them from 2023. Carys, the operations manager, gets the task to put the rules in order, and she asks you to help: one folder, one list of documents, and a program that says what is missing or out of date.

The idea

Three words name the field, and people shorten them to GRC.

  • Governance: who decides about security, by which rules, and who answers for the result.
  • Risk management: find what could go wrong, score it, and decide what to do about it (lesson 4).
  • Compliance: show that you keep the rules that bind you. Some rules are your own, and some come from a law, a contract or a standard.

The rules live in documents of four kinds, and each kind answers a different question. A control is not a document: it is the measure itself, a thing that is done or built to lower a risk.

KindAnswersExample at Brindle BooksChanges
PolicyWhat do we want, and why? Short, approved by top management."Access to customer data is given by need."Rarely
StandardWhich exact requirement must be met?"Admin accounts use a second factor."Sometimes
ProcedureWho does which step, in which order?"How to close the accounts of a leaver."Often
GuidelineWhat is good advice? Not mandatory."How to choose a password manager."Often
ControlWhat is in place?The second factor on the admin login.With the system

Who does what? The three lines model of the Institute of Internal Auditors (IIA) gives the usual answer. The first line is the people who run the work: they own the risks and operate the controls. The second line is the people who help and challenge on risk and compliance: they write the rules and monitor. The third line is internal audit: it is independent of both and tells the governing body whether the system works. In a firm of 14 people one person can hold a first-line and a second-line job, but nobody audits their own work. The governing body is the board, or the owners of a small firm: it oversees management and receives the reports. At Brindle Books the managing director may also be an owner.

The three lines at Brindle Books
First lineSecond lineThird lineGoverning bodyIT and teamsRisk and complianceInternal auditBoard or owners123First lineSecond lineThird lineGoverning bodyIT and teamsRisk and complianceInternal auditBoard or owners123
  1. Risk and compliance → IT and teams: writes the rules, helps and challenges
  2. Internal audit → IT and teams: tests the controls
  3. Internal audit → Board or owners: reports independently

An auditor is a person who checks, independently, whether an organisation does what it says. For each rule the auditor asks four things: show me the rule, show me who approved it, show me that it is current, and show me that people follow it. The first three are in this lesson. The fourth is evidence, and lesson 6 collects it.

Worked example

Work in ~/krlab/security-governance.

1. Write the four documents

Each document is a Markdown file, a text file with simple marks: # starts the title and ### starts a section. A policy has the sections Purpose, Scope, Rules and Roles. Make the folder with mkdir -p policies, then save the four files.

policies/information-security.md

# Information security policy of Brindle Books

### Purpose

Brindle Books protects the data of its customers and staff, and keeps its shop available for orders.

### Scope

This policy covers all staff, all contractors, and every system that holds or handles company data.

### Rules

Access is given by need and removed when the need ends. Every risk has an owner. Changes to systems are approved before they go live. Backups are tested. Staff read this policy when they join and again every year. Top management reviews the management system every six months.

### Roles

The managing director approves this policy. The operations manager owns it. Every manager applies it in their team.

policies/access-control.md

# Access control standard

### Purpose

This standard sets the requirements for accounts and access rights on all company systems.

### Requirements

Every account belongs to one named person. Administrator accounts use a second factor. Access rights are reviewed every quarter. A leaver's accounts are disabled within one working day.

policies/leaver.md

# Leaver procedure

### Purpose

This procedure makes sure that a person who leaves the company loses all access on time.

### Steps

1. The manager tells IT the last working day. 2. IT disables every account on that day. 3. IT records the date in the access review.

policies/password-manager.md

# Password manager guideline

### Purpose

This guideline helps staff to choose and use a password manager for their work accounts.

### Advice

Use the manager that IT offers. Let it create long random passwords. Never share the main password.

2. Write the document register

A document register is the list of all controlled documents with their owner, approver and dates. It is a CSV file (comma-separated values: one row on each line). The parent column says which document a lower one supports. The policy is at the top and has no parent. The chain runs on below the documents, to the control and its evidence.

From a wish to a proof
Policywhat management wants, in a few rulesStandardthe exact requirementsProcedurethe steps and who does themControlthe measure that is in placeEvidencethe record that shows it worksPolicywhat management wants, in a few rulesStandardthe exact requirementsProcedurethe steps and who does themControlthe measure that is in placeEvidencethe record that shows it works

policies/index.csv

id,title,type,file,owner,approved_by,approved,next_review,parent
P1,Information security policy,policy,information-security.md,Carys,Asha,2026-06-01,2027-06-01,
S1,Access control standard,standard,access-control.md,Ben,Carys,2026-06-15,2027-06-15,P1
PR1,Leaver procedure,procedure,leaver.md,Ben,Carys,2026-07-01,2027-01-01,S1
G1,Password manager guideline,guideline,password-manager.md,Dev,Ben,2026-07-01,2027-07-01,S1

3. Write the checker

Path(folder) / "index.csv" builds a path from a folder and a name, read_text returns the text of a file, and is_file says whether it exists. text.split("### ") cuts a text at every ### , and [1:] drops the piece before the first section. p.partition("\n") cuts a piece at its first line break into three values: the section name, the break and the body. {r["id"] for r in rows} builds a set, a collection that holds each value once. continue goes to the next row at once. New here are the register, the four kinds of document and the parent chain.

The checker asks for six things. The type is known. An owner and an approver exist, and they are two people. The review date is not in the past. A policy has no parent, and every other document has a parent that is in the register. The file exists. Each required section has at least 8 words, because a heading with nothing under it is not a rule.

policy_check.py

"""policy_check.py: check a policy set. Usage: python3 policy_check.py policies"""
import sys
from pathlib import Path

from grc import TODAY, day, finish, load

SECTIONS = {"policy": ["Purpose", "Scope", "Rules", "Roles"], "standard": ["Purpose", "Requirements"],
            "procedure": ["Purpose", "Steps"], "guideline": ["Purpose", "Advice"]}
MIN_WORDS = 8


def sections(path):
    """Return {section name: text} for a Markdown file whose sections start with '### '."""
    parts = Path(path).read_text(encoding="utf-8").split("### ")[1:]
    return {p.partition("\n")[0].strip(): p.partition("\n")[2] for p in parts}


def problems(folder):
    folder = Path(folder)
    rows = load(folder / "index.csv")
    ids = {r["id"] for r in rows}
    found = []
    for r in rows:
        name, kind = r["id"], r["type"]
        if kind not in SECTIONS:
            found.append(f"{name}: unknown type {kind}")
            continue
        if not r["owner"] or not r["approved_by"]:
            found.append(f"{name}: owner or approver missing")
        elif r["owner"] == r["approved_by"]:
            found.append(f"{name}: {r['owner']} owns it and approved it")
        if day(r["next_review"]) < TODAY:
            found.append(f"{name}: review overdue since {r['next_review']}")
        if kind == "policy" and r["parent"]:
            found.append(f"{name}: a policy has no parent")
        if kind != "policy" and r["parent"] not in ids:
            found.append(f"{name}: parent is not in the register: {r['parent'] or 'none'}")
        if not (folder / r["file"]).is_file():
            found.append(f"{name}: file missing: {r['file']}")
            continue
        have = sections(folder / r["file"])
        for section in SECTIONS[kind]:
            if len(have.get(section, "").split()) < MIN_WORDS:
                found.append(f"{name}: section missing or under {MIN_WORDS} words: {section}")
    return found


if __name__ == "__main__":
    finish(problems(sys.argv[1]))

4. Run it

sys.argv[1] in the last line is the first word after the script name: the folder. echo prints text, and $? is the shell's name for the exit code of the last command.

python3 policy_check.py policies
echo "exit code $?"
problems: 0
exit code 0

5. Break the set on purpose

A checker that has never failed is not proven. cp -r copies a folder with everything in it. sed -i 's/old/new/' file changes old to new inside a file. Make a copy, set the review date of the procedure to a day in the past, and let Ben approve his own standard.

cp -r policies broken
sed -i 's/2027-01-01/2026-11-01/' broken/index.csv
sed -i 's/S1,Access control standard,standard,access-control.md,Ben,Carys/S1,Access control standard,standard,access-control.md,Ben,Ben/' broken/index.csv
python3 policy_check.py broken
echo "exit code $?"
PROBLEM S1: Ben owns it and approved it
PROBLEM PR1: review overdue since 2026-11-01
problems: 2
exit code 1

The checker names both faults, and the exit code is 1. Remove the copy with rm -r broken.

Your turn

Marlow Physio is an invented clinic with three sites. Its practice manager, Nadia, sends you the policy set below. Make the folder marlow/policies, save the four files in it, and run your checker on that folder. There are no steps.

marlow/policies/index.csv

id,title,type,file,owner,approved_by,approved,next_review,parent
P1,Information security policy,policy,security.md,Nadia,Nadia,2026-02-01,2027-02-01,
S1,Patient record access standard,standard,record-access.md,Omar,Nadia,2025-09-30,2026-09-30,P1
PR1,Lost device procedure,procedure,lost-device.md,Omar,Priya,2026-05-10,2027-05-10,S2
G1,Home working guideline,guideline,home-working.md,Priya,Nadia,2026-05-10,2027-05-10,P1

marlow/policies/security.md

# Information security policy of Marlow Physio

### Purpose

Marlow Physio keeps patient records private, correct and available to the staff who treat the patient.

### Scope

All three sites, all staff, and every system that holds patient or staff data.

### Rules

Patient records are opened only for treatment or billing. Devices are encrypted. Leavers lose access on their last day.

marlow/policies/record-access.md

# Patient record access standard

### Purpose

This standard says who may open a patient record and how each access is logged.

### Requirements

Only treating staff and billing staff open a record. Every access is logged with the name and the time. Logs are kept for one year.

marlow/policies/lost-device.md

# Lost device procedure

### Purpose

This procedure limits the harm when a laptop or a phone with company data is lost.

### Steps

Call Omar. Wipe the device.

Then fix the set in a copy until the checker exits with 0. Some problems you cannot fix alone. Name each one, and say whom you must ask.

Check yourself

"Administrator accounts use a second factor." Is this sentence a policy, a standard or a procedure, and why?

A standard. It states one exact requirement that a person can test with yes or no. A policy would say why and what in general ("access is given by need"), and a procedure would give the steps to switch the second factor on.

Why does the checker fail a document whose owner is also its approver?

An approval is a second pair of eyes with authority. A person who approves their own text has checked nothing. For the top policy the approver is top management, because the policy binds the whole company and somebody must have the power to enforce it.

The checker passes the set. What has it proven, and what not?

It has proven form: every document exists, has two names and a review date that is not in the past, hangs under a parent, and has text in each section. It has not proven that the rules are wise, or that anybody follows them. A person judges the first. Evidence shows the second (lesson 6), and an audit tests it (lesson 11).

In the three lines model, where is Ben, the IT administrator who disables accounts, and where is the person who audits his work?

Ben is in the first line: he operates the control. The auditor is in the third line and must be independent of Ben's work. At Brindle Books an outside person does the audit, because every employee is too close to the systems.

Field notes

  • Keep a policy to one or two pages. Put numbers that change (password length, review intervals) in standards, so that top management does not have to sign again for each small change.
  • Write requirements that can be tested. "Accounts are reviewed every quarter" can be checked against a record. "Access is managed appropriately" cannot.
  • Keep the documents in version control, next to the register. The history then shows who changed which rule and when, and an auditor can see the version that was valid on a given day.
  • ISO/IEC 27001 (lesson 2) asks top management to set the information security policy and asks the organisation to control its documents. A register like this one is a simple way to show both.
  • A rule that the business cannot keep needs a recorded exception with an end date (lesson 8), not silence. An ignored policy teaches staff that policies do not count.