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
3 changes: 3 additions & 0 deletions changelog.d/572-kibana-access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Who may work in Kibana (S-024): the `cloudfall_kibana` role keeps two roles through Kibana's own role API once Kibana is available, `cloudfall-kibana-view` (Kibana's base privilege `read`) and `cloudfall-kibana-edit` (base `all`), on every space and with no privilege in Elasticsearch, reading each first so an unchanged role is not put again. The S-012 user converge gives each user the Kibana service names in `kibana.users` the role of its `access` next to its own role, which stays unchanged, and takes it away when the user's line is removed; a user `kibana.users` does not name keeps its own role alone. Giving or taking Kibana access sends no password hash, so a password the person changed in Kibana stays until the stored one changes. Every task that reads or writes a role or a user is `no_log` (#572)
15 changes: 15 additions & 0 deletions engine/ansible/playbooks/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@
(cloudfall_services_elasticsearch_files | default({}))
[cloudfall_service_item.id] | default({})
}}
# The access of each user the cluster's Kibana names (S-024). The
# Kibana service lands on its own server only, which need not be the
# home that converges the users, so every server's services are read.
cloudfall_elasticsearch_kibana_access: >-
{{
groups['cloudfall_servers'] | default([])
| map('extract', hostvars)
| map(attribute='cloudfall_services', default=[])
| flatten(levels=1)
| selectattr('serviceKind', 'equalto', 'kibana')
| selectattr('kibana.elasticsearch', 'equalto', cloudfall_service_item.id)
| map(attribute='kibana.users')
| flatten(levels=1)
| items2dict(key_name='name', value_name='access')
}}
loop: >-
{{
cloudfall_services | default([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ cloudfall_elasticsearch_service: {}
# Controller paths of the files cloudfall stages for the service's accounts
# (cloudfallPassword, cloudfallHash, elasticHash); never the values.
cloudfall_elasticsearch_account_files: {}
# The access (view or edit) of each user the service's Kibana names in
# kibana.users, by user name, as services.yml finds it (S-024); a user not
# named here holds its own role alone.
cloudfall_elasticsearch_kibana_access: {}
cloudfall_elasticsearch_repository_key_url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
cloudfall_elasticsearch_repository_key_path: /etc/apt/keyrings/elasticsearch.asc
cloudfall_elasticsearch_repository_url: https://artifacts.elastic.co/packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ argument_specs:
existingUsername and existingPassword files, and under users each
declared user's bcrypt hash file; cloudfall passes them, never the
values
cloudfall_elasticsearch_kibana_access:
type: dict
description: >-
The access, view or edit, of each user the service's Kibana names in
kibana.users, by user name (S-024); the user converge gives that user
the role cloudfall-kibana-view or cloudfall-kibana-edit next to its own
cloudfall_elasticsearch_service:
type: dict
required: true
Expand Down
42 changes: 35 additions & 7 deletions engine/ansible/roles/cloudfall_elasticsearch/tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
cloudfall_elasticsearch_service.elasticsearch.users
| map(attribute='name') | list
}}
# The role of each Kibana access (S-024), kept by the Kibana role
cloudfall_elasticsearch_kibana_roles:
view: cloudfall-kibana-view
edit: cloudfall-kibana-edit

- name: Read the users of the cluster
ansible.builtin.uri:
Expand Down Expand Up @@ -149,6 +153,11 @@
changed_when: true
no_log: true

# A user the service's Kibana names in kibana.users holds the Kibana role of
# its access next to its own role (S-024); any other user holds its own role
# alone. The hash is sent only when the user is new or its stored password
# changed: giving or taking Kibana access keeps a password the person changed
# in Kibana.
- name: Put each declared user with its password hash
ansible.builtin.uri:
url: "{{ cloudfall_elasticsearch_api_url }}/_security/user/{{ item.name }}"
Expand All @@ -160,12 +169,12 @@
cloudfall_elasticsearch_account_files.cloudfallPassword) }}
force_basic_auth: true
body_format: json
body:
password_hash: "{{ cloudfall_elasticsearch_user_hash }}"
roles:
- "{{ item.name }}"
enabled: true
metadata: "{{ cloudfall_elasticsearch_user_metadata }}"
body: >-
{{
cloudfall_elasticsearch_user_body
| combine({'password_hash': cloudfall_elasticsearch_user_hash}
if cloudfall_elasticsearch_user_password_changed else {})
}}
status_code: 200
loop: "{{ cloudfall_elasticsearch_service.elasticsearch.users }}"
loop_control:
Expand All @@ -177,11 +186,30 @@
cloudfall_elasticsearch_user_metadata:
cloudfall_managed_by: "{{ cloudfall_elasticsearch_service.id }}"
cloudfall_password_digest: "{{ cloudfall_elasticsearch_user_hash | hash('sha256') }}"
cloudfall_elasticsearch_user_roles: >-
{{
[item.name]
+ (
[cloudfall_elasticsearch_kibana_roles[cloudfall_elasticsearch_kibana_access[item.name]]]
if item.name in cloudfall_elasticsearch_kibana_access
else []
)
}}
cloudfall_elasticsearch_user_body:
roles: "{{ cloudfall_elasticsearch_user_roles }}"
enabled: true
metadata: "{{ cloudfall_elasticsearch_user_metadata }}"
cloudfall_elasticsearch_user_current: >-
{{ cloudfall_elasticsearch_users_current.json.get(item.name) }}
cloudfall_elasticsearch_user_password_changed: >-
{{
cloudfall_elasticsearch_user_current is none
or cloudfall_elasticsearch_user_current.metadata.cloudfall_password_digest
| default('') != cloudfall_elasticsearch_user_metadata.cloudfall_password_digest
}}
when: >-
cloudfall_elasticsearch_user_current is none
or cloudfall_elasticsearch_user_current.roles != [item.name]
or cloudfall_elasticsearch_user_current.roles != cloudfall_elasticsearch_user_roles
or not cloudfall_elasticsearch_user_current.enabled
or cloudfall_elasticsearch_user_current.metadata
!= cloudfall_elasticsearch_user_metadata
Expand Down
5 changes: 5 additions & 0 deletions engine/ansible/roles/cloudfall_kibana/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@
{{ cloudfall_kibana_elasticsearch_service.elasticsearch.version }}
when: not ansible_check_mode

# Through Kibana's role API, so Kibana has to be available first (S-024-6).
- name: Keep the view and edit roles of Kibana
ansible.builtin.include_tasks: roles.yml
when: not ansible_check_mode

# Kibana logs in to the node with its token: the node lists the token among
# the file tokens of elastic/kibana it holds.
- name: Read the file tokens of elastic/kibana the node holds
Expand Down
77 changes: 77 additions & 0 deletions engine/ansible/roles/cloudfall_kibana/tasks/roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
# The two roles a declared user may hold next to its own (S-024, People and
# what they may do): Kibana's base privilege read, or all, on every space,
# and no privilege in Elasticsearch, so neither reaches an index or manages
# users and roles. They are written through Kibana's role API, as Elastic
# tells operators to manage Kibana privileges, and read first: a role that
# already holds what it should is not put again. The S-012 user converge
# gives each user named in kibana.users the role of its access.
- name: Name the roles Kibana keeps
ansible.builtin.set_fact:
cloudfall_kibana_roles:
- name: cloudfall-kibana-view
base: read
- name: cloudfall-kibana-edit
base: all

- name: Read the roles Kibana keeps
ansible.builtin.uri:
url: "{{ cloudfall_kibana_url }}/api/security/role/{{ item.name }}"
url_username: cloudfall
url_password: >-
{{ lookup('ansible.builtin.file',
cloudfall_kibana_elasticsearch_files.cloudfallPassword) }}
force_basic_auth: true
status_code: [200, 404]
loop: "{{ cloudfall_kibana_roles }}"
loop_control:
label: "{{ item.name }}"
register: cloudfall_kibana_roles_current
no_log: true

- name: Put each role Kibana keeps
ansible.builtin.uri:
url: "{{ cloudfall_kibana_url }}/api/security/role/{{ item.item.name }}"
method: PUT
url_username: cloudfall
url_password: >-
{{ lookup('ansible.builtin.file',
cloudfall_kibana_elasticsearch_files.cloudfallPassword) }}
force_basic_auth: true
headers:
kbn-xsrf: cloudfall
body_format: json
body: "{{ cloudfall_kibana_role_body }}"
status_code: [200, 204]
loop: "{{ cloudfall_kibana_roles_current.results }}"
loop_control:
label: "{{ item.item.name }}"
vars:
cloudfall_kibana_role_body:
metadata:
cloudfall_managed_by: "{{ cloudfall_kibana_service.id }}"
elasticsearch:
cluster: []
indices: []
run_as: []
kibana:
- base:
- "{{ item.item.base }}"
feature: {}
spaces:
- "*"
cloudfall_kibana_role_current: "{{ item.json | default({}) }}"
when: >-
item.status == 404
or cloudfall_kibana_role_current.elasticsearch.cluster | default([]) != []
or cloudfall_kibana_role_current.elasticsearch.indices | default([]) != []
or cloudfall_kibana_role_current.elasticsearch.run_as | default([]) != []
or cloudfall_kibana_role_current.elasticsearch.remote_indices | default([]) != []
or cloudfall_kibana_role_current.kibana | default([]) | length != 1
or cloudfall_kibana_role_current.kibana[0].base | default([]) != [item.item.base]
or cloudfall_kibana_role_current.kibana[0].feature | default({}) != {}
or cloudfall_kibana_role_current.kibana[0].spaces | default([]) != ['*']
or cloudfall_kibana_role_current.metadata | default({})
!= cloudfall_kibana_role_body.metadata
changed_when: true
no_log: true
Loading