-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from GEANT/dv_use_community_crypto
Replace shell commands with native ansible modules
- Loading branch information
Showing
11 changed files
with
504 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
--- | ||
- name: Check status of services that can use certificates | ||
command: service "{{ item }}" status | ||
with_items: "{{ tls_cert_services }}" | ||
failed_when: false | ||
changed_when: false | ||
register: svcs | ||
check_mode: no | ||
listen: restart_services | ||
|
||
- name: Reload any running services | ||
- name: Reload services | ||
service: | ||
name: "{{ item.item }}" | ||
name: "{{ item }}" | ||
state: reloaded | ||
with_items: "{{ svcs.results }}" | ||
when: item.rc == 0 | ||
ignore_errors: "{{ ansible_check_mode }}" | ||
listen: restart_services | ||
|
||
loop: "{{ tls_cert_reload_services }}" | ||
listen: reload_services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,69 @@ | ||
--- | ||
- name: Load disto specific vars | ||
include_vars: "{{ item }}" | ||
with_first_found: | ||
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" | ||
- "{{ ansible_os_family }}.yml" | ||
tags: [always] | ||
|
||
- import_tasks: packages.yml | ||
tags: [crt] | ||
- name: Ensure neccessary packages are available | ||
apt: | ||
name: | ||
- ssl-cert | ||
|
||
- import_tasks: verify_pair.yml | ||
tags: [crt,verify] | ||
delegate_to: localhost | ||
become: false | ||
|
||
# Find CA certificate, based on the authority key identifier | ||
- set_fact: | ||
# This list of supported CAs is in vars/main.yml. | ||
tls_cert_ca: "{{ ca_certs|json_query('[?key_id==`' ~ _crt.authority_key_identifier ~ '`].cert|[0]') }}" | ||
tls_cert_ca_file: "{{ tls_cert_crt_dest_dir ~ '/' ~ ( _crt.issuer.commonName | regex_replace(' ', '_')) }}.crt" | ||
|
||
- name: Ensure PEM encoded CA chain is available as {{ tls_cert_ca_name }} | ||
copy: | ||
content: "{{ tls_cert_ca }}" | ||
dest: "{{ tls_cert_ca_file }}" | ||
mode: 0644 | ||
owner: root | ||
group: root | ||
|
||
- name: "Ensure CA chain file is symlinked to {{ tls_cert_ca_file }}" | ||
file: | ||
src: "{{ tls_cert_ca_file }}" | ||
dest: "{{ tls_cert_crt_dest_dir }}/{{ tls_cert_ca_alias }}" | ||
state: link | ||
notify: reload_services | ||
|
||
- name: Ensure PEM encoded private key is available | ||
copy: | ||
content: "{{ tls_cert_key }}" | ||
dest: "{{ tls_cert_key_dest_dir }}/{{ tls_cert_key_dest_name }}" | ||
owner: "{{ tls_cert_key_owner }}" | ||
group: "{{ tls_cert_key_group }}" | ||
mode: "{{ tls_cert_key_mode }}" | ||
notify: reload_services | ||
|
||
# See https://www.digicert.com/ssl-support/pem-ssl-creation.htm#4in1 | ||
# TODO: add the root the bottom | ||
- name: Ensure PEM encoded all-in-one file (key/crt/ca) is available | ||
copy: | ||
content: "{{ tls_cert_key }}{{ tls_cert_crt }}{{ tls_cert_ca }}" | ||
dest: "{{ tls_cert_key_dest_dir }}/{{ tls_cert_allinone_dest_name }}" | ||
owner: "{{ tls_cert_key_owner }}" | ||
group: "{{ tls_cert_key_group }}" | ||
mode: "{{ tls_cert_key_mode }}" | ||
notify: reload_services | ||
|
||
- name: Ensure PEM encoded certificate is available | ||
copy: | ||
content: "{{ tls_cert_crt }}" | ||
dest: "{{ tls_cert_crt_dest_dir }}/{{ tls_cert_crt_dest_name }}" | ||
owner: "{{ tls_cert_crt_owner }}" | ||
group: "{{ tls_cert_crt_group }}" | ||
mode: "{{ tls_cert_crt_mode }}" | ||
notify: reload_services | ||
|
||
- name: Ensure PEM encoded certficate + CA is available | ||
copy: | ||
content: "{{ tls_cert_crt }}\n{{ tls_cert_ca }}" | ||
dest: "{{ tls_cert_crt_dest_dir }}/{{ tls_cert_full_dest_name }}" | ||
owner: "{{ tls_cert_crt_owner }}" | ||
group: "{{ tls_cert_crt_group }}" | ||
mode: "{{ tls_cert_crt_mode }}" | ||
notify: reload_services | ||
|
||
- import_tasks: materials.yml | ||
# Only when key matches cert | ||
when: pubkey_crt.stdout == pubkey_key.stdout | ||
tags: [crt,ca,chain,key,cert] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
--- | ||
- name: Establish public key from certificate | ||
become: false | ||
shell: echo "{{ tls_cert_crt }}" | openssl x509 -pubkey -noout | ||
register: pubkey_crt | ||
changed_when: false | ||
check_mode: false | ||
- name: Fetch certificate info | ||
community.crypto.x509_certificate_info: | ||
content: "{{ tls_cert_crt }}" | ||
register: _crt | ||
|
||
- name: Establish public key from private key | ||
become: false | ||
shell: echo "{{ tls_cert_key }}" | openssl pkey -pubout -outform PEM | ||
register: pubkey_key | ||
changed_when: false | ||
check_mode: false | ||
no_log: true | ||
- name: Fetch private key info | ||
community.crypto.openssl_privatekey_info: | ||
content: "{{ tls_cert_key }}" | ||
register: _key | ||
|
||
- debug: | ||
msg: "Private key and certificate do NOT belong together, there is no use in continuing as it will break your applications" | ||
failed_when: pubkey_crt.stdout != pubkey_key.stdout | ||
when: pubkey_crt.stdout != pubkey_key.stdout | ||
- name: Safety check | ||
assert: | ||
that: _crt.public_key == _key.public_key | ||
fail_msg: "Private key and certificate do NOT belong together, there is no use in continuing as it will break your applications" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.