Skip to content

Commit 9f54ca6

Browse files
committed
Remove some unused leftover Docker logic
Might be useful later, but not today - BuildKit isn't fully implemented, and we don't support remote hosts or similar that would require files to be injected intead of mounted.
1 parent cf13658 commit 9f54ca6

File tree

3 files changed

+16
-199
lines changed

3 files changed

+16
-199
lines changed

src/interceptors/docker/buildkit-interception.ts

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/interceptors/docker/docker-commands.ts

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as _ from 'lodash';
22
import * as Docker from 'dockerode';
33
import * as path from 'path';
4-
import * as tarFs from 'tar-fs';
54
import * as semver from 'semver';
65

76
import {
@@ -92,36 +91,6 @@ const envArrayToObject = (envArray: string[] | null | undefined) =>
9291
const envObjectToArray = (envObject: { [key: string]: string }): string[] =>
9392
Object.keys(envObject).map(k => `${k}=${envObject[k]}`);
9493

95-
function packInterceptionFiles(certContent: string) {
96-
return tarFs.pack(OVERRIDES_DIR, {
97-
map: (fileHeader) => {
98-
fileHeader.name = path.posix.join(HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH, fileHeader.name);
99-
100-
// Owned by root by default
101-
fileHeader.uid = 0;
102-
fileHeader.gid = 0;
103-
104-
// But ensure everything is globally readable & runnable
105-
fileHeader.mode = parseInt('555', 8);
106-
107-
return fileHeader;
108-
},
109-
finalize: false,
110-
finish: (pack) => {
111-
pack.entry({ name: HTTP_TOOLKIT_INJECTED_CA_PATH }, certContent);
112-
pack.finalize();
113-
}
114-
});
115-
}
116-
117-
// The two ways to inject the files required for interception into the image.
118-
// If 'mount', the override files should be bind-mounted directly into the image. If
119-
// 'inject', the override files should be copied into the image. 'Mount' is generally
120-
// better & faster, but not possible for builds or injection into remote hosts.
121-
export type DOCKER_INTERCEPTION_TYPE =
122-
| 'mount'
123-
| 'inject';
124-
12594
/**
12695
* Takes the config for a container, and returns the config to create the
12796
* same container, but fully intercepted.
@@ -133,8 +102,7 @@ export type DOCKER_INTERCEPTION_TYPE =
133102
export function transformContainerCreationConfig(
134103
containerConfig: Docker.ContainerCreateOptions,
135104
baseImageConfig: Docker.ImageInspectInfo | undefined,
136-
{ interceptionType, proxyPort, proxyHost, certPath }: {
137-
interceptionType: DOCKER_INTERCEPTION_TYPE
105+
{ proxyPort, proxyHost, certPath }: {
138106
proxyPort: number,
139107
proxyHost: string,
140108
certPath: string
@@ -164,25 +132,20 @@ export function transformContainerCreationConfig(
164132
const hostConfig: Docker.HostConfig = {
165133
...currentConfig.HostConfig,
166134
// To intercept without modifying the container, we bind mount our overrides and certificate
167-
// files into place:
168-
...(interceptionType === 'mount'
169-
? {
170-
Binds: [
171-
...(currentConfig.HostConfig?.Binds ?? []).filter((existingMount) =>
172-
// Drop any existing mounts for these folders - this allows re-intercepting containers, e.g.
173-
// to switch from one proxy port to another.
174-
!existingMount.startsWith(`${certPath}:`) &&
175-
!existingMount.startsWith(`${OVERRIDES_DIR}:`)
176-
),
177-
// Bind-mount the CA certificate file individually too:
178-
`${certPath}:${HTTP_TOOLKIT_INJECTED_CA_PATH}:ro`,
179-
// Bind-mount the overrides directory into the container:
180-
`${OVERRIDES_DIR}:${HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH}:ro`
181-
// ^ Both 'ro' - untrusted containers must not be able to mess with these!
182-
]
183-
}
184-
: {}
185-
),
135+
// files into place on top of the existing content:
136+
Binds: [
137+
...(currentConfig.HostConfig?.Binds ?? []).filter((existingMount) =>
138+
// Drop any existing mounts for these folders - this allows re-intercepting containers, e.g.
139+
// to switch from one proxy port to another.
140+
!existingMount.startsWith(`${certPath}:`) &&
141+
!existingMount.startsWith(`${OVERRIDES_DIR}:`)
142+
),
143+
// Bind-mount the CA certificate file individually too:
144+
`${certPath}:${HTTP_TOOLKIT_INJECTED_CA_PATH}:ro`,
145+
// Bind-mount the overrides directory into the container:
146+
`${OVERRIDES_DIR}:${HTTP_TOOLKIT_INJECTED_OVERRIDES_PATH}:ro`
147+
// ^ Both 'ro' - untrusted containers must not be able to mess with these!
148+
],
186149
...(process.platform === 'linux'
187150
// On Linux only, we need to add an explicit host to make host.docker.internal work:
188151
? {
@@ -254,8 +217,7 @@ async function connectNetworks(
254217
export async function restartAndInjectContainer(
255218
docker: Docker,
256219
containerId: string,
257-
{ interceptionType, proxyPort, certContent, certPath }: {
258-
interceptionType: DOCKER_INTERCEPTION_TYPE
220+
{ proxyPort, certContent, certPath }: {
259221
proxyPort: number,
260222
certContent: string
261223
certPath: string
@@ -298,7 +260,6 @@ export async function restartAndInjectContainer(
298260
// We don't need image config - inspect result has *everything*
299261
undefined,
300262
{ // The settings to inject:
301-
interceptionType,
302263
certPath,
303264
proxyPort,
304265
proxyHost
@@ -313,11 +274,6 @@ export async function restartAndInjectContainer(
313274
containerDetails.NetworkSettings.Networks
314275
);
315276

316-
if (interceptionType === 'inject') {
317-
// Inject the overide files & MITM cert into the image directly:
318-
await newContainer.putArchive(packInterceptionFiles(certContent), { path: '/' });
319-
}
320-
321277
// Start everything up!
322278
await newContainer.start();
323279
}

src/interceptors/docker/docker-proxy.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const API_VERSION_MATCH = /^\/v?([\.\d]+)\//;
4545
const CREATE_CONTAINER_MATCHER = /^\/[^\/]+\/containers\/create/;
4646
const START_CONTAINER_MATCHER = /^\/[^\/]+\/containers\/([^\/]+)\/start/;
4747
const BUILD_IMAGE_MATCHER = /^\/[^\/]+\/build$/;
48-
const EVENTS_MATCHER = /^\/[^\/]+\/events$/;
4948
const ATTACH_CONTAINER_MATCHER = /^\/[^\/]+\/containers\/([^\/]+)\/attach/;
5049
const CONTAINER_LIST_MATCHER = /^\/[^\/]+\/containers\/json/;
5150
const CONTAINER_INSPECT_MATCHER = /^\/[^\/]+\/containers\/[^\/]+\/json/;
@@ -132,14 +131,10 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
132131
{ apiVersion: dockerApiVersion! },
133132
);
134133

135-
const hasDockerComposeLabels = Object.keys(config.Labels ?? [])
136-
.includes("com.docker.compose.version");
137-
138134
const transformedConfig = transformContainerCreationConfig(
139135
config,
140136
imageConfig,
141137
{
142-
interceptionType: 'mount',
143138
certPath: httpsConfig.certPath,
144139
proxyPort,
145140
proxyHost

0 commit comments

Comments
 (0)