Skip to content

Commit

Permalink
Added setting of seuser and selevel for completeness (#108)
Browse files Browse the repository at this point in the history
Added setting of seuser and selevel for completeness
See Issue #106 "RFE: Support for setting seuser in selinux_fcontexts"
#106

Added explanation of seuser and selevel parameters

Added -F flag to restorecon to force reset
See "man restorecon" for more detail on -F flag

Authored-by: Benjamin Blasco <bblasco@redhat.com>
  • Loading branch information
benblasco committed Jul 28, 2022
1 parent 8363bc9 commit 2dcf33c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ selinux_booleans:
selinux_fcontexts:
- { target: '/tmp/test_dir(/.*)?', setype: 'user_home_dir_t', ftype: 'd', state: 'present' }
```
Users may also pass the following optional parameters:
- `seuser`: to set the SELinux user
- `selevel`: to set the MLS/MCS Security Range (MLS/MCS Systems only) SELinux Range for SELinux login mapping defaults to the SELinux user record range.

Individual modifications can be dropped by setting `state` to `absent`.

Expand Down
7 changes: 4 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@
setype: "{{ item.setype }}"
ftype: "{{ item.ftype | default('a') }}"
state: "{{ item.state | default('present') }}"
# FIXME: selevel, seuser
selevel: "{{ item.selevel | default(omit) }}"
seuser: "{{ item.seuser | default(omit) }}"
with_items: "{{ selinux_fcontexts }}"

- name: Restore SELinux labels on filesystem tree
command: /sbin/restorecon -R -v {{ item }}
command: /sbin/restorecon -R -F -v {{ item }}
with_items: "{{ selinux_restore_dirs }}"
register: restorecon_cmd
changed_when: '"Relabeled" in restorecon_cmd.stdout'

- name: Restore SELinux labels on filesystem tree in check mode
command: /sbin/restorecon -R -v -n {{ item }}
command: /sbin/restorecon -R -F -v -n {{ item }}
with_items: "{{ selinux_restore_dirs }}"
register: restorecon_cmd
changed_when: '"Would relabel" in restorecon_cmd.stdout'
Expand Down

0 comments on commit 2dcf33c

Please sign in to comment.