znerol.certhub
Ansibleロール: Certhub
Linuxサーバーにcerthubとgit-gau
をインストールします。サーバーはsystemd
で制御されます。
要件
- Git
- OpenSSL
- 対象マシンがSSL/TLSサーバーとして動作する場合はRsync
- 対象マシンがコントローラーとして動作する場合は
certbot
、dehydrated
またはlego
のいずれか
ロール変数
このロールには複数のtask
ファイルが含まれています。main
タスクファイルはそのうちのいくつかのみをインポートします。
- certhub-system-setup.yml:
certhub
ユーザーとグループ、構成ディレクトリを作成し、ホームディレクトリを準備します。 - certhub-software-setup.yml:
certhub
とgit-gau
を取得してインストールします。 - certhub-git-setup.yml: gitの
user.name
とuser.email
を設定します。 - certhub-repo-setup.yml: ローカル
certs
Gitリポジトリを初期化します。
次のタスクファイルは追加の設定手順を含んでいます:
- certbot-noroot-config.yml:
certhub
ユーザーとしてのcertbot
の実行を簡略化します。適切なcli.ini
ファイルを配置します。
次のタスクファイルは、証明書の取得と展開の設定に使用される手順を含んでいます。
- systemdユニットのための環境: すべてのcerthub systemdユニットで尊重される環境ファイルへのパスを含む変数。
- repo-push-units.yml: 証明書リポジトリをSSL/TLSサーバーにプッシュするための
systemd
ユニットを設定します。 - certbot-run-units.yml: 証明書の発行/更新を行い、期限切れを監視する
systemd
ユニットを設定します(コントローラー)。 - lego-run-units.yml: 証明書の発行/更新を行い、期限切れを監視する
systemd
ユニットを設定します(コントローラー)。 - cert-export-units.yml: SSL/TLSサーバーに証明書を展開し、影響を受けるサービスを再読み込みまたは指定された宛先に証明書を送信するための
systemd
ユニットを設定します。
certhub-system-setup.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
certhub-software-setup.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
certhub_certhub_releases
とcerthub_gitgau_releases
変数には、すべての公開リリースのURLとチェックサムが含まれています。特定のバージョンを固定するにはcerthub_certhub_version
とcerthub_gitgau_version
を設定します。
certhub-git-setup.ymlの変数
利用可能な変数は以下に示されています(デフォルト値はdefaults/main.yml
に記載されています):
certhub_git_user_name: "{{ certhub_user_name }}"
certhub_git_user_email: "{{ certhub_user_name }}@{{ ansible_fqdn }}"
certhub-repo-setup.ymlの変数
利用可能な変数は以下に示されています(デフォルト値はdefaults/main.yml
に記載されています):
certhub_repo_init_path: "{{ certhub_repo_path }}"
certhub_repo_init_message: Init
certhub_repo_init_path
が空の文字列である場合、Gitリポジトリの設定はスキップされます。
certbot-noroot-config.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
certhub_certbot_cli_ini_content
変数は、追加のcertbot構成を提供するために使用できます。例えば、評価時にステージング環境を選択するためにstaging=true
を指定できます。
systemdユニットのための環境
利用可能な変数は以下に示されています(デフォルト値はdefaults/main.yml
に記載されています):
# すべてのインスタンスとcerthubサービスによって共有される任意の環境ファイル
certhub_env_path: "{{ certhub_config_dir_path }}/env"
# すべてのcerthubサービスによって共有されるインスタンスごとの任意の環境ファイル
certhub_cert_env_path: "{{ certhub_config_dir_path}}/{{ certhub_cert_slug }}.env"
# すべてのcerthubサービスインスタンスのためのサービスごとの任意の環境ファイル
certhub_unit_env_path: "{{ certhub_config_dir_path}}/{{ certhub_unit_prefix }}.env"
# インスタンスおよびサービスごとの任意の環境ファイル
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
この変数をカスタムのcopy
やtemplate
タスクで使用して、certhubサービスの設定用にenv
ファイルを埋め込んでください。注意: certhub_unit_prefix
にはデフォルト値がありません。この変数は、certhubサービスユニットのいずれかのプレフィックスに設定する必要があります。現在、有効な値は次のとおりです:
- certhub-cert-expiry
- certhub-cert-export
- certhub-cert-reload
- certhub-cert-send
- certhub-certbot-run
- certhub-dehydrated-run
- certhub-lego-run
repo-push-units.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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) }}"
リモートを完全にオーバーライドするためにcerthub_repo_push_remote
を指定します。
certbot-run-units.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
証明書インスタンスを指定するためにcerthub_cert_slug
を設定します。
lego-run-units.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
証明書インスタンスを指定するためにcerthub_cert_slug
を設定します。
cert-export-units.ymlの変数
利用可能な変数は以下に示されています(デフォルト値は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"
証明書インスタンスを指定するためにcerthub_cert_slug
を設定します。証明書インスタンスが変更されるたびに再読み込みすべきsystemdサービスユニットのリストはcerthub_cert_services
を使用して指定できます。証明書を送信すべき宛先のリストはcerthub_cert_destinations
で指定できます。
依存関係
なし。
例のプレイブック
- name: Certhubコントローラーのセットアップ
hosts: certhub-controller
tasks:
- name: Certhubの依存関係が揃っている
package:
name:
- certbot
- git
- lexicon
- openssl
state: present
- name: Certhubが存在
import_role:
name: znerol.certhub
- name: TLSサーバーのセットアップ
hosts: tls-server
tasks:
- name: Certhubの依存関係が揃っている
package:
name:
- git
- openssl
state: present
- name: Certhubが存在
import_role:
name: znerol.certhub
- name: リポジトリプッシュユニットのセットアップ
delegate_to: name-of-certhub-controller
import_role:
name: znerol.certhub
tasks_from: repo-push-units.yml
- name: TLS証明書の設定
hosts: tls-server
tasks:
- vars:
certhub_cert_services:
- nginx
import_role:
name: znerol.certhub
tasks_from: cert-export-units.yml
- name: Certbot実行ユニットのセットアップ
delegate_to: name-of-certhub-controller
import_role:
name: znerol.certhub
tasks_from: certbot-run-units.yml
- name: Certbot CSRのインストール
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: Certbot設定のインストール
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: Certbotユニットの環境設定
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="[email protected]"
LEXICON_CLOUDFLARE_TOKEN="cloudflare-api-token"
ライセンス
BSD