Recover a database-backed CA

When using database-backed CA storage, recovery depends on both:

  • The pe-ca database

  • The passphrase file

The passphrase file is the only way to decrypt CA private keys stored in the database. If the passphrase is lost and no backup exists, the CA cannot be recovered.

Recovery scenarios

Scenario Recoverable
Database lost, passphrase intact Yes
Passphrase lost, no backup No
Both lost, backup exists Yes
Both lost, no backup No

Restore from backup

/opt/puppetlabs/bin/puppet-backup restore --force <backup>.tgz 
systemctl start pe-puppetserver 

If passphrase is lost

  • Restore it from backup if available

  • If not:

    • The CA must be rebuilt

    • All agents must re-enroll

Reset the certificate authority as a last resort

Follow these steps only if recovery is not possible:

Run all commands as root on the primary node.
A CA reset invalidates all existing certificates. After rebuilding the CA, you must re-enroll all agents and regenerate certificates for any infrastructure nodes that use the rebuilt CA.
  1. Create a backup before proceeding.

    /opt/puppetlabs/bin/puppet-backup create --force --dir=/tmp --name=pre-reset.tgz
  2. Switch the CA to the filesystem backend.

    Run the CA storage export plan to export the certificate authority from the database and switch the CA to the filesystem backend.

    BOLT_DISABLE_ANALYTICS=true BOLT_GEM=true /opt/puppetlabs/installer/bin/bolt \
      --project /opt/puppetlabs/installer/share/Boltdir \
      plan run puppet_enterprise::ca_storage_export targets=localhost
  3. Copy the classification change into user_data.conf.

    a) Run the following command to update user_data.conf and ensure that the CA backend configuration matches the classification setting.

    puppet infrastructure recover_configuration --pe-environment production

    b) Verify that the CA storage backend is set to filesystem:

    grep ca_storage_backend /etc/puppetlabs/enterprise/conf.d/user_data.conf

    Expected output:

    filesystem
  4. Rebuild the certificate authority.

    Create a new certificate authority and new infrastructure certificates.

    puppet infrastructure run rebuild_certificate_authority
  5. Replace the old CA in pe-ca with the new CA.

    a) Empty the pe-ca tables.

    Remove the existing CA data from pe-ca.

    /opt/puppetlabs/bin/puppetserver ca storage --cleanup-db --force

    b) Import the new CA into pe-ca.

    Import the rebuilt CA, CA keys, and certificates into pe-ca.

    /opt/puppetlabs/bin/puppetserver ca storage --import --full

    c) Switch back to the database backend.

    Run the CA storage import plan to switch the CA back to the database backend.

    BOLT_DISABLE_ANALYTICS=true BOLT_GEM=true /opt/puppetlabs/installer/bin/bolt \
      --project /opt/puppetlabs/installer/share/Boltdir \
      plan run puppet_enterprise::ca_storage_import targets=localhost
  6. Copy the classification change into user_data.conf again.

    a) Run the following command to update user_data.conf and ensure that the CA backend configuration matches the classification setting.

    puppet infrastructure recover_configuration --pe-environment production

    b) Verify that the CA storage backend is set to database:

    grep ca_storage_backend /etc/puppetlabs/enterprise/conf.d/user_data.conf

    Expected output:

    database
  7. Re-enroll all agents.

    Re-enroll each agent so that it trusts the rebuilt certificate authority.

    puppet infrastructure run regenerate_agent_certificate agent=<certname> clean_crl=true \
      --use-ssh --user <user> --private-key <key>

    If your deployment includes compilers or a replica, regenerate their certificates as well using the appropriate certificate regeneration tasks.

  8. Verify that the database-backed CA is active.

    a) Verify that the CA is using the database backend:

    curl -sSk --cert $(puppet config print hostcert) --key $(puppet config print hostprivkey) \
      'https://localhost:8140/status/v1/services/ca-storage?level=info'

    Expected output includes:

    "backend": "database"

    b) Verify that Puppet runs succeed on the primary node and on all re-enrolled agents:

    puppet agent -t