Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string/bytestring comparsion in m_u.basic #70439

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/70244-selinux-special-fs.yml
@@ -0,0 +1,2 @@
bugfixes:
- Fix bytestring vs string comparison in module_utils.basic.is_special_selinux_path() so that special-cased filesystems which don't support SELinux context attributes still allow files to be manipulated on them. (https://github.com/ansible/ansible/issues/70244)
5 changes: 3 additions & 2 deletions lib/ansible/module_utils/basic.py
Expand Up @@ -888,11 +888,12 @@ def is_special_selinux_path(self, path):
f.close()
except Exception:
return (False, None)

path_mount_point = self.find_mount_point(path)

for line in mount_data:
(device, mount_point, fstype, options, rest) = line.split(' ', 4)

if path_mount_point == mount_point:
if to_bytes(path_mount_point) == to_bytes(mount_point):
for fs in self._selinux_special_fs:
if fs in fstype:
special_context = self.selinux_context(path_mount_point)
Expand Down
3 changes: 3 additions & 0 deletions test/integration/targets/copy/tasks/main.yml
Expand Up @@ -74,6 +74,9 @@
- import_tasks: acls.yml
when: ansible_system == 'Linux'

- import_tasks: selinux.yml
when: ansible_os_family == 'RedHat' and ansible_selinux.get('mode') == 'enforcing'

- import_tasks: check_mode.yml

# https://github.com/ansible/ansible/issues/57618
Expand Down
35 changes: 35 additions & 0 deletions test/integration/targets/copy/tasks/selinux.yml
@@ -0,0 +1,35 @@
# Ensure that our logic for special filesystems works as intended
# https://github.com/ansible/ansible/issues/70244
- block:
- name: Install dosfstools
yum:
name: dosfstools
state: present

- name: Create a file to use for a fat16 filesystem
command: dd if=/dev/zero of=/fat16 bs=1024 count=10240

- name: mkfs.fat
command: mkfs.fat -F16 /fat16

- name: Mount it
command: mount /fat16 /mnt

- name: Copy a file to it
copy:
src: /etc/fstab
dest: /mnt/fstab
always:
- name: Unmount it
command: umount /mnt
ignore_errors: true

- name: Nuke /fat16
file:
path: /fat16
state: absent

- name: Uninstall dosfstools
yum:
name: dosfstools
state: absent