Check sign-in settings against written policy.
Done by an agent. Checked twice.
A result for every policy rule on every system, with each failure, missing setting and expired exception listed.
Real files in
- settings_export.json
Sign-in settings pulled from eleven systems, with times in three different units, settings left out and one system in scope missing. 103 lines, 4 KB. - signin_policy.md
The written password and sign-in policy: seven rules, twelve systems in scope and three approved exceptions, one of which has run out. 42 lines, 2 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read the policy and the export
- 2.Test every rule on every system
- 3.Write the result
Claude Sonnet 5.5, 1 min 3 s. No web. It never saw the check.
Checked twice
- Passed: 84 of 84 pairs of system and rule appear once in policy_check.csv
- Passed: 84 of 84 results equal the result recomputed from the settings export and the written policy
- Passed: 16 of 16 checks that are exempt, not shown or not applicable are marked that way and not passed or failed
- Passed: 84 of 84 setting_found cells hold what the export holds: 72 with the exported value and 12 left blank because nothing is shown
- Passed: 84 of 84 reasons carry only that system's own numbers and dates, with the value found and the policy limit where the rule has one
- Passed: 5 of 5 result counts in summary.md equal the recomputed counts
- Passed: 19 of 19 failed checks are on a line of summary.md with their system and rule id
- Passed: summary.md names 1 of 1 systems missing from the export and 2 of 2 exceptions that ran out (with the end date) or are no longer needed
- Passed: 35 of 35 other numbers and dates in summary.md match the setting and limit of the system and rule they sit beside or the totals
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 6 ways on purpose. The check caught 6.
## Failed checks - email R3: Second steps are authenticator_app;sms; sms is among them but policy does not allow it. - payroll R1: Minimum password length is 12; policy requires at least 14. - ledger R2: MFA required for 'admins_only'; policy requires 'all_users' (admins only is not enough). - ledger R4: Account locks after 0 failed attempts (0 means never locks); policy allows 10 or fewer. - ledger R5: Idle timeout is 30 minutes (30 minutes); limit for a sensitive system is 15 minutes. - ledger R6: System supports SSO and it is off; policy requires it on where supported. - ledger R7: Default administrator account enabled is true; policy requires it disabled. - crm R1: Minimum password length is 10; policy requires at least 14. - crm R5: Idle timeout is 8 hours (480 minutes); limit for a non-sensitive system is 60 minutes. - cloud_console R5: Idle timeout is 20 minutes (20 minutes); limit for a sensitive system is 15 minutes. - cloud_console R7: Default administrator account enabled is true; policy requires it disabled. - vpn R3: Second steps are sms; sms is among them but policy does not allow it. - vpn R4: Account locks after 12 failed attempts; policy allows 10 or fewer.
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 1 of 1 on 1 December 2026. The agent took 1 min 3 s.
What the second review verified
- The CSV has 84 unique rows (12 systems x 7 rules). The counts 49 pass + 19 fail + 1 exempt + 12 not_shown + 3 not_applicable add up to 84 and match summary.md.
- Times were converted to minutes correctly: payroll 900 seconds = 15 min, which passes the 15-min limit for sensitive systems. label_printer_portal 3600 seconds = 60 min, which passes the 60-min limit. crm 8 hours = 480 min, which fails. vpn 0 means it never signs people out, which fails. ledger 0 failed attempts means it never locks, which fails.
- Exceptions were checked against the export date of 2026-11-30. warehouse_handhelds R1 (8 characters) is exempt until 2027-03-31. label_printer_portal R2 ran out on 2026-09-30, so it fails and is listed as run out. code_host R5 (45 min, limit 60) now passes and is listed as no longer needed.
- Missing data is marked not_shown. hr_records is not in the export at all, so all 7 rules are not_shown. Also not_shown: wifi_admin R2/R3 (no mfa block), code_host R4 (lockout is null), and crm R7 and label_printer_portal R7 (no default_admin). All 19 failed checks are on their own lines in summary.md with the system and rule id.
What this run does not show
- The settings export is a sample written for this run with eleven systems, while real admin pages name their settings in many more ways.
- The policy limits are written into the check as numbers, so a changed policy needs a changed check.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 6 of 6. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Check sign-in settings against written policy function: it for: the IT manager who must show the sign-in rules are really switched on goal: Every rule in the policy has a result for every system in scope, and every failure, gap and exception is listed with the setting that decided it. ## 1. Read the policy and the export Read input/signin_policy.md and input/settings_export.json. The policy lists the rules by id, the systems in scope and the approved exceptions. The export holds each system's settings as its admin page shows them, and the date of the export. Systems name the same setting in different ways and units. Convert every time to minutes before comparing it with the policy. ## 2. Test every rule on every system For each system in scope and each rule give exactly one result. Use the first that applies: 1. `not_shown` when the export does not hold the setting the rule needs: the system is missing from the export, the setting is missing, or it is null. Never assume a missing setting is fine. 2. `not_applicable` when the policy says the rule does not apply to that system. 3. `pass` when the setting meets the rule. 4. `exempt` when the setting fails the rule and the policy lists an exception for that system and rule whose end date is on or after the export date. 5. `fail` when the setting fails the rule and no exception covers it. An exception that has run out does not count. ## 3. Write the result Write output/policy_check.csv with columns system,rule,setting_found,result,reason. One row for every system in scope and every rule. setting_found is the value as exported, or blank when it is not shown. reason is one plain sentence with the value found and the limit in the policy. Write output/summary.md for the IT manager. Start with five lines in the form `result: count` for pass, fail, exempt, not_shown and not_applicable. Then one line for every failed check, each line starting with the system name and the rule id. Then list the systems in scope that are missing from the export, the exceptions that have run out (one line each with the system, the rule id and the end date), and the exceptions that are no longer needed because the system now passes the rule (one line each with the system and the rule id). ## Done looks like - Every system in scope has one row for every rule in policy_check.csv. - Every failed check is on its own line in summary.md with its system and rule id. - The five counts in summary.md add up to the number of rows in policy_check.csv.
input/settings_export.json · 103 lines, 4 KB
{
"exported_on": "2026-11-30",
"exported_by": "sunniva.abernathy@larkmoor.example",
"note": "Pulled by hand from each admin page. Field names are as each system shows them.",
"systems": [
{
"system": "company_sign_in",
"password": {"min_length": 14},
"mfa": {"required": "all_users", "methods": ["authenticator_app", "security_key"]},
"lockout": {"failed_attempts": 5},
"session": {"idle_timeout_minutes": 15},
"sso": {"supported": false},
"default_admin": {"enabled": false}
},
{
"system": "email",
"password": {"min_length": 14},
"mfa": {"required": "all_users", "methods": ["authenticator_app", "sms"]},
"lockout": {"failed_attempts": 10},
"session": {"idle_timeout_minutes": 60},
"sso": {"supported": true, "enabled": true},
"default_admin": {"enabled": false}
},
{
"system": "payroll",
"password": {"min_length": 12},
"mfa": {"required": "all_users", "methods": ["authenticator_app"]},
"lockout": {"failed_attempts": 5},
"session": {"idle_timeout_seconds": 900},
"sso": {"supported": true, "enabled": true},
"default_admin": {"enabled": false}
},
{
"system": "ledger",
"password": {"min_length": 14},
"mfa": {"required": "admins_only", "methods": ["authenticator_app"]},
"lockout": {"failed_attempts": 0},
"session": {"idle_timeout_minutes": 30},
"sso": {"supported": true, "enabled": false},
"default_admin": {"enabled": true}
},
{
"system": "crm",
"password": {"min_length": 10},
"mfa": {"required": "all_users", "methods": ["authenticator_app", "security_key"]},
"lockout": {"failed_attempts": 8},
"session": {"idle_timeout_hours": 8},
"sso": {"supported": true, "enabled": true}
},
{
"system": "code_host",
"password": {"min_length": 16},
"mfa": {"required": "all_users", "methods": ["security_key"]},
"lockout": null,
"session": {"idle_timeout_minutes": 45},
"sso": {"supported": true, "enabled": true},
"default_admin": {"enabled": false}
},
{
"system": "cloud_console",
"password": {"min_length": 14},
"mfa": {"required": "all_users", "methods": ["authenticator_app", "security_key"]},
"lockout": {"failed_attempts": 6},
"session": {"idle_timeout_minutes": 20},
"sso": {"supported": true, "enabled": true},
"default_admin": {"enabled": true}
},
{
"system": "vpn",
"password": {"min_length": 14},
"mfa": {"required": "all_users", "methods": ["sms"]},
"lockout": {"failed_attempts": 12},
"session": {"idle_timeout_minutes": 0},
"sso": {"supported": true, "enabled": true},
"default_admin": {"enabled": false}
},
{
"system": "wifi_admin",
"password": {"min_length": 8},
"lockout": {"failed_attempts": 10},
"session": {"idle_timeout_minutes": 10},
"sso": {"supported": false},
"default_admin": {"enabled": true}
},
{
"system": "warehouse_handhelds",
"password": {"min_length": 8},
"mfa": {"required": "none", "methods": []},
"lockout": {"failed_attempts": 5},
"session": {"idle_timeout_minutes": 5},
"sso": {"supported": false},
"default_admin": {"enabled": false}
},
{
"system": "label_printer_portal",
"password": {"min_length": 14},
"mfa": {"required": "none", "methods": []},
"lockout": {"failed_attempts": 10},
"session": {"idle_timeout_seconds": 3600},
"sso": {"supported": true, "enabled": false}
}
]
}
input/signin_policy.md · 42 lines, 2 KB
# Larkmoor Outfitters password and sign-in policy Version 3. In force from 2026-07-01. Owner: IT Manager. ## Rules | Rule | What it requires | |---|---| | R1 | Passwords are at least 14 characters long. | | R2 | A second step at sign-in (MFA) is required for every user. Required for administrators only is not enough. | | R3 | Codes sent by text message are not an allowed second step. A system fails when text message (sms) is among its second steps and passes when it is not. | | R4 | An account locks after 10 failed attempts or fewer. A value of 0 means the account never locks, which fails. | | R5 | People are signed out when idle. Sensitive systems: after 15 minutes or less. All other systems: after 60 minutes or less. A value of 0 means never, which fails. | | R6 | Where a system supports company sign-in (SSO) it is turned on. This rule does not apply to a system that does not support it. | | R7 | The built-in default administrator account is disabled. | ## Systems in scope | System | Sensitive | |---|---| | company_sign_in | yes | | email | no | | payroll | yes | | ledger | yes | | crm | no | | code_host | no | | cloud_console | yes | | hr_records | yes | | vpn | no | | wifi_admin | no | | warehouse_handhelds | no | | label_printer_portal | no | ## Approved exceptions An exception covers one rule on one system until its end date. After that date the rule applies again. | System | Rule | Reason | Approved until | |---|---|---|---| | warehouse_handhelds | R1 | Handhelds only accept an 8 digit code. Replacement planned. | 2027-03-31 | | label_printer_portal | R2 | Vendor promised a second step in the autumn release. | 2026-09-30 | | code_host | R5 | Long builds were being cut off. Fixed in June. | 2027-01-31 |
output/policy_check.csv · written by the agent, 85 lines
system,rule,setting_found,result,reason company_sign_in,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. company_sign_in,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). company_sign_in,R3,methods=authenticator_app;security_key,pass,"Second steps are authenticator_app;security_key; sms is not among them, as policy requires." company_sign_in,R4,failed_attempts=5,pass,Account locks after 5 failed attempts; policy allows 10 or fewer. company_sign_in,R5,idle_timeout_minutes=15,pass,Idle timeout is 15 minutes (15 minutes); limit for a sensitive system is 15 minutes. company_sign_in,R6,supported=false,not_applicable,"System does not support SSO, so the policy says R6 does not apply." company_sign_in,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. email,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. email,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). email,R3,methods=authenticator_app;sms,fail,Second steps are authenticator_app;sms; sms is among them but policy does not allow it. email,R4,failed_attempts=10,pass,Account locks after 10 failed attempts; policy allows 10 or fewer. email,R5,idle_timeout_minutes=60,pass,Idle timeout is 60 minutes (60 minutes); limit for a non-sensitive system is 60 minutes. email,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. email,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. payroll,R1,min_length=12,fail,Minimum password length is 12; policy requires at least 14. payroll,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). payroll,R3,methods=authenticator_app,pass,"Second steps are authenticator_app; sms is not among them, as policy requires." payroll,R4,failed_attempts=5,pass,Account locks after 5 failed attempts; policy allows 10 or fewer. payroll,R5,idle_timeout_seconds=900,pass,Idle timeout is 900 seconds (15 minutes); limit for a sensitive system is 15 minutes. payroll,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. payroll,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. ledger,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. ledger,R2,required=admins_only,fail,MFA required for 'admins_only'; policy requires 'all_users' (admins only is not enough). ledger,R3,methods=authenticator_app,pass,"Second steps are authenticator_app; sms is not among them, as policy requires." ledger,R4,failed_attempts=0,fail,Account locks after 0 failed attempts (0 means never locks); policy allows 10 or fewer. ledger,R5,idle_timeout_minutes=30,fail,Idle timeout is 30 minutes (30 minutes); limit for a sensitive system is 15 minutes. ledger,R6,supported=true;enabled=false,fail,System supports SSO and it is off; policy requires it on where supported. ledger,R7,enabled=true,fail,Default administrator account enabled is true; policy requires it disabled. crm,R1,min_length=10,fail,Minimum password length is 10; policy requires at least 14. crm,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). crm,R3,methods=authenticator_app;security_key,pass,"Second steps are authenticator_app;security_key; sms is not among them, as policy requires." crm,R4,failed_attempts=8,pass,Account locks after 8 failed attempts; policy allows 10 or fewer. crm,R5,idle_timeout_hours=8,fail,Idle timeout is 8 hours (480 minutes); limit for a non-sensitive system is 60 minutes. crm,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. crm,R7,,not_shown,default_admin.enabled is not in the export; policy requires the default admin account disabled. code_host,R1,min_length=16,pass,Minimum password length is 16; policy requires at least 14. code_host,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). code_host,R3,methods=security_key,pass,"Second steps are security_key; sms is not among them, as policy requires." code_host,R4,,not_shown,"lockout.failed_attempts is not in the export (lockout is null or missing); policy needs 10 or fewer, and 0 fails." code_host,R5,idle_timeout_minutes=45,pass,Idle timeout is 45 minutes (45 minutes); limit for a non-sensitive system is 60 minutes. code_host,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. code_host,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. cloud_console,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. cloud_console,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). cloud_console,R3,methods=authenticator_app;security_key,pass,"Second steps are authenticator_app;security_key; sms is not among them, as policy requires." cloud_console,R4,failed_attempts=6,pass,Account locks after 6 failed attempts; policy allows 10 or fewer. cloud_console,R5,idle_timeout_minutes=20,fail,Idle timeout is 20 minutes (20 minutes); limit for a sensitive system is 15 minutes. cloud_console,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. cloud_console,R7,enabled=true,fail,Default administrator account enabled is true; policy requires it disabled. hr_records,R1,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R2,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R3,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R4,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R5,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R6,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." hr_records,R7,,not_shown,"System is in scope but missing from the export, so the rule cannot be checked." vpn,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. vpn,R2,required=all_users,pass,MFA required for 'all_users'; policy requires 'all_users' (admins only is not enough). vpn,R3,methods=sms,fail,Second steps are sms; sms is among them but policy does not allow it. vpn,R4,failed_attempts=12,fail,Account locks after 12 failed attempts; policy allows 10 or fewer. vpn,R5,idle_timeout_minutes=0,fail,"Idle timeout is 0 minutes (0 minutes, meaning never); limit for a non-sensitive system is 60 minutes." vpn,R6,supported=true;enabled=true,pass,System supports SSO and it is on; policy requires it on where supported. vpn,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. wifi_admin,R1,min_length=8,fail,Minimum password length is 8; policy requires at least 14. wifi_admin,R2,,not_shown,mfa.required is not in the export; policy needs MFA for all users. wifi_admin,R3,,not_shown,mfa.methods is not in the export; policy does not allow sms as a second step. wifi_admin,R4,failed_attempts=10,pass,Account locks after 10 failed attempts; policy allows 10 or fewer. wifi_admin,R5,idle_timeout_minutes=10,pass,Idle timeout is 10 minutes (10 minutes); limit for a non-sensitive system is 60 minutes. wifi_admin,R6,supported=false,not_applicable,"System does not support SSO, so the policy says R6 does not apply." wifi_admin,R7,enabled=true,fail,Default administrator account enabled is true; policy requires it disabled. warehouse_handhelds,R1,min_length=8,exempt,Minimum password length is 8; policy requires at least 14. Approved exception until 2027-03-31 covers it. warehouse_handhelds,R2,required=none,fail,MFA required for 'none'; policy requires 'all_users' (admins only is not enough). warehouse_handhelds,R3,methods=(none),pass,"Second steps are (none); sms is not among them, as policy requires." warehouse_handhelds,R4,failed_attempts=5,pass,Account locks after 5 failed attempts; policy allows 10 or fewer. warehouse_handhelds,R5,idle_timeout_minutes=5,pass,Idle timeout is 5 minutes (5 minutes); limit for a non-sensitive system is 60 minutes. warehouse_handhelds,R6,supported=false,not_applicable,"System does not support SSO, so the policy says R6 does not apply." warehouse_handhelds,R7,enabled=false,pass,Default administrator account enabled is false; policy requires it disabled. label_printer_portal,R1,min_length=14,pass,Minimum password length is 14; policy requires at least 14. label_printer_portal,R2,required=none,fail,"MFA required for 'none'; policy requires 'all_users' (admins only is not enough). The exception ended 2026-09-30, before the export date 2026-11-30." label_printer_portal,R3,methods=(none),pass,"Second steps are (none); sms is not among them, as policy requires." label_printer_portal,R4,failed_attempts=10,pass,Account locks after 10 failed attempts; policy allows 10 or fewer. label_printer_portal,R5,idle_timeout_seconds=3600,pass,Idle timeout is 3600 seconds (60 minutes); limit for a non-sensitive system is 60 minutes. label_printer_portal,R6,supported=true;enabled=false,fail,System supports SSO and it is off; policy requires it on where supported. label_printer_portal,R7,,not_shown,default_admin.enabled is not in the export; policy requires the default admin account disabled.
output/summary.md · written by the agent, 44 lines
pass: 49 fail: 19 exempt: 1 not_shown: 12 not_applicable: 3 ## Failed checks - email R3: Second steps are authenticator_app;sms; sms is among them but policy does not allow it. - payroll R1: Minimum password length is 12; policy requires at least 14. - ledger R2: MFA required for 'admins_only'; policy requires 'all_users' (admins only is not enough). - ledger R4: Account locks after 0 failed attempts (0 means never locks); policy allows 10 or fewer. - ledger R5: Idle timeout is 30 minutes (30 minutes); limit for a sensitive system is 15 minutes. - ledger R6: System supports SSO and it is off; policy requires it on where supported. - ledger R7: Default administrator account enabled is true; policy requires it disabled. - crm R1: Minimum password length is 10; policy requires at least 14. - crm R5: Idle timeout is 8 hours (480 minutes); limit for a non-sensitive system is 60 minutes. - cloud_console R5: Idle timeout is 20 minutes (20 minutes); limit for a sensitive system is 15 minutes. - cloud_console R7: Default administrator account enabled is true; policy requires it disabled. - vpn R3: Second steps are sms; sms is among them but policy does not allow it. - vpn R4: Account locks after 12 failed attempts; policy allows 10 or fewer. - vpn R5: Idle timeout is 0 minutes (0 minutes, meaning never); limit for a non-sensitive system is 60 minutes. - wifi_admin R1: Minimum password length is 8; policy requires at least 14. - wifi_admin R7: Default administrator account enabled is true; policy requires it disabled. - warehouse_handhelds R2: MFA required for 'none'; policy requires 'all_users' (admins only is not enough). - label_printer_portal R2: MFA required for 'none'; policy requires 'all_users' (admins only is not enough). The exception ended 2026-09-30, before the export date 2026-11-30. - label_printer_portal R6: System supports SSO and it is off; policy requires it on where supported. ## In scope but missing from the export - hr_records ## Exceptions that have run out - label_printer_portal R2 ended 2026-09-30 ## Exceptions no longer needed (system now passes the rule) - code_host R5 ## Not shown (setting missing or null in the export) - crm R7 - code_host R4 - wifi_admin R2 - wifi_admin R3 - label_printer_portal R7 Export date 2026-11-30; 84 checks (12 systems x 7 rules). hr_records is counted as not_shown on all 7 rules.
check.py · the check, written before the run
"""Tests every policy rule on every system in scope from the settings export, then compares."""
import csv, json, re, sys
from datetime import date
from pathlib import Path
FOUND = {}
RESULTS = ["pass", "fail", "exempt", "not_shown", "not_applicable"]
RULES = ["R1", "R2", "R3", "R4", "R5", "R6", "R7"]
NUM = re.compile(r"(?<![\w.-])\d(?:[\d,]*\d)?(?:\.\d+)?(?![\w-])")
DAY = re.compile(r"\d{4}-\d{2}-\d{2}")
LIMITS = {"R1": {14.0}, "R4": {10.0}, "R5": {15.0, 60.0}}
def table(text, heading):
part = text.split("## " + heading, 1)[1].split("\n## ", 1)[0]
out = []
for line in part.splitlines():
cells = [c.strip() for c in line.strip().strip("|").split("|")]
if line.strip().startswith("|") and not set(line.strip()) <= set("|- "): out.append(cells)
return out[1:]
def expected(root):
inp = root / "input"
policy = (inp / "signin_policy.md").read_text()
scope = {r[0]: r[1].lower() == "yes" for r in table(policy, "Systems in scope")}
exceptions = {(r[0], r[1]): date.fromisoformat(r[3]) for r in table(policy, "Approved exceptions")}
export = json.loads((inp / "settings_export.json").read_text())
day = date.fromisoformat(export["exported_on"])
systems = {s["system"]: s for s in export["systems"]}
def get(s, *keys):
for k in keys:
if not isinstance(s, dict) or s.get(k) is None: return None
s = s[k]
return s
def minutes(s):
sess = get(s, "session")
if not isinstance(sess, dict): return None
for key, mult in (("idle_timeout_minutes", 1), ("idle_timeout_seconds", 1 / 60), ("idle_timeout_hours", 60)):
if sess.get(key) is not None: return sess[key] * mult
return None
def test(s, rule, sensitive):
if rule == "R1":
v = get(s, "password", "min_length"); return None if v is None else v >= 14
if rule == "R2":
v = get(s, "mfa", "required"); return None if v is None else v in ("all_users", True)
if rule == "R3":
v = get(s, "mfa", "methods"); return None if v is None else "sms" not in [str(x).lower() for x in v]
if rule == "R4":
v = get(s, "lockout", "failed_attempts"); return None if v is None else 0 < v <= 10
if rule == "R5":
v = minutes(s); return None if v is None else 0 < v <= (15 if sensitive else 60)
if rule == "R6":
sup = get(s, "sso", "supported")
if sup is None: return None
if sup is False: return "n/a"
v = get(s, "sso", "enabled"); return None if v is None else v is True
if rule == "R7":
v = get(s, "default_admin", "enabled"); return None if v is None else v is False
want, expired, unneeded = {}, [], []
for name, sensitive in scope.items():
for rule in RULES:
t = test(systems[name], rule, sensitive) if name in systems else None
until = exceptions.get((name, rule))
if t is None: r = "not_shown"
elif t == "n/a": r = "not_applicable"
elif t: r = "pass"
elif until and until >= day: r = "exempt"
else: r = "fail"
want[(name, rule)] = r
if until and r == "fail": expired.append((name, rule, until.isoformat()))
if until and r == "pass": unneeded.append((name, rule))
missing = [n for n in scope if n not in systems]
# what the export really holds for each system and rule: the words, numbers and dates that may be said about it
for name, sensitive in scope.items():
s = systems.get(name, {})
raw = {"R1": [get(s, "password", "min_length")], "R2": [get(s, "mfa", "required")], "R3": get(s, "mfa", "methods") or [],
"R4": [get(s, "lockout", "failed_attempts")], "R5": [v for v in (get(s, "session") or {}).values()] if isinstance(get(s, "session"), dict) else [],
"R6": [get(s, "sso", "supported"), get(s, "sso", "enabled")], "R7": [get(s, "default_admin", "enabled")]}
for rule in RULES:
vals = [v for v in raw[rule] if v is not None]
nums = {float(v) for v in vals if isinstance(v, (int, float)) and not isinstance(v, bool)}
if rule == "R5" and minutes(s) is not None: nums |= {float(minutes(s)), 15.0 if sensitive else 60.0}
if rule in ("R1", "R4"): nums |= LIMITS[rule]
until = exceptions.get((name, rule))
FOUND[(name, rule)] = {"words": [str(v).lower() for v in vals if not isinstance(v, (int, float)) or isinstance(v, bool)],
"raw_nums": {float(v) for v in vals if isinstance(v, (int, float)) and not isinstance(v, bool)}, "nums": nums,
"dates": {day.isoformat()} | ({until.isoformat()} if until else set()), "shown": want[(name, rule)] != "not_shown",
"limit": (15.0 if sensitive else 60.0) if rule == "R5" else next(iter(LIMITS.get(rule, {None})))}
return want, missing, expired, unneeded
def main():
root = Path(sys.argv[1]); ok = True
def say(passed, text):
nonlocal ok
ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
want, missing, expired, unneeded = expected(root)
path = root / "output/policy_check.csv"
if not path.exists():
say(False, "output/policy_check.csv was not written"); sys.exit(1)
with path.open(newline="") as fh:
got_rows = list(csv.DictReader(fh))
got = {((r.get("system") or "").strip(), (r.get("rule") or "").strip().upper()): (r.get("result") or "").strip().lower() for r in got_rows}
n = len(want)
say(len(got_rows) == n and set(got) == set(want), f"{len(set(got) & set(want))} of {n} pairs of system and rule appear once in policy_check.csv")
right = sum(1 for k, r in want.items() if got.get(k) == r)
say(right == n, f"{right} of {n} results equal the result recomputed from the settings export and the written policy")
hard = [k for k, r in want.items() if r in ("exempt", "not_shown", "not_applicable")]
h_ok = sum(1 for k in hard if got.get(k) == want[k])
say(h_ok == len(hard), f"{h_ok} of {len(hard)} checks that are exempt, not shown or not applicable are marked that way and not passed or failed")
text_of = {((r.get("system") or "").strip(), (r.get("rule") or "").strip().upper()): r for r in got_rows}
def numbers(s):
return [float(m.group(0).replace(",", "")) for m in re.finditer(r"(?<![\w.-])\d+(?:\.\d+)?(?![\w-])", DAY.sub(" ", s))]
def found_ok(k):
f, cell = FOUND[k], (text_of.get(k, {}).get("setting_found") or "").strip().lower()
if not f["shown"]: return cell == ""
if not cell or any(w not in cell for w in f["words"]): return False
if set(numbers(cell)) != f["raw_nums"]: return False
said = set(re.findall(r"\b(true|false)\b", cell)); real = {w for w in f["words"] if w in ("true", "false")}
return said == real and ("sms" in re.findall(r"[a-z_]+", cell)) == ("sms" in f["words"])
s_found = sum(1 for k in want if found_ok(k))
shown = sum(1 for f in FOUND.values() if f["shown"])
say(s_found == n, f"{s_found} of {n} setting_found cells hold what the export holds: {shown} with the exported value and {n - shown} left blank because nothing is shown")
def reason_ok(k):
f, text = FOUND[k], (text_of.get(k, {}).get("reason") or "").strip()
if len(text.split()) < 4 or any(d not in f["dates"] for d in DAY.findall(text)): return False
nums = numbers(text)
if any(v not in f["nums"] | f["raw_nums"] for v in nums if v >= 10): return False
if f["shown"] and f["raw_nums"] and f["limit"] is not None:
return bool(set(nums) & (f["raw_nums"] | f["nums"] - {f["limit"]} or {f["limit"]})) and f["limit"] in nums
return True
r_ok = sum(1 for k in want if reason_ok(k))
say(r_ok == n, f"{r_ok} of {n} reasons carry only that system's own numbers and dates, with the value found and the policy limit where the rule has one")
summary = (root / "output/summary.md").read_text() if (root / "output/summary.md").exists() else ""
s_ok = 0
for name in RESULTS:
m = re.search(r"(?<![a-z_])" + name + r"[`*\s]*:[`*\s]*(\d+)", summary)
if m and int(m.group(1)) == sum(1 for r in want.values() if r == name): s_ok += 1
say(s_ok == len(RESULTS), f"{s_ok} of {len(RESULTS)} result counts in summary.md equal the recomputed counts")
lines = summary.splitlines()
fails = [k for k, r in want.items() if r == "fail"]
f_ok = sum(1 for (system, rule) in fails if any(system in ln and re.search(r"\b" + rule + r"\b", ln) for ln in lines))
say(f_ok == len(fails), f"{f_ok} of {len(fails)} failed checks are on a line of summary.md with their system and rule id")
m_ok = sum(1 for s in missing if s in summary)
e_ok = sum(1 for (system, rule, until) in expired if any(system in ln and re.search(r"\b" + rule + r"\b", ln) and until in ln for ln in lines))
e_ok += sum(1 for (system, rule) in unneeded if any(system in ln and re.search(r"\b" + rule + r"\b", ln) for ln in lines))
say(m_ok == len(missing) and e_ok == len(expired) + len(unneeded),
f"summary.md names {m_ok} of {len(missing)} systems missing from the export and {e_ok} of {len(expired) + len(unneeded)} exceptions that ran out (with the end date) or are no longer needed")
seen = bad = 0
totals = {float(x) for x in [n, len({k[0] for k in want}), len({k[0] for k in want}) - len(missing), len(RULES), *[sum(1 for r in want.values() if r == name) for name in RESULTS]]}
all_days = set().union(*[f["dates"] for f in FOUND.values()])
for ln in lines:
pairs = [k for k in want if re.search(r"(?<![\w-])" + re.escape(k[0]) + r"(?![\w-])", ln) and re.search(r"\b" + k[1] + r"\b", ln)]
nums = set(totals) if not pairs else set().union(*[FOUND[k]["nums"] | FOUND[k]["raw_nums"] for k in pairs])
days = all_days if not pairs else set().union(*[FOUND[k]["dates"] for k in pairs])
for d in DAY.findall(ln):
seen += 1; bad += d not in days
for m in NUM.finditer(DAY.sub(" ", ln)):
if len(m.group(0)) >= 2:
seen += 1; bad += float(m.group(0).replace(",", "")) not in nums
if len(pairs) == 1 and want[pairs[0]] == "fail" and FOUND[pairs[0]]["limit"] is not None:
f = FOUND[pairs[0]]; listed = numbers(re.sub(r"\bR\d\b", " ", ln)); here = set(listed)
if len(listed) >= 2:
seen += 1; bad += not (f["limit"] in here and here & ((f["raw_nums"] | f["nums"]) - {f["limit"]}))
say(seen > 0 and bad == 0, f"{seen - bad} of {seen} other numbers and dates in summary.md match the setting and limit of the system and rule they sit beside or the totals")
sys.exit(0 if ok else 1)
if __name__ == "__main__":
main()
settings_export.json: sample data written by Atris. Fingerprint f4055a05f434.
signin_policy.md: sample data written by Atris. Fingerprint 4226c45e9f1a.
policy_check.csv: written by the agent. Fingerprint 0a86c811a733.
summary.md: written by the agent. Fingerprint 18f5647e32d5.