-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add modifications in SELinux disabled mode
When targeted SELinux policy is installed it should be possible to setup SELinux while disabled and before it's changed to permissive/enforcing. Related to #188 Signed-off-by: Petr Lautrbach <[email protected]>
- Loading branch information
1 parent
109aa62
commit d7d9b6b
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
- name: Ensure the default is targeted, enforcing, without local modifications | ||
hosts: all | ||
gather_facts: true | ||
vars: | ||
selinux_all_purge: true | ||
selinux_logins_purge: true | ||
|
||
tasks: | ||
- name: Ensure selinux-policy-targeted | ||
package: | ||
name: | ||
- selinux-policy-targeted | ||
state: present | ||
|
||
- name: Add a Linux System Roles SELinux User | ||
user: | ||
comment: Linux System Roles SELinux User | ||
name: sar-user | ||
- name: Switch to permissive to allow login when selinuxfs is not mounted | ||
command: setenforce 0 | ||
changed_when: true | ||
when: ansible_selinux.status != "disabled" and | ||
ansible_selinux.mode != "permissive" | ||
register: selinux_switch_to_enforcing | ||
- name: Get selinuxfs mountpoint | ||
command: findmnt -n -t selinuxfs --output=target | ||
changed_when: false | ||
register: selinux_mountpoint | ||
- name: >- | ||
Umount selinux mountpoint to emulate SELinux disabled | ||
system {{ selinux_mountpoint.stdout }} | ||
command: umount -l {{ selinux_mountpoint.stdout }} | ||
changed_when: true | ||
when: selinux_mountpoint.stdout != "" | ||
- name: Execute the role | ||
block: | ||
- name: Include role | ||
include_role: | ||
name: linux-system-roles.selinux | ||
vars: | ||
# https://github.com/ansible-collections/ansible.posix/pull/496 | ||
# selinux_booleans: | ||
# - {name: 'ssh_sysadm_login', state: 'off', persistent: 'yes'} | ||
selinux_fcontexts: | ||
- {target: '/tmp/test_dir(/.*)?', setype: 'user_home_dir_t', | ||
ftype: 'd'} | ||
selinux_ports: | ||
- {ports: '22100', proto: 'tcp', setype: 'ssh_port_t', | ||
state: 'present'} | ||
selinux_logins: | ||
- {login: 'sar-user', seuser: 'staff_u', | ||
serange: 's0-s0:c0.c1023', state: 'present'} | ||
always: | ||
- name: >- | ||
Mount selinux mountpoint back to | ||
system {{ selinux_mountpoint.stdout }} | ||
# noqa command-instead-of-module | ||
command: >- | ||
mount -t selinuxfs selinuxfs {{ selinux_mountpoint.stdout }} | ||
changed_when: true | ||
- name: Switch back to enforcing | ||
command: setenforce 1 | ||
changed_when: true | ||
when: selinux_switch_to_enforcing.skipped is not defined | ||
- name: Gather facts again | ||
setup: | ||
- name: Remove Linux System Roles SELinux User | ||
user: | ||
name: sar-user | ||
remove: true | ||
state: absent | ||
- name: Include role to purge everything | ||
include_role: | ||
name: linux-system-roles.selinux | ||
vars: | ||
selinux_all_purge: true |