Skip to content

Commit cdf1c2d

Browse files
authored
Merge pull request #7426 from tsmithsz/fix-proxy
fix(amazonq): Add proxy configuration support with SSL Cert Validation
2 parents 62d50d9 + 523fc16 commit cdf1c2d

File tree

7 files changed

+96
-2
lines changed

7 files changed

+96
-2
lines changed

packages/amazonq/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@
213213
"items": {
214214
"type": "string"
215215
}
216+
},
217+
"amazonQ.proxy.certificateAuthority": {
218+
"type": "string",
219+
"markdownDescription": "%AWS.configuration.description.amazonq.proxy.certificateAuthority%",
220+
"default": null,
221+
"scope": "application"
216222
}
217223
}
218224
},

packages/amazonq/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
Experiments,
3535
isSageMaker,
3636
isAmazonLinux2,
37+
ProxyUtil,
3738
} from 'aws-core-vscode/shared'
3839
import { ExtStartUpSources } from 'aws-core-vscode/telemetry'
3940
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
@@ -119,6 +120,10 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
119120
const extContext = {
120121
extensionContext: context,
121122
}
123+
124+
// Configure proxy settings early
125+
ProxyUtil.configureProxyForLanguageServer()
126+
122127
// This contains every lsp agnostic things (auth, security scan, code scan)
123128
await activateCodeWhisperer(extContext as ExtContext)
124129
if (

packages/core/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"AWS.configuration.description.amazonq.workspaceIndexIgnoreFilePatterns": "File patterns to ignore when indexing your workspace files",
9999
"AWS.configuration.description.amazonq.workspaceIndexCacheDirPath": "The path to the directory that contains the cache of the index of your workspace files",
100100
"AWS.configuration.description.amazonq.ignoredSecurityIssues": "Specifies a list of code issue identifiers that Amazon Q should ignore when reviewing your workspace. Each item in the array should be a unique string identifier for a specific code issue. This allows you to suppress notifications for known issues that you've assessed and determined to be false positives or not applicable to your project. Use this setting with caution, as it may cause you to miss important security alerts.",
101-
"AWS.command.apig.copyUrl": "Copy URL",
101+
"AWS.configuration.description.amazonq.proxy.certificateAuthority": "Path to a Certificate Authority (PEM file) for SSL/TLS verification when using a proxy.",
102102
"AWS.command.apig.invokeRemoteRestApi": "Invoke in the cloud",
103103
"AWS.command.apig.invokeRemoteRestApi.cn": "Invoke on Amazon",
104104
"AWS.appBuilder.explorerTitle": "Application Builder",

packages/core/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export {
3939
CodewhispererUserDecision,
4040
CodewhispererSecurityScan,
4141
} from './telemetry/telemetry.gen'
42+
export { ProxyUtil } from './utilities/proxyUtil'
4243
export { randomUUID } from './crypto'
4344
export * from './environmentVariables'
4445
export * from './vscode/setContext'

packages/core/src/shared/logger/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type LogTopic =
2121
| 'nextEditPrediction'
2222
| 'resourceCache'
2323
| 'telemetry'
24+
| 'proxyUtil'
2425

2526
class ErrorLog {
2627
constructor(

packages/core/src/shared/settings-amazonq.gen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const amazonqSettings = {
3636
"amazonQ.workspaceIndexMaxFileSize": {},
3737
"amazonQ.workspaceIndexCacheDirPath": {},
3838
"amazonQ.workspaceIndexIgnoreFilePatterns": {},
39-
"amazonQ.ignoredSecurityIssues": {}
39+
"amazonQ.ignoredSecurityIssues": {},
40+
"amazonQ.proxy.certificateAuthority": {}
4041
}
4142

4243
export default amazonqSettings
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import vscode from 'vscode'
7+
import { getLogger } from '../logger/logger'
8+
9+
interface ProxyConfig {
10+
proxyUrl: string | undefined
11+
certificateAuthority: string | undefined
12+
}
13+
14+
/**
15+
* Utility class for handling proxy configuration
16+
*/
17+
export class ProxyUtil {
18+
private static readonly logger = getLogger('proxyUtil')
19+
20+
/**
21+
* Sets proxy environment variables based on VS Code settings for use with the Flare Language Server
22+
*
23+
* See documentation here for setting the environement variables which are inherited by Flare LS process:
24+
* https://github.com/aws/language-server-runtimes/blob/main/runtimes/docs/proxy.md
25+
*/
26+
public static configureProxyForLanguageServer(): void {
27+
try {
28+
const proxyConfig = this.getProxyConfiguration()
29+
30+
this.setProxyEnvironmentVariables(proxyConfig)
31+
} catch (err) {
32+
this.logger.error(`Failed to configure proxy: ${err}`)
33+
}
34+
}
35+
36+
/**
37+
* Gets proxy configuration from VS Code settings
38+
*/
39+
private static getProxyConfiguration(): ProxyConfig {
40+
const httpConfig = vscode.workspace.getConfiguration('http')
41+
const proxyUrl = httpConfig.get<string>('proxy')
42+
this.logger.debug(`Proxy URL Setting in VSCode Settings: ${proxyUrl}`)
43+
44+
const amazonQConfig = vscode.workspace.getConfiguration('amazonQ')
45+
const proxySettings = amazonQConfig.get<{
46+
certificateAuthority?: string
47+
}>('proxy', {})
48+
49+
return {
50+
proxyUrl,
51+
certificateAuthority: proxySettings.certificateAuthority,
52+
}
53+
}
54+
55+
/**
56+
* Sets environment variables based on proxy configuration
57+
*/
58+
private static setProxyEnvironmentVariables(config: ProxyConfig): void {
59+
const proxyUrl = config.proxyUrl
60+
61+
// Always enable experimental proxy support for better handling of both explicit and transparent proxies
62+
process.env.EXPERIMENTAL_HTTP_PROXY_SUPPORT = 'true'
63+
// Add OpenSSL certificate store support
64+
process.env.NODE_OPTIONS = '--use-openssl-ca'
65+
66+
// Set proxy environment variables
67+
if (proxyUrl) {
68+
process.env.HTTPS_PROXY = proxyUrl
69+
process.env.HTTP_PROXY = proxyUrl
70+
this.logger.debug(`Set proxy environment variables: ${proxyUrl}`)
71+
}
72+
73+
// Set certificate bundle environment variables if configured
74+
if (config.certificateAuthority) {
75+
process.env.NODE_EXTRA_CA_CERTS = config.certificateAuthority
76+
process.env.AWS_CA_BUNDLE = config.certificateAuthority
77+
this.logger.debug(`Set certificate bundle path: ${config.certificateAuthority}`)
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)