Skip to content

Commit 89c2d53

Browse files
authored
Fix broken keys on some systems (NETWAYS#136)
* Fix broken keys on some systems fixes NETWAYS#135 It looks like there are still some hosts where pkcs8 keys for Logstash Beats input must not be encrypted. The strange thing about it is that it works on some systems (CentOS 7) and on some it doesn't (so far Ubuntu 20.04). I tried recreating the keys and some other ways but the Ubuntu host didn't like encrypted keys at all. So here's a workaround. Several other potential issues came up and were fixed, namely: * There's now a variable to disable encryption of the key used for the Beats input in Logstash * Logstash certificates created with `certutil` get now a suffix to their name. This helps when you have different passwords for keys in different tools. Otherwise they overwrite each other and you don't know which file has which passphrase * Rename certificate archive
1 parent b8cb20d commit 89c2d53

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Aside from `logstash.yml` we can manage Logstashs pipelines.
5151
* *logstash_beats_input*: Enable default pipeline with `beats` input (default: `true`)
5252
* *logstash_beats_input_congestion*: Optional congestion threshold for the beats input pipeline
5353
* *logstash_beats_tls*: Activate TLS for the beats input pipeline (default: none but `true` with full stack setup if not set)
54+
* *logstash_beats_tls_encryptkey*: Enable encryption of key for beats input - disabling used as a workaround on certain hosts (default: true)
5455
* *logstash_tls_key_passphrase*: Passphrase for Logstash certificates (default: `ChangeMe`)
5556
* *logstash_connector*: Create pipelines to connect git managed pipelines. (default: `true`)
5657
* *logstash_connector_pipelines*: Definition of connector pipelines. See docs/connector-pipelines.md for details

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ logstash_no_pipelines: false
2626
# source: https://github.com/widhalmt/shipper-logstash-pipeline.git
2727
logstash_elasticsearch_output: true
2828
logstash_beats_input: true
29+
logstash_beats_tls_encryptkey: true
2930
logstash_connector: true
3031

3132
# logstash security

tasks/logstash-security.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
--ca-pass {{ elastic_ca_pass }}
2626
--name {{ ansible_hostname }}
2727
--ip {{ ansible_default_ipv4.address }}
28-
--dns {{ ansible_hostname }},{{ ansible_fqdn }}
29-
--pass "{{ logstash_tls_key_passphrase }}"
30-
--out {{ elastic_ca_dir }}/{{ ansible_hostname }}.p12
28+
--dns {{ ansible_hostname }},{{ ansible_fqdn }},{{ inventory_hostname }}
29+
--pass {{ logstash_tls_key_passphrase }}
30+
--out {{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.p12
3131
delegate_to: "{{ elasticsearch_ca }}"
3232
args:
33-
creates: "{{ elastic_ca_dir }}/{{ ansible_hostname }}.p12"
33+
creates: "{{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.p12"
3434
tags:
3535
- certificates
3636

3737
- name: Fetch certificate from ca host to master
3838
fetch:
39-
src: "{{ elastic_ca_dir }}/{{ ansible_hostname }}.p12"
40-
dest: "/tmp/{{ ansible_hostname }}.p12"
39+
src: "{{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.p12"
40+
dest: "/tmp/{{ ansible_hostname }}-ls.p12"
4141
flat: yes
4242
delegate_to: "{{ elasticsearch_ca }}"
4343
tags:
@@ -55,7 +55,7 @@
5555

5656
- name: Copy the certificate to actual node
5757
copy:
58-
src: "/tmp/{{ ansible_hostname }}.p12"
58+
src: "/tmp/{{ ansible_hostname }}-ls.p12"
5959
dest: "{{ logstash_certs_dir }}/keystore.pfx"
6060
owner: root
6161
group: logstash
@@ -72,26 +72,26 @@
7272
--ca-pass {{ elastic_ca_pass }}
7373
--name {{ ansible_hostname }}
7474
--ip {{ ansible_default_ipv4.address }}
75-
--dns {{ ansible_hostname }},{{ ansible_fqdn }}
75+
--dns {{ ansible_hostname }},{{ ansible_fqdn }},{{ inventory_hostname }}
7676
--pass {{ logstash_tls_key_passphrase }}
7777
--pem
78-
--out {{ elastic_ca_dir }}/{{ ansible_hostname }}.zip
78+
--out {{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.zip
7979
delegate_to: "{{ elasticsearch_ca }}"
8080
args:
81-
creates: "{{ elastic_ca_dir }}/{{ ansible_hostname }}.zip"
81+
creates: "{{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.zip"
8282

8383
- name: Fetch certificate from ca host to master
8484
fetch:
85-
src: "{{ elastic_ca_dir }}/{{ ansible_hostname }}.zip"
86-
dest: "/tmp/{{ ansible_hostname }}.zip"
85+
src: "{{ elastic_ca_dir }}/{{ ansible_hostname }}-ls.zip"
86+
dest: "/tmp/{{ ansible_hostname }}-ls.zip"
8787
flat: yes
8888
delegate_to: "{{ elasticsearch_ca }}"
8989
tags:
9090
- certificates
9191

9292
- name: Copy the certificate to actual node
9393
unarchive:
94-
src: "/tmp/{{ ansible_hostname }}.zip"
94+
src: "/tmp/{{ ansible_hostname }}-ls.zip"
9595
dest: "{{ logstash_certs_dir }}/"
9696
owner: root
9797
group: logstash
@@ -135,6 +135,19 @@
135135
-passout pass:{{ logstash_tls_key_passphrase }}
136136
args:
137137
creates: "{{ logstash_certs_dir }}/{{ inventory_hostname }}-pkcs8.key"
138+
when: logstash_beats_tls_encryptkey | bool
139+
140+
- name: Create unencrypted Logstash compatible key
141+
command: >
142+
openssl pkcs8
143+
-in {{ logstash_certs_dir }}/{{ inventory_hostname }}.key
144+
-topk8
145+
-passin pass:{{ logstash_tls_key_passphrase }}
146+
-out {{ logstash_certs_dir }}/{{ inventory_hostname }}-pkcs8.key
147+
-nocrypt
148+
args:
149+
creates: "{{ logstash_certs_dir }}/{{ inventory_hostname }}-pkcs8.key"
150+
when: not logstash_beats_tls_encryptkey | bool
138151

139152
- name: Set permissions on Logstash key
140153
file:

templates/beats-input.conf.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ input {
88
ssl_verify_mode => force_peer
99
ssl_certificate_authorities => ["{{ logstash_certs_dir }}/ca.crt"]
1010
ssl_peer_metadata => false
11+
{% if logstash_beats_tls_encryptkey | bool %}
1112
ssl_key_passphrase => "{{ logstash_tls_key_passphrase }}"
13+
{% endif %}
1214
{% endif %}
1315

1416
}

0 commit comments

Comments
 (0)