Harden Dry-Run Remediation and Least-Privilege Roles¶
Read CLI Flags & Exit Codes before you start.
Prerequisites¶
- Confirm database administrator access to create read-only accounts.
- Confirm that a secret vault stores all audit passwords.
Safety Instructions¶
CAUTION: Never grant SUPER, SUPERUSER, or write privileges to audit
accounts.
Excess privileges allow destructive database changes if an attacker steals
audit credentials.
CAUTION: Never execute generated sql, shell, or ansible artifacts
without change approval.
Unreviewed edits can restart database services or block client connections.
Procedure¶
- Create a read-only audit account for MariaDB or MySQL:
CREATE USER 'cis_audit'@'localhost' IDENTIFIED BY 'VAULT_SECRET';
GRANT PROCESS, SHOW DATABASES, SELECT ON mysql.* TO 'cis_audit'@'localhost';
GRANT SELECT ON performance_schema.* TO 'cis_audit'@'localhost';
- Create a read-only audit role for PostgreSQL:
CREATE ROLE cis_audit LOGIN PASSWORD 'VAULT_SECRET';
GRANT pg_read_all_settings, pg_read_all_stats, pg_monitor TO cis_audit;
- For MongoDB or Cassandra, grant read-only monitor roles (
clusterMonitororSELECTonsystem_auth). - Restrict
.my.cnf,.pgpass, andcqlshrcfiles to mode600:
- Run audits with
--defaults-fileand the dedicated read-only user:
python3 audit_cis.py -t mariadb106 -u cis_audit --defaults-file ~/.my.cnf --local -f json -o reports/m106.json
python3 audit_cis.py -t postgresql16 -u cis_audit --defaults-file ~/.pgpass --local -f json -o reports/pg16.json
python3 audit_cis.py -t cassandra50 -u cis_audit --defaults-file ~/.cassandra/cqlshrc --local -f json -o reports/cas50.json
- Generate offline
diff,sql,shell, andansibledry-run outputs fromreports/pg16.json:
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format diff --remediation-output reports/pg16.diff
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format sql --remediation-output reports/pg16.sql
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format shell --remediation-output reports/pg16.sh
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format ansible --remediation-output reports/pg16.yml
- Export the JSON dry-run remediation plan:
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format json --remediation-output reports/pg16_plan.json
- Inspect
risk_level,requires_restart, andaction_typebefore approval:
python3 -c "import json; p=json.load(open('reports/pg16_plan.json')); assert p['dry_run'] is True; print([(i['control_id'], i['risk_level'], i['requires_restart'], i['action_type']) for i in p['items']])"
- Review
pg16.diff,pg16.sql,pg16.sh, andpg16.ymlwith the change board.
NOTE: --remediate-dry-run enforces dry_run=True and executes zero OS
or SQL mutations.
Verification¶
- Confirm mode
600on every option file:
- Confirm that
audit_cis.pyexits with code0undercis_audit. - Confirm that
reports/pg16.ymlsetscheck_mode: trueon shell tasks. - Run credential and remediation unit tests:
Rollback¶
- Revoke privileges or drop
cis_audit(DROP USERorDROP ROLE). - If option files expose secrets, delete
~/.my.cnf,~/.pgpass, and~/.cassandra/cqlshrc. - Delete unapproved
diff,sql,sh,yml, andjsonfiles fromreports/. - Rotate affected database passwords in the secret vault immediately.