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

Do not error on trying to write IMA xattr as rootless #5741

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

mheon
Copy link
Member

@mheon mheon commented Sep 17, 2024

Rootless users cannot set the security.ima xattr on files (presumably for security reasons, they get an EPERM on trying to do so). We will normally try and preserve that xattr, so when trying to add a file with an IMA xattr to a build on a Buildah without this patch, you get an error. With this patch, the error is downgraded to a warning, as it's better to successfully build with a missing xattr than blocking all builds which want to include the offending file.

The urgency on this has become somewhat higher as it seems like F41/Rawhide are installing rpm-plugin-ima by default, which is setting IMA xattrs on some files that Podman relies on - for example, the catatonit binary we use for pid pause images. Without this patch, building the pause image as rootless will always fail on a system with rpm-plugin-ima installed.

Fixes: containers/podman#18543

What type of PR is this?

/kind bug

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Including a file with the `security.ima` xattr set as a non-root user will no longer fail as the xattr could not be set.

@mheon
Copy link
Member Author

mheon commented Sep 17, 2024

I don't know if testing this is particularly possible in CI, as it would require the file to be set up as root, and then an integration test run as a non-root user to verify the functionality. Could be done by including the test file in the VM images, maybe?

@rhatdan
Copy link
Member

rhatdan commented Sep 17, 2024

LGTM

@edsantiago
Copy link
Member

For testing purposes only, feel free to use c20240826t190000z-f40f39d13 (built in containers/automation_images#384). Those images have the default catatonit, i.e., do not include the Cirrus F41 workaround. See that PR diff for more.

Please do not merge with those VM images, they are old. I will be happy to build new ones if such is desired.

@mheon
Copy link
Member Author

mheon commented Sep 18, 2024

@edsantiago The Podman package is installed in the test VMs, right? That should have dragged in catatonit, which we know has IMA xattrs we can test on.

@nalind Are any of the existing integration tests run rootless?

@edsantiago
Copy link
Member

@mheon please see my comment above. TL;DR we have a kludge workaround in test VMs, where we strip IMA. Without that, we would have no CI. The test images I mention in my comment above are built without that workaround, so you can use them in your testing.

@nalind
Copy link
Member

nalind commented Sep 18, 2024

@nalind Are any of the existing integration tests run rootless?

Yes, there are rootless test jobs.

@mheon
Copy link
Member Author

mheon commented Sep 18, 2024

@edsantiago Mind taking a look at the test I added?

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.

LGTM with a few questions and nits. Suggestion:

@test "bud with ADD with file with IMA xattr" {
  _prefetch alpine

  local catatonit=/usr/libexec/catatonit/catatonit
  if [[ ! -e $catatonit ]]; then
      skip "Catatonit path $catatonit not found"
  fi

  run getfattr -d -n security.ima $catatonit
  echo "getfattr $catatonit -> '$output'"
  if [[ $status -ne 0 ]]; then
      skip "pointless: $catatonit does not have the desired xattr"
  fi

  local contextdir=${TEST_SCRATCH_DIR}/add-ima
  mkdir -p $contextdir
  cat > $contextdir/Dockerfile <<EOF
FROM alpine
ADD $catatonit /bin/catatonit
EOF

  # We do not care if the attribute was actually added, as rootless is allowed to discard it.
  # Only that the file builds successfully.
  run_buildah build $contextdir
}

Do we know if the attr package is installed in CI VMs?

tests/bud.bats Outdated

# Verify that /usr/libexec/catatonit/catatonit both exists and has an IMA xattr
if getfattr -d -m 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then
skip "catatonit does not exist or does not have an appropriate xattr"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of ambiguous skips or test failures. If I were looking at this skip, I'd want to know more.

tests/bud.bats Outdated
EOF

# Verify that /usr/libexec/catatonit/catatonit both exists and has an IMA xattr
if getfattr -d -m 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to use -m (match)? Not the tighter -n (name)?

tests/bud.bats Outdated

# We do not care if the attribute was actually added, as rootless is allowed to discard it.
# Only that the file builds successfully.
run_buildah build -f $contextdir/Dockerfile $contextdir
Copy link
Member

Choose a reason for hiding this comment

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

Can probably ditch the -f Dockerfile and save some duplication

@edsantiago
Copy link
Member

Welp. (1) Buildah CI doesn't test on rawhide; (2) Debian doesn't have attr; (3) f40 is failing in a way that makes no sense to me

@nalind
Copy link
Member

nalind commented Sep 18, 2024

The current iteration of the test doesn't ensure that there's a /usr/libexec/catatonit/catatonit under the build context directory. I'd suggest either copying it first, then checking for the extended attribute, or reworking the test to use buildah add, which should hit the same code paths.

@mheon
Copy link
Member Author

mheon commented Sep 19, 2024

@nalind Can't copy it, that strips the xattr. I'll rework to use buildah add.

@nalind
Copy link
Member

nalind commented Sep 19, 2024

/lgtm
This doesn't address cases where the a file with this xattr is part of a base image, but we don't control that in this repository.

@mheon
Copy link
Member Author

mheon commented Sep 19, 2024

I'm inclined to just let those error for now - we've never heard of a case where that has actually happened.

@mheon
Copy link
Member Author

mheon commented Sep 19, 2024

/cherry-pick v1.37

@openshift-cherrypick-robot

@mheon: once the present PR merges, I will cherry-pick it on top of v1.37 in a new PR and assign it to you.

In response to this:

/cherry-pick v1.37

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@nalind
Copy link
Member

nalind commented Sep 19, 2024

/approve
/cherry-pick release-1.37

@openshift-cherrypick-robot

@nalind: once the present PR merges, I will cherry-pick it on top of release-1.37 in a new PR and assign it to you.

In response to this:

/approve
/cherry-pick release-1.37

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Contributor

openshift-ci bot commented Sep 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, mheon, nalind

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

tests/add.bats Outdated
@@ -321,3 +321,16 @@ stuff/mystuff"
run_buildah 125 add --retry-delay=0.142857s --retry=14 --cert-dir ${TEST_SCRATCH_DIR} $cid https://localhost:${HTTP_SERVER_PORT}/randomfile
assert "$output" =~ "retrying in 142.*ms .*14/14.*"
}

@test "add file with IMA xattr" {
if getfattr -d -n 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if getfattr -d -n 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then
if ! getfattr -d -n 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then

Copy link
Member

Choose a reason for hiding this comment

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

Also note that this will not be tested in podman CI, because that only runs bud.bats. When this is vendored into podman, a new test will be required.

Rootless users cannot set the `security.ima` xattr on files
(presumably for security reasons, they get an EPERM on trying to
do so). We will normally try and preserve that xattr, so when
trying to add a file with an IMA xattr to a build on a Buildah
without this patch, you get an error. With this patch, the error
is downgraded to a warning, as it's better to successfully build
with a missing xattr than blocking all builds which want to
include the offending file.

The urgency on this has become somewhat higher as it seems like
F41/Rawhide are installing rpm-plugin-ima by default, which is
setting IMA xattrs on some files that Podman relies on - for
example, the catatonit binary we use for pid pause images.
Without this patch, building the pause image as rootless will
always fail on a system with rpm-plugin-ima installed.

Fixes: containers/podman#18543

Signed-off-by: Matt Heon <[email protected]>
@nalind
Copy link
Member

nalind commented Sep 19, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Sep 19, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit d8a9a87 into containers:main Sep 19, 2024
33 checks passed
@openshift-cherrypick-robot

@mheon: cannot checkout v1.37: error checking out "v1.37": exit status 1 error: pathspec 'v1.37' did not match any file(s) known to git

In response to this:

/cherry-pick v1.37

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-cherrypick-robot

@nalind: #5741 failed to apply on top of branch "release-1.37":

Applying: Do not error on trying to write IMA xattr as rootless
Using index info to reconstruct a base tree...
M	.cirrus.yml
M	copier/xattrs.go
M	tests/add.bats
Falling back to patching base and 3-way merge...
Auto-merging tests/add.bats
CONFLICT (content): Merge conflict in tests/add.bats
Auto-merging copier/xattrs.go
Auto-merging .cirrus.yml
CONFLICT (content): Merge conflict in .cirrus.yml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Do not error on trying to write IMA xattr as rootless
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/approve
/cherry-pick release-1.37

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mheon
Copy link
Member Author

mheon commented Sep 19, 2024

@edsantiago We should consider new VM builds once this lands in Podman. Not super urgent though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error setting extended attributes on "/catatonit"
5 participants