Skip to content

Commit 425ee5c

Browse files
authored
Merge pull request #676 from snyk/feat/load-rego-policy
fix: load Rego policy from a different location
2 parents 4151ea1 + 14129ac commit 425ee5c

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

snyk-monitor-deployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ spec:
3535
- name: registries-conf
3636
mountPath: "/srv/app/.config/containers"
3737
- name: workload-policies
38-
mountPath: "/var/tmp/policies"
38+
mountPath: "/tmp/policies"
39+
readOnly: true
3940
env:
4041
- name: SNYK_INTEGRATION_ID
4142
valueFrom:

snyk-monitor/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
- name: ssl-certs
5151
mountPath: "/srv/app/certs"
5252
- name: workload-policies
53-
mountPath: "/var/tmp/policies"
53+
mountPath: "/tmp/policies"
5454
readOnly: true
5555
- name: registries-conf
5656
mountPath: "/srv/app/.config/containers"

src/common/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config.AGENT_ID = uuidv4();
99
config.INTEGRATION_ID = config.INTEGRATION_ID.trim();
1010
config.CLUSTER_NAME = config.CLUSTER_NAME || 'Default cluster';
1111
config.IMAGE_STORAGE_ROOT = '/var/tmp';
12+
config.POLICIES_STORAGE_ROOT = '/tmp/policies';
1213

1314
/**
1415
* Important: we delete the following env vars because we don't want to proxy requests to the Kubernetes API server.

src/common/policy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export async function loadAndSendWorkloadAutoImportPolicy(): Promise<void> {
1313
try {
1414
/** This path is set in snyk-monitor during installation/deployment and is defined in the Helm chart. */
1515
const userProvidedRegoPolicyPath = resolvePath(
16-
config.IMAGE_STORAGE_ROOT,
17-
'policies',
16+
config.POLICIES_STORAGE_ROOT,
1817
'workload-auto-import.rego',
1918
);
2019
if (!existsSync(userProvidedRegoPolicyPath)) {

test/integration/kubernetes.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ test('snyk-monitor secure configuration is as expected', async () => {
516516
mountPath: '/srv/app/.docker',
517517
readOnly: true,
518518
}),
519+
expect.objectContaining({
520+
name: 'workload-policies',
521+
mountPath: '/tmp/policies',
522+
readOnly: true,
523+
}),
519524
]),
520525
env: expect.arrayContaining([{ name: 'HOME', value: '/srv/app' }]),
521526
}),

test/system/kind.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const existsAsync = promisify(exists);
2525
* Error: Client network socket disconnected before secure TLS connection was established
2626
*/
2727
import { state as kubernetesMonitorState } from '../../src/state';
28+
import { tmpdir } from 'os';
2829

2930
async function tearDown() {
3031
console.log('Begin removing the snyk-monitor...');
@@ -75,7 +76,7 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
7576

7677
// Create a copy of the policy file fixture in the location that snyk-monitor is expecting to load it from.
7778
const regoPolicyFixturePath = resolvePath('./test/fixtures/workload-auto-import.rego');
78-
const expectedPoliciesPath = resolvePath('/var/tmp/policies');
79+
const expectedPoliciesPath = resolvePath('/tmp/policies');
7980
if (!(await existsAsync(expectedPoliciesPath))) {
8081
await mkdirAsync(expectedPoliciesPath);
8182
}

0 commit comments

Comments
 (0)