Skip to content

Conversation

@jterry75
Copy link
Contributor

Adds support for Windows container images built by Docker
that contain the ArgsEscaped boolean in the ImageConfig. This
is a non-OCI entry that tells the runtime that the Entrypoint
and/or Cmd are a single element array with the args pre-escaped
into a single CommandLine that should be passed directly to
Windows rather than passed as an args array which will be
additionally escaped.

Signed-off-by: Justin Terry [email protected]

@k8s-ci-robot
Copy link

Hi @jterry75. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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/test-infra repository.

@jterry75
Copy link
Contributor Author

Should resolve: #5067

@jterry75 jterry75 requested review from kevpar and kzys January 26, 2022 22:26
@jterry75
Copy link
Contributor Author

@thaJeztah - Know its been ages since you have thought about this problem :). But mind taking a look as well?

Copy link
Member

@kzys kzys left a comment

Choose a reason for hiding this comment

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

Looks good to me. I personally prefer to have that in OCI Image Spec for interoperability. The last time, @kevpar opened and closed the issue. So it wasn't really discussed much.

opencontainers/image-spec#829

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM; reasoning makes sense.

But I agree it makes sense to re-open the image-spec discussion in the OCI if this is the long-term direction/solution for this on Windows.

@jterry75
Copy link
Contributor Author

I actually already made the carry of the image spec changes and then decided to do it this way I'll open that PR right now. Maybe we can just get this formally supported in OCI and then we don't have to hack it here. It will be the exact same solution just wont need the extended structs.

@kevpar
Copy link
Member

kevpar commented Jan 27, 2022

Our current thinking internally was that ArgsEscaped in the image spec is kind of a hack. The reality is that Windows doesn't naturally use an argument array for launching a process, but rather a single command line. The idea was instead of formalizing ArgsEscaped on the image spec, we should instead add a CommandLine field (or perhaps EntrypointCommandLine/CmdCommandLine to match Entrypoint/Cmd), since this more naturally represents Windows process launching capabilties. This would also mirror the Args/CommandLine split on the runtime spec.

So I would suggest we consider that for the image spec change, rather than reviving my old PR. :)

@kevpar
Copy link
Member

kevpar commented Jan 27, 2022

By the way, thanks @jterry75 for working on this!

@thaJeztah
Copy link
Member

I saw the ping, but haven't had time yet to read up (will try to if still needed); I do recall indeed that this was a bit "hairy", and a bit of a hack.

@kzys
Copy link
Member

kzys commented Jan 27, 2022

From the implementations' standpoint, it would be great if following OCI Image Spec assures that existing container images work as expected. I see the Image Spec as a "retro" spec like HTML5, rather than an aspiring new standard like XHTML.

So while I don't have strong opinions regarding CommandLine (I honestly am not familiar about the semantics in Windows), I'd like to see ArgsEscaped documented and standardnized, even that is considered as Deprecated from the beginning.

@jterry75
Copy link
Contributor Author

I'm ok with continuing to drive ArgsEscaped into OCI even if deprecated just to signify that a world out there exists that already uses this. But are we ok doing that separate from this PR? Do we need that to happen before we can take this PR to support these types of images today?

@kzys
Copy link
Member

kzys commented Jan 28, 2022

I'm fine having OCI discussions later.


// WithImageConfigArgs configures the spec to from the configuration of an Image with additional args that
// replaces the CMD of the image
func WithImageConfigArgs(image Image, args []string) SpecOpts {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like WithImageConfigArgs is not used by CRI. I think we would need a similar change here as well.

@kevpar
Copy link
Member

kevpar commented Jan 28, 2022

I like the idea of adding ArgsEscaped to OCI and immediately marking it as deprecated, and also figuring out the right long term solution (such as CommandLine). Agree we can get this in to fix these images working in containerd, and worry about OCI later.

@jterry75 I'll give this more of a look on Monday.

/ok-to-test

@jterry75
Copy link
Contributor Author

I like the idea of adding ArgsEscaped to OCI and immediately marking it as deprecated, and also figuring out the right long term solution (such as CommandLine). Agree we can get this in to fix these images working in containerd, and worry about OCI later.

@jterry75 I'll give this more of a look on Monday.

/ok-to-test

Sounds like a plan!

@kzys
Copy link
Member

kzys commented Jan 31, 2022

BTW would this fix #6300?

@kevpar
Copy link
Member

kevpar commented Jan 31, 2022

BTW would this fix #6300?

Yup, that looks like the same issue as #5067, which this will fix.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Some random thoughts / suggestions 😅

@jterry75 jterry75 force-pushed the jterry75/args_escaped branch from f032016 to 124dde3 Compare February 2, 2022 20:34
@jterry75
Copy link
Contributor Author

jterry75 commented Feb 2, 2022

@kevpar - Still need to look at CRI WithProcessArgs you left. But this fixes all of @thaJeztah's comments.

@jterry75
Copy link
Contributor Author

jterry75 commented Feb 2, 2022

@kevpar - Turns out this is quite complicated to fix for CRI. There are two entrypoints for CRI via for sandbox_run and container_create. For both cases they apply with opts.WithProcessArgs as you linked above. Problem is that these operate on a v1.ImageConfig which has already been pre-resolved. So we cannot do any extra logic here to deserialize and try to handle this with a forked implementation as it exists today.

I looked at instead trying to do this by updating the callers to use WithImageConfigArgs from the oci package and then WithProcessArgs if the config has overrides but again, the oci package from containerd expects a containerd.Image not an v1.Image. Because of this mismatch we would need to re-write the apply logic in CRI for both Windows and Linux which seems risky in the scope of this change. I do think it needs to be done though as there is literally zero reason that CRI should have a forked application here.

oci.WithImageConfigArgs applies Env, Cwd, User, Args and on Windows potentially CommandLine. It also takes care of appending additional args via the config passed in.

And sandbox_run and container_create do the exact same code.... and eventually the custom WithProcessArgs func that again, overloads the same code for image arg combining.

CRI should in theory be able to say:

`WithImageConfigArgs(image, config.Args)`
if (len(config.GetCommand()) > 0) {
  WithProcessArgs(append(config.Command, config.Args)) // Overwrite image default entrypoint/command
}
if (config.User != "") {
  WithUser(...) // Overwrite image spec user.
}

You get the idea, but this will be a very large change to do in this PR.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM (but it's related to windows things, so won't hurt to have more eyes 🤗)

Thanks for making the changes 👍

@jterry75
Copy link
Contributor Author

jterry75 commented Feb 7, 2022

Anything else needed here? Would love to get this in if no objections. Thanks

@jterry75
Copy link
Contributor Author

Ok, @kevpar - We now have a test case for every combination of Entrypoint, Cmd, Args for both ArgsEscaped==false (the normal, sane, supported, actually good, way), and ArgsEscaped==true (the ...). I believe this mirrors Docker behavior and solves the problem for the exact same set of cases Docker supports. Plz take one final look

@kevpar
Copy link
Member

kevpar commented Feb 25, 2022

I think my only final feedback is we should probably add a comment summarizing the discussion/design decisions that went into this. Since from looking at it it's pretty unintuitive what it's doing and why.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 25, 2022

Build succeeded.

@jterry75 jterry75 force-pushed the jterry75/args_escaped branch from 87afb83 to 4fec5ea Compare February 25, 2022 23:23
@jterry75
Copy link
Contributor Author

jterry75 commented Feb 25, 2022

I think my only final feedback is we should probably add a comment summarizing the discussion/design decisions that went into this. Since from looking at it it's pretty unintuitive what it's doing and why.

Done.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 25, 2022

Build succeeded.

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM. Test failure appears unrelated.

@kevpar
Copy link
Member

kevpar commented Mar 1, 2022

@kzys @thaJeztah @estesp would one of you mind re-reviewing? The logic has changed quite a bit.

Adds support for Windows container images built by Docker
that contain the ArgsEscaped boolean in the ImageConfig. This
is a non-OCI entry that tells the runtime that the Entrypoint
and/or Cmd are a single element array with the args pre-escaped
into a single CommandLine that should be passed directly to
Windows rather than passed as an args array which will be
additionally escaped.

Signed-off-by: Justin Terry <[email protected]>
@jterry75 jterry75 force-pushed the jterry75/args_escaped branch from 4fec5ea to de3d999 Compare March 1, 2022 21:40
@theopenlab-ci
Copy link

theopenlab-ci bot commented Mar 1, 2022

Build succeeded.

@dmcgowan dmcgowan merged commit 2a3f109 into containerd:main Mar 1, 2022
@jterry75
Copy link
Contributor Author

jterry75 commented Mar 1, 2022

IT MERGED!!!!!! Thanks all

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.

8 participants