Skip to content

Commit 8179085

Browse files
authored
Merge pull request #336 from snyk/fix/ocp-home-override
fix: hardcode HOME in the deployment of snyk-monitor
2 parents 94de70c + b8fa099 commit 8179085

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

snyk-monitor-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ spec:
5656
optional: true
5757
- name: SNYK_MONITOR_VERSION
5858
value: IMAGE_TAG_OVERRIDE_WHEN_PUBLISHING
59+
- name: HOME
60+
value: /srv/app
5961
resources:
6062
requests:
6163
cpu: '250m'

snyk-monitor/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ spec:
4646
value: {{ .Values.clusterName }}
4747
- name: SNYK_MONITOR_VERSION
4848
value: {{ .Values.image.tag }}
49+
- name: HOME
50+
value: /srv/app
4951
resources:
5052
requests:
5153
cpu: '250m'

src/common/process.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function exec(bin: string, ...processArgs: IProcessArgument[]):
1616
// For example, that process doesn't need to know secrets like our integrationId!
1717
const env = {
1818
PATH: process.env.PATH,
19+
HOME: process.env.HOME,
1920
};
2021

2122
const allArguments = processArgs.map((arg) => arg.body);

test/helpers/deployment.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import * as tap from 'tap';
22
import { V1Deployment } from '@kubernetes/client-node';
33

4+
export function validateEnvironmentVariables(test: tap, deployment: V1Deployment) {
5+
if (
6+
!deployment.spec ||
7+
!deployment.spec.template.spec ||
8+
!deployment.spec.template.spec.containers ||
9+
deployment.spec.template.spec.containers.length === 0 ||
10+
!deployment.spec.template.spec.containers[0].env
11+
) {
12+
test.fail('bad container spec or missing env');
13+
return;
14+
}
15+
16+
const env = deployment.spec.template.spec.containers[0].env;
17+
18+
const envHasHomeEntry = env.some(
19+
(entry) => entry.name === 'HOME' && entry.value === '/srv/app',
20+
);
21+
test.ok(envHasHomeEntry, 'has HOME entry in env variables');
22+
}
23+
424
export function validateSecureConfiguration(test: tap, deployment: V1Deployment) {
525
if (
626
!deployment.spec ||

test/integration/kubernetes.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
validateUpstreamStoredMetadata,
99
getUpstreamResponseBody,
1010
} from '../helpers/kubernetes-upstream';
11-
import { validateSecureConfiguration, validateVolumeMounts } from '../helpers/deployment';
11+
import {
12+
validateSecureConfiguration,
13+
validateVolumeMounts,
14+
validateEnvironmentVariables,
15+
} from '../helpers/deployment';
1216
import * as kubectl from '../helpers/kubectl';
1317

1418
let integrationId: string;
@@ -241,6 +245,7 @@ tap.test('snyk-monitor secure configuration is as expected', async (t) => {
241245

242246
validateSecureConfiguration(t, deployment);
243247
validateVolumeMounts(t, deployment);
248+
validateEnvironmentVariables(t, deployment);
244249
});
245250

246251
/**

test/unit/deployment-files.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { parse } from 'yaml';
33
import { readFileSync } from 'fs';
44
import { V1Deployment } from '@kubernetes/client-node';
55
import * as snykConfig from '../../src/common/config';
6-
import { validateSecureConfiguration, validateVolumeMounts } from '../helpers/deployment';
6+
import {
7+
validateSecureConfiguration,
8+
validateVolumeMounts,
9+
validateEnvironmentVariables,
10+
} from '../helpers/deployment';
711

812
/**
913
* Note that these checks are also performed at runtime on the deployed snyk-monitor, see the integration tests.
@@ -20,5 +24,6 @@ tap.test('ensure the security properties of the deployment files are unchanged',
2024

2125
validateSecureConfiguration(t, deployment);
2226
validateVolumeMounts(t, deployment);
27+
validateEnvironmentVariables(t, deployment);
2328
}
2429
});

0 commit comments

Comments
 (0)