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

unshare: fix creating a userns when running as root #1415

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

giuseppe
Copy link
Member

this check would prevent the function to ever be used when running as root, since we won't check what capabilities are currently available to the process.

Signed-off-by: Giuseppe Scrivano gscrivan@redhat.com

@rhatdan
Copy link
Member

rhatdan commented Oct 28, 2022

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

What is this actually fixing?

Some situation where we are in a user namespace already, one that wasn’t created by this subpackage (no environment variables), we do have CAP_ADMIN (per IsRootless), but don’t have some other capability?

Something else?

Does that mean that the semantics of IsRootless is also incorrect and needs updating? (The documentation of IsRootless says basically nothing, so I have absolutely no idea.)


I’m not saying that this change is incorrect, I’m saying that I have no way to tell, and this might be a good opportunity to actually clarify the semantics.

@@ -464,11 +464,6 @@ func bailOnError(err error, format string, a ...interface{}) { // nolint: golint

// MaybeReexecUsingUserNamespace re-exec the process in a new namespace
func MaybeReexecUsingUserNamespace(evenForRoot bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this changes the semantics of the function in caller-visible ways, I’d expect that to show up at least in the documentation, if not in the name.

IMHO doc strings should be enough for a caller to understand what the function does (from the caller’s perspective) without needing to read the implementation, and this one is way below that standard.

this check would prevent the function to ever be used when running
as root, since we won't check what capabilities are currently
available to the process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the fix-maybe-reexec-using-userns branch from dbc6c4e to 1af3928 Compare October 29, 2022 19:21
@giuseppe
Copy link
Member Author

What is this actually fixing?

the issue I've observed is that if we run as root but without CAP_SYS_ADMIN, then the function exits immediately without creating the user namespace as it was asked to do.

I've changed the patch so we avoid the additional checks if we an unprivileged user (uid > 0) created the user namespace and we are not already running with euid == 0

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM Just confirming that this PR does not appears to be functionally changing anything and just avoiding checks for capabilities when it is guaranteed that efffective UID is 0 and this is rootless session.

@giuseppe
Copy link
Member Author

giuseppe commented Nov 4, 2022

can we please move this forward? It is needed for buildah inside a container

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM
/lgtm

@slonopotamus
Copy link

It is needed for buildah inside a container

This change broke my usage of buildah inside container.

Before this change:

$ docker run --rm -it quay.io/buildah/stable:v1.28.0 buildah unshare echo hi
hi

After this change:

$ docker run --rm -it quay.io/buildah/upstream:latest buildah unshare echo hi
Error during unshare(CLONE_NEWUSER): Operation not permitted
ERRO[0000] parsing PID "": strconv.Atoi: parsing "": invalid syntax 
ERRO[0000] (Unable to determine exit status)

@rhatdan
Copy link
Member

rhatdan commented Feb 8, 2023

@giuseppe WDYT?

@slonopotamus
Copy link

slonopotamus commented Feb 8, 2023

We've discussed that a bit in containers/buildah#4538, but since they're kinda separate issues, I've created containers/buildah#4563 specifically to address regression.

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.

None yet

5 participants