-
Notifications
You must be signed in to change notification settings - Fork 32
Perform selabel lookup during file resource synchronization #229
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
base: main
Are you sure you want to change the base?
Perform selabel lookup during file resource synchronization #229
Conversation
|
@eciii thanks for the PR! @alexjfisher is that something you can take a look? I think you debugged various selinux issues with the file resource in the past? |
lib/puppet/type/file/selcontext.rb
Outdated
|
|
||
| @event = :file_changed | ||
| defaultto { retrieve_default_context(:seluser) } | ||
| defaultto { Puppet::Util::Platform.windows? || @resource[:selinux_ignore_defaults] == :true ? nil : :lookup } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like repeating this line. And it's too complex to be a one-liner.
I don't think it's correct either. Previously on Windows, this would be nil and now it's true.
|
@eciii can you rebase against our latest main branch please? |
|
@bastelfreak I'm trying to address the failures reported by the test suite and found some issues in this PR that I'm trying to improve. Unfortunately I have stumbled with several problems when trying to run the full test suite locally. I'll try to get this PR in good shape again soon, rebase it to the latest main branch and address the comments made by @binford2k . In the meantime I opened a separate PR to address one of the problems regarding the test suite. |
7a669d4 to
04b8c3a
Compare
|
@bastelfreak @binford2k I was able to get this commit into good shape, at least in my opinion. I made some small changes with respect with the previous attempt. In particular the I also ran the full test suite locally on Ubuntu 24.04 LTS and on CentOS Stream 10. This allowed me to catch one bug in the actual proposed solution (catch
I'll fix the rubocop issue so that the GitHub tests are successful. |
The default values of the SELinux-related properties of a file resource are calculated at the beginning of the catalog application phase, before the catalog resources are actually synchronized. However, by the time the file resource is synchronized, these default values might be outdated due to new policy rules being added in previous parts of the catalog (for example, a package was installed that included new policy rules that affect the file currently being created by the file resource.). On these cases the file created by the file resource ends up with the wrong SELinux context. This commit delays the lookup of the default values until the very moment the file resource is being synchronized. More precisely, the following process is implemented: - A `:lookup` symbol is introduced as the default value. It means that the actual value is to be looked up later during synchronization. However, maintaining the previous behaviour, a default value of `nil` is used if either the platform doesn't support SELinux (e.g Windows, or Ubuntu by default) or the user explicitly stated to ignore the default values (using the `selinux_ignore_defaults` parameter). - During resource synchronization, when the `insync?` method is executed, the `:lookup` symbol is replaced with the actual looked up value and then the sync status is calculated as usual. The unit tests have been adjusted accordingly the best I could but a somewhat larger improvement/refactoring of these tests is still needed (and hopefully will be made later) to get them into good shape.
After the introduction of the `:lookup` symbol as the default value of the SELinux-related properties of the file resource, some tests now fail because they expect the file resource to not have properties with such behaviour. This commit disables SELinux for such tests. Note that the failures occur only when the tests are executed on systems with SELinux enabled (e.g CentOS).
04b8c3a to
a2b7afa
Compare
|
The code looks okay to me, but I'm really not an selinux expert |
The default values of the SELinux-related properties of a file resource are calculated at the beginning of the catalog application phase, before the catalog resources are actually synchronized. However, by the time the file resource is synchronized, these default values might be outdated due to new policy rules being added in previous parts of the catalog.
This behavior can be easily reproduced in Rocky Linux 9 and probably other RHEL-like distros (maybe even Fedora):
The
testfile is created with the wrong SELinux context because:seltypeproperty is calculated before thegrafanapackage is installed.grafanapackage is then installed, pulling in thegrafana-selinuxpackage, which in turn creates thegrafana_var_lib_ttype.testfile is created using an outdated SELinux type.This PR fixes the described behavior:
This PR also adjusts the corresponding unit tests accordingly. As far as I cat tell, all the relevant tests pass:
More details about the actual changes can be found in the commit description.