Skip to content

Commit 00d247c

Browse files
committed
feat: add CA support for proxy in aqua plugin
The commercial trivy plugin supports providing a proxy and a CA certificate. This is now configurable through the "Configure Aqua Platform" webview. When the proxy has a value it will be set, same with the CA Cert.
1 parent a851edd commit 00d247c

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ contrib
88
trivy
99
trivy.exe
1010
.vscode/settings.json
11+
cert.pem
12+
key.pem

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 1.8.9
4+
5+
- Add support for custom proxy server and CA certificate provision
6+
37
## 1.8.8
48

59
- Add skip directories with defaults that can be overridden in the workspace

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publisher": "AquaSecurityOfficial",
55
"description": "Find vulnerabilities, misconfigurations and exposed secrets in your code",
66
"icon": "images/icon.png",
7-
"version": "1.8.8",
7+
"version": "1.8.9",
88
"engines": {
99
"vscode": "^1.56.0"
1010
},
@@ -143,6 +143,16 @@
143143
"default": "",
144144
"description": "Aqua API URL"
145145
},
146+
"trivy.proxyServer": {
147+
"type": "string",
148+
"default": "",
149+
"description": "HTTP/HTTPS proxy server URL for Aqua Platform communication (format: http://proxy-host:port or https://proxy-host:port)"
150+
},
151+
"trivy.caCertPath": {
152+
"type": "string",
153+
"default": "",
154+
"description": "Path to CA Cert file for Aqua Platform communication"
155+
},
146156
"trivy.useAquaPlatform": {
147157
"type": "boolean",
148158
"default": false,

src/commercial/env.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const ENV_KEYS = Object.freeze({
1919
TRIVY_SKIP_REPOSITORY_UPLOAD: 'TRIVY_SKIP_REPOSITORY_UPLOAD',
2020
TRIVY_SKIP_RESULT_UPLOAD: 'TRIVY_SKIP_RESULT_UPLOAD',
2121
TRIVY_IDE_IDENTIFIER: 'TRIVY_IDE_IDENTIFIER',
22+
CA_CERT: 'CA_CERT',
23+
HTTP_PROXY: 'HTTP_PROXY',
24+
HTTPS_PROXY: 'HTTPS_PROXY',
2225
});
2326

2427
/**
@@ -63,6 +66,16 @@ export async function updateEnvironment(
6366
const aquaApiUrl = config.get<string>('aquaApiUrl');
6467
const aquaAuthUrl = config.get<string>('aquaAuthenticationUrl');
6568

69+
const proxyServer = config.get<string>('proxyServer');
70+
if (proxyServer) {
71+
newEnv[ENV_KEYS.HTTP_PROXY] = proxyServer;
72+
newEnv[ENV_KEYS.HTTPS_PROXY] = proxyServer;
73+
}
74+
const caCertPath = config.get<string>('caCertPath');
75+
if (caCertPath) {
76+
newEnv[ENV_KEYS.CA_CERT] = caCertPath;
77+
}
78+
6679
if (aquaApiUrl && aquaAuthUrl) {
6780
newEnv[ENV_KEYS.API_URL] = aquaApiUrl;
6881
newEnv[ENV_KEYS.AUTH_URL] = aquaAuthUrl;

src/commercial/setup.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ export async function setupCommercial(context: vscode.ExtensionContext) {
173173
}
174174
config.update('aquaApiUrl', aquaUrl);
175175
config.update('aquaAuthenticationUrl', cspmUrl);
176+
if (message.proxyServer && message.prxoyServer.startsWith('http')) {
177+
config.update('proxyServer', message.proxyServer);
178+
} else if (message.proxyServer === '') {
179+
config.update('proxyServer', undefined);
180+
}
181+
config.update('caCertPath', message.caCertPath);
176182
config.update('useAquaPlatform', message.enableAquaPlatform);
177183
vscode.commands.executeCommand(
178184
'setContext',
@@ -195,6 +201,29 @@ export async function setupCommercial(context: vscode.ExtensionContext) {
195201
case 'openExtenalLink':
196202
vscode.env.openExternal(vscode.Uri.parse(message.url));
197203
return;
204+
case 'browseCaCert': {
205+
const options: vscode.OpenDialogOptions = {
206+
canSelectFiles: true,
207+
canSelectFolders: false,
208+
canSelectMany: false,
209+
openLabel: 'Select CA Certificate',
210+
filters: {
211+
'Certificate Files': ['pem', 'crt', 'cer', 'der'],
212+
'All Files': ['*'],
213+
},
214+
title: 'Select CA Certificate',
215+
};
216+
217+
vscode.window.showOpenDialog(options).then((fileUri) => {
218+
if (fileUri && fileUri[0]) {
219+
panel.webview.postMessage({
220+
command: 'updateCaCertPath',
221+
path: fileUri[0].fsPath,
222+
});
223+
}
224+
});
225+
return;
226+
}
198227
}
199228
},
200229
undefined,
@@ -324,6 +353,17 @@ function getWebviewContent(
324353
API Authentication Url
325354
<span slot="start" class="codicon codicon-globe"></span>
326355
</vscode-text-field>
356+
<vscode-text-field size="48" id="proxyServer" name="proxyServer" value="${config.get<string>('proxyServer') || ''}" ${!useAquaPlatform ? 'disabled' : ''}>
357+
HTTP Proxy Server
358+
<span slot="start" class="codicon codicon-globe"></span>
359+
</vscode-text-field>
360+
<div style="display: flex; align-items: center; gap: 8px;">
361+
<vscode-text-field size="48" id="caCertPath" name="caCertPath" value="${config.get<string>('caCertPath') || ''}" ${!useAquaPlatform ? 'disabled' : ''}>
362+
CA Certificate Path
363+
364+
<span slot="end" class="codicon codicon-folder-opened" style="cursor: pointer; opacity: ${!useAquaPlatform ? '0.4' : '1'};" id="browse-cert-icon"></span>
365+
</vscode-text-field>
366+
</div>
327367
</div>
328368
<vscode-button id="save-button" appearance="primary" type="submit" >Save</vscode-button>
329369
</form>
@@ -338,13 +378,31 @@ function getWebviewContent(
338378
vscode.postMessage({ command: 'openExternalLink', url: target.href });
339379
}
340380
});
381+
382+
window.addEventListener('message', event => {
383+
const message = event.data;
384+
if (message && message.command) {
385+
switch (message.command) {
386+
case 'updateCaCertPath':
387+
const caCertPathElem = document.getElementById('caCertPath');
388+
if (caCertPathElem) {
389+
caCertPathElem.value = message.path;
390+
}
391+
break;
392+
}
393+
}
394+
});
395+
341396
document.getElementById('enableAquaPlatform').addEventListener('change', event => {
342397
const checked = event.target.checked;
343398
document.getElementById('apiKey').disabled = !checked;
344399
document.getElementById('apiSecret').disabled = !checked;
345400
document.getElementById('aqua-platform-region').disabled = !checked;
346401
document.getElementById('customApiUrl').disabled = !checked;
347402
document.getElementById('custonAuthUrl').disabled = !checked;
403+
document.getElementById('proxyServer').disabled = !checked;
404+
document.getElementById('caCertPath').disabled = !checked;
405+
document.getElementById('browse-cert-icon').style.opacity = checked ? '1' : '0.4';
348406
const regionLabel = document.getElementById('region-label');
349407
if (!checked) {
350408
regionLabel.classList.add('disabled');
@@ -353,6 +411,15 @@ function getWebviewContent(
353411
}
354412
});
355413
414+
document.getElementById('browse-cert-icon').addEventListener('click', (event) => {
415+
if (!document.getElementById('enableAquaPlatform').checked) {
416+
return;
417+
}
418+
vscode.postMessage({
419+
command: 'browseCaCert'
420+
});
421+
});
422+
356423
document.getElementById('aqua-platform-region').addEventListener('change', event => {
357424
const selectedValue = event.target.value;
358425
const customApiUrl = document.getElementById('customApiUrl');
@@ -382,8 +449,10 @@ function getWebviewContent(
382449
customAuthUrl = document.getElementById('custonAuthUrl').value;
383450
}
384451
452+
const proxyServer = document.getElementById('proxyServer').value;
453+
const caCertPath = document.getElementById('caCertPath').value;
385454
const enableAquaPlatform = document.getElementById('enableAquaPlatform').checked;
386-
vscode.postMessage({ command: 'storeSecrets', apiKey, apiSecret, aquaRegionValue, enableAquaPlatform, customApiUrl, customAuthUrl });
455+
vscode.postMessage({ command: 'storeSecrets', apiKey, apiSecret, aquaRegionValue, enableAquaPlatform, customApiUrl, customAuthUrl, proxyServer, caCertPath });
387456
});
388457
</script>
389458
</body>

0 commit comments

Comments
 (0)