Skip to content

Cleanup unused SSL certificates

Maksym Zaporozhets edited this page Jun 19, 2023 · 2 revisions

maintenance:traefik:cleanup-certificates

Clean up unused SSL certificates.

Description

  1. Search for SSL certificates in all virtual-host.conf files within the $DOCKERIZER_PROJECTS_ROOT_DIR directory.
  2. Remove SSL certificates from the $DOCKERIZER_SSL_CERTIFICATES_DIR if they are not found in any of the virtual-host.conf files.
  3. Get a list of certificate files left on the disk.
  4. Clean up the $DOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE file from the entries that do not exist on the disk.

Use at your own responsibility. Generating new certificates with mkcert if needed.

Removing unused certificates:

  • Decreases a mess in the $DOCKERIZER_SSL_CERTIFICATES_DIR directory.
  • Decreases a mess in the $DOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE file.
  • Reduces the growth of the Traefik log file size.

Usage

php bin/dockerizer maintenance:traefik:cleanup-certificates

How it works

  1. Collect all .pem file names from the virtual-host.conf files within the $DOCKERIZER_PROJECTS_ROOT_DIR directory.
  2. Remove all .pem files from the $DOCKERIZER_SSL_CERTIFICATES_DIR directory that are not present in the list from the previous step.
  3. Get a list of files left in the $DOCKERIZER_SSL_CERTIFICATES_DIR directory.
  4. Remove all entries from the $DOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE file that are not present in the list from the previous step.

Required environment variables

  • DOCKERIZER_PROJECTS_ROOT_DIR: The directory where projects are stored. Acts as a firewall to prevent commands from deleting files outside of this directory or system temp directory.
  • DOCKERIZER_SSL_CERTIFICATES_DIR: In the docker-compose.yaml - the directory where SSL certificates are stored.
  • DOCKERIZER_TRAEFIK_SSL_CONFIGURATION_FILE (.env.local): The path to the Traefik SSL configuration file. Configured automatically to /home/$USER/misc/apps/traefik-reverse-proxy/traefik/configuration/certificates.toml when you install Traefik (see Configuring the tool section on the Wiki home page).
Clone this wiki locally