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

Ensure that --userns=keep-id sets user in config #9942

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

mheon
Copy link
Member

@mheon mheon commented Apr 5, 2021

One of the side-effects of the --userns=keep-id command is switching the default user of the container to the UID of the user running Podman (though this can still be overridden by the --user flag). However, it did this by setting the UID and GID in the OCI spec, and not by informing Libpod of its intention to switch users via the WithUser() option. Because of this, a lot of the code that should have triggered when the container ran with a non-root user was not triggering. In the case of the issue that this fixed, the code to remove capabilities from non-root users was not triggering. Adjust the keep-id code to properly inform Libpod of our intention to use a non-root user to fix this.

Also, fix an annoying race around short-running exec sessions where Podman would always print a warning that the exec session had already stopped.

Fixes #9919

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 5, 2021
@mheon
Copy link
Member Author

mheon commented Apr 5, 2021

Still need to write tests

@mheon
Copy link
Member Author

mheon commented Apr 5, 2021

@edsantiago Poke - do we have an issue for exec throwing warnings to the effect of:

WARN[0000] Error resizing exec session 626b91169ae09e7feb2ad75ebf595a53a8ed2b0455d60347aba6b6a6c1b0ce96: could not open ctl file for terminal resize for container 9ecdf6282b9d7824e6b681b3d40cb39a5c0c83ded8cf42860b470e3e0d853b3d: open /home/mheon/.local/share/containers/storage/overlay-containers/9ecdf6282b9d7824e6b681b3d40cb39a5c0c83ded8cf42860b470e3e0d853b3d/userdata/626b91169ae09e7feb2ad75ebf595a53a8ed2b0455d60347aba6b6a6c1b0ce96/ctl: no such device or address 

I think I remember one but I can't find it. Anyways, that's fixed here.

@mheon mheon force-pushed the fix_9919 branch 2 times, most recently from 0ccf569 to 752a39b Compare April 5, 2021 20:14
@rhatdan
Copy link
Member

rhatdan commented Apr 5, 2021

@mheon if I do a podman inspect after this is done, does the user say the UID/GID of the calling user?

@mheon
Copy link
Member Author

mheon commented Apr 5, 2021

@rhatdan Yep:

mheon@Marlborough containers/podman (fix_9919) » podman inspect -l  | grep User                  
            "User": "1000:1000",

Before:

mheon@Marlborough containers/podman (fix_9919) » podman inspect -l  | grep User
            "User": "",

@edsantiago
Copy link
Member

@mheon that error doesn't look familiar, and I can't find any emails with "ctl" and "resizing" nor "resizing" and "exec" in my well-indexed archives. If you want tests, take a look at the new https://github.com/containers/podman/blob/master/test/system/450-interactive.bats

@mheon
Copy link
Member Author

mheon commented Apr 5, 2021

Unfortunately, it still says:

            "UsernsMode": "private",

I think that's a separate, more involved fix, though.

@mheon
Copy link
Member Author

mheon commented Apr 5, 2021

@edsantiago Huh. It is a race, so if CI isn't seeing it, my working theory is that CI is too slow to actually experience it.

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

One of the side-effects of the `--userns=keep-id` command is
switching the default user of the container to the UID of the
user running Podman (though this can still be overridden by the
`--user` flag). However, it did this by setting the UID and GID
in the OCI spec, and not by informing Libpod of its intention to
switch users via the `WithUser()` option. Because of this, a lot
of the code that should have triggered when the container ran
with a non-root user was not triggering. In the case of the issue
that this fixed, the code to remove capabilities from non-root
users was not triggering. Adjust the keep-id code to properly
inform Libpod of our intention to use a non-root user to fix
this.

Also, fix an annoying race around short-running exec sessions
where Podman would always print a warning that the exec session
had already stopped.

Fixes containers#9919

Signed-off-by: Matthew Heon <[email protected]>
@mheon
Copy link
Member Author

mheon commented Apr 6, 2021

Added a check in Libpod to make sure this doesn't happen again. Test added. Should be good to merge.

Copy link
Member

@rhatdan rhatdan left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2021
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2021
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, mheon, 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:
  • OWNERS [giuseppe,mheon,rhatdan]

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

@mheon
Copy link
Member Author

mheon commented Apr 6, 2021

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2021
@openshift-merge-robot openshift-merge-robot merged commit 382b5b8 into containers:master Apr 6, 2021
@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 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 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.

process capabilities for run / exec are inconsistent when --userns=keep-id is set
6 participants