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

Adds file context for runner script with SELinux enabled #1607

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krayon
Copy link

@krayon krayon commented Jan 13, 2022

When SELinux is Enforcing, the initrc_exec_t context is needed in order for systemd to execute the script and start the runner.

This patch adds the adding and removing of this context from the script for the svc.sh install and svc.sh uninstall commands respectively.

NOTE: A potential alternative to this may be to make the systemd process a user instance instead of a system one however that would require more significant changes and require the system to be configured with lingering user systemd services for the given user (loginctl enable-linger [username])

Fixes #1606
Related: #1193

@krayon krayon requested a review from a team as a code owner January 13, 2022 07:14
Comment on lines +90 to +91
semanage fcontext --add --type initrc_exec_t "${RUNNER_ROOT}/runsvc.sh" ||\
semanage fcontext --modify --type initrc_exec_t "${RUNNER_ROOT}/runsvc.sh" ||\

Choose a reason for hiding this comment

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

semanage doesn't appear to be installed on a stock Fedora system

Choose a reason for hiding this comment

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

$ sudo chcon -t initrc_exec_t runsvc.sh

has worked locally. Of course that's only a temporary relabelling but wanted to let you know you've got the right context.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @istathar , how annoying. CentOS and RedHat do ship with semanage. I guess the other option is to check for the context and bail if:

  1. Context is wrong; and
  2. no semanage is present

Copy link
Member

Choose a reason for hiding this comment

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

I created a new CentOS 8 Azure VM and it doesn't come with semanage 😢

if [[ "${selinuxEnabled}" == "Enforcing" ]]; then
# We will need to add the initrc_exec_t context for the script
# (if we can't add, softfail first and try modify instead)
semanage fcontext --add --type initrc_exec_t "${RUNNER_ROOT}/runsvc.sh" ||\
Copy link
Member

Choose a reason for hiding this comment

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

should we error if we can't find semanage installed?

Copy link
Author

@krayon krayon Feb 3, 2022

Choose a reason for hiding this comment

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

Yes, I guess we can either:

  • Bail if SELinux is enabled and Enforcing but semanage isn't present; or
  • Report the issue to the user but continue to fail (as it does now).

Additionally, we could optionally check the context in case they've done something clever and the file has inherited the correct context anyway. In my tests with CentOS semanage was installed but right now we have more reports of it missing than present so it may have been how I did my installation.

Copy link

@JAORMX JAORMX Jun 29, 2022

Choose a reason for hiding this comment

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

Well, you could probably still adjust the context even if SELinux is not enforcing. I'd just check if semanage is installed and try do do the context change.... or use chcon as suggested in a comment above.

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.

SELinux Enforcing stops systemd service from starting
4 participants