Skip to content

Commit b2c2683

Browse files
authored
Merge pull request #1136 from berndfinger/combine-selinux-and-fapolicyd-dir-definitions-02
sap_hana_install: simplified and more flexible SELinux and fapolicyd handling
2 parents 71d4c57 + 47899df commit b2c2683

File tree

15 files changed

+175
-119
lines changed

15 files changed

+175
-119
lines changed

roles/sap_hana_install/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ This part is performed when:
229229
- Existing SAP HANA was not detected.
230230

231231
Steps:
232-
1. If the variable `sap_hana_install_use_fapolicyd` is set to `true` and operating system is `RedHat`, install and disable `fapolicyd` on all new hosts.
232+
1. If the variable `sap_hana_install_configure_fapolicyd` is set to `true` and operating system is `RedHat`, install and disable `fapolicyd` on all new hosts.
233233
2. Configure permissions for the SAP HANA directories on all new hosts.
234-
3. If the variable `sap_hana_install_modify_selinux_labels` is set to `true`, configure `SElinux` on all new hosts.
234+
3. If the variable `sap_hana_install_configure_selinux` is set to `true`, configure `SELinux` on all new hosts.
235235
4. Prepare the directory defined in variable `sap_hana_install_software_directory`.
236236
5. If the `hdblcm` was not found in the directory `sap_hana_install_software_directory`:
237237
- Find latest `SAPCAR` executable in the directory `sap_hana_install_software_directory` and use latest one matching OS Architecture.
@@ -253,9 +253,9 @@ Steps:
253253
- Generate password hash for `sapadm` user using the value of `sap_hana_install_sapadm_password` variable.
254254
2. Create the user `<sid>adm` on all addhosts.
255255
- This is not required during installation, because the `root` user is used instead.
256-
3. If the variable `sap_hana_install_use_fapolicyd` is set to `true` and operating system is `RedHat`, install and disable `fapolicyd` on all new hosts.
256+
3. If the variable `sap_hana_install_configure_fapolicyd` is set to `true` and operating system is `RedHat`, install and disable `fapolicyd` on all new hosts.
257257
4. Configure permissions for the SAP HANA directories on all new hosts.
258-
5. If the variable `sap_hana_install_modify_selinux_labels` is set to `true`, configure `SElinux` on all new hosts.
258+
5. If the variable `sap_hana_install_configure_selinux` is set to `true`, configure `SELinux` on all new hosts.
259259
6. If the file `configfiles/configfile.cfg` is found in the directory defined in `sap_hana_install_software_directory`, make copy of it and use it for installation.
260260
- If the file was not found, create template using `hdblcm` command and fill it in with jinja2 template.
261261

@@ -291,8 +291,9 @@ Steps:
291291
4. Recreate the initial tenant database if the variable `sap_hana_install_recreate_tenant_database` is set to `true`, for new installations.
292292
5. Set expiration of unix users to `never` if the variable `sap_hana_install_set_sidadm_noexpire` is set to `true`, for new installations.
293293
6. Apply firewall rules if the variable `sap_hana_install_update_firewall` is set to `true`.
294-
7. Apply SElinux policies if the variable `sap_hana_install_modify_selinux_labels` is set to `true`.
295-
8. (Red Hat specific) Configure `fapolicyd` if the variable `sap_hana_install_use_fapolicyd` is set to `true`.
294+
7. Apply SELinux policies if the variable `sap_hana_install_configure_selinux` is set to `true`.
295+
8. (Red Hat specific) Configure `fapolicyd` if the variable `sap_hana_install_configure_fapolicyd` is set to `true`.
296+
Additionally, if `sap_hana_install_enable_fapolicyd` is set to `true`, also enable and start the `fapolicyd` service.
296297
9. Output final status of installed system.
297298

298299

@@ -304,8 +305,9 @@ Steps:
304305
1. Update Secure User Store configuration (`hdbuserstore`) for `<sid>adm` user, for new hosts.
305306
5. Set expiration of unix users to `never` if the variable `sap_hana_install_set_sidadm_noexpire` is set to `true`, for new hosts.
306307
6. Apply firewall rules if the variable `sap_hana_install_update_firewall` is set to `true`.
307-
7. Apply SElinux policies if the variable `sap_hana_install_modify_selinux_labels` is set to `true`.
308-
8. (Red Hat specific) Configure `fapolicyd` if the variable `sap_hana_install_use_fapolicyd` is set to `true`.
308+
7. Apply SELinux policies if the variable `sap_hana_install_configure_selinux` is set to `true`.
309+
8. (Red Hat specific) Configure `fapolicyd` if the variable `sap_hana_install_configure_fapolicyd` is set to `true`.
310+
Additionally, if `sap_hana_install_enable_fapolicyd` is set to `true`, also enable and start the `fapolicyd` service.
309311
9. Output final status of installed system.
310312
<!-- END Execution Flow -->
311313

roles/sap_hana_install/defaults/main.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,29 @@ sap_hana_install_keep_copied_sarfiles: false
3232

3333
# (RedHat specific) fapolicyd package is present on RedHat systems
3434
# For installing SAP HANA with fapolicyd support, set the following variable to `true`:
35-
sap_hana_install_use_fapolicyd: false
35+
sap_hana_install_configure_fapolicyd: false
3636

37-
# (RedHat specific) fapolicyd package is present on RedHat systems
37+
# (RedHat specific) desired fapolicyd service status (only if sap_hana_install_configure_fapolicyd is 'true')
38+
# For not enabling and not starting the fapolicyd service after the installation has finished, set the following
39+
# variable to `false`:
40+
sap_hana_install_enable_fapolicyd: true
41+
42+
# (RedHat specific) fapolicyd integrity level
3843
# When using fapolicyd, you can set the following variable to one of `none`, `size`, `sha256`, or `ima`. Note that before setting
3944
# to `ima`, it is essential to prepare the system accordingly (e.g. boot with a different kernel parameter). See the
4045
# RHEL 9 Managing, monitoring, and updating the kernel guide for more information on this topic.
4146
sap_hana_install_fapolicyd_integrity: 'sha256'
4247

43-
# (RedHat specific) fapolicyd package is present on RedHat systems
48+
# (RedHat specific) name of fapolicyd rule file for protecting shell scripts
4449
# When using fapolicyd, the following variable is used to define the fapolicyd rule file in which the rules for
4550
# protecting shell scripts are stored. The rule file will be created in the directory '/etc/fapolicyd/rules.d'.
4651
# Note: The mandatory file ending '.rules' will be added in the corresponding task of this role.
4752
sap_hana_install_fapolicyd_rule_file: '71-sap-shellscripts'
4853

49-
# (RedHat specific) fapolicyd package is present on RedHat systems
50-
# When using fapolicyd, modify the following variable to change or add the directories which contain SAP HANA executables:
51-
sap_hana_install_fapolicyd_trusted_directories:
54+
# Directories which are used for the SAP HANA installation (relevant for SELinux relabeling and for fapolicyd protection)
55+
sap_hana_install_directories:
5256
- "{{ sap_hana_install_root_path }}"
57+
- '/lss/shared'
5358
- '/usr/sap'
5459

5560
# File name of SAPCAR*EXE in the software directory. If the variable is not set and there is more than one SAPCAR executable
@@ -117,10 +122,11 @@ sap_hana_install_new_system: true
117122
# In case this is not desired, you can set the following parameter to `true` to recreate the initial tenant database.
118123
sap_hana_install_recreate_tenant_database: false
119124

120-
# For compatibility of SAP HANA with SELinux in enforcing mode, the role will recursively relabel directories and files
121-
# in `/hana` before the installation starts and in `/usr/sap` after the installation has finished.
122-
# If relabeling not desired, set the following variable to `false`.
123-
sap_hana_install_modify_selinux_labels: true
125+
# For compatibility of SAP HANA with SELinux in enforcing mode, the role will set the SELinux boolean 'selinuxuser_execmod' to 'on'.
126+
# It will also recursively relabel directories and files in `/hana` before the installation starts and in all other directories
127+
# specified in 'sap_hana_install_directories' after the installation has finished.
128+
# If this not desired, set the following variable to `false`.
129+
sap_hana_install_configure_selinux: true
124130

125131
################
126132
# Parameters for hdblcm:

roles/sap_hana_install/tasks/hana_install.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
- 'Once the task "Install SAP HANA" has started, you can use the following command'
1919
- 'in a terminal session on {{ inventory_hostname }} to watch the install progress in real time:'
2020
- "{{ __sap_hana_install_register_tmpdir.path }}/tail-f-hdblcm-install-trc.sh"
21-
- 'Alternatively, you can run the following command on the control node:'
22-
- "ssh {{ inventory_hostname }} {{ __sap_hana_install_register_tmpdir.path }}/tail-f-hdblcm-install-trc.sh"
2321

2422
- name: SAP HANA - Install - Set fact for the hdblcm verify_signature argument
2523
ansible.builtin.set_fact:

roles/sap_hana_install/tasks/main.yml

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,17 @@
11
# SPDX-License-Identifier: Apache-2.0
22
---
33

4-
# Load variables while maintaining backwards compatibility when variable is empty string.
5-
# Check if variable is defined and non-empty before using it, otherwise fall back to backwards
6-
# compatible variable or default empty string that will fail asserts afterwards.
7-
# NOTE: This is not __var assignment so it will not override user specified vars due to precedence!
8-
- name: SAP HANA - Main - Set mandatory variables used by hdblcm configfile
9-
ansible.builtin.set_fact:
10-
sap_hana_install_sid:
11-
"{{ sap_hana_sid | d('')
12-
if sap_hana_install_sid | string | length == 0
13-
else sap_hana_install_sid }}"
14-
sap_hana_install_number:
15-
"{{ sap_hana_instance_number | d(sap_hana_install_instance_nr) | d(sap_hana_install_instance_number) | d('')
16-
if sap_hana_install_number | string | length == 0
17-
else sap_hana_install_number }}"
18-
sap_hana_install_system_usage: "{{ sap_hana_install_env_type | d(sap_hana_install_system_usage) | d('custom') }}"
19-
sap_hana_install_restrict_max_mem: "{{ sap_hana_install_mem_restrict | d(sap_hana_install_restrict_max_mem) | d('n') }}"
20-
tags:
21-
- sap_hana_install_check_hana_exists
22-
- sap_hana_install_check_installation
23-
- sap_hana_install_preinstall
24-
- sap_hana_install_set_log_mode
25-
- sap_hana_install_configure_firewall
26-
27-
# Separate task for password with no_log
28-
- name: SAP HANA - Main - Set mandatory variables used by hdblcm configfile - passwords
29-
ansible.builtin.set_fact:
30-
sap_hana_install_master_password:
31-
"{{ sap_hana_install_common_master_password | d('')
32-
if sap_hana_install_master_password is not defined or sap_hana_install_master_password | string | length == 0
33-
else sap_hana_install_master_password }}"
34-
no_log: true # Required for password handling
35-
tags:
36-
- sap_hana_install_check_hana_exists
37-
- sap_hana_install_check_installation
38-
- sap_hana_install_preinstall
39-
- sap_hana_install_set_log_mode
40-
- sap_hana_install_configure_firewall
41-
42-
- name: SAP HANA - Main - Validate the role variables
4+
# SAP HANA
5+
- name: SAP HANA - Main - Prepare some variables
436
ansible.builtin.include_tasks:
44-
file: pre_tasks/assert_variables.yml
7+
file: pre_tasks/prepare_variables.yml
458
tags:
469
- sap_hana_install_check_hana_exists
4710
- sap_hana_install_check_installation
4811
- sap_hana_install_preinstall
4912
- sap_hana_install_set_log_mode
5013
- sap_hana_install_configure_firewall
5114

52-
# SELinux is not currently supported by SAP using SLES4SAP
53-
# This can still be overwritten by extra variables.
54-
- name: SAP HANA Pre Install - Ensure SELinux does not execute for SLES
55-
ansible.builtin.set_fact:
56-
sap_hana_install_modify_selinux_labels: false
57-
when: ansible_os_family == "Suse"
58-
59-
6015
# SAP HANA presence has to be validated for both new system and adding new hosts.
6116
- name: SAP HANA - Main - Validate presence of existing SAP HANA database
6217
ansible.builtin.include_tasks:
@@ -93,7 +48,6 @@
9348
- name: SAP HANA - Install - Pre-Tasks
9449
ansible.builtin.include_tasks:
9550
file: pre_install.yml
96-
tags: sap_hana_install_preinstall
9751

9852
- name: SAP HANA - Install
9953
ansible.builtin.include_tasks:
@@ -169,11 +123,11 @@
169123
{% if sap_hana_install_update_firewall %}
170124
Firewall is enabled and SAP HANA ports are open.
171125
{% endif %}
172-
{% if sap_hana_install_modify_selinux_labels %}
173-
SELinux file contexts are configured for SAP folders '{{ sap_hana_install_root_path }}' and '/usr/sap'.
126+
{% if __sap_hana_install_configure_selinux %}
127+
SELinux file contexts are configured for SAP folders ({{ sap_hana_install_directories | map('quote') | join(', ') }}).
174128
{% endif %}
175-
{% if ansible_os_family == "RedHat" and sap_hana_install_use_fapolicyd %}
176-
Fapolicyd is configured for SAP folders '{{ sap_hana_install_root_path }}' and '/usr/sap'.
129+
{% if ansible_os_family == "RedHat" and __sap_hana_install_configure_fapolicyd %}
130+
Fapolicyd is configured for SAP folders ({{ sap_hana_install_directories | map('quote') | join(', ') }}).
177131
{% endif %}
178132
vars:
179133
__sap_hana_install_fact_hana_version: "{{ __sap_hana_install_register_completion_result.stdout.split(';')[0] }}"

roles/sap_hana_install/tasks/post_addhosts.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
- name: SAP HANA - Addhosts - Post-Tasks - SELinux
2626
ansible.builtin.include_tasks:
2727
file: post_tasks/selinux.yml
28-
when: sap_hana_install_modify_selinux_labels
28+
when: __sap_hana_install_configure_selinux
2929

3030
- name: SAP HANA - Addhosts - Post-Tasks - Fapolicyd
3131
ansible.builtin.include_tasks:
3232
file: post_tasks/fapolicyd.yml
3333
when:
3434
# Ensure fapolicyd is checked only on supported systems.
3535
- ansible_os_family == "RedHat"
36-
- sap_hana_install_use_fapolicyd
37-
tags: sap_hana_install_use_fapolicyd
36+
- __sap_hana_install_configure_fapolicyd
37+
tags: sap_hana_install_configure_fapolicyd

roles/sap_hana_install/tasks/post_install.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@
7676
- name: SAP HANA - Install - Post-Tasks - SELinux
7777
ansible.builtin.include_tasks:
7878
file: post_tasks/selinux.yml
79-
when: sap_hana_install_modify_selinux_labels
79+
when: __sap_hana_install_configure_selinux
8080

8181
- name: SAP HANA - Install - Post-Tasks - Fapolicyd
8282
ansible.builtin.include_tasks:
8383
file: post_tasks/fapolicyd.yml
8484
when:
8585
# Ensure fapolicyd is checked only on supported systems.
8686
- ansible_os_family == "RedHat"
87-
- sap_hana_install_use_fapolicyd
88-
tags: sap_hana_install_use_fapolicyd
87+
- __sap_hana_install_configure_fapolicyd
88+
tags: sap_hana_install_configure_fapolicyd

roles/sap_hana_install/tasks/post_tasks/fapolicyd.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
msg: "{{ sap_hana_install_register_fagenrules_load.stdout_lines }}"
7070

7171
# We want to add files which have the execute mode bit set AND which are reported as executables
72-
# by fapolicyd-cli -t, one for each directory of sap_hana_install_fapolicyd_trusted_directories.
72+
# by fapolicyd-cli -t, one for each directory of sap_hana_install_directories.
7373
# The fapolicy trust file name will be created from the directory names by replacing '/' by '_' and
7474
# omitting the first '_'.
75-
- name: SAP HANA - Post-Tasks - Put all executable files from 'sap_hana_install_fapolicyd_trusted_directories' into fapolicyd trust files
75+
- name: SAP HANA - Post-Tasks - Put all executable files from 'sap_hana_install_directories' into fapolicyd trust files
7676
ansible.builtin.shell: |
7777
set -o pipefail &&
7878
find {{ __sap_hana_install_item }} -type f -executable -exec fapolicyd-cli -t {} \; -print |
@@ -83,7 +83,7 @@
8383
{{ __sap_hana_install_item | regex_replace('//*', '_') | regex_replace("^_", "") }}"); a=0; b=0
8484
}
8585
}'
86-
loop: "{{ sap_hana_install_fapolicyd_trusted_directories }}"
86+
loop: "{{ sap_hana_install_directories }}"
8787
loop_control:
8888
loop_var: __sap_hana_install_item
8989
label: >-
@@ -98,9 +98,11 @@
9898
name: fapolicyd
9999
enabled: true
100100
state: started
101+
when: sap_hana_install_enable_fapolicyd
101102

102103
- name: SAP HANA - Post-Tasks - Restart fapolicyd
103104
ansible.builtin.service:
104105
name: fapolicyd
105106
enabled: true
106107
state: restarted
108+
when: sap_hana_install_enable_fapolicyd
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
# SPDX-License-Identifier: Apache-2.0
22
---
33

4-
# This configuration includes also Pre-Tasks content to ensure they are all set same.
5-
- name: SAP HANA - Post-Tasks - Configure 'sap_hana_install_root_path' SELinux file contexts
4+
# We do not need to configure sap_hana_install_root_path here because that was already configured in Pre-Tasks.
5+
- name: SAP HANA - Post-Tasks - Define dict for selinux_fcontexts
6+
ansible.builtin.set_fact:
7+
__sap_hana_install_fcontexts_list: "{{ __sap_hana_install_fcontexts_list | d([]) + [__sap_hana_install_target_setype_dict] }}"
8+
loop: "{{ sap_hana_install_directories | reject('equalto', sap_hana_install_root_path) }}"
9+
loop_control:
10+
loop_var: __sap_hana_install_directory_item
11+
vars:
12+
__sap_hana_install_target_setype_dict:
13+
target: "{{ __sap_hana_install_directory_item }}(/.*)?"
14+
setype: 'usr_t'
15+
16+
- name: SAP HANA - Post-Tasks - Configure SELinux file contexts for the remaining directories
617
ansible.builtin.include_role:
718
name: '{{ sap_hana_install_system_roles_collection }}.selinux'
819
vars:
920
selinux_booleans:
1021
- { name: 'selinuxuser_execmod', state: 'on' }
11-
selinux_fcontexts:
12-
- { target: '{{ sap_hana_install_root_path }}(/.*)?', setype: 'usr_t' }
13-
- { target: '/usr/sap(/.*)?', setype: 'usr_t' }
22+
selinux_fcontexts: "{{ __sap_hana_install_fcontexts_list }}"
1423
selinux_restore_dirs:
15-
- '{{ sap_hana_install_root_path }}'
16-
- /usr/sap
24+
- "{{ sap_hana_install_directories | reject('equalto', sap_hana_install_root_path) }}"

roles/sap_hana_install/tasks/pre_addhosts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
# Ensure fapolicyd is checked only on supported systems.
5252
- ansible_os_family == "RedHat"
5353
- __sap_hana_install_fact_is_new_addhost_host
54-
tags: sap_hana_install_use_fapolicyd
54+
tags: sap_hana_install_configure_fapolicyd
5555

5656

5757
- name: SAP HANA - Addhosts - Pre-Tasks - Configure SELinux file contexts for {{ sap_hana_install_root_path }}
5858
ansible.builtin.include_tasks:
5959
file: pre_tasks/selinux.yml
6060
when:
61-
- sap_hana_install_modify_selinux_labels
61+
- __sap_hana_install_configure_selinux
6262
- __sap_hana_install_fact_is_new_addhost_host
6363

6464

roles/sap_hana_install/tasks/pre_install.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
# Ensure fapolicyd is checked only on supported systems.
99
- ansible_os_family == "RedHat"
1010
- not __sap_hana_install_fact_is_installed
11-
tags: sap_hana_install_use_fapolicyd
11+
tags: sap_hana_install_configure_fapolicyd
1212

1313

1414
- name: SAP HANA - Install - Pre-Tasks - Configure SELinux file contexts for {{ sap_hana_install_root_path }}
1515
ansible.builtin.include_tasks:
1616
file: pre_tasks/selinux.yml
1717
when:
18-
- sap_hana_install_modify_selinux_labels
18+
- __sap_hana_install_configure_selinux
1919
- not __sap_hana_install_fact_is_installed
2020

2121

0 commit comments

Comments
 (0)