selinux icon indicating copy to clipboard operation
selinux copied to clipboard

Allow override built-in fcontext

Open ywei2017 opened this issue 1 year ago • 5 comments

:frowning_person: Problem Statement

The selinux_fcontext::manage/modify does not allow override of built-in contexts. :add action would skip if semanage fcontext -l returns an entry, and :modify would fail if there is no such entry in the .local spec file. Hence there is no way to override a built-in context.

:grey_question: Possible Solution

The most straightforward solution is to check whether the type matches at the conditional statement. Instead of checking "if fcontext is already registered", it should check "if the desired fcontext is already registered". So the conditional check will the same as the :modify action.

:arrow_heading_up: Describe alternatives you've considered

One possibility is to clone and hack it, but that defeats the purpose of a re-usable cookbook.

:heavy_plus_sign: Additional context

I can submit a PR if the proposed solution is acceptable.

ywei2017 avatar Apr 21 '24 13:04 ywei2017

A PR will help to better understand the issue and the fix.

Stromweld avatar Apr 22 '24 15:04 Stromweld

@Stromweld I will submit a PR in the next day or 2. Thanks.

ywei2017 avatar Apr 22 '24 20:04 ywei2017

@Stromweld , please take a look at PR #120. If the approach makes sense, I will update the test cases and the rest for the PR.

Thanks

ywei2017 avatar Apr 23 '24 22:04 ywei2017

That looks good to me. I'm not very versed in selinux though. I think it'll help to add the test cases for each scenario as well as to make sure future regression isn't introduced.

Would you also be able to open PR for the same thing here https://github.com/chef/chef/blob/main/lib/chef/resource/selinux_fcontext.rb. This resource was based on this cookbooks resource. It'll help chef-client as well as cinc-client since it's based on chef-client.

Stromweld avatar Apr 23 '24 23:04 Stromweld

@Stromweld Will do. Let me do it in 2 steps.

  1. Add the test case for this PR so it all good. I can use some education to make sure the proper procedures are followed.
  2. Then I will submit a PR to https://github.com/chef/chef/blob/main/lib/chef/resource/selinux_fcontext.rb

Thanks for the quick feedback.

ywei2017 avatar Apr 23 '24 23:04 ywei2017