Skip to content

Commit 84c2424

Browse files
committed
Don't inject DOCKER_HOST proxy address into Docker containers
This could work in theory. We'd have to inject the variable along with mounting the socket itself though. We'd only want to do that in cases where we were sure that the socket was already being mounted (or its a big security risk), and that's a) hard to detect and b) extra hard to redirect. Doable, probably, but not worth it for now. It's also possible that some DinD setups might work regardless. If they check DOCKER_HOST to find the path to the socket, they'll end up mounting our intercepted socket correctly all by themselves.
1 parent 8d3058b commit 84c2424

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/interceptors/docker/docker-build-injection.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,24 @@ export function injectIntoBuildStream(
3939

4040
let commandsAddedToDockerfile = getDeferred<number>();
4141

42+
const envVars = getTerminalEnvVars(
43+
config.proxyPort,
44+
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
45+
'posix-runtime-inherit', // Dockerfile commands can reference vars directly
46+
{
47+
httpToolkitIp: DOCKER_HOST_HOSTNAME,
48+
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
49+
targetPlatform: 'linux'
50+
}
51+
);
52+
53+
// For now, we don't inject DOCKER_HOST into the container, so we don't try to intercept DinD. It
54+
// should be doable in theory, but it seems complicated and of limited value.
55+
delete envVars['DOCKER_HOST'];
56+
4257
const dockerfileConfig = {
4358
...config,
44-
envVars: getTerminalEnvVars(
45-
config.proxyPort,
46-
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
47-
'posix-runtime-inherit', // Dockerfile commands can reference vars directly
48-
{
49-
httpToolkitIp: DOCKER_HOST_HOSTNAME,
50-
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
51-
targetPlatform: 'linux'
52-
}
53-
)
59+
envVars
5460
};
5561

5662
extractionStream.on('entry', async (headers, entryStream, next) => {

src/interceptors/docker/docker-commands.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ export function transformContainerCreationConfig(
129129
}
130130
};
131131

132+
const envVarsToInject = getTerminalEnvVars(
133+
proxyPort,
134+
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
135+
envArrayToObject(currentConfig.Env),
136+
{
137+
httpToolkitIp: DOCKER_HOST_HOSTNAME,
138+
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
139+
targetPlatform: 'linux'
140+
}
141+
);
142+
143+
// For now, we don't inject DOCKER_HOST into the container, so we don't try to intercept DinD. It
144+
// should be doable in theory, but it seems complicated and of limited value.
145+
delete envVarsToInject['DOCKER_HOST'];
146+
132147
const hostConfig: Docker.HostConfig = {
133148
...currentConfig.HostConfig,
134149
// To intercept without modifying the container, we bind mount our overrides and certificate
@@ -165,18 +180,7 @@ export function transformContainerCreationConfig(
165180
HostConfig: hostConfig,
166181
Env: [
167182
...(currentConfig.Env ?? []),
168-
...envObjectToArray(
169-
getTerminalEnvVars(
170-
proxyPort,
171-
{ certPath: HTTP_TOOLKIT_INJECTED_CA_PATH },
172-
envArrayToObject(currentConfig.Env),
173-
{
174-
httpToolkitIp: DOCKER_HOST_HOSTNAME,
175-
overridePath: HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH,
176-
targetPlatform: 'linux'
177-
}
178-
)
179-
)
183+
...envObjectToArray(envVarsToInject)
180184
],
181185
Labels: {
182186
...transformComposeCreationLabels(proxyPort, currentConfig.Labels),

0 commit comments

Comments
 (0)