Skip to content

Commit 93ffe5a

Browse files
authored
make network access configurable (#1310)
1 parent 27952d6 commit 93ffe5a

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

docs/env.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
137137
{
138138
"socketPath": "/var/run/docker.sock",
139139
"scanImages": true,
140+
"enableNetwork": false,
140141
"imageRetentionDays": 7,
141142
"imageCleanupInterval": 86400,
142143
"resources": [
@@ -195,7 +196,9 @@ The `DOCKER_COMPUTE_ENVIRONMENTS` environment variable should be a JSON array of
195196
#### Configuration Options
196197

197198
- **socketPath**: Path to the Docker socket (e.g., docker.sock).
198-
- **scanImages**: If the docker images should be scan for vulnerabilities using trivy. If yes and critical vulnerabilities are found, then C2D job is refused
199+
- **scanImages**: Whether Docker images should be scanned for vulnerabilities using Trivy. If enabled and critical vulnerabilities are found, the C2D job is rejected.
200+
- **scanImageDBUpdateInterval**: How often to update the vulnerability database, in seconds. Default: 43200 (12 hours)
201+
- **enableNetwork**: Whether networking is enabled for algorithm containers. Default: false
199202
- **imageRetentionDays** - how long docker images are kept, in days. Default: 7
200203
- **imageCleanupInterval** - how often to run cleanup for docker images, in seconds. Min: 3600 (1hour), Default: 86400 (24 hours)
201204
- **paymentClaimInterval** - how often to run payment claiming, in seconds. Default: 3600 (1 hour)

src/@types/C2D/C2D.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface C2DDockerConfig {
161161
paymentClaimInterval?: number // Default: 3600 seconds (1 hours)
162162
scanImages?: boolean
163163
scanImageDBUpdateInterval?: number // Default: 12 hours
164+
enableNetwork?: boolean // whether network is enabled for algorithm containers
164165
}
165166

166167
export type ComputeResultType =

src/components/c2d/compute_engine_docker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class C2DEngineDocker extends C2DEngine {
8080
private cpuAllocations: Map<string, number[]> = new Map()
8181
private envCpuCores: number[] = []
8282
private cpuOffset: number
83+
private enableNetwork: boolean
8384

8485
public constructor(
8586
clusterConfig: C2DClusterInfo,
@@ -105,6 +106,7 @@ export class C2DEngineDocker extends C2DEngine {
105106
this.paymentClaimInterval = clusterConfig.connection.paymentClaimInterval || 3600 // 1 hour
106107
this.scanImages = clusterConfig.connection.scanImages || false // default is not to scan images for now, until it's prod ready
107108
this.scanImageDBUpdateInterval = clusterConfig.connection.scanImageDBUpdateInterval
109+
this.enableNetwork = clusterConfig.connection.enableNetwork ?? false
108110
if (
109111
clusterConfig.connection.protocol &&
110112
clusterConfig.connection.host &&
@@ -1726,7 +1728,6 @@ export class C2DEngineDocker extends C2DEngine {
17261728
// create the container
17271729
const mountVols: any = { '/data': {} }
17281730
const hostConfig: HostConfig = {
1729-
NetworkMode: 'none', // no network inside the container
17301731
Mounts: [
17311732
{
17321733
Type: 'volume',
@@ -1736,6 +1737,9 @@ export class C2DEngineDocker extends C2DEngine {
17361737
}
17371738
]
17381739
}
1740+
if (!this.enableNetwork) {
1741+
hostConfig.NetworkMode = 'none' // no network inside the container
1742+
}
17391743
// disk
17401744
// if (diskSize && diskSize > 0) {
17411745
// hostConfig.StorageOpt = {

src/utils/config/schemas.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ export const C2DDockerConfigSchema = z.array(
183183
fees: z.record(z.string(), z.array(ComputeEnvFeesSchema)).optional(),
184184
free: ComputeEnvironmentFreeOptionsSchema.optional(),
185185
imageRetentionDays: z.number().int().min(1).optional().default(7),
186-
imageCleanupInterval: z.number().int().min(3600).optional().default(86400) // min 1 hour, default 24 hours
186+
imageCleanupInterval: z.number().int().min(3600).optional().default(86400), // min 1 hour, default 24 hours
187+
scanImages: z.boolean().optional().default(false),
188+
scanImageDBUpdateInterval: z.number().int().min(3600).optional().default(43200), // default 43200 (12 hours)
189+
enableNetwork: z.boolean().optional().default(false)
187190
})
188191
.refine(
189192
(data) =>

0 commit comments

Comments
 (0)