znerol.certhub

Ansible Role: Certhub

Instaluje certhub i git-gau na serwerach linuxowych zarządzanych przez systemd.

Wymagania

  • Git
  • OpenSSL
  • Rsync, jeśli docelowa maszyna działa jako serwer SSL/TLS.
  • certbot, dehydrated lub lego, gdy docelowa maszyna działa jako kontroler.

Zmienne roli

Ta rola zawiera wiele plików task. Główny plik zadań importuje tylko niektóre z nich:

  1. certhub-system-setup.yml: Tworzy użytkownika i grupę certhub, katalog konfiguracyjny oraz przygotowuje katalog domowy.
  2. certhub-software-setup.yml: Pobiera i instaluje certhub i git-gau.
  3. certhub-git-setup.yml: Konfiguruje user.name i user.email w git.
  4. certhub-repo-setup.yml: Inicjalizuje lokalne repozytorium git certs.

Następujące pliki zadań zawierają dodatkowe kroki konfiguracyjne:

  1. certbot-noroot-config.yml: Ułatwia uruchamianie certbot jako mniej uprzywilejowany użytkownik certhub, umieszczając odpowiedni plik cli.ini.

Następujące pliki zadań zawierają kroki dotyczące pozyskiwania i wdrażania certyfikatów.

  1. Środowisko dla jednostek systemd: Zmienne zawierające ścieżki do plików środowiskowych respektowanych przez wszystkie jednostki systemd certhub.
  2. repo-push-units.yml: Ustawia jednostki systemd odpowiedzialne za przesyłanie repozytoriów certyfikatów do serwerów SSL/TLS, gdy tylko nastąpi zmiana.
  3. certbot-run-units.yml: Ustawia jednostki systemd odpowiedzialne za wydawanie/odnawianie certyfikatu oraz monitorowanie jego ważności (kontroler).
  4. lego-run-units.yml: Ustawia jednostki systemd odpowiedzialne za wydawanie/odnawianie certyfikatu oraz monitorowanie jego ważności (kontroler).
  5. cert-export-units.yml: Ustawia jednostki systemd odpowiedzialne za wdrażanie certyfikatu na serwerze SSL/TLS, przeładowanie usług oraz/lub wysłanie certyfikatów do określonych miejsc przeznaczenia.

Zmienne dla certhub-system-setup.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Zmienne dla certhub-software-setup.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Zmienne certhub_certhub_releases i certhub_gitgau_releases zawierają adresy URL i sumy kontrolne wszystkich publicznych wydań. Ustaw certhub_certhub_version i certhub_gitgau_version, aby określić konkretną wersję.

Zmienne dla certhub-git-setup.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz defaults/main.yml):

certhub_git_user_name: "{{ certhub_user_name }}"
certhub_git_user_email: "{{ certhub_user_name }}@{{ ansible_fqdn }}"

Zmienne dla certhub-repo-setup.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz defaults/main.yml):

certhub_repo_init_path: "{{ certhub_repo_path }}"
certhub_repo_init_message: Init

Konfiguracja repozytorium git jest pomijana, gdy certhub_repo_init_path jest pustym ciągiem.

Zmienne dla certbot-noroot-config.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Zmienna certhub_certbot_cli_ini_content może być użyta do dostarczenia dodatkowej konfiguracji certbota. Na przykład staging=true, aby wybrać środowisko testowe podczas ewaluacji.

Środowisko dla jednostek systemd

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz defaults/main.yml):

# Opcjonalny plik środowiskowy wspólny dla wszystkich instancji i usług certhub.
certhub_env_path: "{{ certhub_config_dir_path }}/env"
# Opcjonalny plik środowiskowy dla każdej instancji, wspólny dla wszystkich usług certhub.
certhub_cert_env_path: "{{ certhub_config_dir_path}}/{{ certhub_cert_slug }}.env"
# Opcjonalny plik środowiskowy dla każdej usługi, wspólny dla wszystkich instancji usług certhub.
certhub_unit_env_path: "{{ certhub_config_dir_path}}/{{ certhub_unit_prefix }}.env"
# Opcjonalny plik środowiskowy dla każdej instancji i każdej usługi.
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

Użyj tych zmiennych w niestandardowych zadaniach copy lub template, aby uzupełnić pliki env konfiguracją dla usług certhub. Uwaga: dla zmiennej certhub_unit_prefix nie ma wartości domyślnej. Ta zmienna musi być ustawiona na jeden z prefiksów jednostek usługi certhub. Następujące wartości są obecnie ważne:

  • certhub-cert-expiry
  • certhub-cert-export
  • certhub-cert-reload
  • certhub-cert-send
  • certhub-certbot-run
  • certhub-dehydrated-run
  • certhub-lego-run

Zmienne dla repo-push-units.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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) }}"

Określ certhub_repo_push_remote, aby całkowicie nadpisać zdalne repozytorium.

Zmienne dla certbot-run-units.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Ustaw certhub_cert_slug, aby określić instancję certyfikatu.

Zmienne dla lego-run-units.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Ustaw certhub_cert_slug, aby określić instancję certyfikatu.

Zmienne dla cert-export-units.yml

Dostępne zmienne są wymienione poniżej, wraz z wartościami domyślnymi (patrz 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"

Ustaw certhub_cert_slug, aby określić instancję certyfikatu. Lista jednostek usług systemd, które powinny być przeładowane, gdy zmienia się instancja certyfikatu, może być określona za pomocą certhub_cert_services. Lista miejsc przeznaczenia, do których certyfikat powinien być wysyłany, można określić w certhub_cert_destinations.

Zależności

Brak.

Przykład playbooka

- name: Konfiguracja kontrolera Certhub
  hosts: certhub-controller
  tasks:
    - name: Zależności Certhub obecne
      package:
        name:
          - certbot
          - git
          - lexicon
          - openssl
        state: present

    - name: Certhub obecny
      import_role:
        name: znerol.certhub

- name: Konfiguracja serwera TLS
  hosts: tls-server
  tasks:
    - name: Zależności Certhub obecne
      package:
        name:
          - git
          - openssl
        state: present

    - name: Certhub obecny
      import_role:
        name: znerol.certhub

    - name: Ustawienie jednostek Push repo
      delegate_to: nazwa-kontrolera-certhub
      import_role:
        name: znerol.certhub
        tasks_from: repo-push-units.yml

- name: Konfiguracja certyfikatu TLS
  hosts: tls-server
  tasks:
    - vars:
        certhub_cert_services:
          - nginx
      import_role:
        name: znerol.certhub
        tasks_from: cert-export-units.yml

    - name: Ustawienie jednostek uruchamiania certbota
      delegate_to: nazwa-kontrolera-certhub
      import_role:
        name: znerol.certhub
        tasks_from: certbot-run-units.yml

    - name: CSR certbota zainstalowany
      delegate_to: nazwa-kontrolera-certhub
      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: Konfiguracja certbota zainstalowana
      delegate_to: nazwa-kontrolera-certhub
      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: Środowisko jednostki certbota skonfigurowane
      delegate_to: nazwa-kontrolera-certhub
      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="[email protected]"
          LEXICON_CLOUDFLARE_TOKEN="cloudflare-api-token"

Licencja

BSD

O projekcie

Certhub - centralized certificate management the unix way

Zainstaluj
ansible-galaxy install znerol.certhub
Licencja
Unknown
Pobrania
276
Właściciel