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

Drop present? and booted? systemd checks #11

Merged
merged 2 commits into from
Aug 29, 2020

Conversation

ehelms
Copy link
Contributor

@ehelms ehelms commented Aug 20, 2020

The check of whether NOTIFY_SOCKET is set should be sufficient for
enabling the plugin. Using this plugin and setting notify are
intentional use cases that should suffice. For systems with
SELinux enabled, the check of the systemctl binary and shelling
out to run systemctl can cause policy violations that provide
additional complications for users of the plugin.

@ehelms ehelms mentioned this pull request Aug 27, 2020
@ehelms
Copy link
Contributor Author

ehelms commented Aug 27, 2020

@sj26 If you could also take a look at this one for inclusion in the release... this simplifies things and makes SELinux less complex for projects. Appreciate you reviewing and considering!

@sj26
Copy link
Owner

sj26 commented Aug 28, 2020

I had this debate with myself when initially writing the plugin. But systemd's documentation specifically recommending using the sd_booted() function before activating systemd specific functionality, and that was calling systemd's dbus interface equivalent to this command line invocation, which is why I did it. I didn't want to introduce a dbus dependency. 😅 I'm torn between doing it "right" and making it "work".

Could you help me understand the failure case, maybe demonstrate it?

# https://www.freedesktop.org/software/systemd/man/sd_booted.html
#
def booted?
IO.popen(["systemctl", "is-system-running"], &:read).chomp != "offline"
Copy link

Choose a reason for hiding this comment

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

From that page:

Internally, this function checks whether the directory /run/systemd/system/ exists. A simple check like this can also be implemented trivially in shell or any other language.

Perhaps this better? It doesn't have to exec anything which is safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this and it worked. I know the original comment seemed to warn against this:

    # We could check for the systemd run directory directly, but we can't be
    # absolutely sure of it's location and breaks encapsulation. We can be sure
    # that systemctl is present on a systemd system and understand whether
    # systemd is running. The systemd-notify binary actually recommends this.

However, if that page on sd_booted is correct this ought to be a safe option that doesn't make things more complex for SELinux users.

Copy link

Choose a reason for hiding this comment

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

I can't find that part in the current man pages. Perhaps the recommendations have changed?

Copy link
Owner

Choose a reason for hiding this comment

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

Right, I was considering the edge case that systemd might be installed with a different prefix and so best deferred to the system's $PATH a la pkg-config. But a non-default prefix would be very irregular. I also thought that the implementation of sd_booted was more complex, but it is not, and is in fact just detecting that one and only directory path. So I'm not even sure a non-default directory is possible.

So this implementation looks good. 👍

@ehelms
Copy link
Contributor Author

ehelms commented Aug 28, 2020

The failure case arises if you are running puma within a confined SELinux process; shelling out to systemctl requires an execption:

type=AVC msg=audit(1598616113.087:3870): avc:  denied  { getattr } for  pid=459 comm="ruby" path="/usr/bin/systemctl" dev="vda1" ino=925596 scontext=system_u:system_r:foreman_rails_t:s0 tcontext=system_u:object_r:systemd_systemctl_exec_t:s0 tclass=file

lib/puma/plugin/systemd.rb Outdated Show resolved Hide resolved
For systems with SELinux enabled, the check of the systemctl binary
and shelling out to run systemctl can cause policy violations that provide
additional complications for users of the plugin.
@@ -28,10 +28,10 @@ def start(launcher)
@launcher.events.debug "systemd: WATCHDOG_PID=#{ENV["WATCHDOG_PID"].inspect}"
@launcher.events.debug "systemd: WATCHDOG_USEC=#{ENV["WATCHDOG_USEC"].inspect}"

# Only install hooks if systemd is present, the systemd is booted by
# Only install hooks if systemd is booted by
Copy link

@ekohl ekohl Aug 28, 2020

Choose a reason for hiding this comment

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

Suggested change
# Only install hooks if systemd is booted by
# Only install hooks if the system is booted by

@sj26 sj26 merged commit dfea7d6 into sj26:master Aug 29, 2020
@sj26
Copy link
Owner

sj26 commented Aug 29, 2020

Thanks! 🙌

@sj26
Copy link
Owner

sj26 commented Aug 29, 2020

Released in v0.1.5

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.

3 participants