Skip to content

Commit a6bd139

Browse files
authored
Merge pull request #12 from NETWAYS/fix-logstashwriter-10
Use version dependent API paths
2 parents b976e56 + 1ee5daf commit a6bd139

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

docs/role-logstash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ Aside from `logstash.yml` we can manage Logstashs pipelines.
5959
* *logstash_tls_key_passphrase*: Passphrase for Logstash certificates (default: `ChangeMe`)
6060
* *logstash_elasticsearch*: Address of Elasticsearch instance for default output (default: list of Elasticsearch nodes from `elasticsearch` role or `localhost` when used standalone)
6161
* *logstash_security*: Enable X-Security (No default set, but will be activated when in full stack mode)
62+
* *logstash_user*: Name of the user to connect to Elasticsearch (Default: `logstash_writer`)
63+
* *logstash_password*: Password of Elasticsearch user (Default: `password`)
64+
* *logstash_user_indices*: Indices the user has access to (Default: `'"ecs-logstash*", "logstash*", "logs*"'`)
65+
* *logstash_reset_writer_role*: Reset user and role with every run: (Default: `true`)
66+
67+
68+
6269
* *logstash_legacy_monitoring*: Enables legacy monitoring - ignored when `elastic_stack_full_stack` is not set. (default: `true`)
6370

6471
The following variables configure Log4j for Logstash. All default to `true` as this is the default after the installation.

roles/logstash/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ logstash_beats_tls_encryptkey: true
4040
# logstash security
4141
logstash_user: logstash_writer
4242
logstash_password: password
43+
logstash_user_indices: '"ecs-logstash*", "logstash*", "logs*"'
44+
logstash_reset_writer_role: true
4345

4446
logstash_tls_key_passphrase: ChangeMe
4547
logstash_certs_dir: /etc/logstash/certs

roles/logstash/tasks/logstash-security.yml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,33 @@
220220
register: logstash_writer_role_present
221221
run_once: true
222222

223-
- name: Put logstash_writer role into Elasticsearch
223+
# we doubled the task and didn't use a more sophisticated way to just change
224+
# the URI because we expect this task to be removed when ES 7 is out of
225+
# support
226+
227+
- name: Put logstash_writer role into Elasticsearch < 8
224228
command: >
225229
curl -T /root/logstash_writer_role --header 'Content-Type: application/json'
226230
--cacert {{ elastic_ca_dir }}/ca.crt
227231
-u elastic:{{ elastic_password_logstash.stdout }}
228232
https://{{ elasticsearch_ca }}:9200/_xpack/security/role/logstash_writer
229233
delegate_to: "{{ elasticsearch_ca }}"
230234
run_once: true
231-
when: logstash_writer_role_present.rc > 0
235+
when:
236+
- logstash_writer_role_present.rc > 0 or logstash_reset_writer_role | bool
237+
- elastic_release | int < 8
238+
239+
- name: Put logstash_writer role into Elasticsearch > 7
240+
command: >
241+
curl -T /root/logstash_writer_role --header 'Content-Type: application/json'
242+
--cacert {{ elastic_ca_dir }}/ca.crt
243+
-u elastic:{{ elastic_password_logstash.stdout }}
244+
https://{{ elasticsearch_ca }}:9200/_security/role/logstash_writer
245+
delegate_to: "{{ elasticsearch_ca }}"
246+
run_once: true
247+
when:
248+
- logstash_writer_role_present.rc > 0 or logstash_reset_writer_role | bool
249+
- elastic_release | int > 7
232250

233251
- name: Check for logstash_writer user
234252
shell: >
@@ -242,12 +260,30 @@
242260
register: logstash_writer_user_present
243261
run_once: true
244262

245-
- name: Put logstash_writer user into Elasticsearch
263+
# we doubled the task and didn't use a more sophisticated way to just change
264+
# the URI because we expect this task to be removed when ES 7 is out of
265+
# support
266+
267+
- name: Put logstash_writer user into Elasticsearch < 8
246268
command: >
247269
curl -T /root/logstash_writer_user --header 'Content-Type: application/json'
248270
--cacert {{ elastic_ca_dir }}/ca.crt
249271
-u elastic:{{ elastic_password_logstash.stdout }}
250272
https://{{ elasticsearch_ca }}:9200/_xpack/security/user/{{ logstash_user }}
251273
delegate_to: "{{ elasticsearch_ca }}"
252274
run_once: true
253-
when: logstash_writer_user_present.rc > 0
275+
when:
276+
- logstash_writer_user_present.rc > 0
277+
- elastic_release | int < 8
278+
279+
- name: Put logstash_writer user into Elasticsearch > 7
280+
command: >
281+
curl -T /root/logstash_writer_user --header 'Content-Type: application/json'
282+
--cacert {{ elastic_ca_dir }}/ca.crt
283+
-u elastic:{{ elastic_password_logstash.stdout }}
284+
https://{{ elasticsearch_ca }}:9200/_security/user/{{ logstash_user }}
285+
delegate_to: "{{ elasticsearch_ca }}"
286+
run_once: true
287+
when:
288+
- logstash_writer_user_present.rc > 0
289+
- elastic_release | int > 7

roles/logstash/templates/logstash_writer_role.j2

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"cluster": ["manage_index_templates", "monitor", "manage_ilm"],
33
"indices": [
44
{
5-
{% if logstash_global_ecs is defined and logstash_global_ecs != "disabled" %}
6-
"names": [ "ecs-logstash*", "logstash*" ],
7-
{% else %}
8-
"names": [ "logstash*" ],
9-
{% endif %}
5+
"names": [ {{ logstash_user_indices }} ],
106
"privileges": ["write","create","delete","create_index","manage","manage_ilm"]
117
}
128
]

0 commit comments

Comments
 (0)