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

[3006.x] Allow for semange fcontext -l having trailing whitespace in selinux.fcontext_get_policy #64950

Merged
merged 1 commit into from
Aug 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/63336.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix SELinux get policy with trailing whitespace
4 changes: 3 additions & 1 deletion salt/modules/selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ def fcontext_get_policy(
if filetype:
_validate_filetype(filetype)
re_spacer = "[ ]+"
re_optional_spacer = "[ |\t]*"
cmd_kwargs = {
"spacer": re_spacer,
"ospacer": re_optional_spacer,
"filespec": re.escape(name),
"sel_user": sel_user or "[^:]+",
"sel_role": "[^:]+", # se_role for file context is always object_r
Expand All @@ -490,7 +492,7 @@ def fcontext_get_policy(
)
cmd = (
"semanage fcontext -l | egrep "
+ "'^{filespec}{spacer}{filetype}{spacer}{sel_user}:{sel_role}:{sel_type}:{sel_level}$'".format(
+ "'^{filespec}{spacer}{filetype}{spacer}{sel_user}:{sel_role}:{sel_type}:{sel_level}{ospacer}$'".format(
**cmd_kwargs
)
)
Expand Down
6 changes: 3 additions & 3 deletions tests/pytests/unit/modules/test_selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_fcontext_get_policy_parsing():
{
"semanage_out": (
"/var/www(/.*)? all files "
" system_u:object_r:httpd_sys_content_t:s0"
" system_u:object_r:httpd_sys_content_t:s0 "
),
"name": "/var/www(/.*)?",
"filetype": "all files",
Expand All @@ -31,7 +31,7 @@ def test_fcontext_get_policy_parsing():
{
"semanage_out": (
"/var/www(/.*)? all files "
" system_u:object_r:httpd_sys_content_t:s0"
" system_u:object_r:httpd_sys_content_t:s0 "
),
"name": "/var/www(/.*)?",
"filetype": "all files",
Expand All @@ -43,7 +43,7 @@ def test_fcontext_get_policy_parsing():
{
"semanage_out": (
"/var/lib/dhcp3? directory "
" system_u:object_r:dhcp_state_t:s0"
" system_u:object_r:dhcp_state_t:s0 "
),
"name": "/var/lib/dhcp3?",
"filetype": "directory",
Expand Down