Skip to content

Commit f55c122

Browse files
authored
Merge pull request jenkinsci#97 from docwhat/pr/blacklist-envvars
Blacklist EnvVars for docker run -e
2 parents 59fa26a + 01ed84e commit f55c122

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.ArrayList;
4747
import java.util.Arrays;
4848
import java.util.Collection;
49+
import java.util.Iterator;
4950
import java.util.List;
5051
import java.util.Map;
5152
import java.util.LinkedHashMap;
@@ -126,7 +127,11 @@ public static class Execution extends AbstractStepExecutionImpl {
126127
EnvVars envReduced = new EnvVars(env);
127128
EnvVars envHost = computer.getEnvironment();
128129
envReduced.entrySet().removeAll(envHost.entrySet());
130+
131+
// Remove PATH during cat.
132+
envReduced.remove("PATH");
129133
envReduced.remove("");
134+
130135
LOGGER.log(Level.FINE, "reduced environment: {0}", envReduced);
131136
workspace.mkdirs(); // otherwise it may be owned by root when created for -v
132137
String ws = workspace.getRemote();
@@ -236,7 +241,17 @@ private static class Decorator extends LauncherDecorator implements Serializable
236241
} // otherwise we are loading an old serialized Decorator
237242
Set<String> envReduced = new TreeSet<String>(Arrays.asList(starter.envs()));
238243
envReduced.removeAll(Arrays.asList(envHost));
244+
245+
// Remove PATH during `exec` as well.
246+
Iterator<String> it = envReduced.iterator();
247+
while (it.hasNext()) {
248+
if (it.next().startsWith("PATH=")) {
249+
it.remove();
250+
}
251+
}
252+
LOGGER.log(Level.FINE, "(exec) reduced environment: {0}", envReduced);
239253
prefix.addAll(envReduced);
254+
240255
// Adapted from decorateByPrefix:
241256
starter.cmds().addAll(0, prefix);
242257
if (starter.masks() != null) {

0 commit comments

Comments
 (0)