Open marcindulak opened 2 years ago
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
cc @dagwieers click here for bot help
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
Hello! I have a similar problem with this module.
I need to create a directory, but I need to avoid explicitly setting the SELinux label using the file
builtin module, since the label may be changed later if the directory is to be used for automounting:
- name: SELinux context is set to allow read-write access to user directories
community.general.sefcontext:
target: "/var/ftp/users(/.*)?"
ftype: a
seuser: system_u
setype: public_content_rw_t
state: present
become: yes
- name: Root directory for virtual host serving home directories is created
ansible.builtin.file:
path: /var/ftp/users
state: directory
owner: ftp
group: ftp
mode: "0750"
become: yes
After completing the tasks, I see that the label has not changed:
# semanage fcontext -l | grep /var/ftp/users
/var/ftp/users(/.*)? all files system_u:object_r:public_content_rw_t:s0
# ls -lZd /var/ftp/users/
drwxr-x---. 2 ftp ftp unconfined_u:object_r:public_content_t:s0 6 Sep 17 14:49 /var/ftp/users/
If I set setype: _default
I get the following problem when the automount point is already set:
TASK [proftpd : Root directory for virtual host serving projects is created] *********************************************************************************
fatal: [ftpdev.bp.local]: FAILED! => {"changed": false, "cur_context": ["system_u", "object_r", "autofs_t", "s0"], "gid": 50, "group": "ftp", "input_was": ["system_u", null, "public_content_t", null], "mode": "0750", "msg": "invalid selinux context: [Errno 95] Operation not supported", "new_context": ["system_u", "object_r", "public_content_t", "s0"], "owner": "ftp", "path": "/var/ftp/projects", "secontext": "system_u:object_r:autofs_t:s0", "size": 0, "state": "directory", "uid": 14}
This is an example for a different directory with a different label, but the principle is the same.
Can this issue be given a higher priority?
Summary
The documentation https://docs.ansible.com/ansible/2.9/modules/sefcontext_module.html says
The part
it is advisable to first create the SELinux file contexts before creating files
suggests that new files/directories may be created using the context defined using sefcontext. Also an older comment ansible/issues/33577#issuecomment-403003170 suggests this, but it does always not seem to be the case, as discussed also in selinux-canonical-way-of-automatically-applying-a-context-on-file-creation.Here is an example that illustrates the problem:
Actual result:
Expected result (requires
restorecon
)However, it the file task sets the parameter to
setype: _default
parameter, a freshly created/srv/git_repos
directory receives the expected selinux context.Issue Type
Documentation Report
Component Name
sefcontext
Ansible Version
Community.general Version
As part of ansible 2.9, no separate community modules are used.
Configuration
OS / Environment
Additional Information
The
it is advisable to first create the SELinux file contexts before creating files
part needs more clarification about the expected behavior. Currently a solution, recommended in docs, consists of runningrestorecon
aftersefcontext
, however this is reported as a "changed", possibly non-idempotent step by ansible:Alternatively, using the file module and setting the
setype: _default
parameter, could be used to force the selinux context on new files/directories as expected.Code of Conduct