Skip to content
Closed
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
22 changes: 11 additions & 11 deletions roles/elasticstack/tasks/certs/cert_validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# _validate_key_fact Fact name to store resolved key path
# _validate_ca_extracted_fact Fact name for whether CA was auto-extracted from chain

- name: "Check certificate file exists — {{ _validate_service }}"

Check warning on line 16 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_cert_stat)

Check warning on line 16 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_cert_stat)
ansible.builtin.stat:
path: "{{ _validate_cert_path }}"
register: _validate_cert_stat
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Fail if certificate file missing — {{ _validate_service }}"
ansible.builtin.fail:
Expand All @@ -29,16 +29,16 @@

# --- Format detection ---

- name: "Probe for PEM format — {{ _validate_service }}"

Check warning on line 32 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_pem_probe)

Check warning on line 32 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_pem_probe)
ansible.builtin.command:
cmd: openssl x509 -in {{ _validate_cert_path }} -noout
register: _validate_pem_probe
failed_when: false
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Probe for P12 format — {{ _validate_service }}"

Check warning on line 41 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_p12_probe)

Check warning on line 41 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_p12_probe)
ansible.builtin.command:
cmd: >-
openssl pkcs12 -in {{ _validate_cert_path }} -noout
Expand All @@ -47,7 +47,7 @@
failed_when: false
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"
no_log: true
when: _validate_pem_probe.rc != 0

Expand All @@ -71,16 +71,16 @@
- (_validate_key_path | default('', true)) | length == 0
- _validate_pem_probe.rc == 0
block:
- name: "Compute derived key path — {{ _validate_service }}"

Check warning on line 74 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (set_fact: _validate_derived_key)

Check warning on line 74 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (set_fact: _validate_derived_key)
ansible.builtin.set_fact:
_validate_derived_key: "{{ _validate_cert_path | regex_replace('\\.(crt|pem|cert)$', '.key') }}"

- name: "Check derived key exists — {{ _validate_service }}"

Check warning on line 78 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_derived_key_stat)

Check warning on line 78 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_derived_key_stat)
ansible.builtin.stat:
path: "{{ _validate_derived_key }}"
register: _validate_derived_key_stat
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Fail if derived key not found — {{ _validate_service }}"
ansible.builtin.fail:
Expand Down Expand Up @@ -110,13 +110,13 @@
- name: "Check for CA chain in PEM bundle — {{ _validate_service }}"
when: _validate_pem_probe.rc == 0
block:
- name: "Count PEM blocks in certificate file — {{ _validate_service }}"

Check warning on line 113 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_pem_count)

Check warning on line 113 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_pem_count)
ansible.builtin.command:
cmd: grep -c 'BEGIN CERTIFICATE' {{ _validate_cert_path }}
register: _validate_pem_count
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Set CA extracted fact — {{ _validate_service }}"
ansible.builtin.set_fact:
Expand All @@ -129,14 +129,14 @@

# --- Certificate expiry check ---

- name: "Check certificate has not expired — {{ _validate_service }}"

Check warning on line 132 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_expiry_check)

Check warning on line 132 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_beats / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_expiry_check)
ansible.builtin.command:
cmd: openssl x509 -in {{ _validate_cert_path }} -noout -checkend 0
register: _validate_expiry_check
failed_when: false
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"
when: _validate_pem_probe.rc == 0

- name: "Fail if certificate already expired — {{ _validate_service }}"
Expand All @@ -155,16 +155,16 @@
- _validate_pem_probe.rc == 0
- lookup('vars', _validate_key_fact) | length > 0
block:
- name: "Get certificate modulus — {{ _validate_service }}"

Check warning on line 158 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_cert_modulus)
ansible.builtin.shell:
cmd: set -o pipefail && openssl x509 -in {{ _validate_cert_path }} -noout -modulus 2>/dev/null | openssl md5
executable: /bin/bash
register: _validate_cert_modulus
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Get key modulus — {{ _validate_service }}"

Check warning on line 167 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_key_modulus)
ansible.builtin.shell:
cmd: >-
set -o pipefail &&
Expand All @@ -176,11 +176,11 @@
changed_when: false
failed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"
no_log: true

# If RSA modulus failed, try EC key
- name: "Get EC key fingerprint — {{ _validate_service }}"

Check warning on line 183 in roles/elasticstack/tasks/certs/cert_validate.yml

View workflow job for this annotation

GitHub Actions / lint_kibana / lint

var-naming[no-role-prefix]

Variables names from within roles should use elasticstack_ as a prefix. (register: _validate_ec_key_fp)
ansible.builtin.shell:
cmd: >-
set -o pipefail &&
Expand All @@ -192,7 +192,7 @@
changed_when: false
failed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"
no_log: true
when: _validate_key_modulus.rc != 0

Expand All @@ -203,7 +203,7 @@
register: _validate_ec_cert_fp
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"
when: _validate_key_modulus.rc != 0

- name: "Fail if RSA key does not match certificate — {{ _validate_service }}"
Expand Down Expand Up @@ -240,7 +240,7 @@
register: _validate_san_output
changed_when: false
delegate_to: "{{ omit if (_validate_remote_src | bool) else 'localhost' }}"
become: false
become: "{{ _validate_remote_src | bool }}"

- name: "Warn if SAN does not include this node — {{ _validate_service }}"
ansible.builtin.debug:
Expand Down
Loading