Rotate credentials and remove logs that may contain passwords

Use this procedure after upgrading CD to 5.19.1 if you ran affected plans on CD 5.0.0 through 5.19.0.

Before you begin:

Upgrade CD to 5.19.1 before rotating credentials. You need access to the Bolt runner and Hiera data, and root access to the CD hosts. Check your log-retention policy before removing system logs.

Credential rotation is the remediation. Removing logs only removes local copies; credentials may also remain in support bundles or forwarded logs. Passwords were visible in the host process list only while the commands ran, so no process-list cleanup is needed. For affected logs and exposure conditions, see Database and root admin passwords can appear in plaintext in logs.

  1. Upgrade CD to 5.19.1 before changing any passwords. Earlier versions can write the new passwords to logs during the next plan run.
  2. Rotate the cd4pe and query database passwords:
    • If you use a managed database, set new values for database.managed.cd4pe_db_password and database.managed.query_db_password in Hiera, then run:
      Copy
      bolt plan run cd4peadm::apply_configuration

      The plan updates the database roles and services.

    • If you use an external database, change the role passwords on the PostgreSQL server first. Then update database.external.cd4pe_db_password and database.external.query_db_password in Hiera and run bolt plan run cd4peadm::apply_configuration.
  3. Set a new root_password value in Hiera and run bolt plan run cd4peadm::apply_configuration to rotate the CD root admin password.
  4. This step only applies if you’ve run the external migration but are still using a managed database. If you ran an external-database migration plan as a non-root Bolt user, rotate the managed PostgreSQL superuser password. The apply_configuration plan does not rotate this password. Replace <runtime> with docker or podman, then run the command and enter the new password at the prompt:
    Copy
    <runtime> exec -it postgres psql -U postgres -c '\password postgres'

    Update database.managed.admin_db_password in Hiera to match the new password.

  5. On the Bolt runner, delete bolt-debug.log from the Bolt project directory and remove old support bundles under <bolt project>/downloads/cd4pe/supportbundle-*.
  6. If you use a managed database, clean up postgresql.log on the database host. The log is in /var/lib/docker/volumes/postgres-logs/_data/ for Docker or /var/lib/containers/storage/volumes/postgres-logs/_data/ for Podman. Change to the directory for your runtime before running these commands.
    1. Check for affected entries:
      Copy
      zgrep -c 'CREATE ROLE' postgresql.log*

      A nonzero count means a file is affected.

    2. Truncate the active log in place. Do not delete it because PostgreSQL continues writing to it:
      Copy
      : > postgresql.log
    3. Remove the rotated log copies:
      Copy
      rm -f postgresql.log.*.gz
  7. Clean up host system logs only if Bolt connected as a non-root user and escalated with run-as or sudo, or if the host has an execve audit rule:
    • For authentication logs, find files that contain the credentials and redact the matching values. Run the redaction command for each file returned by grep:
      Copy
      grep -lE 'PGPASSWORD=|CD4PE_ROOT_PASSWORD=|CD4PE_ROOT_EMAIL=' /var/log/secure* /var/log/auth.log*
      sed -i -E 's/((PGPASSWORD|CD4PE_ROOT_PASSWORD|CD4PE_ROOT_EMAIL)=)[^ ]*/\1[REDACTED]/g' <file>
    • Individual systemd journal entries cannot be edited. The following commands rotate the journal and delete all archived journal history. Check this against your retention policy first:
      Copy
      journalctl --rotate
      journalctl --vacuum-time=1s
    • Audit log commands are hex-encoded. Check for matching records, then rotate the audit log and remove old files only as your policy allows:
      Copy
      ausearch -i -m USER_CMD,EXECVE | grep -E 'PGPASSWORD=|CD4PE_ROOT_PASSWORD=|CD4PE_ROOT_EMAIL='
      service auditd rotate
  8. Ask the teams that own forwarded logs, such as a SIEM or log aggregator, and any recipients of shared support bundles to purge or restrict matching copies.
Results
You have rotated the affected credentials and removed the local log copies. Log cleanup does not remove copies in support bundles or forwarded logging systems, and it does not replace credential rotation.