Skip to content

Commit c7cb879

Browse files
authored
Merge pull request #431 from kubero-dev/fix/vulnerability-scan
fix vulnerability scans
2 parents b4cc84d + 2093da6 commit c7cb879

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

server/src/kubero.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,15 @@ export class Kubero {
12631263
} else {
12641264
debug.log('no git repo found to run scan');
12651265
}
1266+
} else if (app?.spec?.deploymentstrategy === 'git' && app?.spec?.buildstrategy != 'plain') {
1267+
if (contextName) {
1268+
this.kubectl.setCurrentContext(contextName);
1269+
this.kubectl.createScanImageJob(namespace, appName, app.spec.image.repository, app.spec.image.tag, true);
1270+
}
12661271
} else {
12671272
if (contextName) {
12681273
this.kubectl.setCurrentContext(contextName);
1269-
this.kubectl.createScanImageJob(namespace, appName, app.spec.image.repository, app.spec.image.tag);
1274+
this.kubectl.createScanImageJob(namespace, appName, app.spec.image.repository, app.spec.image.tag, false);
12701275
}
12711276
}
12721277

server/src/modules/kubectl.ts

+29-24
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,9 @@ export class Kubectl {
746746
}
747747
}
748748

749-
public async createScanImageJob(namespace: string, app: string, image: string, tag: string): Promise<any> {
749+
public async createScanImageJob(namespace: string, app: string, image: string, tag: string, withCredentials: boolean): Promise<any> {
750750
await this.deleteScanJob(namespace, app+'-kuberoapp-vuln');
751-
const job = {
751+
let job = {
752752
apiVersion: 'batch/v1',
753753
kind: 'Job',
754754
metadata: {
@@ -788,34 +788,39 @@ export class Kubectl {
788788
"--exit-code",
789789
"0"
790790
],
791-
env: [
792-
{
793-
name: 'TRIVY_USERNAME',
794-
valueFrom: {
795-
secretKeyRef: {
796-
name: 'registry-credentials',
797-
key: 'username',
798-
optional: true
799-
}
800-
}
801-
},
802-
{
803-
name: 'TRIVY_PASSWORD',
804-
valueFrom: {
805-
secretKeyRef: {
806-
name: 'registry-credentials',
807-
key: 'password',
808-
optional: true
809-
}
810-
}
811-
}
812-
],
791+
env: [] as { name: string; valueFrom: { secretKeyRef: { name: string; key: string; optional: true; }; }; }[],
813792
}
814793
]
815794
}
816795
}
817796
}
818797
};
798+
799+
if (withCredentials) {
800+
job.spec.template.spec.containers[0].env = [
801+
{
802+
name: 'TRIVY_USERNAME',
803+
valueFrom: {
804+
secretKeyRef: {
805+
name: 'registry-credentials',
806+
key: 'username',
807+
optional: true
808+
}
809+
}
810+
},
811+
{
812+
name: 'TRIVY_PASSWORD',
813+
valueFrom: {
814+
secretKeyRef: {
815+
name: 'registry-credentials',
816+
key: 'password',
817+
optional: true
818+
}
819+
}
820+
}
821+
]
822+
}
823+
819824
try {
820825
return await this.batchV1Api.createNamespacedJob(namespace, job);
821826
} catch (error) {

0 commit comments

Comments
 (0)