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

lineinfile resets extended acl #72929

Closed
bsolomon1124 opened this issue Dec 9, 2020 · 8 comments · Fixed by #82818
Closed

lineinfile resets extended acl #72929

bsolomon1124 opened this issue Dec 9, 2020 · 8 comments · Fixed by #82818
Assignees
Labels
affects_2.16 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@bsolomon1124
Copy link

bsolomon1124 commented Dec 9, 2020

Note: root/UID 0 # prompt has been changed to $ here to help GitHub get markdown shell syntax highlighting right.

SUMMARY

lineinfile removes existing ACL as if setfacl --remove-all had been called on file.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

lineinfile

ANSIBLE VERSION
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Mar 20 2020, 17:08:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION

None overriden.

OS / ENVIRONMENT

RHEL 7.9

STEPS TO REPRODUCE
$ whoami
root
$ echo 'foo' > temp.txt
$ chmod 640 temp.txt
$ setfacl -m g:administrators:r temp.txt
$ ls -ld temp.txt
-rw-r-----+ 1 root root 4 Dec  9 21:05 temp.txt

$ getfacl temp.txt
# file: temp.txt
# owner: root
# group: root
user::rw-
group::r--
group:administrators:r--
mask::r--
other::---

$ cat << EOF > toypb.yaml
> - name: test
>   hosts: localhost
>   connection: local
>   gather_facts: false
>   tasks:
>     - lineinfile:
>         path: temp.txt
>         regexp: '^foo'
>         line: bar
>         owner: root
>         group: root
>         mode: 0640
> EOF

$ ansible-playbook toypb.yaml

$ cat temp.txt
bar
$ ls -ld temp.txt
-rw-r-----. 1 root root 4 Dec  9 21:06 temp.txt
$ getfacl !$
getfacl temp.txt
# file: temp.txt
# owner: root
# group: root
user::rw-
group::r--
other::---
EXPECTED RESULTS

Result of getfacl should shown extended read permissions, unchanged before task execution.

ACTUAL RESULTS
$ getfacl temp.txt
# file: temp.txt
# owner: root
# group: root
user::rw-
group::r--
other::---
@ansibot
Copy link
Contributor

ansibot commented Dec 9, 2020

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.

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Dec 9, 2020
@bsolomon1124
Copy link
Author

Going to venture a guess this occurs during/as a result of atomic_move(tmpfile, dest) though it claims to "[copy] attributes from dest."

def atomic_move(self, src, dest, unsafe_writes=False):

@Shrews Shrews added needs_verified This issue needs to be verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Dec 10, 2020
@Shrews
Copy link
Contributor

Shrews commented Dec 10, 2020

I'm not a SELinux expert by any means, but it looks to me like if atomic_move() attempts to maintain file SELinux context, but not the ACLs. I'm not totally sure why, but looking at the libselinux library, I'm not seeing any API methods that we'd be able to use to set ACLs. The acl module (now in the ansible.posix collection) uses calls to the setfacl and getfacl command line utilities, maybe because of the library limitations.

One workaround for your issue, then, is to use the acl module mentioned above.

Maybe @bcoca can lend an assist here, since I think he may have more background on how and why atomic_move() works the way it does?

@bsolomon1124
Copy link
Author

One workaround for your issue, then, is to use the acl module mentioned above.

Yes, in this case, it seems like we were basically required to follow any lineinfile call with an acl. (I'm not sure what other modules might use atomic_move(), but guessing there are at least a few.)

@samdoran
Copy link
Contributor

Similar to #51868.

@AdrianOsica
Copy link

Hi, this bug is still unsolved?

@bcoca
Copy link
Member

bcoca commented Jul 18, 2023

that is what an open ticket means

@AdrianOsica
Copy link

Oh, ok. Fyi bug also affect for me

@jborean93 jborean93 removed the affects_2.9 This issue/PR affects Ansible v2.9 label Mar 6, 2024
@ansibot ansibot added the has_pr This issue has an associated PR. label Mar 13, 2024
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Mar 18, 2024
@ansible ansible locked and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.16 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants