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

Unset SocketLabel after system finishes checkpointing #12388

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 22, 2021

This should fix the SELinux issue we are seeing with talking to
/run/systemd/private.

Fixes: #12362

Also unset the XDG_RUNTIME_DIR if set, since we don't know when running
as a service if this will cause issue.s

Signed-off-by: Daniel J Walsh [email protected]

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 22, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 22, 2021
@rhatdan
Copy link
Member Author

rhatdan commented Nov 22, 2021

@edsantiago no idea if this will help the failure situation, but if this works we know we have a race condition.

@edsantiago
Copy link
Member

Oh, interesting idea. Thank you!

@edsantiago
Copy link
Member

Flake is #9597, restarted.

@edsantiago
Copy link
Member

And, this time, flake is #10710. Restarted.

@edsantiago
Copy link
Member

Oh well. Third flake is the one you were trying to prevent.

[+0664s] not ok 278 podman shell completion test
[+0664s] # (from function `die' in file test/system/helpers.bash, line 460,
[+0664s] #  from function `run_podman' in file test/system/helpers.bash, line 221,
[+0664s] #  in test file test/system/600-completion.bats, line 259)
[+0664s] #   `run_podman pod create --name created-$random_pod_name' failed with status 125
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE rm -t 0 --all --force
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE ps --all --external --format {{.ID}} {{.Names}}
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE images --all --format {{.Repository}}:{{.Tag}} {{.ID}}
[+0664s] # quay.io/libpod/testimage:20210610 9f9ec7f2fdef
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE create --name created-p4ZtmHxyR5m67mCgT5TLv4UFzhys05 quay.io/libpod/testimage:20210610
[+0664s] # f32e96ea3817936278c801b48d5675a117d63d8261fe9870261baf0716244cf4
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE run --name running-p4ZtmHxyR5m67mCgT5TLv4UFzhys05 -d quay.io/libpod/testimage:20210610 top
[+0664s] # 4a5d6074204f8f606a209593af8ff9cdfde138b92352fe21594828bdfdb60bf9
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE run --name pause-p4ZtmHxyR5m67mCgT5TLv4UFzhys05 -d quay.io/libpod/testimage:20210610 top
[+0664s] # ef90bd744f77dd16670a8350937a3713eb04c85fb73dd4d4c5ff2e72eda71bfb
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE pause pause-p4ZtmHxyR5m67mCgT5TLv4UFzhys05
[+0664s] # ef90bd744f77dd16670a8350937a3713eb04c85fb73dd4d4c5ff2e72eda71bfb
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE run --name exited-p4ZtmHxyR5m67mCgT5TLv4UFzhys05 -d quay.io/libpod/testimage:20210610 echo exited
[+0664s] # 77160b9c6d2f8371e9027b83504bd684024bee75e0fd13344998419c616dc6c8
[+0664s] # # /var/tmp/go/src/github.com/containers/podman/bin/podman-remote --url unix:/tmp/podman_tmp_fOdE pod create --name created-y9Rwq0XT9azRRaYJmpaNexIfeFnwpb
[+0664s] # Error: failed to make pod: unable to create pod cgroup for pod 47019f796c7be245084a4a3e867ecb5860f2ec4e09d46737f7b2e5e448ffe264: error creating cgroup machine.slice/machine-libpod_pod_47019f796c7be245084a4a3e867ecb5860f2ec4e09d46737f7b2e5e448ffe264.slice: dial unix /run/systemd/private: connect: permission denied
[+0664s] # [ rc=125 (** EXPECTED 0 **) ]

@rhatdan rhatdan force-pushed the test branch 2 times, most recently from 515d145 to 647b834 Compare November 22, 2021 21:26
@edsantiago
Copy link
Member

TIL that one can Re-run a test that passed. Took two retries but here's the log, and here's the (not-especially-helpful) excerpt:

# # podman-remote --url unix:/tmp/podman_tmp_gziP run --name exited-7rV55nsSBeNTe4r3EeAXOrusassEwD -d quay.io/libpod/testimage:20210610 echo exited
# a771a557c06e9a94b9e2e5dde9c754a29a9092dff7cd606be3e10a3e39ee3446
# srwxrwxrwx. 1 root root 0 Nov 22 20:06 /run/systemd/private
# uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0
# # podman-remote --url unix:/tmp/podman_tmp_gziP pod create --name created-XqxyN3U6CV7ZB0ut2FNZMA2AQjU15p
# Error: failed to make pod: unable to create pod cgroup for pod 3989b7fd353d90c20bc7d23316a3bc3fb356d675fca5e2071ca551d53d0cfc44: error creating cgroup machine.slice/machine-libpod_pod_3989b7fd353d90c20bc7d23316a3bc3fb356d675fca5e2071ca551d53d0cfc44.slice: dial unix /run/systemd/private: connect: permission denied

@rhatdan
Copy link
Member Author

rhatdan commented Nov 23, 2021

@giuseppe WDYT? Does not look like DAC or SELinux, could this error happen because systemd refused the connection and gave permission denied?

@rhatdan rhatdan changed the title Switch order of pod creation Unset SocketLabel after system finishes checkpointing Nov 23, 2021
@rhatdan rhatdan force-pushed the test branch 2 times, most recently from c5a2fcd to 3274ad4 Compare November 23, 2021 20:46
@rhatdan
Copy link
Member Author

rhatdan commented Nov 23, 2021

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

Very quick first pass. This is way above my head, so please take my comments (except the misspelling) with a chunk of salt.

runtime.UnlockOSThread()
if oldRuntimeDirSet {
if err = os.Setenv("XDG_RUNTIME_DIR", oldRuntimeDir); err != nil {
logrus.Warnf("cannot unsset XDG_RUNTIME_DIR: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

This should be "restore", not unset (unless I'm misunderstanding, which is very possible)

Also, should this be done in a defer? I can see code paths that would bail out before reset/unset.

}
} else {
if err = os.Unsetenv("XDG_RUNTIME_DIR"); err != nil {
logrus.Warnf("cannot unsset XDG_RUNTIME_DIR: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

one 's' in "unset"

runtime.LockOSThread()
if err := label.SetSocketLabel(ctr.ProcessLabel()); err != nil {
return 0, err
}
runtimeCheckpointStarted := time.Now()
err = utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, nil, r.path, args...)
Copy link
Member

Choose a reason for hiding this comment

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

linter is complaining about unused err

@adrianreber
Copy link
Collaborator

I have seen this error when experimenting with checkpoint and restore in CRI-O but never thought that it might be a problem for Podman. It was needed for CRI-O because it keeps running, but I have never seen it with Podman. The problem I had was that if during setting the label and resetting the label another Go thread was created it was created with the wrong socket label. I see that you are using LockOSThread() and UnlockOSThread(). I was not aware that something like that exist. Good to know.

Overall this is exactly what I tried in CRI-O (minus locking and unlocking OSThread) and looks like the right solution.

This should fix the SELinux issue we are seeing with talking to
/run/systemd/private.

Fixes: containers#12362

Also unset the XDG_RUNTIME_DIR if set, since we don't know when running
as a service if this will cause issue.s

Signed-off-by: Daniel J Walsh <[email protected]>
@edsantiago
Copy link
Member

Yay, CI is green on the first try!

@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Nov 24, 2021
@openshift-merge-robot openshift-merge-robot merged commit 04be1e6 into containers:main Nov 24, 2021
@rhatdan
Copy link
Member Author

rhatdan commented Nov 24, 2021

I am taking @adrianreber And @edsantiago as two LGTM

@giuseppe
Copy link
Member

LGTM, I had just a comment that I've fixed in a follow up PR: #12404

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[remote] error creating cgroup [...]: dial unix /run/systemd/private: connect: EPERM
5 participants