-
Notifications
You must be signed in to change notification settings - Fork 198
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
Move reboot handling to client #2845
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just some questions/comments.
@@ -1526,7 +1526,10 @@ deploy_transaction_execute (RpmostreedTransaction *transaction, | |||
} | |||
|
|||
if (deploy_has_bool_option (self, "reboot")) | |||
rpmostreed_reboot (cancellable, error); | |||
{ | |||
sd_journal_print (LOG_INFO, "daemon-initiated reboot is deprecated"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just wondering why we don't log a warning in the other methods too (e.g. initramfs_etc_transaction_execute()
, kernel_arg_transaction_execute()
, rollback_transaction_execute()
, etc.)? Or if they should never be used anyways, since no one should be calling with that option, what if we just removed rpmostreed_reboot()
from those functions?
For Zincati's purposes though, since it cares about the rpm-ostree finalize-deployment
CLI command, which eventually calls the finalize_deployment_transaction_execute()
daemon function, it looks like the reboot will still be on the daemon side. Is it possible to move the reboot to the client side for rpm-ostree finalize-deployment
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initramfs_etc_transaction_execute()
Good catch! I missed at least that one because it used a different function for looking up the "reboot"
flag so my code search missed it. Will update.
Is it possible to move the reboot to the client side for rpm-ostree finalize-deployment too?
Ah right, I should have mentioned this in the PR. I looked at finalize-deployment
but the problem I see is that (this relates to your first point too) the DBus API should generally be considered a stable interface.
For example, https://github.com/cockpit-project/cockpit-ostree/blob/master/src/client.js and https://gitlab.gnome.org/GNOME/gnome-software/-/blob/master/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
So what we'd likely need to do for e.g. finalize-deployment
is add a reboot
option, make it the default, and have our CLI pass FALSE
or so.
Probably cleanest as a followup PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Decided to fix FinalizeDeployment
in this PR too, then we can log the deprecation in one place)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think CI highlighted a regression here. The previous reboot logic was reachable by non-privileged processes through polkit ACL. This new code instead moves it client-side, where the same processes cannot directly trigger a reboot. That is the case for zincati
:
zincati[1029]: [ERROR] failed to finalize deployment: rpm-ostree finalize-deployment failed:
zincati[1029]: Failed to set wall message, ignoring: Interactive authentication required.
zincati[1029]: Failed to reboot system via logind: Interactive authentication required.
zincati[1029]: Failed to open initctl fifo: Permission denied
zincati[1029]: Failed to talk to init daemon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm. OK what about actually pushing the reboot
all the way into zincati, i.e. we extend the polkit rules there to allow it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be fine for zincati specifically, I'll look into if/how it can be done directly in polkit (I think so) or granular capabilities.
I am not sure about other consumers though, in particular the ones running containerized under their own PID namespace where "reboot" has a bit more nuances.
gboolean | ||
rpmostree_client_reboot (GError ** error) | ||
{ | ||
execlp ("reboot", "reboot", NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this exec
really intended here? I was somehow expecting some kind of fork+exec spawning (like in the original rpmostreed_reboot
). This way instead it looks a bit like a dangerous landmine, because in the non-error case any other code following this function call won't really be reached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a non-error case, the process will get killed by SIGTERM
at some point soon later, so any code after would be inherently racy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-note, I had a personal doubt related to blocking-behavior of this action, and I double-checked the systemd manual:
This command is asynchronous; it will return after the reboot operation is enqueued, without waiting for it to complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brutal but fair point. Although Rust type-system represents such kind of never-returning functions, while here it's one more thing to keep in mind. At least a comment would help to highlight the intentional blackhole.
Anyway I agree this way it makes potential races obvious upfront, and we don't seem to currently have any critical logic running afterwards, so fine for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it can return, just on error. This is where the Rust type system shows its strength because unlike almost every other function it doesn't return Result<()>
it returns Error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you're completely right that the command itself is async...which is not usually what one wants. But that's also not a new issue here. The bug we're fixing is that the client can sometimes spuriously exit with an error because the daemon gets killed before it can send the success reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"never" as in the underlying diverging a case which can't be represented here. Sorry English language is confusing :)
Anyway I think we are in agreement. Mind adding a docstring highlighting that the TRUE
case does not really return from this function blackhole and the whole execution flow diverges instead, and then we land it?
Having the daemon start the reboot means that it can be killed by `SIGTERM` before the client processes the completion, causing the client to exit with a spurious error. Instead, have the client start the reboot. This is cleaner in numerous ways. An additional benefit for example is that if there are systemd reboot inhibitors present, it will be the client that blocks, not the daemon.
Alternative to coreos#2845 which moved the `reboot` invocation into the client (which I think still makes sense in some cases). Previously we were starting the reboot before we're returned a success reply to the client, so it could see the daemon killed by `SIGTERM` and hence emit a spurious error. (Really in this case any 3 of the calling process, the client binary or the daemon could be killed in any order, so it's messy but this just closes one race) For cleanliness we reject starting any new transactions after the daemon has started a reboot. Closes: coreos#1348
Closing in favor of #2848 |
Alternative to #2845 which moved the `reboot` invocation into the client (which I think still makes sense in some cases). Previously we were starting the reboot before we're returned a success reply to the client, so it could see the daemon killed by `SIGTERM` and hence emit a spurious error. (Really in this case any 3 of the calling process, the client binary or the daemon could be killed in any order, so it's messy but this just closes one race) For cleanliness we reject starting any new transactions after the daemon has started a reboot. Closes: #1348
Having the daemon start the reboot means that it can be killed
by
SIGTERM
before the client processes the completion, causingthe client to exit with a spurious error.
Instead, have the client start the reboot. This is cleaner
in numerous ways. An additional benefit for example is that
if there are systemd reboot inhibitors present, it will be
the client that blocks, not the daemon.