-
Notifications
You must be signed in to change notification settings - Fork 275
Set PATHEXT for job containers to handle binaries with no extension #1174
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
Set PATHEXT for job containers to handle binaries with no extension #1174
Conversation
This change sets the PATHEXT environment variable which Go checks during exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon separated list of extensions to check against if a path ended without one (e.g. /path/to/my/binary). This simply adds an empty string entry to the end so that binaries with no extension can be launched correctly. Although this isn't a common occurrence it's still a good thing to support. Windows Server containers are able to handle this fine, and CreateProcess is perfectly happy launching a valid executable without an extension. This is mainly to support the agnhost image which is a common k8s testing image whose entrypoint is a binary named agnhost with no extension. https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows Signed-off-by: Daniel Canter <[email protected]>
| if err := os.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD; "); err != nil { | ||
| return nil, errors.Wrap(err, "failed to set PATHEXT") | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add this only to the environment that's passed to the cmd instead of setting it on the running environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed to find the process to launch in the first place so nope. Basically exec.Cmd calls exec.LookPath as one of the steps before launching the process and this is what fails as it doesn't treat a file with an extension not in its default set of extensions (and no extension falls in this category) as valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we're adding an empty string entry so it deems this as valid now.
Related work items: microsoft#1062, microsoft#1087, microsoft#1089, microsoft#1095, microsoft#1104, microsoft#1112, microsoft#1117, microsoft#1118, microsoft#1125, microsoft#1137, microsoft#1139, microsoft#1140, microsoft#1141, microsoft#1142, microsoft#1143, microsoft#1145, microsoft#1146, microsoft#1150, microsoft#1151, microsoft#1153, microsoft#1154, microsoft#1155, microsoft#1156, microsoft#1157, microsoft#1158, microsoft#1159, microsoft#1161, microsoft#1162, microsoft#1163, microsoft#1164, microsoft#1165, microsoft#1166, microsoft#1167, microsoft#1168, microsoft#1169, microsoft#1171, microsoft#1172, microsoft#1173, microsoft#1174, microsoft#1178
…on-fix Set PATHEXT for job containers to handle binaries with no extension
This change sets the PATHEXT environment variable which Go checks during
exec.Cmd startup to do some path resolution. PATHEXT contains a semicolon
separated list of extensions to check against if a path ended without one
(e.g. /path/to/my/binary). This simply adds an empty string entry to the end
so that binaries with no extension can be launched correctly. Although this isn't
a common occurrence it's still a good thing to support. Windows Server containers
are able to handle this fine, and CreateProcess is perfectly happy launching
a valid executable without an extension.
This is mainly to support the agnhost image which is a common k8s testing image whose
entrypoint is a binary named agnhost with no extension.
https://github.com/kubernetes/kubernetes/blob/d64e91878517b1208a0bce7e2b7944645ace8ede/test/images/agnhost/Dockerfile_windows
Signed-off-by: Daniel Canter [email protected]