Skip to content

Conversation

@dcantah
Copy link
Contributor

@dcantah dcantah commented Oct 22, 2021

We already escape the arguments passed to us by Containerd to form a
Windows style commandline, however the commandline was being split back
into arguments and then passed to exec.Cmd from the go stdlib. exec.Cmd
internally also does escaping, which ended up applying some extra quotes
in some cases where the commandline had double/single quotes present. This change
just passes the commandline as is to the Cmdline field on the Windows
syscall.SysProcAttr. Go takes this field as is and doesn't do any further
processing on it which is the behavior we desire.

@dcantah dcantah requested a review from a team as a code owner October 22, 2021 22:17
@katiewasnothere
Copy link

Is there a test we could add here?

@dcantah
Copy link
Contributor Author

dcantah commented Oct 22, 2021

Is there a test we could add here?

Oh oop, this was supposed to be draft. Mark confirmed the commandline looks fine now but he's running tests right now to make sure it works. And, probably? Not sure how best to test this as it was Go doing the mangling. I guess we could have some binary that checks os.Args to make sure there's no wonky quotes in a specific position.

@dcantah dcantah marked this pull request as draft October 22, 2021 22:27
@dcantah dcantah force-pushed the jobcontainer-cmdline-fix branch from ed85b3d to 594236e Compare October 22, 2021 23:39
@dcantah
Copy link
Contributor Author

dcantah commented Oct 22, 2021

@katiewasnothere Added a test. Will wait to hear back from Mark on if his experiment worked now.

We already escape the arguments passed to us by Containerd to form a
Windows style commandline, however the commandline was being split back
into arguments and then passed to exec.Cmd from the go stdlib. exec.Cmd
internally also does escaping, which ended up applying some extra quotes
in some cases where the commandline had double/single quotes present. This change
just passes the commandline as is to the Cmdline field on the Windows
syscall.SysProcAttr. Go takes this field as is and doesn't do any further
processing on it which is the behavior we desire.

Signed-off-by: Daniel Canter <[email protected]>
This change adds a test to verify that commandlines with quotes don't get
additional quotes added on to them when combining the arguments given.

Signed-off-by: Daniel Canter <[email protected]>
@dcantah dcantah force-pushed the jobcontainer-cmdline-fix branch from 594236e to bc5e914 Compare October 25, 2021 16:57
@dcantah dcantah marked this pull request as ready for review October 26, 2021 21:40
@dcantah
Copy link
Contributor Author

dcantah commented Oct 26, 2021

@katiewasnothere Mark confirmed this works, PTAL

@dcantah
Copy link
Contributor Author

dcantah commented Oct 26, 2021

@anmaxvl @ambarve @helsaawy Anyone able to give this a quick check?

@@ -0,0 +1,11 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

I use this to debug arg parsing issues:

package main

import (
	"fmt"
	"os"
)

func main() {
	for i, arg := range os.Args {
		fmt.Printf("%d: %s\n", i, arg)
	}
}

Find it a little easier to understand with the numbered args.

Copy link
Contributor Author

@dcantah dcantah Oct 26, 2021

Choose a reason for hiding this comment

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

Would you prefer we do this here and check a specific position for the test?

Copy link
Member

Choose a reason for hiding this comment

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

I think it will make it slightly easier to tell what's going on if something breaks

// from whatever process is going to launch the container.
CreationFlags: windows.CREATE_NEW_PROCESS_GROUP | windows.CREATE_BREAKAWAY_FROM_JOB,
Token: syscall.Token(token),
CmdLine: commandLine,
Copy link
Member

Choose a reason for hiding this comment

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

yay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ashamed I didn't know of this

Copy link
Member

Choose a reason for hiding this comment

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

Learning is fun though

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.

Little suggestion but LGTM either way

@dcantah
Copy link
Contributor Author

dcantah commented Oct 27, 2021

@kevpar Thanks for review! I have a note to add some extra job container tests regardless so I think I'll check this in and revisit the arg image layout and maybe add some more tests regarding cmdline.

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.

Command line arguments are process differently for HostProcess containers and Windows Server containers

3 participants