Skip to content

Commit b88dba3

Browse files
committed
feat: set readOnlyRootFilesystem, change temp storage mount path
Upgrade and pin to snyk-docker-plugin version 1.34.0. The static scanning options now accept a file path to a temporary directory for saving snyk-docker-plugin files. To be used in combination with readOnlyRootFilesystem and the directory for pulling temporary images. Enable readOnlyRootFilesystem on the deployment files but also change the temporary storage mount path. Regardless of where we store pulled images, skopeo seems to pull temporary files under /var/tmp and this behaviour is not configurable. Because of that we cannot enable readOnlyRootFilesystem unless we also mount our temporary storage there.
1 parent 71f6050 commit b88dba3

File tree

8 files changed

+17
-7
lines changed

8 files changed

+17
-7
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"needle": "^2.4.0",
4545
"response-time": "^2.3.2",
4646
"snyk-config": "^2.2.0",
47-
"snyk-docker-plugin": "^1.33.0",
47+
"snyk-docker-plugin": "1.34.0",
4848
"source-map-support": "^0.5.9",
4949
"tslib": "^1.9.3",
5050
"ws": "^7.0.0",

snyk-monitor-deployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
readOnly: true
2626
mountPath: "/root/.docker"
2727
- name: temporary-storage
28-
mountPath: "/snyk-monitor"
28+
mountPath: "/var/tmp"
2929
env:
3030
- name: SNYK_INTEGRATION_ID
3131
valueFrom:
@@ -58,6 +58,7 @@ spec:
5858
cpu: '1'
5959
memory: '2Gi'
6060
securityContext:
61+
readOnlyRootFilesystem: true
6162
capabilities:
6263
drop:
6364
- ALL

snyk-monitor/templates/deployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
readOnly: true
3232
mountPath: "/root/.docker"
3333
- name: temporary-storage
34-
mountPath: "/snyk-monitor"
34+
mountPath: "/var/tmp"
3535
env:
3636
- name: SNYK_INTEGRATION_ID
3737
valueFrom:
@@ -52,6 +52,7 @@ spec:
5252
cpu: '1'
5353
memory: '2Gi'
5454
securityContext:
55+
readOnlyRootFilesystem: true
5556
capabilities:
5657
drop:
5758
- ALL

src/common/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ const config = require('snyk-config')(__dirname + '/../..', {
77
config.AGENT_ID = uuidv4();
88
config.INTEGRATION_ID = config.INTEGRATION_ID.trim();
99
config.CLUSTER_NAME = config.CLUSTER_NAME || 'Default cluster';
10-
config.IMAGE_STORAGE_ROOT = '/snyk-monitor';
10+
config.IMAGE_STORAGE_ROOT = '/var/tmp';
1111

1212
export = config;

src/kube-scanner/image-scanner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as plugin from 'snyk-docker-plugin';
22
import logger = require('../common/logger');
33
import { IStaticAnalysisOptions, StaticAnalysisImageType } from './types';
44
import { IPullableImage } from '../images/types';
5+
import config = require('../common/config');
56

67
export interface IScanResult {
78
image: string;
@@ -33,6 +34,7 @@ function constructStaticAnalysisOptions(
3334
staticAnalysisOptions: {
3435
imagePath: fileSystemPath,
3536
imageType: StaticAnalysisImageType.DockerArchive,
37+
tmpDirPath: config.IMAGE_STORAGE_ROOT,
3638
},
3739
};
3840
}

src/kube-scanner/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum StaticAnalysisImageType {
2929
export interface IStaticAnalysisOptions {
3030
imagePath: string;
3131
imageType: StaticAnalysisImageType;
32+
tmpDirPath: string;
3233
}
3334

3435
export interface KubeObjectMetadata {

test/helpers/deployment.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ export function validateSecureConfiguration(test: tap, deployment: V1Deployment)
3333
'CAP_SYS_ADMIN not added',
3434
);
3535
}
36+
37+
test.ok(
38+
securityContext.readOnlyRootFilesystem === true,
39+
'readOnlyRootFilesystem is set',
40+
);
3641
}
3742

0 commit comments

Comments
 (0)