Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ssl provider: cloudflare-origin-ca #870

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions group_vars/all/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ntp_manage_config: true
www_root: /srv/www
ip_whitelist:
- "{{ (env == 'development') | ternary(ansible_default_ipv4.gateway, ipify_public_ip | default('')) }}"
cloudflare_origin_ca_api_key: "{{ vault_cloudflare_origin_ca_api_key }}" # Define this variable in group_vars/all/vault.yml

# Values of raw_vars will be wrapped in `{% raw %}` to avoid templating problems if values include `{%` and `{{`.
# Will recurse dicts/lists. `*` is wildcard for one or more dict keys, list indices, or strings. Example:
Expand All @@ -18,3 +19,4 @@ raw_vars:
- vault_users.*.password
- vault_users.*.salt
- vault_wordpress_sites
- vault_cloudflare_origin_ca_api_key
1 change: 1 addition & 0 deletions group_vars/all/vault.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Documentation: https://roots.io/trellis/docs/vault/
vault_mail_password: smtp_password
vault_cloudflare_origin_ca_api_key: example_api_key
37 changes: 37 additions & 0 deletions roles/wordpress-setup/tasks/cloudflare-origin-ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Add Cloudflare key
apt_key:
url: 'https://pkg.cloudflare.com/pubkey.gpg'

- name: Add Cloudflare PPA
apt_repository:
repo: 'deb http://pkg.cloudflare.com/ xenial main'
update_cache: yes

- name: Install CFCA
apt:
name: cfca
state: present
force: yes

- name: Create directoriy and set permission
file:
path: "{{ nginx_ssl_path }}/cloudflare-origin-ca"
mode: 0700
state: directory

- name: Generate Cloudflare Origin CA
shell: "cfca getcert \
-hostnames {{ site_hosts | union(multisite_subdomains_wildcards) | join(',') }} \
-key-out {{ item.key | quote }}.key \
-certificate-out {{ item.key | quote }}.pem"
args:
executable: "/bin/bash"
chdir: "{{ nginx_ssl_path }}/cloudflare-origin-ca"
creates: "{{ item.key }}.*"
environment:
CF_API_KEY: "{{ cloudflare_origin_ca_api_key }}"
no_log: true
with_dict: "{{ wordpress_sites }}"
when: ssl_enabled and item.value.ssl.provider | default('manual') == 'cloudflare-origin-ca'
notify: reload nginx
3 changes: 3 additions & 0 deletions roles/wordpress-setup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
tags: wordpress-setup-database
- include: self-signed-certificate.yml
tags: wordpress-setup-self-signed-certificate
- include: cloudflare-origin-ca.yml
when: '"cloudflare-origin-ca" in wordpress_sites|json_query("*.ssl.provider")'
tags: wordpress-setup-cloudflare-origin-ca

- name: Create web root
file:
Expand Down
4 changes: 4 additions & 0 deletions roles/wordpress-setup/templates/wordpress-site.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ server {
ssl_certificate {{ nginx_path }}/ssl/letsencrypt/{{ item.key }}-{{ letsencrypt_cert_ids[item.key] }}-bundled.cert;
ssl_certificate_key {{ nginx_path }}/ssl/letsencrypt/{{ item.key }}.key;

{% elif item.value.ssl.provider | default('manual') == 'cloudflare-origin-ca' -%}
ssl_certificate {{ nginx_path }}/ssl/cloudflare-origin-ca/{{ item.key }}.pem;
ssl_certificate_key {{ nginx_path }}/ssl/cloudflare-origin-ca/{{ item.key }}.key;

{% elif item.value.ssl.provider | default('manual') == 'self-signed' -%}
ssl_certificate {{ nginx_path }}/ssl/{{ item.key }}.cert;
ssl_trusted_certificate {{ nginx_path }}/ssl/{{ item.key }}.cert;
Expand Down