znerol.certhub
Rol de Ansible: Certhub
Instala certhub y git-gau
en servidores linux controlados por systemd
.
Requisitos
- Git
- OpenSSL
- Rsync si la máquina objetivo funciona como un servidor SSL/TLS.
- Ya sea
certbot
,dehydrated
olego
cuando la máquina objetivo funciona como el controlador.
Variables de Rol
Este rol contiene varios archivos de tareas
. El archivo de tareas principal
solo importa algunas de ellas:
- certhub-system-setup.yml: Crea el usuario y grupo
certhub
, el directorio de configuración y prepara el directorio personal. - certhub-software-setup.yml: Descarga e instala
certhub
ygit-gau
. - certhub-git-setup.yml: Configura
user.name
yuser.email
de git. - certhub-repo-setup.yml: Inicializa el repositorio local de git
certs
.
Los siguientes archivos de tareas contienen pasos adicionales de configuración:
- certbot-noroot-config.yml: Simplifica la ejecución de
certbot
como el usuariocerthub
sin privilegios colocando un archivocli.ini
adecuado.
Los siguientes archivos de tareas contienen pasos utilizados para configurar la adquisición y despliegue de certificados.
- Entorno para unidades systemd: Variables que contienen rutas a archivos de entorno respetadas por todas las unidades de certhub de systemd.
- repo-push-units.yml: Configura unidades de
systemd
responsables de empujar el repositorio de certificados a los servidores SSL/TLS cada vez que cambie. - certbot-run-units.yml: Configura unidades de
systemd
responsables de emitir/renovar un certificado y también lo monitorea para su vencimiento (controlador). - lego-run-units.yml: Configura unidades de
systemd
responsables de emitir/renovar un certificado y también lo monitorea para su vencimiento (controlador). - cert-export-units.yml: Configura unidades de
systemd
responsables de desplegar un certificado en un servidor SSL/TLS, recargar servicios afectados y/o enviar los certificados a destinos específicos.
Variables para certhub-system-setup.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_user_group: certhub
certhub_user_name: certhub
certhub_user_shell: /usr/bin/git-shell
certhub_home_dir_path: /var/lib/certhub
certhub_home_dir_mode: 0755
certhub_config_dir_path: /etc/certhub
certhub_config_dir_owner: root
certhub_config_dir_group: root
certhub_config_dir_mode: 0755
certhub_status_dir_path: "{{ certhub_home_dir_path }}/status"
certhub_status_dir_owner: "{{ certhub_user_name }}"
certhub_status_dir_group: "{{ certhub_user_group }}"
certhub_status_dir_mode: 0755
certhub_certs_dir_path: "{{ certhub_home_dir_path }}/certs"
certhub_certs_dir_owner: "{{ certhub_user_name }}"
certhub_certs_dir_group: "{{ certhub_user_group }}"
certhub_certs_dir_mode: 0755
certhub_private_dir_path: "{{ certhub_home_dir_path }}/private"
certhub_private_dir_owner: "{{ certhub_user_name }}"
certhub_private_dir_group: "{{ certhub_user_group }}"
certhub_private_dir_mode: 0700
certhub_repo_path: "{{ certhub_home_dir_path}}/certs.git"
Variables para certhub-software-setup.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_certhub_version: v1.0.0
certhub_certhub_checksum: "{{ certhub_certhub_releases[certhub_certhub_version]['checksum'] }}"
certhub_certhub_url: "{{ certhub_certhub_releases[certhub_certhub_version]['url'] }}"
certhub_certhub_prefix: /usr/local
certhub_certhub_archive_path: "{{ certhub_private_dir_path }}/certhub-dist-{{ certhub_certhub_version }}.tar.gz"
certhub_gitgau_version: v1.3.0
certhub_gitgau_checksum: "{{ certhub_gitgau_releases[certhub_gitgau_version]['checksum'] }}"
certhub_gitgau_url: "{{ certhub_gitgau_releases[certhub_gitgau_version]['url'] }}"
certhub_gitgau_prefix: /usr/local
certhub_gitgau_archive_path: "{{ certhub_private_dir_path }}/git-gau-dist-{{ certhub_gitgau_version }}.tar.gz"
Las variables certhub_certhub_releases
y certhub_gitgau_releases
contienen URLs y sumas de verificación de todas las versiones públicas. Establezca certhub_certhub_version
y certhub_gitgau_version
para fijar una versión específica.
Variables para certhub-git-setup.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_git_user_name: "{{ certhub_user_name }}"
certhub_git_user_email: "{{ certhub_user_name }}@{{ ansible_fqdn }}"
Variables para certhub-repo-setup.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_repo_init_path: "{{ certhub_repo_path }}"
certhub_repo_init_message: Init
La configuración del repositorio de git se omite cuando certhub_repo_init_path
es una cadena vacía.
Variables para certbot-noroot-config.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_certbot_cli_ini_path: "{{ certhub_home_dir_path }}/.config/letsencrypt/cli.ini"
certhub_certbot_cli_ini_content: ""
certhub_certbot_work_dir: "{{ certhub_private_dir_path }}/certbot/work"
certhub_certbot_logs_dir: "{{ certhub_private_dir_path }}/certbot/logs"
certhub_certbot_config_dir: "{{ certhub_private_dir_path }}/certbot/config"
La variable certhub_certbot_cli_ini_content
se puede utilizar para proporcionar configuración adicional de certbot. Por ejemplo, staging=true
para seleccionar el entorno de prueba durante la evaluación.
Entorno para unidades systemd
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
# Archivo de entorno opcional compartido por todas las instancias y servicios certhub.
certhub_env_path: "{{ certhub_config_dir_path }}/env"
# Archivo de entorno opcional por instancia, compartido por todos los servicios certhub.
certhub_cert_env_path: "{{ certhub_config_dir_path}}/{{ certhub_cert_slug }}.env"
# Archivo de entorno opcional por servicio, compartido por todas las instancias de servicios certhub.
certhub_unit_env_path: "{{ certhub_config_dir_path}}/{{ certhub_unit_prefix }}.env"
# Archivo de entorno opcional por instancia y por servicio.
certhub_cert_unit_env_path: "{{ certhub_config_dir_path}}/{{ certhub_cert_slug }}.{{ certhub_unit_prefix }}.env"
certhub_env_owner: root
certhub_env_group: "{{ certhub_user_group }}"
certhub_env_mode: 0640
Utilice estas variables en tareas copy
o template
personalizadas para llenar archivos env
con la configuración para los servicios de certhub. Nota: No hay valor predeterminado para certhub_unit_prefix
. Esta variable debe establecerse en uno de los prefijos de unidad de servicio de certhub. Los siguientes valores son actualmente válidos:
- certhub-cert-expiry
- certhub-cert-export
- certhub-cert-reload
- certhub-cert-send
- certhub-certbot-run
- certhub-dehydrated-run
- certhub-lego-run
Variables para repo-push-units.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_repo_push_user: "{{ certhub_user_name }}"
certhub_repo_push_host: "{{ inventory_hostname }}"
certhub_repo_push_path: "{{ certhub_repo_path }}"
certhub_repo_push_remote: "{{ '{:s}@{:s}:{:s}'.format(certhub_repo_push_user, certhub_repo_push_host, certhub_repo_push_path) }}"
certhub_repo_push_path_unit: "{{ lookup('pipe', 'systemd-escape [email protected] ' + certhub_repo_push_remote | quote) }}"
Especifique certhub_repo_push_remote
para anular completamente el remoto.
Variables para certbot-run-units.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_cert_slug: "{{ inventory_hostname }}"
certhub_cert_expiry_timer_unit: "certhub-cert-expiry@{{ certhub_cert_slug }}.timer"
certhub_certbot_run_path_unit: "certhub-certbot-run@{{ certhub_cert_slug }}.path"
Establezca certhub_cert_slug
para especificar la instancia del certificado.
Variables para lego-run-units.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_cert_slug: "{{ inventory_hostname }}"
certhub_cert_expiry_timer_unit: "certhub-cert-expiry@{{ certhub_cert_slug }}.timer"
certhub_lego_run_path_unit: "certhub-lego-run@{{ certhub_cert_slug }}.path"
Establezca certhub_cert_slug
para especificar la instancia del certificado.
Variables para cert-export-units.yml
Las variables disponibles se enumeran a continuación, junto con valores predeterminados (ver defaults/main.yml
):
certhub_cert_slug: "{{ inventory_hostname }}"
certhub_cert_export_path_unit: "certhub-cert-export@{{ certhub_cert_slug }}.path"
certhub_cert_services: []
certhub_cert_reload_config_path: "{{ certhub_config_dir_path }}/{{ certhub_cert_slug }}.services-reload.txt"
certhub_cert_reload_path_unit: "certhub-cert-reload@{{ certhub_cert_slug }}.path"
certhub_cert_destinations: []
certhub_cert_send_config_path: "{{ certhub_config_dir_path }}/{{ certhub_cert_slug }}.destinations-send.txt"
certhub_cert_send_path_unit: "certhub-cert-send@{{ certhub_cert_slug }}.path"
Establezca certhub_cert_slug
para especificar la instancia del certificado. Se puede especificar una lista de unidades de servicio de systemd que deberían recargarse cada vez que cambie la instancia del certificado utilizando certhub_cert_services
. Se puede especificar una lista de destinos a los que se enviará el certificado en certhub_cert_destinations
.
Dependencias
Ninguna.
Ejemplo de Playbook
```yaml
name: Configuración del controlador Certhub hosts: certhub-controller tasks:
name: Dependencias de Certhub presentes package: name: - certbot - git - lexicon - openssl state: present
name: Certhub presente import_role: name: znerol.certhub
name: Configuración del Servidor TLS hosts: tls-server tasks:
name: Dependencias de Certhub presentes package: name: - git - openssl state: present
name: Certhub presente import_role: name: znerol.certhub
name: Configuración de unidades de push de repositorio delegate_to: name-of-certhub-controller import_role: name: znerol.certhub tasks_from: repo-push-units.yml
name: Configuración del Certificado TLS hosts: tls-server tasks:
vars: certhub_cert_services: - nginx import_role: name: znerol.certhub tasks_from: cert-export-units.yml
name: Configuración de unidades de ejecución de Certbot delegate_to: name-of-certhub-controller import_role: name: znerol.certhub tasks_from: certbot-run-units.yml
name: CSR de Certbot instalada delegate_to: name-of-certhub-controller become: yes become_user: root copy: dest: "{{ certhub_cert_csr_path }}" owner: root group: root mode: 0644 content: | -----BEGIN CERTIFICATE REQUEST----- MIH6MIGhAgEAMBYxFDASBgNVBAMMC2V4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI KoZIzj0DAQcDQgAE1XubF1Uc4T595zSzikHAJTkXRlV5Fn5MhVUhr/18bm++5z2j 759NpRh/gbEieCT4sKZ0fUcPWBrLp5zf0CFaYqApMCcGCSqGSIb3DQEJDjEaMBgw FgYDVR0RBA8wDYILZXhhbXBsZS5jb20wCgYIKoZIzj0EAwIDSAAwRQIhANwIuwCc 45XooSB4bleXURLDGuChxcdFYYSHnnQjArizAiBYefMa83Kk1AJUIArnJ0Rk162D Fw3tPbiEVAmmvl0/5A== -----END CERTIFICATE REQUEST-----
name: Configuración de Certbot instalada delegate_to: name-of-certhub-controller become: yes become_user: root copy: dest: "{{ certhub_certbot_config_path }}" owner: root group: root mode: 0644 content: | staging=true agree-tos=true register-unsafely-without-email=true manual-public-ip-logging-ok=true preferred-challenges=dns manual=true manual-auth-hook=/usr/local/lib/certhub/certbot-hooks/hook-lexicon-auth manual-cleanup-hook=/usr/local/lib/certhub/certbot-hooks/hook-lexicon-cleanup
name: Entorno de unidad de Certbot configurado delegate_to: name-of-certhub-controller become: yes become_user: root vars: certhub_unit_prefix: certhub-certbot-run copy: dest: "{{ certhub_cert_unit_env_path }}" owner: "{{ certhub_env_owner }}" group: "{{ certhub_env_group }}" mode: "{{ certhub_env_mode }}" content: | CERTHUB_LEXICON_PROVIDER=cloudflare LEXICON_CLOUDFLARE_USERNAME="myusername@example.com" LEXICON_CLOUDFLARE_TOKEN="cloudflare-api-token"
Licencia
BSD
ansible-galaxy install znerol.certhub