Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
minor_changes:
- Replace the ``openssl x509`` command invocation with the ``community.crypto.x509_certificate_convert`` module when converting the VMCA CA certificate from DER to PEM in the ``mtv_provider`` role, and read the converted certificate from the resulting file instead of parsing command output.
bugfixes:
- Remove temporary VMCA certificate files (DER and PEM) after validation in the ``mtv_provider`` role so they no longer linger on disk when validation fails.
2 changes: 1 addition & 1 deletion roles/mtv_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Description: Ensure host OpenShift provider and source provider CRs exist on tar
| validate ¦ Retrieve leaf certificate from source | `community.crypto.get_certificate` | False |
| validate ¦ Fetch CA certificate from VMCA endpoint | `block` | True |
| validate ¦ Download VMCA CA certificate (DER format) | `ansible.builtin.uri` | False |
| validate ¦ Convert VMCA CA certificate from DER to PEM | `ansible.builtin.command` | False |
| validate ¦ Convert VMCA CA certificate from DER to PEM | `community.crypto.x509_certificate_convert` | False |
| validate ¦ Store VMCA root CA certificate | `ansible.builtin.set_fact` | False |
| validate ¦ Store leaf certificate (non-VMware or VMCA fallback) | `ansible.builtin.set_fact` | True |
| validate ¦ Resolve effective certificate | `ansible.builtin.set_fact` | False |
Expand Down
24 changes: 16 additions & 8 deletions roles/mtv_provider/tasks/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
when: mtv_provider_source_type == 'vmware'
vars:
_mtv_provider_vmca_der_path: /tmp/.mtv_provider_vmca_ca.der
_mtv_provider_vmca_pem_path: /tmp/.mtv_provider_vmca_ca.pem
block:
- name: validate | Download VMCA CA certificate (DER format)
ansible.builtin.uri:
Expand All @@ -149,25 +150,32 @@
register: _mtv_provider_vmca_fetch

- name: validate | Convert VMCA CA certificate from DER to PEM
ansible.builtin.command:
cmd: >-
openssl x509 -inform DER
-in {{ _mtv_provider_vmca_der_path }}
-outform PEM
register: _mtv_provider_vmca_pem
changed_when: false
community.crypto.x509_certificate_convert:
src_path: "{{ _mtv_provider_vmca_der_path }}"
dest_path: "{{ _mtv_provider_vmca_pem_path }}"
format: pem

- name: validate | Store VMCA root CA certificate
ansible.builtin.set_fact:
_mtv_provider_source_certificate: >-
{{ _mtv_provider_vmca_pem.stdout ~ '\n' }}
{{ lookup('ansible.builtin.file', _mtv_provider_vmca_pem_path) }}
rescue:
- name: validate | VMCA endpoint unavailable, falling back to leaf cert
ansible.builtin.debug:
msg: >-
VMCA CA endpoint was not available on
'{{ mtv_provider_source_host }}'. Falling back to the
leaf certificate.
always:
- name: validate | Remove temporary certificate files
ansible.builtin.file:
path: "{{ __mtv_provider_tmp_cert_path }}"
state: absent
loop_control:
loop_var: __mtv_provider_tmp_cert_path
loop:
- "{{ _mtv_provider_vmca_der_path }}"
- "{{ _mtv_provider_vmca_pem_path }}"

- name: validate | Store leaf certificate (non-VMware or VMCA fallback)
ansible.builtin.set_fact:
Expand Down
Loading