Skip to content

Tutorial 4: CIS Sync and Compliance Verification Lab

Goal: Verify local CIS specs, preview dry-run sync, inspect all five compliance states, and export ansible/shell plans in /tmp/cis-sync.

Warning

Isolated Lab Only: Store files in /tmp/cis-sync. --dry-run and --remediate-dry-run execute zero downloads and zero host edits.

flowchart LR
    VER["--verify-cis (SHA-256)"] --> SYN["--sync-cis --dry-run"]
    SYN --> ST["5 Compliance States (JSON)"]
    ST --> REM["--remediate-dry-run -> ansible / shell"]

Prerequisites

Step 1: Verify Local CIS Specs (--verify-cis)

rm -rf /tmp/cis-sync && mkdir -p /tmp/cis-sync
python3 audit_cis.py --verify-cis --cis-types md
python3 audit_cis.py --verify-cis --target postgresql16 --cis-types md

Expected output checks SHA-256 digests against conf/cis_manifest.json. The first run prints Total: 22 | Verified: 22 | Missing: 0 | Corrupted: 0, and the second prints Total: 1 | Verified: 1 | Missing: 0 | Corrupted: 0.

Step 2: Preview Dry-Run Sync (--sync-cis --dry-run)

Combine --dry-run with --cis-types (md, pdf, md,pdf, or all) to preview spec actions without network writes.

python3 audit_cis.py --sync-cis --dry-run --cis-types md,pdf --target postgresql16
python3 audit_cis.py --sync-cis --dry-run --cis-types md

Expected output marks verified Markdown files as UP_TO_DATE, marks uncached PDFs as DRY_RUN, and reports Downloaded: 0 with Failed: 0.

Step 3: Inspect All Five Compliance States

Every control resolves to one of five states. Only Pass and Fail enter the score denominator.

State JSON Value In Score Meaning
Pass PASS Yes Automated control passed
Fail FAIL Yes Security non-compliance found
Error ERROR No Environment or execution error
Manual MANUAL No Human review required
Not Applicable N/A No Control does not apply

Create a five-state report and verify scoring via cis_core_engine.

python3 -c 'import json; json.dump({"target":"rhel9","results":[{"id":"1.1.1.1","name":"Disable cramfs","category":"1. FS","type":"Automated","status":"FAIL","output":"on"},{"id":"5.2.1","name":"Disable root SSH","category":"5. Auth","type":"Automated","status":"PASS","output":"no"},{"id":"5.2.2","name":"Block empty pwd","category":"5. Auth","type":"Automated","status":"ERROR","output":"missing"},{"id":"1.1.2","name":"Check /tmp mount","category":"1. FS","type":"Manual","status":"MANUAL","remediation":"Verify."},{"id":"2.1.1","name":"Disable xinetd","category":"2. Svc","type":"Automated","status":"N/A","output":"absent"}]}, open("/tmp/cis-sync/states.json","w"))'
python3 -c "import json, cis_core_engine as e; r=json.load(open('/tmp/cis-sync/states.json'))['results']; s=e.calculate_scores(r); print(f'score={s[0]:.1f}% pass={s[5]} fail={s[6]} error={s[3]} manual={s[2]} na={s[4]}')"

Expected output: score=50.0% pass=1 fail=1 error=1 manual=1 na=1.

Step 4: Export Offline ansible and shell Remediation

Generate deterministic Ansible and Bash dry-run plans from the saved JSON report with zero host changes.

python3 audit_cis.py --remediate-dry-run --from-report /tmp/cis-sync/states.json --remediation-format ansible --remediation-output /tmp/cis-sync/fix.yml
python3 audit_cis.py --remediate-dry-run --from-report /tmp/cis-sync/states.json --remediation-format shell --remediation-output /tmp/cis-sync/fix.sh
cat /tmp/cis-sync/fix.yml
cat /tmp/cis-sync/fix.sh

Expected output prints check_mode: true tasks in fix.yml and # DRY-RUN SHELL (rhel9 / rhel) in fix.sh. Both plans cover FAIL and MANUAL controls and skip PASS, ERROR, and N/A.

Step 5: Clean Up /tmp/cis-sync

rm -rf /tmp/cis-sync

Next Steps