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
systemd (initrc_t) does not domain transition when executing shell_exec_t
#778
Comments
|
I also triple checked this by doing |
I don't know if it was made intentionally, but I know it is used as it is now. Any change like the suggested transition needs to be considered very carefully. |
Agree. I think what we may need to do in the short term is add some sort of easy opt-in way to do this. I guess today one can explicitly: But I think that's hardcoding too much of the policy in the unit. Hmm. Maybe something like |
|
Unless I'm mistaken, (Note: The above is based on assumptions and may not be accurate - my UNIX/SELinux beard is not that long and I don't know the full history behind all this :) If you need to enforce a specific transition for your shell-based service, you should simply put the commands into an executable file with a shell shebang, label that file with the appropriate type, and execute that file directly from the systemd unit ( |
Yes...the tricky case is more that it's often convenient to inline |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1956836 Unfortunately right now, executing `bash` skips a domain transition (see fedora-selinux/selinux-policy#778) so the way we're sourcing the script means we stay in `initrc_t` and end up triggering a SELinux policy denial. (BTW this denial turns out to just delay the successful exit of the script, which will then end up just delaying kubelet start. it's otherwise harmless, but we also don't want SELinux policy denials in our product by default) Fix this in two ways: - First, just move the thing to `/usr/local/bin` to avoid issues with labeling of `/usr/local/sbin` that were fixed in openshift/os#551 - Second, rework it to be executed directly While we're here: - Clean the confusing+outdated comment about being a NM dispatcher - Drop the `logger` bit which was only necessary as a NM dispatcher; since we're *always* running under systemd, this makes `journalctl -u node-valid-hostname` actually show the script output. - Make it crystal clear that the "truncate hostname" is only run in GCP. - Fix various typos - Use the more precise term "non-localhost" in various places instead of the more ambiguous terms "real"/"valid"
|
Ondrej is correct. Frankly, I don't know how we can help you further. For instant testing, you can use transient services: |
|
@cgwalters Currently I don't have anything else to comment on. If you don't mind, I'll close this issue. |
|
Well, I think this comment still stands - it'd be nice to have some easy way to force the domain transition for "one liners". Or perhaps even better, try to eventually flip the default and force anyone who wants the old behavior to opt-in to it. Something short and declarative in unit file syntax perhaps like: And linting tools could start emitting a warning for any systemd units which Which admittedly isn't much. But this issue sure confused the heck out of me when working on some systemd units in OpenShift. |
|
I think my notes are still valid, too. If you are not satisfied with using tools like these, let's restart and describe what is the actual goal. |
|
For the case I hit in OpenShift we wanted to define a static service, not a dynamic one via I think the point I'm trying to make here is the current behavior did probably make sense in the early days of the SysV ➡️ systemd transition, but now seems like a relic. In other words, I'd say only pid 1 should be running as We shouldn't hardcode We could try to push everything to execute code via a separate binary. But it's annoying for "one liners". Hence my argument for something simple that allows opting-in. |
|
I guess taking my argument out, even the very naming is a legacy now, i.e. it should be |
|
Colin Walters ***@***.***> writes:
Well, I think this comment still stands - it'd be nice to have some easy way to force the
domain transition for "one liners".
Or perhaps even better, try to eventually flip the default and force anyone who wants the
old behavior to opt-in to it.
Something short and declarative in unit file syntax perhaps like:
SELinuxTransition=default|legacy
And linting tools could start emitting a warning for any systemd units which
ExecStart=/bin/(ba)sh ... In a quick grep in this shell,
$ grep -rE 'ExecStart=.*/bin/(ba)?sh' /usr/lib/systemd/system/
/usr/lib/systemd/system/nfs-server.service:ExecStart=-/bin/sh -c 'if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi'
/usr/lib/systemd/system/iscsi-init.service:ExecStart=/usr/bin/sh -c 'echo "InitiatorName=`/usr/sbin/iscsi-iname`" > /etc/iscsi/initiatorname.iscsi'
/usr/lib/systemd/system/man-db-cache-update.service:ExecStart=/bin/sh -c '[ "$SERVICE" != "no" ] && /usr/bin/mandb $OPTS || true'
/usr/lib/systemd/system/debug-shell.service:ExecStart=/bin/sh
$
Which admittedly isn't much. But this issue sure confused the heck out of me when working
on some systemd units in OpenShift.
initrc_t is not the domain of pid1, that is init_t. AFAIK the difference
between initrc_t and unconfined_service_t is that there are automatic
transitions associated with with initrc_t and there are little to no
automatic transitions associated with unconfined_service_t.
That makes initrc_t handy for ExecStart=/bin/sh -c '...' because unknown
and coreutils like commands run unconfined but targeted commands run
with a automatic domain transitions. This is why ExecStart=/bin/sh -c 'bin/id' runs
with initrc_t, but if you would for example run some targeted command
like httpd like so ExecStart=/bin/sh -c '/bin/httpd' then that will
AFAIK transition to httpd_t automatically.
'sh' interprets shell code and so the policy cannot anticipate what
permissions are needed as it can in theory be anything. So the best of
both worlds is to run unknown stuff unconfined and known stuff with a
domain transition.
This does not apply to unconfined_service_t.
My 0.02$
…
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
--
gpg --locate-keys ***@***.***
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6 E0FF DA7E 521F 10F6 4098
Dominick Grift
|
|
Closing this issue as no new information has appeared since 2 months ago. |
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables.
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables.
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables.
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables. Co-authored-by: Colin Walters <walters@verbum.org>
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables.
This will reportedly fix a SELinux issue that happens with the RHEL 9 rebase for OCP 4.13, where the dispatcher policy is a bit tighter for scripts by default. See also fedora-selinux/selinux-policy#778 which is highly related to this - the policy is stricter for bash versus executables. Co-authored-by: Colin Walters <walters@verbum.org>
See https://bugzilla.redhat.com/show_bug.cgi?id=1956836#c35
And this is true on FCOS too, it has nothing to do with the label of
/usr/local/sbin.Invoking things via
bashis suppressing the domain transition. This seems like a general selinux-policy issue, though I amnot sure if it's an intentional design decision or not. I find this very surprising and it's going to be a recurring source of bugs.
Is this intentional?
The text was updated successfully, but these errors were encountered: