Skip to content

Rework LCOW username setup/exec behavior#1178

Merged
dcantah merged 2 commits intomicrosoft:masterfrom
dcantah:exec-username
Sep 29, 2021
Merged

Rework LCOW username setup/exec behavior#1178
dcantah merged 2 commits intomicrosoft:masterfrom
dcantah:exec-username

Conversation

@dcantah
Copy link
Contributor

@dcantah dcantah commented Sep 27, 2021

This change swaps to checking the OCI specs username field instead of
our custom annotation to match upstream. The real change is in how what
user an exec runs as is handled. In most places in Containerd an execed process
gets assigned the process spec of the container it’s getting launched in
(so it will inherit anything set on the container spec), but due to the nature
of LCOW there’s some OCI spec fields we set in the UVM instead as they’re not
able to be handled on the host (in a clean manner at least). One of these is
the user for the container.

On a Linux host, Containerd will check if the user exists in the filesystem for
the container before setting the user on the spec. On LCOW we just have vhd’s with
the contents of the layers when making the spec which makes this a bit infeasible, so
we defer that work until we’re in the guest and then edit the spec if the user exists.
This has the outcome that the user is never set on the containers spec on the host for
LCOW, but we do have the final amended spec in the UVM with whatever user was
requested (or was set in the image via USER and so on).

The way this is handled is by setting the Username field on the spec and then
grabbing the uid:gid based on this string in the guest. The same is done for
an exec. If a custom user is specified, try and find the uid:gid for the string
provided. Otherwise, if Username is an empty string, just inherit whatever user
the container spec contained.

Signed-off-by: Daniel Canter dcanter@microsoft.com

@dcantah dcantah requested a review from a team as a code owner September 27, 2021 22:42
This change swaps to checking the OCI specs username field instead of
our custom annotation to match upstream. The real change is in how what
user an exec runs as is handled. In most places in Containerd an execed process
gets assigned the process spec of the container it’s getting launched in
(so it will inherit anything set on the container spec), but due to the nature
of LCOW there’s some OCI spec fields we set in the UVM instead as they’re not
able to be handled on the host (in a clean manner at least). One of these is
the user for the container.

On a Linux host, Containerd will check if the user exists in the filesystem for
the container before setting the user on the spec. On LCOW we just have vhd’s with
the contents of the layers when making the spec which makes this a bit infeasible, so
we defer that work until we’re in the guest and then edit the spec if the user exists.
This has the outcome that the user is never set on the containers spec on the host for
LCOW, but we do have the final amended spec in the UVM with whatever user was
requested (or was set in the image via USER and so on).

The way this is handled is by setting the Username field on the spec and then
grabbing the uid:gid based on this string in the guest. The same is done for
an exec. If a custom user is specified, try and find the uid:gid for the string
provided. Otherwise, if Username is an empty string, just inherit whatever user
the container spec contained.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
A previous change I'd made that was just for local testing changed the panic
in our cri-containerd test suite to choose a set image. This simply reverts
that.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
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.

3 participants