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

Set-up · 15 minutes

Set up your lab for security governance and compliance

After this lesson you can
  • Create the lab folder of the course and check the tools
  • Save the helper that every checker of the course uses
  • Prove with a check script that the lab works
Lab files of this lesson (2)

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. Type the code yourself first: you learn more.

What you need

  • The courses "Linux" (Part 1), "Python for security work", "Security fundamentals" and "Security operations basics". This course uses their ideas (files and folders, short Python programs, risk scoring, hashes, incident records) and does not teach them again.
  • Python 3.12 or newer (the lab was run on Python 3.14, and its programs use no syntax newer than 3.12). Every program of the course uses only the standard library. No package to install.
  • Linux, or WSL (the Linux layer of Windows). The course was run on Linux only. On macOS most programs run, but lesson 6 would list only root, because people there have user numbers from 501, and sha256sum is shasum -a 256 there.
  • The tools tar, sha256sum and diff. Linux has them.
  • A terminal and a text editor. No account, no network, no paid service and no administrator rights.

Everything runs on your own computer, in one folder: ~/krlab/security-governance. Lesson 6 reads the user list of your own machine, and nothing else leaves the lab folder. All other data is invented: every company, person, supplier and domain in this course is made up, and no file holds a real person's data.

Governance means that an organisation decides its security on purpose: who decides, by which rules, and how it proves that the rules are kept. This course treats governance as files that a program can check. In each lesson you write one kind of record (a policy list, a risk register, an evidence list, an audit finding) and a checker that fails when the record has a gap.

This course is not a law course and gives no legal advice. It names standards and laws, says what each asks an organisation to keep, and shows how to keep it as files. Whether a rule applies to your organisation is a question for your legal and compliance people, and the current official text decides it. The course does not train for a certificate, and no lesson needs you to buy a standard.

Set it up

1. Make the lab folder

mkdir -p (make directory, with its parents) creates the folder. cd (change directory) moves you into it. pwd (print working directory) shows where you are.

mkdir -p ~/krlab/security-governance
cd ~/krlab/security-governance
pwd
/home/you/krlab/security-governance

2. Check your Python

python3 --version prints the version of Python. If the number is below 3.12, install a newer Python first. On Debian or Ubuntu the command is sudo apt install python3.12, and then you type python3.12 in place of python3. That command needs sudo and a network, so it is not tested here.

python3 --version
Python 3.14.4

3. Know how the files reach your folder

You can type or paste every file of this course from the lessons. A block with a file name above it is a whole file: save it under that name in the lab folder. A name with a folder in front, such as policies/index.csv, goes into that folder: make the folder first with mkdir -p policies.

As a shortcut, the course page has a button "Lab files" for a zip. The zip keeps the files of each lesson in a folder of that lesson, and the course works in one flat folder, so the zip holds a script, kr-lab.sh. It copies the files of all lessons up to the lesson that you name. The folder of a lesson has the name of its file without .md. Unzip the zip, go into the unzipped folder security-governance, and run sh kr-lab.sh <lesson folder> ~/krlab/security-governance. For example, sh kr-lab.sh 04-assess-and-treat-risk-in-a-register ~/krlab/security-governance builds the lab as it stands after lesson 4. The script copies files only. Files that a command makes (the evidence of lesson 6, the backup of lesson 10) come from running the commands of those lessons. Lessons 14 to 16 say which commands to run first if you started from the zip.

4. Save the helper of the course

Every checker of this course ends in the same way: it prints each problem, then a count, and sets an exit code. An exit code is a number that a program gives back when it ends: 0 means success, and 1 here means "problems found". Another program or a build job can read that number. Lesson 16 ends with one.

The course also fixes one date. Many checks ask "is this overdue?", and the answer depends on the day. With today's real date, your answers would differ from the answers of this page. So TODAY is fixed at 2026-11-21 for every reader. A real organisation would use the real date.

csv.DictReader reads a file of comma-separated values and gives each row as a dictionary with the column names as keys. date.fromisoformat turns a text such as 2026-11-21 into a date. sys.exit(n) ends the program with exit code n.

grc.py

"""grc.py: the helpers that every checker of this course uses."""
import csv
import sys
from datetime import date

TODAY = date(2026, 11, 21)      # the fixed date of the course. A real run uses date.today().


def load(path):
    """Read a CSV file and return its rows as a list of dictionaries."""
    with open(path, newline="", encoding="utf-8") as f:
        return list(csv.DictReader(f))


def day(text):
    """Turn a text like 2026-11-21 into a date. A wrong text raises ValueError."""
    return date.fromisoformat(text.strip())


def finish(problems):
    """Print the problems and their count, then end with exit code 1 if there are any."""
    for problem in problems:
        print("PROBLEM", problem)
    print(f"problems: {len(problems)}")
    sys.exit(1 if problems else 0)

Check your lab

The script labcheck.py prints one line for each requirement. shutil.which looks for a program in the folders where the shell finds programs. The modules pwd and grp read the user list and the group list of a Unix system, and lesson 6 needs them. hashlib.sha256 makes a fingerprint (a hash) of some bytes, as in the course "Security fundamentals" (lesson 5). (grc.TODAY - grc.day("2026-01-01")).days subtracts two dates and gives the number of days between them.

labcheck.py

"""labcheck.py: prove that the lab of "Security governance and compliance" works."""
import hashlib
import shutil
import sys

results = []


def check(name, ok, detail):
    results.append(ok)
    print(("ok   " if ok else "FAIL ") + name.ljust(10) + detail)


v = sys.version_info
check("python", v >= (3, 12), f"{v.major}.{v.minor}.{v.micro}")
check("tar", shutil.which("tar") is not None, "packs and unpacks a backup")
check("sha256", shutil.which("sha256sum") is not None or shutil.which("shasum") is not None, "sha256sum or shasum")
check("diff", shutil.which("diff") is not None, "compares two folders")
try:
    import grp
    import pwd
    check("users", len(pwd.getpwall()) > 0 and len(grp.getgrall()) > 0, "can read the user list and the group list")
except ImportError:
    check("users", False, "no pwd module: use Linux or WSL")
try:
    import grc
    days = (grc.TODAY - grc.day("2026-01-01")).days
    check("grc.py", days == 324, f"the fixed date is {grc.TODAY}, day {days} after 1 January")
except ImportError:
    check("grc.py", False, "grc.py is not in this folder")
check("hash", hashlib.sha256(b"evidence").hexdigest()[:8] == "ee8250fb", "sha256 gives the known fingerprint")

print(f"lab ready: {sum(results)} of {len(results)}")
sys.exit(0 if all(results) else 1)
python3 labcheck.py
ok   python    3.14.4
ok   tar       packs and unpacks a backup
ok   sha256    sha256sum or shasum
ok   diff      compares two folders
ok   users     can read the user list and the group list
ok   grc.py    the fixed date is 2026-11-21, day 324 after 1 January
ok   hash      sha256 gives the known fingerprint
lab ready: 7 of 7

Your Python version can differ. Every other line must be the same. Type the last line of your own output and the day number that the grc.py line shows.

If it fails

Read the first line that starts with FAIL. Fix that one, then run python3 labcheck.py again.

The script saysWhat it meansWhat to do
FAIL pythonPython is older than 3.12.Install Python 3.12 or newer and run the script with that python3.
FAIL tar or FAIL diffThe tool is not installed.On Debian or Ubuntu: sudo apt install tar diffutils.
FAIL sha256Neither sha256sum nor shasum exists.On Debian or Ubuntu: sudo apt install coreutils. On macOS, shasum comes with the system.
FAIL users no pwd moduleYou run Python on Windows itself.Use WSL (the Linux layer of Windows), as the course "Linux" shows.
FAIL grc.py grc.py is not in this folderThe helper is missing, or you are in another folder.cd ~/krlab/security-governance, and save grc.py from step 4.
FAIL grc.py the fixed date is ...You changed TODAY.Save grc.py again exactly as printed.