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

add flag for building bluechi-selinux with any port #850

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

engelmi
Copy link
Member

@engelmi engelmi commented Mar 25, 2024

Fixes: #836

Previously, the SELinux policy for BlueChi only contained one type for the port and was used only by the bluechi-agent. This adds a new port type and and uses one for the bind of bluechi-controller and another for the connect of bluechi-agent.
Based on this, tunable policies are added to turn on/off the option to use any port for both components.
In addition, it removes the implicit permissive policy so that violations to the policies are enforced by default (can be set permissive later on by the user again).

This PR also updates the RPM spec of BlueChi so that it does not require the semange tool and thus is not pulling in python as a dependency anymore. It adds also another option to the build to enable any port policy for bluechi-controller an bluechi-agent.

It also adds documentation about BueChi's SELinux policy, restructuring the order of the table of contents and introducing the section Security which contains the selinux policy and mTLS double proxy approach.

NOTE:

The changes for the documentation look like this:
image

@engelmi engelmi requested a review from mwperina March 25, 2024 09:17
@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 6d9fb64 to 8f5453d Compare March 25, 2024 09:17
@coveralls
Copy link

coveralls commented Mar 25, 2024

Coverage Status

coverage: 84.169% (+0.02%) from 84.151%
when pulling 382e6d5 on engelmi:loosen-selinux-port-policy
into b3c1a68 on eclipse-bluechi:main.

Copy link
Member

@mwperina mwperina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@engelmi
Copy link
Member Author

engelmi commented Mar 25, 2024

@rhatdan PTAL

@engelmi engelmi force-pushed the loosen-selinux-port-policy branch 3 times, most recently from 212d0d2 to 8d59ceb Compare April 2, 2024 07:25
doc/docs/security/selinux.md Outdated Show resolved Hide resolved
doc/docs/security/selinux.md Outdated Show resolved Hide resolved
@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 8d59ceb to 9c8153c Compare April 2, 2024 07:42
@engelmi engelmi changed the title loosen selinux port policy add flag for building bluechi-selinux with default port Apr 2, 2024
@alexlarsson
Copy link
Contributor

This doesn't seem right to me. The selinux module still references the bluechi_port_t type, and if the semanage call was never called, then this will not be set to anything. I don't know selinux that well, so I'm not sure if that will lead to some error, or if the port is assumed to be zero or something.

Either way, unless I'm totally off, there is no way this can correctly work.

I think we need something like systemd_socket_proxyd_bind_any in
https://github.com/fedora-selinux/selinux-policy/blob/85bbb6d1bc69e84ea2440cff647e426b74f1b40a/policy/modules/system/systemd.te

This has both a port type which can be assigned with semanage (systemd_socket_proxyd_port_t) and boolean options ( systemd_socket_proxyd_bind_any and systemd_socket_proxyd_connect_any) which instead makes the rules work on any port. I think the right approach is to use something like that with the boolean options set to true by default, and then have the optional rpm post-scripts set both the port and the boolean.

@alexlarsson
Copy link
Contributor

This doesn't seem right to me. The selinux module still references the bluechi_port_t type, and if the semanage call was never called, then this will not be set to anything. I don't know selinux that well, so I'm not sure if that will lead to some error, or if the port is assumed to be zero or something.

I guess what happen is that no port will ever get that label assigned, so no port will ever pass the rules.

@engelmi
Copy link
Member Author

engelmi commented Apr 2, 2024

This doesn't seem right to me. The selinux module still references the bluechi_port_t type, and if the semanage call was never called, then this will not be set to anything. I don't know selinux that well, so I'm not sure if that will lead to some error, or if the port is assumed to be zero or something.

I guess what happen is that no port will ever get that label assigned, so no port will ever pass the rules.

The port would need to be assigned to that label with semanage later on. Till then, basically no port is assigned and an AVC is always created - but the name bind itself is not blocked.

I'll have a look at the systemd_socket_proxyd_bind_any.

@alexlarsson
Copy link
Contributor

The port would need to be assigned to that label with semanage later on. Till then, basically no port is assigned and an AVC is always created - but the name bind itself is not blocked.

I feel this being permissive like this makes the whole selinux module not very useful though.

@engelmi engelmi force-pushed the loosen-selinux-port-policy branch 2 times, most recently from 7451496 to 4211f4e Compare April 3, 2024 11:32
@engelmi
Copy link
Member Author

engelmi commented Apr 3, 2024

I feel this being permissive like this makes the whole selinux module not very useful though.

I agree. In addition, I think it can't be changed from permissive to enforcing later on (since it wasn't added by semanage according to [the man page]).

I did a bunch of changes, incl. the tunable policy for the ports based on the systemd example.
Could you have another look? @alexlarsson

@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 4211f4e to 60ee7b8 Compare April 3, 2024 11:44
@engelmi engelmi changed the title add flag for building bluechi-selinux with default port add flag for building bluechi-selinux with any port Apr 3, 2024
doc/docs/security/selinux.md Outdated Show resolved Hide resolved
doc/docs/security/selinux.md Show resolved Hide resolved
selinux/bluechi.te Outdated Show resolved Hide resolved
bluechi.spec.in Show resolved Hide resolved
@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 60ee7b8 to 494e461 Compare April 3, 2024 12:07
Copy link
Member

@mwperina mwperina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that we forgot to remove dependency on policycoreutils-python-utils

@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 494e461 to 0fa07a0 Compare April 4, 2024 07:27
bluechi.spec.in Outdated Show resolved Hide resolved
selinux/bluechi.te Outdated Show resolved Hide resolved
@alexlarsson
Copy link
Contributor

Other than the default change pointed out by dan i think this looks good.

@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 0fa07a0 to 0853bb5 Compare April 4, 2024 09:09
README.developer.md Outdated Show resolved Hide resolved
engelmi added 3 commits April 4, 2024 11:52
Relates to: eclipse-bluechi#836

Previously, the SELinux policy for BlueChi only contained one
type for the port and was used only by the bluechi-agent. This
adds a new port type and and uses one for the bind of bluechi-
controller and another for the connect of bluechi-agent.
Based on this, tunable policies are added to turn on/off the
option to use any port for both components.
In addition, it removes the implicit permissive policy so that
violations to the policies are enforced by default (can be set
permissive later on by the user again).

Signed-off-by: Michael Engel <mengel@redhat.com>
Fixes: eclipse-bluechi#836

Based on the previous work, this updates the RPM spec of
BlueChi so that it does not require the semange tool and
thus is not pulling in python as a dependency anymore.
It adds also another option to the build to enable any
port policy for bluechi-controller an bluechi-agent.

Signed-off-by: Michael Engel <mengel@redhat.com>
This PR reorders the table of contents for the readthedoc
and bundles the mTLS as well as the networking and the
new SELinux subsection together under the Security section.

Signed-off-by: Michael Engel <mengel@redhat.com>
@engelmi engelmi force-pushed the loosen-selinux-port-policy branch from 0853bb5 to 382e6d5 Compare April 4, 2024 09:54
@engelmi
Copy link
Member Author

engelmi commented Apr 4, 2024

Thank you for your help! @alexlarsson @rhatdan @mwperina
Merging.

@engelmi engelmi merged commit 72c7ccb into eclipse-bluechi:main Apr 4, 2024
18 checks passed
@engelmi engelmi deleted the loosen-selinux-port-policy branch June 17, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the requirement on policycoreutils-python-utils for the bluechi-selinux package
5 participants