mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
openssl_pkcs12: Add idempotency checks (#54633)
* Added idempotency logic to openssl_pkcs12 Also decoupled the 'parse' and 'generate' function from the file write as they are now used in different places that do not need the file to be written to disk. * Added idempotency tests for openssl_pkcs12 Also adds a new test for pkcs12 files with multiple certificates * Regenerate if parsed file is invalid * pkcs12_other_certificates check was wrong * Updated ca_certificates to other_certificates ca_certificates is left as an alias to other_certificates; friendlyname depends on private key, so it will be ignored while checking for idempotency if the pkey is not set; idempotency check only checks for correct certs in the stack * use different keys for different certs * Added other_certificates in module docs * Added changelog and porting guide * removed unrelated porting guide entry * renamed ca_cert* occurrence with other_cert
This commit is contained in:
committed by
John R Barker
parent
0b5b353e37
commit
0303ea2bfa
@@ -1,21 +1,48 @@
|
||||
---
|
||||
- block:
|
||||
- name: 'Generate privatekey with'
|
||||
- name: 'Generate privatekey'
|
||||
openssl_privatekey:
|
||||
path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
|
||||
- name: 'Generate CSR with'
|
||||
- name: 'Generate privatekey2'
|
||||
openssl_privatekey:
|
||||
path: "{{ output_dir }}/ansible_pkey2.pem"
|
||||
|
||||
- name: 'Generate privatekey3'
|
||||
openssl_privatekey:
|
||||
path: "{{ output_dir }}/ansible_pkey3.pem"
|
||||
|
||||
- name: 'Generate CSR'
|
||||
openssl_csr:
|
||||
path: "{{ output_dir }}/ansible.csr"
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
commonName: 'www.ansible.com'
|
||||
|
||||
- name: 'Generate CSR 2'
|
||||
openssl_csr:
|
||||
path: "{{ output_dir }}/ansible2.csr"
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey2.pem"
|
||||
commonName: 'www2.ansible.com'
|
||||
|
||||
- name: 'Generate CSR 3'
|
||||
openssl_csr:
|
||||
path: "{{ output_dir }}/ansible3.csr"
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey3.pem"
|
||||
commonName: 'www3.ansible.com'
|
||||
|
||||
- name: 'Generate certificate'
|
||||
openssl_certificate:
|
||||
path: "{{ output_dir }}/ansible.crt"
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
csr_path: "{{ output_dir }}/ansible.csr"
|
||||
path: "{{ output_dir }}/{{ item.name }}.crt"
|
||||
privatekey_path: "{{ output_dir }}/{{ item.pkey }}"
|
||||
csr_path: "{{ output_dir }}/{{ item.name }}.csr"
|
||||
provider: selfsigned
|
||||
loop:
|
||||
- name: ansible
|
||||
pkey: ansible_pkey.pem
|
||||
- name: ansible2
|
||||
pkey: ansible_pkey2.pem
|
||||
- name: ansible3
|
||||
pkey: ansible_pkey3.pem
|
||||
|
||||
- name: 'Generate PKCS#12 file'
|
||||
openssl_pkcs12:
|
||||
@@ -26,6 +53,15 @@
|
||||
state: present
|
||||
register: p12_standard
|
||||
|
||||
- name: 'Generate PKCS#12 file again, idempotency'
|
||||
openssl_pkcs12:
|
||||
path: "{{ output_dir }}/ansible.p12"
|
||||
friendly_name: 'abracadabra'
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
certificate_path: "{{ output_dir }}/ansible.crt"
|
||||
state: present
|
||||
register: p12_standard_idempotency
|
||||
|
||||
- name: 'Generate PKCS#12 file (force)'
|
||||
openssl_pkcs12:
|
||||
path: "{{ output_dir }}/ansible.p12"
|
||||
@@ -54,6 +90,37 @@
|
||||
action: 'parse'
|
||||
state: 'present'
|
||||
|
||||
- name: 'Generate PKCS#12 file with multiple certs'
|
||||
openssl_pkcs12:
|
||||
path: "{{ output_dir }}/ansible_multi_certs.p12"
|
||||
friendly_name: 'abracadabra'
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
certificate_path: "{{ output_dir }}/ansible.crt"
|
||||
ca_certificates:
|
||||
- "{{ output_dir }}/ansible2.crt"
|
||||
- "{{ output_dir }}/ansible3.crt"
|
||||
state: present
|
||||
register: p12_multiple_certs
|
||||
|
||||
- name: 'Generate PKCS#12 file with multiple certs, again (idempotency)'
|
||||
openssl_pkcs12:
|
||||
path: "{{ output_dir }}/ansible_multi_certs.p12"
|
||||
friendly_name: 'abracadabra'
|
||||
privatekey_path: "{{ output_dir }}/ansible_pkey.pem"
|
||||
certificate_path: "{{ output_dir }}/ansible.crt"
|
||||
ca_certificates:
|
||||
- "{{ output_dir }}/ansible2.crt"
|
||||
- "{{ output_dir }}/ansible3.crt"
|
||||
state: present
|
||||
register: p12_multiple_certs_idempotency
|
||||
|
||||
- name: 'Dump PKCS#12 with multiple certs'
|
||||
openssl_pkcs12:
|
||||
src: "{{ output_dir }}/ansible_multi_certs.p12"
|
||||
path: "{{ output_dir }}/ansible_parse_multi_certs.pem"
|
||||
action: 'parse'
|
||||
state: 'present'
|
||||
|
||||
- name: Generate privatekey with password
|
||||
openssl_privatekey:
|
||||
path: '{{ output_dir }}/privatekeypw.pem'
|
||||
@@ -163,10 +230,11 @@
|
||||
- name: 'Delete PKCS#12 file'
|
||||
openssl_pkcs12:
|
||||
state: absent
|
||||
path: '{{ output_dir }}/ansible.p12'
|
||||
path: '{{ output_dir }}/{{ item }}.p12'
|
||||
loop:
|
||||
- 'ansible'
|
||||
- 'ansible_no_pkey'
|
||||
- 'ansible_multi_certs'
|
||||
- 'ansible_pw1'
|
||||
- 'ansible_pw2'
|
||||
- 'ansible_pw3'
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
---
|
||||
- name: 'Install pexpect'
|
||||
pip:
|
||||
name: 'pexpect'
|
||||
state: 'present'
|
||||
|
||||
- name: 'Validate PKCS#12'
|
||||
command: "openssl pkcs12 -info -in {{ output_dir }}/ansible.p12 -nodes -passin pass:''"
|
||||
register: p12
|
||||
@@ -12,6 +6,10 @@
|
||||
command: "openssl pkcs12 -info -in {{ output_dir }}/ansible_no_pkey.p12 -nodes -passin pass:''"
|
||||
register: p12_validate_no_pkey
|
||||
|
||||
- name: 'Validate PKCS#12 with multiple certs'
|
||||
shell: "openssl pkcs12 -info -in {{ output_dir }}/ansible_multi_certs.p12 -nodes -passin pass:'' | grep subject"
|
||||
register: p12_validate_multi_certs
|
||||
|
||||
- name: 'Validate PKCS#12 (assert)'
|
||||
assert:
|
||||
that:
|
||||
@@ -21,6 +19,11 @@
|
||||
- p12_validate_no_pkey.stdout_lines[-1] == '-----END CERTIFICATE-----'
|
||||
- p12_force.changed
|
||||
- p12_force_and_mode.mode == '0644' and p12_force_and_mode.changed
|
||||
- not p12_standard_idempotency.changed
|
||||
- not p12_multiple_certs_idempotency.changed
|
||||
- "'www.' in p12_validate_multi_certs.stdout"
|
||||
- "'www2.' in p12_validate_multi_certs.stdout"
|
||||
- "'www3.' in p12_validate_multi_certs.stdout"
|
||||
|
||||
- name: Check passphrase on private key
|
||||
assert:
|
||||
|
||||
Reference in New Issue
Block a user