Skip to content

Commit 50a5685

Browse files
committed
Change oci.WithUser behavior for LCOW
The `oci.WithUser` function relies on checking a path on the hosts disk to grab/validate the uid:gid pair for the user string provided. For LCOW it's a bit harder to confirm that the user actually exists on the host as a rootfs isn't mounted on the host and shared into the guest, but rather the rootfs is constructed entirely in the guest itself. To accomodate this, a spot to place the user string provided by a client as-is is needed. The `Username` field on the runtime spec is marked by Platform as only for Windows, and in this case it *is* being set on a Windows host at least, but will be used as a temporary holding spot until the guest can use the string to perform these same operations to grab the uid:gid inside. Signed-off-by: Daniel Canter <[email protected]>
1 parent 7ddf5e5 commit 50a5685

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

oci/spec_opts.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,18 @@ func WithNamespacedCgroup() SpecOpts {
522522
func WithUser(userstr string) SpecOpts {
523523
return func(ctx context.Context, client Client, c *containers.Container, s *Spec) error {
524524
setProcess(s)
525+
526+
// For LCOW it's a bit harder to confirm that the user actually exists on the host as a rootfs isn't
527+
// mounted on the host and shared into the guest, but rather the rootfs is constructed entirely in the
528+
// guest itself. To accommodate this, a spot to place the user string provided by a client as-is is needed.
529+
// The `Username` field on the runtime spec is marked by Platform as only for Windows, and in this case it
530+
// *is* being set on a Windows host at least, but will be used as a temporary holding spot until the guest
531+
// can use the string to perform these same operations to grab the uid:gid inside.
532+
if s.Windows != nil && s.Linux != nil {
533+
s.Process.User.Username = userstr
534+
return nil
535+
}
536+
525537
parts := strings.Split(userstr, ":")
526538
switch len(parts) {
527539
case 1:
@@ -663,7 +675,9 @@ func WithUserID(uid uint32) SpecOpts {
663675
// WithUsername sets the correct UID and GID for the container
664676
// based on the image's /etc/passwd contents. If /etc/passwd
665677
// does not exist, or the username is not found in /etc/passwd,
666-
// it returns error.
678+
// it returns error. On Windows this sets the username as provided,
679+
// the operating system will validate the user when going to run
680+
// the container.
667681
func WithUsername(username string) SpecOpts {
668682
return func(ctx context.Context, client Client, c *containers.Container, s *Spec) (err error) {
669683
setProcess(s)

0 commit comments

Comments
 (0)