Skip to content

Harden Dry-Run Remediation and Least-Privilege Roles

Read CLI Flags & Exit Codes before you start.

Prerequisites

  1. Confirm database administrator access to create read-only accounts.
  2. 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

  1. 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';
  1. 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;
  1. For MongoDB or Cassandra, grant read-only monitor roles (clusterMonitor or SELECT on system_auth).
  2. Restrict .my.cnf, .pgpass, and cqlshrc files to mode 600:
chmod 600 ~/.my.cnf ~/.pgpass ~/.cassandra/cqlshrc
  1. Run audits with --defaults-file and 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
  1. Generate offline diff, sql, shell, and ansible dry-run outputs from reports/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
  1. 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
  1. Inspect risk_level, requires_restart, and action_type before 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']])"
  1. Review pg16.diff, pg16.sql, pg16.sh, and pg16.yml with the change board.

NOTE: --remediate-dry-run enforces dry_run=True and executes zero OS or SQL mutations.

Verification

  1. Confirm mode 600 on every option file:
stat -c "%a %n" ~/.my.cnf ~/.pgpass ~/.cassandra/cqlshrc
  1. Confirm that audit_cis.py exits with code 0 under cis_audit.
  2. Confirm that reports/pg16.yml sets check_mode: true on shell tasks.
  3. Run credential and remediation unit tests:
python3 -m unittest tests/test_credential_injection.py tests/test_remediation_generator.py -v

Rollback

  1. Revoke privileges or drop cis_audit (DROP USER or DROP ROLE).
  2. If option files expose secrets, delete ~/.my.cnf, ~/.pgpass, and ~/.cassandra/cqlshrc.
  3. Delete unapproved diff, sql, sh, yml, and json files from reports/.
  4. Rotate affected database passwords in the secret vault immediately.