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

cmd: add detection for containers and pid1 #248

Closed
wants to merge 2 commits into from

Conversation

flotter
Copy link
Contributor

@flotter flotter commented Jun 26, 2023

The system manager currently makes some assumptions about the environment it is running in.

For example, it assumes that a shutdown program is available in userspace and accessible with PATH configured appropriately.

internals/daemon/daemon.go:
:
cmd := exec.Command("shutdown", "-r", ...
:

This patch adds two detection mechanisms that will allow code to make environment specific decisions in the future (not part of this patch):

  • cmd.IsConfined() returns true if running inside a container runtime

  • cmd.IsInit() returns true if the system manager was started as PID 1

In addition, the overlord code currently disables reboot failure detection if the system manager is running as PID 1. However, this change is only required for container runtimes, and not generically.

  • Update the boot id workaround code to only apply for container runtimes.

@flotter
Copy link
Contributor Author

flotter commented Jun 26, 2023

@cjdcordeiro @hpidcock Could I kindly use your expertise to scrutinise the proposed change to the boot id code for containers, as well as the container detection logic?

Copy link
Member

@hpidcock hpidcock left a comment

Choose a reason for hiding this comment

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

A few comments but otherwise looks ok.

cmd/version.go Outdated Show resolved Hide resolved
cmd/version.go Outdated Show resolved Hide resolved
cmd/version.go Outdated Show resolved Hide resolved
cmd/version.go Outdated Show resolved Hide resolved

// ResetContainerInit forces the container runtime check
// to retry with globals reset
func ResetContainerInit() {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this if we seperate out the logic from the variable/sync


// MockPid2ProcPath assigns a temporary path to where the PID2
// status can be found.
func MockPid2ProcPath(path string) (restore func()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, if we allow the implementation to be tested directly, we don't need this.

cmd/version.go Outdated Show resolved Hide resolved
cmd/version.go Outdated Show resolved Hide resolved
@cjdcordeiro cjdcordeiro requested a review from woky June 27, 2023 11:51
Copy link
Contributor

@woky woky left a comment

Choose a reason for hiding this comment

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

Nifty! It seems there's no more straightforward way to tell from a child PID namespace that a process is in a child PID namespace. Besides comments by Harry, LGTM.

EDIT: OK, it can by thwarted by --pid host as in the comment above.

The system manager currently makes some assumptions about the environment
it is running in.

For example, it assumes that a shutdown program is available in userspace
and accessible with PATH configured appropriately.

internals/daemon/daemon.go:
:
cmd := exec.Command("shutdown", "-r", ...
:

This patch adds two detection mechanisms that will allow code to make
environment specific decisions in the future (not part of this patch):

- cmd.IsConfined() returns true if running inside a container runtime

- cmd.IsInit() returns true if the system manager was started as PID 1

In addition, the overlord code currently disables reboot failure detection
if the system manager is running as PID 1. However, this change is only
required for container runtimes, and not generically.

- Update the boot id workaround code to only apply for container runtimes.
@flotter
Copy link
Contributor Author

flotter commented Jun 29, 2023

Sorry people for talking your time for reviews on this, but it was agreed the scope at which I was trying to solve my own little problem is too inflated here, so I am going to have to close this for now. Perhaps this will be needed again.

The next person to find this closed PR with a hope to detect container runtimes / VMs - have a look here:

virt-what from Redhat

systemd-detect-virt from Systemd

@flotter flotter closed this Jun 29, 2023
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.

4 participants