diff --git a/packages/databricks-vscode/package.json b/packages/databricks-vscode/package.json index 6560e9556..bc6b1bc98 100644 --- a/packages/databricks-vscode/package.json +++ b/packages/databricks-vscode/package.json @@ -1856,6 +1856,14 @@ "type": "number", "default": 5, "description": "The interval in minutes at which the remote state of the bundle is refreshed." + }, + "databricks.proxy.strictSSL": { + "type": "boolean", + "markdownDescription": "Controls whether TLS certificates are verified for the extension's Databricks SDK calls. When unset, the built-in `#http.proxyStrictSSL#` value is used. Set to `false` only when a corporate CA certificate cannot be resolved from the system trust store." + }, + "databricks.proxy.caCert": { + "type": "string", + "markdownDescription": "Absolute path to a PEM bundle of additional CA certificates to trust for the extension's Databricks SDK calls, merged with the OS trust store and Node's built-in roots. Use when a corporate CA cannot be read from the system store — in particular on Windows, where the extension does not read the system certificate store and relies on this setting for internal CAs." } } } @@ -1893,7 +1901,7 @@ "package:copy-webview-toolkit": "cp ./node_modules/@vscode/webview-ui-toolkit/dist/toolkit.js ./out/toolkit.js", "package:copy-markdown-it": "cp ./node_modules/markdown-it/dist/browser/markdown-it.umd.min.js ./out/markdown-it.min.js", "package:copy-highlight": "esbuild ./node_modules/highlight.js/lib/common.js --bundle --format=iife --global-name=hljs --outfile=out/highlight.min.js --minify", - "esbuild:base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --sourcemap --target=es2019", + "esbuild:base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --external:@vscode/windows-ca-certs --format=cjs --platform=node --sourcemap --target=es2019", "build": "yarn run package:wrappers:write && yarn run package:jupyter-init-script:write && tsc --build --force", "watch": "yarn run package:wrappers:write && yarn run package:jupyter-init-script:write && yarn run package:copy-webview-toolkit && yarn run package:copy-markdown-it && yarn run package:copy-highlight && tsc --build --watch --verbose", "fix": "eslint src --fix && prettier . --write", @@ -1918,11 +1926,14 @@ "@types/shell-quote": "^1.7.5", "@vscode/debugadapter": "^1.64.0", "@vscode/extension-telemetry": "^1.5.2", + "@vscode/proxy-agent": "^0.28.0", "@vscode/webview-ui-toolkit": "^1.4.0", "add": "^2.0.6", "ansi-to-html": "^0.7.2", "bcryptjs": "^3.0.3", "highlight.js": "^11.10.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", "lodash": "^4.18.1", "markdown-it": "^15.0.0", "minimatch": "^10.2.3", diff --git a/packages/databricks-vscode/scripts/package-vsix.sh b/packages/databricks-vscode/scripts/package-vsix.sh index 66799b107..0cb85bf68 100755 --- a/packages/databricks-vscode/scripts/package-vsix.sh +++ b/packages/databricks-vscode/scripts/package-vsix.sh @@ -63,4 +63,5 @@ if [ $ARCH != "win32-arm64" ]; then fi yarn run prettier package.json --write + TAG="release-v$(cat package.json | jq -r .version)" yarn run package -t $VSXI_ARCH diff --git a/packages/databricks-vscode/src/configuration/auth/AuthProvider.ts b/packages/databricks-vscode/src/configuration/auth/AuthProvider.ts index 268d4b2af..bcb724fc8 100644 --- a/packages/databricks-vscode/src/configuration/auth/AuthProvider.ts +++ b/packages/databricks-vscode/src/configuration/auth/AuthProvider.ts @@ -1,22 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { - Config, - ProductVersion, - WorkspaceClient, - logging, -} from "@databricks/sdk-experimental"; +import {Config, WorkspaceClient, logging} from "@databricks/sdk-experimental"; import {CancellationToken, ProgressLocation, window} from "vscode"; import {normalizeHost} from "../../utils/urlUtils"; import {workspaceConfigs} from "../../vscode-objs/WorkspaceConfigs"; -// eslint-disable-next-line @typescript-eslint/no-require-imports -const extensionVersion = require("../../../package.json") - .version as ProductVersion; - import {AzureCliCheck} from "./AzureCliCheck"; import {DatabricksCliCheck} from "./DatabricksCliCheck"; import {Loggers} from "../../logger"; import {CliWrapper} from "../../cli/CliWrapper"; +import {ProxyAgent} from "../../utils"; // TODO: Resolve this with SDK's AuthType. export type AuthType = @@ -52,11 +44,7 @@ export abstract class AuthProvider { async getWorkspaceClient(): Promise { const config = await this.getSdkConfig(); - - return new WorkspaceClient(config, { - product: "databricks-vscode", - productVersion: extensionVersion, - }); + return ProxyAgent.createWorkspaceClient(config, this.host); } /** diff --git a/packages/databricks-vscode/src/configuration/auth/AzureCliCheck.ts b/packages/databricks-vscode/src/configuration/auth/AzureCliCheck.ts index 3029b7905..ede9d14a3 100644 --- a/packages/databricks-vscode/src/configuration/auth/AzureCliCheck.ts +++ b/packages/databricks-vscode/src/configuration/auth/AzureCliCheck.ts @@ -1,14 +1,9 @@ -import { - Context, - ProductVersion, - WorkspaceClient, - logging, -} from "@databricks/sdk-experimental"; +import {Context, logging} from "@databricks/sdk-experimental"; import {CancellationToken, commands, Disposable, Uri, window} from "vscode"; import {Loggers} from "../../logger"; import {AzureCliAuthProvider} from "./AuthProvider"; import {orchestrate, OrchestrationLoopError, Step} from "./orchestrate"; -import {ShellUtils} from "../../utils"; +import {ProxyAgent, ShellUtils} from "../../utils"; import {cancellableExecFile} from "../../cli/CliWrapper"; import { FileNotFoundException, @@ -18,10 +13,6 @@ import { // eslint-disable-next-line @typescript-eslint/naming-convention const {NamedLogger} = logging; -// eslint-disable-next-line @typescript-eslint/no-require-imports -const extensionVersion = require("../../../package.json") - .version as ProductVersion; - type AzureCloud = "AzureCloud" | "AzureChinaCloud" | "AzureUSGovernment"; type AzureStepName = @@ -212,16 +203,13 @@ export class AzureCliCheck implements Disposable { expired: boolean; error?: Error; }> { - const workspaceClient = new WorkspaceClient( + const workspaceClient = await ProxyAgent.createWorkspaceClient( { host: host.toString(), authType: "azure-cli", azureLoginAppId: this.azureLoginAppId, }, - { - product: "databricks-vscode", - productVersion: extensionVersion, - } + host ); try { await workspaceClient.currentUser.me( diff --git a/packages/databricks-vscode/src/configuration/auth/DatabricksCliCheck.ts b/packages/databricks-vscode/src/configuration/auth/DatabricksCliCheck.ts index 1d06988f7..0aa2c0069 100644 --- a/packages/databricks-vscode/src/configuration/auth/DatabricksCliCheck.ts +++ b/packages/databricks-vscode/src/configuration/auth/DatabricksCliCheck.ts @@ -1,8 +1,6 @@ import { CancellationToken, Context, - ProductVersion, - WorkspaceClient, logging, } from "@databricks/sdk-experimental"; import { @@ -14,10 +12,7 @@ import {DatabricksCliAuthProvider} from "./AuthProvider"; import {orchestrate, OrchestrationLoopError, Step} from "./orchestrate"; import {Loggers} from "../../logger"; import {execFile} from "../../cli/CliWrapper"; - -// eslint-disable-next-line @typescript-eslint/no-require-imports -const extensionVersion = require("../../../package.json") - .version as ProductVersion; +import {ProxyAgent} from "../../utils"; type StepName = "tryLogin" | "login"; @@ -111,7 +106,7 @@ export class DatabricksCliCheck implements Disposable { private async tryLogin( cancellationToken?: CancellationToken ): Promise { - const workspaceClient = new WorkspaceClient( + const workspaceClient = await ProxyAgent.createWorkspaceClient( { host: this.authProvider.host.toString(), authType: "databricks-cli", @@ -121,10 +116,7 @@ export class DatabricksCliCheck implements Disposable { ? {workspaceId: this.authProvider.workspaceId} : {}), }, - { - product: "databricks-vscode", - productVersion: extensionVersion, - } + this.authProvider.host ); try { diff --git a/packages/databricks-vscode/src/extension.ts b/packages/databricks-vscode/src/extension.ts index 3b819341f..7cb14583e 100644 --- a/packages/databricks-vscode/src/extension.ts +++ b/packages/databricks-vscode/src/extension.ts @@ -34,6 +34,7 @@ import {workspaceConfigs} from "./vscode-objs/WorkspaceConfigs"; import { FileUtils, PackageJsonUtils, + ProxyAgent, TerraformUtils, UrlUtils, UtilsCommands, @@ -675,20 +676,16 @@ export async function activate( customWhenContext.updateShowClusterView(); } - function updateStrictSSLEnv() { - const httpConfig = workspace.getConfiguration("http"); - const proxyStrictSSL = httpConfig.get("proxyStrictSSL"); - process.env["DATABRICKS_SDK_PROXY_STRICT_SSL"] = proxyStrictSSL - ? "true" - : "false"; - } - updateFeatureContexts(); - updateStrictSSLEnv(); + // Resolve TLS strict-SSL through the same layered setting the SDK client + // path uses (databricks.proxy.strictSSL -> http.proxyStrictSSL -> true), so + // both writers of DATABRICKS_SDK_PROXY_STRICT_SSL agree and verification + // stays on by default when nothing is configured. + ProxyAgent.applyProxyStrictSSLEnv(); context.subscriptions.push( workspace.onDidChangeConfiguration(() => { updateFeatureContexts(); - updateStrictSSLEnv(); + ProxyAgent.applyProxyStrictSSLEnv(); }) ); diff --git a/packages/databricks-vscode/src/utils/envVarGenerators.test.ts b/packages/databricks-vscode/src/utils/envVarGenerators.test.ts index 22ab6e72c..19ab0b4e3 100644 --- a/packages/databricks-vscode/src/utils/envVarGenerators.test.ts +++ b/packages/databricks-vscode/src/utils/envVarGenerators.test.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import {anything, instance, mock, when} from "ts-mockito"; +import {anything, instance, mock, reset, spy, when} from "ts-mockito"; import {ConnectionManager} from "../configuration/ConnectionManager"; import {DatabricksWorkspace} from "../configuration/DatabricksWorkspace"; import {ApiClient, Config} from "@databricks/sdk-experimental"; @@ -13,6 +13,7 @@ import { import {Uri} from "vscode"; import assert from "assert"; import {AuthProvider} from "../configuration/auth/AuthProvider"; +import {workspaceConfigs} from "../vscode-objs/WorkspaceConfigs"; describe(__filename, () => { let mockConnectionManager: ConnectionManager; @@ -22,8 +23,14 @@ describe(__filename, () => { const mockHost = "http://example.com"; let mockApiClient: ApiClient; let existingEnv: any; + let configsSpy: typeof workspaceConfigs; beforeEach(() => { + configsSpy = spy(workspaceConfigs); + // Default: no proxy configured via VS Code settings, so getProxyEnvVars + // falls back to the process env vars the tests set explicitly. + when(configsSpy.httpProxy).thenReturn(undefined); + when(configsSpy.httpNoProxy).thenReturn([]); mockConnectionManager = mock(ConnectionManager); mockDatabricksWorkspace = mock(DatabricksWorkspace); mockCluster = mock(Cluster); @@ -45,6 +52,7 @@ describe(__filename, () => { }); afterEach(() => { + reset(configsSpy); process.env = existingEnv; }); @@ -86,6 +94,51 @@ describe(__filename, () => { }); }); + it("should use the http.proxy setting for both schemes when set", () => { + delete process.env.HTTP_PROXY; + delete process.env.HTTPS_PROXY; + delete process.env.http_proxy; + delete process.env.https_proxy; + when(configsSpy.httpProxy).thenReturn("http://proxy.local:8080"); + + const actual = getProxyEnvVars(); + assert.deepEqual(actual, { + HTTP_PROXY: "http://proxy.local:8080", + HTTPS_PROXY: "http://proxy.local:8080", + NO_PROXY: undefined, + }); + }); + + it("should let the http.proxy setting win over env vars", () => { + process.env.HTTP_PROXY = "http://env-proxy.local:1"; + process.env.HTTPS_PROXY = "http://env-proxy.local:1"; + when(configsSpy.httpProxy).thenReturn("http://setting-proxy.local:2"); + + const actual = getProxyEnvVars(); + assert.deepEqual(actual, { + HTTP_PROXY: "http://setting-proxy.local:2", + HTTPS_PROXY: "http://setting-proxy.local:2", + NO_PROXY: undefined, + }); + }); + + it("should merge http.noProxy setting with the NO_PROXY env var", () => { + delete process.env.no_proxy; + process.env.NO_PROXY = "shared.example.com,env.example.com"; + when(configsSpy.httpNoProxy).thenReturn([ + "setting.example.com", + "shared.example.com", + ]); + + const actual = getProxyEnvVars(); + assert.deepEqual(actual, { + HTTP_PROXY: undefined, + HTTPS_PROXY: undefined, + // Deduped: "shared.example.com" appears in both sources but once here. + NO_PROXY: "setting.example.com,shared.example.com,env.example.com", + }); + }); + it("should generate env vars with expected cluster id", () => { const actual = getCommonDatabricksEnvVars( instance(mockConnectionManager), diff --git a/packages/databricks-vscode/src/utils/envVarGenerators.ts b/packages/databricks-vscode/src/utils/envVarGenerators.ts index cf34e0139..5cdcb0ec8 100644 --- a/packages/databricks-vscode/src/utils/envVarGenerators.ts +++ b/packages/databricks-vscode/src/utils/envVarGenerators.ts @@ -4,6 +4,8 @@ import {ExtensionContext, Uri} from "vscode"; import {logging, Headers} from "@databricks/sdk-experimental"; import {ConnectionManager} from "../configuration/ConnectionManager"; import {TerraformMetadata} from "./terraformUtils"; +import {workspaceConfigs} from "../vscode-objs/WorkspaceConfigs"; +import {mergeNoProxy} from "./network/proxyAgent"; // eslint-disable-next-line @typescript-eslint/no-require-imports const packageJson = require("../../package.json"); @@ -140,12 +142,41 @@ export async function getDbConnectEnvVars( /* eslint-enable @typescript-eslint/naming-convention */ } +/** + * Proxy env vars forwarded to the bundled Databricks CLI (and any other + * subprocess). The Go CLI does no proxy handling of its own — it relies on Go's + * `http.ProxyFromEnvironment`, which reads only these env vars — so this is the + * only way to route CLI traffic through a proxy. + * + * Precedence mirrors the in-process SDK path (`proxyAgent.ts` + * `getProxyAgentParams`): the VS Code `http.proxy` setting wins over the OS + * `http(s)_proxy` env vars. That keeps the CLI and the SDK resolving the same + * proxy from the same inputs, so a user who configures the proxy purely through + * the VS Code setting gets it applied to both. `no_proxy` is the exception — the + * `http.noProxy` setting and the env var are *unioned* (not overridden), since a + * bypass list is only ever safer when it's broader. + * + * Absent values stay `undefined` so `removeUndefinedKeys(...)` at the call sites + * strips them, leaving the CLI's own env untouched when nothing is configured. + */ export function getProxyEnvVars() { + // The `http.proxy` setting is a single URL used for both schemes. + const settingProxy = workspaceConfigs.httpProxy; + const httpProxy = + settingProxy || process.env.HTTP_PROXY || process.env.http_proxy; + const httpsProxy = + settingProxy || process.env.HTTPS_PROXY || process.env.https_proxy; + + // Merge the `http.noProxy` setting with the NO_PROXY env var (shared with + // the in-process SDK proxy resolver), then join back to the comma-separated + // form the CLI expects. + const noProxy = mergeNoProxy().join(",") || undefined; + return { /* eslint-disable @typescript-eslint/naming-convention */ - HTTP_PROXY: process.env.HTTP_PROXY || process.env.http_proxy, - HTTPS_PROXY: process.env.HTTPS_PROXY || process.env.https_proxy, - NO_PROXY: process.env.NO_PROXY || process.env.no_proxy, + HTTP_PROXY: httpProxy, + HTTPS_PROXY: httpsProxy, + NO_PROXY: noProxy, /* eslint-enable @typescript-eslint/naming-convention */ }; } diff --git a/packages/databricks-vscode/src/utils/index.ts b/packages/databricks-vscode/src/utils/index.ts index ed6f6af75..6e6b26ba1 100644 --- a/packages/databricks-vscode/src/utils/index.ts +++ b/packages/databricks-vscode/src/utils/index.ts @@ -7,3 +7,4 @@ export * as EnvVarGenerators from "./envVarGenerators"; export * as DateUtils from "./DateUtils"; export * as TerraformUtils from "./terraformUtils"; export * as HostUtils from "./hostUtils"; +export {ProxyAgent} from "./network"; diff --git a/packages/databricks-vscode/src/utils/network/index.ts b/packages/databricks-vscode/src/utils/network/index.ts new file mode 100644 index 000000000..b925a5a94 --- /dev/null +++ b/packages/databricks-vscode/src/utils/network/index.ts @@ -0,0 +1 @@ +export * as ProxyAgent from "./proxyAgent"; diff --git a/packages/databricks-vscode/src/utils/network/proxyAgent.test.ts b/packages/databricks-vscode/src/utils/network/proxyAgent.test.ts new file mode 100644 index 000000000..deabe9649 --- /dev/null +++ b/packages/databricks-vscode/src/utils/network/proxyAgent.test.ts @@ -0,0 +1,418 @@ +import * as assert from "assert"; +import * as https from "node:https"; +import * as http from "node:http"; +import * as tls from "node:tls"; +import * as fs from "node:fs"; +import * as os from "node:os"; +import * as path from "node:path"; +import {reset, spy, when} from "ts-mockito"; +import {HttpsProxyAgent} from "https-proxy-agent"; +import {HttpProxyAgent} from "http-proxy-agent"; +import {workspaceConfigs} from "../../vscode-objs/WorkspaceConfigs"; +import {WorkspaceClient} from "@databricks/sdk-experimental"; +import { + applyProxyStrictSSLEnv, + createWorkspaceClient, + getDatabricksHttpAgent, + resetProxyAgentCaches, + setSystemCertificatesLoaderForTests, + strictSSL, +} from "./proxyAgent"; + +// A syntactically-valid but throwaway PEM used to assert it lands in the agent's +// `ca` list. It never has to verify anything — the tests only check membership. +const FAKE_CA_PEM = + "-----BEGIN CERTIFICATE-----\nMIIBFake\n-----END CERTIFICATE-----\n"; + +describe(__filename, () => { + let configsSpy: typeof workspaceConfigs; + let existingEnv: NodeJS.ProcessEnv; + + beforeEach(() => { + existingEnv = Object.assign({}, process.env); + resetProxyAgentCaches(); + configsSpy = spy(workspaceConfigs); + // Defaults: strict SSL on, no proxy or custom CA configured. + when(configsSpy.proxyStrictSSL).thenReturn(true); + when(configsSpy.httpProxy).thenReturn(undefined); + when(configsSpy.httpNoProxy).thenReturn([]); + when(configsSpy.proxyCaCert).thenReturn(undefined); + }); + + afterEach(() => { + reset(configsSpy); + setSystemCertificatesLoaderForTests(); + process.env = existingEnv; + }); + + describe("strictSSL / applyProxyStrictSSLEnv", () => { + it("reflects the effective setting", () => { + when(configsSpy.proxyStrictSSL).thenReturn(true); + assert.strictEqual(strictSSL(), true); + + when(configsSpy.proxyStrictSSL).thenReturn(false); + assert.strictEqual(strictSSL(), false); + }); + + it("sets DATABRICKS_SDK_PROXY_STRICT_SSL only when disabled", () => { + when(configsSpy.proxyStrictSSL).thenReturn(false); + applyProxyStrictSSLEnv(); + assert.strictEqual( + process.env.DATABRICKS_SDK_PROXY_STRICT_SSL, + "false" + ); + + when(configsSpy.proxyStrictSSL).thenReturn(true); + applyProxyStrictSSLEnv(); + assert.strictEqual( + process.env.DATABRICKS_SDK_PROXY_STRICT_SSL, + undefined + ); + }); + }); + + describe("getDatabricksHttpAgent", () => { + it("returns a plain https agent when no proxy is configured", async () => { + const agent = await getDatabricksHttpAgent( + new URL("https://example.com") + ); + assert.ok(agent instanceof https.Agent); + assert.ok(!(agent instanceof HttpsProxyAgent)); + }); + + it("returns an https proxy agent when http.proxy is set", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + const agent = await getDatabricksHttpAgent( + new URL("https://example.com") + ); + assert.ok(agent instanceof HttpsProxyAgent); + }); + + it("honours the http.proxy setting for http hosts", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + const agent = await getDatabricksHttpAgent( + new URL("http://example.com") + ); + assert.ok(agent instanceof HttpProxyAgent); + }); + + it("uses HTTP_PROXY for http hosts when env proxies differ", async () => { + process.env.HTTP_PROXY = "http://127.0.0.1:8080"; + process.env.HTTPS_PROXY = "http://127.0.0.1:8443"; + delete process.env.http_proxy; + delete process.env.https_proxy; + delete process.env.NO_PROXY; + delete process.env.no_proxy; + + const agent = (await getDatabricksHttpAgent( + new URL("http://example.com") + )) as HttpProxyAgent; + + assert.ok(agent instanceof HttpProxyAgent); + assert.strictEqual(agent.proxy.href, "http://127.0.0.1:8080/"); + }); + + it("returns a plain agent when the host matches noProxy", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + when(configsSpy.httpNoProxy).thenReturn(["example.com"]); + const agent = await getDatabricksHttpAgent( + new URL("https://example.com") + ); + assert.ok(agent instanceof https.Agent); + assert.ok(!(agent instanceof HttpsProxyAgent)); + }); + + it("returns a plain agent when the host matches NO_PROXY and http.noProxy is also set", async () => { + process.env.NO_PROXY = "example.com"; + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + when(configsSpy.httpNoProxy).thenReturn(["setting.example.com"]); + + const agent = await getDatabricksHttpAgent( + new URL("https://example.com") + ); + + assert.ok(agent instanceof https.Agent); + assert.ok(!(agent instanceof HttpsProxyAgent)); + }); + + it("falls back to a plain http agent for http hosts without a proxy", async () => { + const agent = await getDatabricksHttpAgent( + new URL("http://example.com") + ); + assert.ok(agent instanceof http.Agent); + assert.ok(!(agent instanceof HttpProxyAgent)); + }); + + it("sets the SDK default request timeout on plain agents", async () => { + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + + assert.strictEqual( + (agent.options as https.AgentOptions).timeout, + 5000 + ); + }); + + it("preserves the configured SDK request timeout on plain agents", async () => { + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com"), + 60 + )) as https.Agent; + + assert.strictEqual( + (agent.options as https.AgentOptions).timeout, + 60000 + ); + }); + + it("preserves the configured SDK request timeout on proxy agents", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com"), + 60 + )) as HttpsProxyAgent; + + assert.strictEqual(agent.connectOpts.timeout, 60000); + }); + + it("merges the system trust store with Node's bundled roots (never replaces them)", async () => { + // Inject the system store instead of reading the host's: CI runners + // (notably headless Windows) can return an empty OS store, which + // would legitimately omit `ca` and make this merge assertion flaky. + // Re-listing a bundled root also exercises the dedupe path below. + setSystemCertificatesLoaderForTests(async () => [ + FAKE_CA_PEM, + tls.rootCertificates[0], + ]); + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca; + assert.ok(Array.isArray(ca)); + // tls.getCACertificates('system') returns only the OS store; setting + // `ca` to that alone would drop Node's bundled public roots. The + // agent must carry at least all of the bundled roots. + assert.ok( + (ca as unknown[]).length >= tls.rootCertificates.length, + `expected >= ${tls.rootCertificates.length} CAs, got ${ + (ca as unknown[]).length + }` + ); + // A known bundled root is still present. + assert.ok((ca as string[]).includes(tls.rootCertificates[0])); + // Deduped: the OS store often re-lists the bundled roots, but each + // cert appears at most once in the handed-off list. + assert.strictEqual( + new Set(ca as string[]).size, + (ca as string[]).length + ); + }); + + it("disables certificate verification when strict SSL is off", async () => { + when(configsSpy.proxyStrictSSL).thenReturn(false); + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + assert.strictEqual( + (agent.options as https.AgentOptions).rejectUnauthorized, + false + ); + }); + + // Drive an https:// target through a proxy and assert the CA / strict-SSL + // land on the *endpoint* tunnel (the per-request `opts` that reach + // `tls.connect` for the Databricks host), not just the proxy socket + // (`connectOpts`). The base agent applies constructor options only to the + // proxy connection, so a merged `ca` there never verifies the host — this + // is the regression the CA-aware subclass fixes. + async function captureEndpointConnectOpts( + agent: HttpsProxyAgent + ) { + let capturedOpts: https.AgentOptions | undefined; + const superConnect = HttpsProxyAgent.prototype.connect; + // `super.connect` in the subclass resolves to this at call time; stub + // it so no real proxy connection is attempted. + HttpsProxyAgent.prototype.connect = async function (_req, opts) { + capturedOpts = opts as https.AgentOptions; + return {} as never; + }; + try { + await agent.connect( + {} as never, + { + secureEndpoint: true, + host: "example.com", + port: 443, + } as never + ); + } finally { + HttpsProxyAgent.prototype.connect = superConnect; + } + return capturedOpts; + } + + it("applies the CA to the endpoint TLS handshake through a proxy", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + setSystemCertificatesLoaderForTests(async () => [FAKE_CA_PEM]); + + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as HttpsProxyAgent; + assert.ok(agent instanceof HttpsProxyAgent); + + const opts = await captureEndpointConnectOpts(agent); + const ca = opts?.ca as string[]; + assert.ok(Array.isArray(ca)); + assert.ok(ca.includes(FAKE_CA_PEM)); + assert.strictEqual(opts?.rejectUnauthorized, true); + }); + + it("disables endpoint verification through a proxy when strict SSL is off", async () => { + when(configsSpy.httpProxy).thenReturn("http://127.0.0.1:8080"); + when(configsSpy.proxyStrictSSL).thenReturn(false); + + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as HttpsProxyAgent; + + const opts = await captureEndpointConnectOpts(agent); + assert.strictEqual(opts?.rejectUnauthorized, false); + }); + + it("falls back to Node's bundled CAs when the system store can't be read", async () => { + // @vscode/proxy-agent's own reader catches internally and reads the + // host's real store, so swap the loader for one that rejects. + setSystemCertificatesLoaderForTests(async () => { + throw new Error("system store unavailable"); + }); + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + // `ca` must be omitted (not [] / undefined) so Node keeps its + // bundled roots instead of trusting nothing. + assert.ok(!("ca" in (agent.options as https.AgentOptions))); + assert.strictEqual( + (agent.options as https.AgentOptions).rejectUnauthorized, + true + ); + }); + + it("merges databricks.proxy.caCert onto the trust store", async () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dbx-ca-")); + const pemPath = path.join(dir, "corp-ca.pem"); + fs.writeFileSync(pemPath, FAKE_CA_PEM); + when(configsSpy.proxyCaCert).thenReturn(pemPath); + try { + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca as string[]; + assert.ok(Array.isArray(ca)); + assert.ok(ca.includes(FAKE_CA_PEM)); + // Still anchored on the bundled roots. + assert.ok(ca.includes(tls.rootCertificates[0])); + } finally { + fs.rmSync(dir, {recursive: true, force: true}); + } + }); + + it("applies databricks.proxy.caCert even when the system store can't be read", async () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dbx-ca-")); + const pemPath = path.join(dir, "corp-ca.pem"); + fs.writeFileSync(pemPath, FAKE_CA_PEM); + when(configsSpy.proxyCaCert).thenReturn(pemPath); + setSystemCertificatesLoaderForTests(async () => { + throw new Error("system store unavailable"); + }); + try { + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca as string[]; + assert.ok(Array.isArray(ca)); + assert.ok(ca.includes(FAKE_CA_PEM)); + assert.ok(ca.includes(tls.rootCertificates[0])); + } finally { + fs.rmSync(dir, {recursive: true, force: true}); + } + }); + + it("ignores an unreadable databricks.proxy.caCert path", async () => { + when(configsSpy.proxyCaCert).thenReturn( + path.join(os.tmpdir(), "does-not-exist-xyz.pem") + ); + // Must not throw; falls back to the rest of the trust store. + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca as string[]; + assert.ok(!ca || !ca.includes(FAKE_CA_PEM)); + }); + + it("folds NODE_EXTRA_CA_CERTS into the trust store", async () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dbx-ca-")); + const pemPath = path.join(dir, "extra-ca.pem"); + fs.writeFileSync(pemPath, FAKE_CA_PEM); + process.env.NODE_EXTRA_CA_CERTS = pemPath; + try { + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca as string[]; + assert.ok(Array.isArray(ca)); + assert.ok(ca.includes(FAKE_CA_PEM)); + // Still anchored on the bundled roots. + assert.ok(ca.includes(tls.rootCertificates[0])); + } finally { + fs.rmSync(dir, {recursive: true, force: true}); + } + }); + + it("ignores an unreadable NODE_EXTRA_CA_CERTS path", async () => { + process.env.NODE_EXTRA_CA_CERTS = path.join( + os.tmpdir(), + "does-not-exist-extra-xyz.pem" + ); + // Must not throw; falls back to the rest of the trust store. + const agent = (await getDatabricksHttpAgent( + new URL("https://example.com") + )) as https.Agent; + const ca = (agent.options as https.AgentOptions).ca as string[]; + assert.ok(!ca || !ca.includes(FAKE_CA_PEM)); + }); + }); + + describe("createWorkspaceClient", () => { + it("builds a client tagged with the extension product and a proxy-aware agent", async () => { + const client = await createWorkspaceClient( + {host: "https://example.com", authType: "pat", token: "t"}, + new URL("https://example.com") + ); + assert.ok(client instanceof WorkspaceClient); + assert.strictEqual(client.apiClient.product, "databricks-vscode"); + const agent = await client.apiClient.getAgent(); + assert.ok(agent instanceof https.Agent); + }); + + it("preserves the configured SDK request timeout on the injected agent", async () => { + const client = await createWorkspaceClient( + { + host: "https://example.com", + authType: "pat", + token: "t", + httpTimeoutSeconds: 60, + }, + new URL("https://example.com") + ); + + const agent = (await client.apiClient.getAgent()) as https.Agent; + + assert.strictEqual( + (agent.options as https.AgentOptions).timeout, + 60000 + ); + }); + }); +}); diff --git a/packages/databricks-vscode/src/utils/network/proxyAgent.ts b/packages/databricks-vscode/src/utils/network/proxyAgent.ts new file mode 100644 index 000000000..7c868f927 --- /dev/null +++ b/packages/databricks-vscode/src/utils/network/proxyAgent.ts @@ -0,0 +1,399 @@ +import * as http from "node:http"; +import * as https from "node:https"; +import * as tls from "node:tls"; +import {readFile} from "node:fs/promises"; +import { + createProxyResolver, + loadSystemCertificates, + LogLevel, + type Log, + type ProxyAgentParams, +} from "@vscode/proxy-agent"; +import {HttpProxyAgent} from "http-proxy-agent"; +import {HttpsProxyAgent} from "https-proxy-agent"; +import { + logging, + ProductVersion, + WorkspaceClient, +} from "@databricks/sdk-experimental"; +import {Loggers} from "../../logger"; +import {workspaceConfigs} from "../../vscode-objs/WorkspaceConfigs"; + +// eslint-disable-next-line @typescript-eslint/no-require-imports +const extensionVersion = require("../../../package.json") + .version as ProductVersion; + +// Mirror the SDK's own default agent tuning (see @databricks/sdk-experimental +// api-client.js ApiClient.getAgent), so behaviour is unchanged apart from the +// proxy + CA wiring we add on top. +const KEEP_ALIVE_MSECS = 15000; +const DEFAULT_HTTP_TIMEOUT_SECONDS = 5; + +function getLog(): Log { + const logger = logging.NamedLogger.getOrCreate(Loggers.Extension); + return { + trace: (message, ...args) => logger.debug(message, args), + debug: (message, ...args) => logger.debug(message, args), + info: (message, ...args) => logger.info(message, args), + warn: (message, ...args) => logger.warn(message, args), + error: (message, ...args) => + logger.error( + message instanceof Error ? message.message : message, + args + ), + }; +} + +/** + * Build the params @vscode/proxy-agent needs to resolve a proxy the same way + * VS Code core does: `http.proxy` setting first, then the `http(s)_proxy` env + * vars, honouring `http.noProxy` and `NO_PROXY`. System/PAC auto-detection is + * intentionally disabled (`useHostProxy: false`) — it needs Electron's proxy + * resolver, which the extension host doesn't expose. + */ +function getProxyAgentParams(host: URL): ProxyAgentParams { + const log = getLog(); + const env = {...process.env}; + if (host.protocol === "http:") { + delete env.HTTPS_PROXY; + delete env.https_proxy; + } + return { + resolveProxy: async () => undefined, + getProxyURL: () => workspaceConfigs.httpProxy, + getProxySupport: () => "on", + getNoProxyConfig: () => mergeNoProxy(), + isAdditionalFetchSupportEnabled: () => false, + addCertificatesV1: () => false, + addCertificatesV2: () => true, + loadAdditionalCertificates: async () => [], + log, + getLogLevel: () => LogLevel.Error, + proxyResolveTelemetry: () => {}, + useHostProxy: false, + env, + }; +} + +/** + * Merge the `http.noProxy` VS Code setting (an array) with the comma-separated + * `NO_PROXY`/`no_proxy` env var into a deduped host list. The two are *unioned* + * (not overridden) since a bypass list is only ever safer when it's broader. + * Shared by the in-process SDK proxy resolver here and the CLI env-var builder + * (`getProxyEnvVars` in envVarGenerators.ts) so both resolve the same list. + */ +export function mergeNoProxy(): string[] { + const envNoProxy = process.env.NO_PROXY || process.env.no_proxy || ""; + const noProxyParts = [ + ...workspaceConfigs.httpNoProxy, + ...envNoProxy.split(","), + ] + .map((v) => v.trim()) + .filter((v) => v.length > 0); + + return [...new Set(noProxyParts)]; +} + +let systemCertificatesPromise: Promise | undefined; + +// The system-certificate reader, indirected through a module-level binding so +// tests can simulate an unreadable OS store. @vscode/proxy-agent's own reader +// catches internally and reads the host machine's real store, so there's no +// other seam to force the failure path. +let loadSystemCertificatesImpl: (params: {log: Log}) => Promise = + loadSystemCertificates; + +/** + * Load and cache the OS certificate trust store. Cached for the session; call + * {@link resetProxyAgentCaches} in tests. + * + * Returns `undefined` (never a rejected promise) when the store can't be read. + * @vscode/proxy-agent reads it via native readers: `security` on macOS and PEM + * bundle files on Linux, which work out of the box. On Windows the store is read + * through the native `@vscode/windows-ca-certs` addon — which we deliberately do + * *not* ship (it publishes no prebuilds and can't be cross-compiled on the Linux + * release runner), so on Windows that read throws and we fall back here. When the + * read fails we swallow it so the caller uses Node's bundled roots instead of + * failing the whole SDK request. Windows users behind an internal CA point + * `databricks.proxy.caCert` at their PEM (or opt out via + * `databricks.proxy.strictSSL`): a missing custom CA is recoverable, a broken + * agent is not. + */ +async function getSystemCertificates( + params: ProxyAgentParams +): Promise { + if (!systemCertificatesPromise) { + systemCertificatesPromise = loadSystemCertificatesImpl({ + log: params.log, + }).catch((e) => { + params.log.error( + "Failed to load system certificates; falling back to Node's " + + "bundled CAs. Custom/corporate CAs may not be trusted.", + e + ); + // Don't cache the rejection — leave the promise unset so a later + // call can retry. + systemCertificatesPromise = undefined; + return undefined; + }); + } + return systemCertificatesPromise; +} + +/** Reset the cached system certificates. Test-only. */ +export function resetProxyAgentCaches() { + systemCertificatesPromise = undefined; +} + +/** + * Override the system-certificate loader (and drop the cache). Test-only: lets + * tests exercise the "OS store unreadable" fallback without depending on the + * host machine's real trust store. Pass `undefined` to restore the default. + */ +export function setSystemCertificatesLoaderForTests( + loader?: (params: {log: Log}) => Promise +) { + loadSystemCertificatesImpl = loader ?? loadSystemCertificates; + systemCertificatesPromise = undefined; +} + +/** + * Whether the SDK must verify TLS certificates. `false` only when the user + * opted out via `databricks.proxy.strictSSL` or `http.proxyStrictSSL`. + */ +export function strictSSL(): boolean { + return workspaceConfigs.proxyStrictSSL; +} + +/** + * Keep the SDK's own fetch path (fetch.js reads DATABRICKS_SDK_PROXY_STRICT_SSL) + * and the bundled CLI subprocess consistent with the injected agent's + * `rejectUnauthorized`. + */ +export function applyProxyStrictSSLEnv() { + if (strictSSL()) { + delete process.env.DATABRICKS_SDK_PROXY_STRICT_SSL; + } else { + process.env.DATABRICKS_SDK_PROXY_STRICT_SSL = "false"; + } +} + +/** + * Read the user-configured `databricks.proxy.caCert` PEM bundle, if set. Returns + * `undefined` when the setting is empty or the file can't be read — a bad path + * shouldn't break every TLS handshake, so we log and fall back to the rest of + * the trust store. + */ +async function loadConfiguredCaCert(): Promise { + const caCertPath = workspaceConfigs.proxyCaCert; + if (!caCertPath) { + return undefined; + } + try { + return await readFile(caCertPath, "utf8"); + } catch (e) { + getLog().error( + `Failed to read databricks.proxy.caCert from "${caCertPath}"; ` + + "ignoring it. The certificate it points at will not be trusted.", + e + ); + return undefined; + } +} + +/** + * Read the PEM bundle(s) named by `NODE_EXTRA_CA_CERTS`, if set. Node only + * merges this file into its *default* trust store, and only at process startup — + * so once we set an explicit `ca` (which replaces the default store), any CA a + * user trusts solely via `NODE_EXTRA_CA_CERTS` would silently stop being trusted + * after upgrade. Folding it back into the bundle preserves that trust. + * + * A bad path shouldn't break every TLS handshake, so we log and fall back to the + * rest of the trust store (same policy as {@link loadConfiguredCaCert}). + */ +async function loadNodeExtraCaCerts(): Promise { + const extraCaCertsPath = process.env.NODE_EXTRA_CA_CERTS; + if (!extraCaCertsPath) { + return undefined; + } + try { + return await readFile(extraCaCertsPath, "utf8"); + } catch (e) { + getLog().error( + `Failed to read NODE_EXTRA_CA_CERTS from "${extraCaCertsPath}"; ` + + "ignoring it. The certificate it points at will not be trusted.", + e + ); + return undefined; + } +} + +/** + * Assemble the CA trust list for the SDK's HTTPS agent, or `undefined` to leave + * Node's default store in place. + * + * Any list we build is anchored on `tls.rootCertificates` (Node's bundled public + * roots) and then extended with the OS trust store, the configured PEM, and the + * `NODE_EXTRA_CA_CERTS` bundle. Setting `ca` *replaces* Node's defaults, so if we + * set it to only the extra certs, public-root TLS would break — hence the merge. + * When we have nothing to add (system store unreadable, no `caCert`, no + * `NODE_EXTRA_CA_CERTS`), return `undefined` so the caller omits `ca` and Node + * keeps its defaults. + * + * Deduped because the OS store commonly re-lists the public roots already in + * `tls.rootCertificates`; a `Set` keeps the handed-off list minimal. + */ +function buildCaBundle( + systemCerts: string[] | undefined, + configuredCaCert: string | undefined, + nodeExtraCaCerts: string | undefined +): string[] | undefined { + // @vscode/proxy-agent swallows a failed OS-store read and returns `[]`, so + // treat empty the same as unreadable: nothing to add on top of Node's + // bundled roots. + if (!systemCerts?.length && !configuredCaCert && !nodeExtraCaCerts) { + return undefined; + } + return [ + ...new Set([ + ...tls.rootCertificates, + ...(systemCerts ?? []), + ...(configuredCaCert ? [configuredCaCert] : []), + ...(nodeExtraCaCerts ? [nodeExtraCaCerts] : []), + ]), + ]; +} + +// The per-request options `agent-base` hands to `connect`. Derived from the +// agent's own `connect` signature so we don't take a direct dependency on +// `agent-base` (it resolves only transitively via the proxy agents). +type ProxyConnectOpts = Parameters["connect"]>[1]; + +/** + * `HttpsProxyAgent`, but with the CA bundle / strict-SSL setting applied to the + * *endpoint* TLS handshake, not just the connection to the proxy. + * + * `https-proxy-agent`'s constructor options only govern the TLS socket to the + * proxy (`this.connectOpts`). The final handshake to the Databricks host is + * `tls.connect({...opts, socket})`, where `opts` is the SDK's per-request object + * — which carries no `ca`. So a merged `ca` passed to the constructor never + * reaches the endpoint, and an internal CA is silently ignored whenever a proxy + * is set. We fold the trust material into `opts` here (which *does* flow to the + * endpoint `tls.connect`) before delegating to the base implementation. + */ +class CaAwareHttpsProxyAgent extends HttpsProxyAgent { + constructor( + proxy: string, + opts: https.AgentOptions, + private readonly endpointCa: string[] | undefined, + private readonly endpointRejectUnauthorized: boolean + ) { + super(proxy, opts); + } + + override async connect( + req: Parameters["connect"]>[0], + opts: ProxyConnectOpts + ) { + // Only for the endpoint TLS handshake (`secureEndpoint`); the proxy + // socket already trusts the same bundle via the constructor options. + if (opts.secureEndpoint) { + opts.rejectUnauthorized = this.endpointRejectUnauthorized; + if (this.endpointCa) { + opts.ca = this.endpointCa; + } + } + return super.connect(req, opts); + } +} + +/** + * Build the HTTP(S) agent the Databricks SDK should use, wiring in the proxy + * (VS Code `http.proxy` setting + `http(s)_proxy` env vars, honouring + * `NO_PROXY`) and the OS certificate trust store. This is what lets the + * in-process SDK calls work behind corporate proxies and internal-CA TLS + * interception, matching the bundled CLI's behaviour. + */ +export async function getDatabricksHttpAgent( + host: URL, + httpTimeoutSeconds?: number +): Promise { + const params = getProxyAgentParams(host); + const isHttps = host.protocol === "https:"; + + // Independent reads (OS trust store, the configured PEM, the + // NODE_EXTRA_CA_CERTS bundle) — run them together rather than serially. + const [systemCerts, configuredCaCert, nodeExtraCaCerts] = await Promise.all( + [ + getSystemCertificates(params), + loadConfiguredCaCert(), + loadNodeExtraCaCerts(), + ] + ); + const ca = buildCaBundle(systemCerts, configuredCaCert, nodeExtraCaCerts); + const rejectUnauthorized = strictSSL(); + + const resolver = createProxyResolver(params); + const proxyUrl = await resolver.resolveProxyURL(host.toString()); + const usesTls = + isHttps || + (proxyUrl !== undefined && new URL(proxyUrl).protocol === "https:"); + + // Only set `ca` when we have certs to add on top of Node's bundled roots + // (which `buildCaBundle` already folds in). On the fallback path `ca` is + // `undefined`, so we omit it entirely and Node keeps its default store — + // passing `undefined`/`[]` would instead trust nothing. + const agentOptions: https.AgentOptions = { + keepAlive: true, + keepAliveMsecs: KEEP_ALIVE_MSECS, + timeout: (httpTimeoutSeconds || DEFAULT_HTTP_TIMEOUT_SECONDS) * 1000, + ...(usesTls ? {rejectUnauthorized, ...(ca ? {ca} : {})} : {}), + }; + + if (proxyUrl) { + // For an https endpoint the CA/strict-SSL must also land on the endpoint + // handshake, not just the proxy socket — the base agent only applies the + // constructor options to the proxy connection. An http endpoint through a + // proxy never does an endpoint TLS handshake, so the plain agent is fine. + return isHttps + ? new CaAwareHttpsProxyAgent( + proxyUrl, + agentOptions, + ca, + rejectUnauthorized + ) + : new HttpProxyAgent(proxyUrl, agentOptions); + } + + return isHttps + ? new https.Agent(agentOptions) + : new http.Agent(agentOptions); +} + +// The config shape the WorkspaceClient constructor accepts (ConfigOptions | Config), +// derived from the constructor so we don't depend on ConfigOptions — the SDK index +// doesn't re-export it. +type WorkspaceClientConfig = ConstructorParameters[0]; + +/** + * Construct a WorkspaceClient wired for the extension's network environment. + * + * The SDK pins its own agent per request, bypassing VS Code's global proxy/CA + * patching. This injects a proxy- and system-CA-aware agent (and keeps the SDK + * fetch path and bundled-CLI subprocess consistent via the strict-SSL env) so + * in-process SDK calls work behind corporate proxies and internal-CA TLS + * interception, matching the bundled CLI's behaviour. This is the only place + * the extension should build a WorkspaceClient. + */ +export async function createWorkspaceClient( + config: WorkspaceClientConfig, + host: URL +): Promise { + applyProxyStrictSSLEnv(); + const agent = await getDatabricksHttpAgent(host, config.httpTimeoutSeconds); + return new WorkspaceClient(config, { + product: "databricks-vscode", + productVersion: extensionVersion, + agent, + }); +} diff --git a/packages/databricks-vscode/src/vscode-objs/WorkspaceConfigs.ts b/packages/databricks-vscode/src/vscode-objs/WorkspaceConfigs.ts index ae54745eb..77f252242 100644 --- a/packages/databricks-vscode/src/vscode-objs/WorkspaceConfigs.ts +++ b/packages/databricks-vscode/src/vscode-objs/WorkspaceConfigs.ts @@ -181,6 +181,51 @@ export const workspaceConfigs = { return new Time(config, TimeUnits.minutes).toMillSeconds().value; }, + + /** + * Whether TLS certificates must be verified for the extension's SDK HTTP + * calls. `databricks.proxy.strictSSL`, when explicitly set, overrides the + * built-in `http.proxyStrictSSL`; both default to `true`. + */ + get proxyStrictSSL(): boolean { + const override = workspace + .getConfiguration("databricks") + .get("proxy.strictSSL"); + if (override !== undefined && override !== null) { + return override; + } + return ( + workspace.getConfiguration("http").get("proxyStrictSSL") ?? + true + ); + }, + + /** The `http.proxy` VS Code setting, mirrored for the SDK proxy resolver. */ + get httpProxy(): string | undefined { + return ( + workspace.getConfiguration("http").get("proxy") || undefined + ); + }, + + /** The `http.noProxy` VS Code setting, mirrored for the SDK proxy resolver. */ + get httpNoProxy(): string[] { + return workspace.getConfiguration("http").get("noProxy", []); + }, + + /** + * Absolute path to a PEM bundle of additional CA certificates to trust for + * the extension's SDK calls, merged with the OS trust store and Node's + * built-in roots. An escape hatch for corporate CAs that can't be read from + * the system store (e.g. older runtimes where the native reader is + * unavailable). + */ + get proxyCaCert(): string | undefined { + return ( + workspace + .getConfiguration("databricks") + .get("proxy.caCert") || undefined + ); + }, }; export type WorkspaceConfigs = typeof workspaceConfigs; diff --git a/yarn.lock b/yarn.lock index 1434f48e5..653561ced 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1528,6 +1528,13 @@ __metadata: languageName: node linkType: hard +"@tootallnate/once@npm:^3.0.0": + version: 3.0.1 + resolution: "@tootallnate/once@npm:3.0.1" + checksum: 1ec82a3ff0dd2270eb09631789bd63a34445f62dd3031f0d620f4b1c81c5916d5cdb312ae651c4e390ecf62115279165421024efa75b2bb708d0699dc80c4a42 + languageName: node + linkType: hard + "@tootallnate/quickjs-emscripten@npm:^0.23.0": version: 0.23.0 resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0" @@ -2066,6 +2073,25 @@ __metadata: languageName: node linkType: hard +"@vscode/proxy-agent@npm:^0.28.0": + version: 0.28.0 + resolution: "@vscode/proxy-agent@npm:0.28.0" + dependencies: + "@tootallnate/once": ^3.0.0 + "@vscode/windows-ca-certs": ^0.3.1 + agent-base: ^7.0.1 + debug: ^4.3.4 + http-proxy-agent: ^7.0.0 + https-proxy-agent: ^7.0.2 + socks-proxy-agent: ^8.0.1 + undici: ^6.20.1 + dependenciesMeta: + "@vscode/windows-ca-certs": + optional: true + checksum: dc1124d52f9ab684a8e4c109b2e91598c069beebfe2826fb38ce6f8c7ef38e9e77843a7254dbb177d499ef9474bf7dbdf4240deb1f3ed5070b37dbd7b19031e3 + languageName: node + linkType: hard + "@vscode/test-electron@npm:^2.4.1": version: 2.5.2 resolution: "@vscode/test-electron@npm:2.5.2" @@ -2106,6 +2132,16 @@ __metadata: languageName: node linkType: hard +"@vscode/windows-ca-certs@npm:^0.3.1": + version: 0.3.4 + resolution: "@vscode/windows-ca-certs@npm:0.3.4" + dependencies: + node-addon-api: ^8.2.0 + node-gyp: latest + conditions: os=win32 + languageName: node + linkType: hard + "@wdio/allure-reporter@npm:^9.1.3": version: 9.29.0 resolution: "@wdio/allure-reporter@npm:9.29.0" @@ -2530,6 +2566,13 @@ __metadata: languageName: node linkType: hard +"agent-base@npm:^7.0.1": + version: 7.1.4 + resolution: "agent-base@npm:7.1.4" + checksum: 86a7f542af277cfbd77dd61e7df8422f90bac512953709003a1c530171a9d019d072e2400eab2b59f84b49ab9dd237be44315ca663ac73e82b3922d10ea5eafa + languageName: node + linkType: hard + "agent-base@npm:^7.1.0": version: 7.1.0 resolution: "agent-base@npm:7.1.0" @@ -4024,6 +4067,7 @@ __metadata: "@typescript-eslint/utils": ^8.62.0 "@vscode/debugadapter": ^1.64.0 "@vscode/extension-telemetry": ^1.5.2 + "@vscode/proxy-agent": ^0.28.0 "@vscode/test-electron": ^3.1.0 "@vscode/webview-ui-toolkit": ^1.4.0 "@wdio/cli": ^9.29.0 @@ -4042,6 +4086,8 @@ __metadata: fs-extra: ^11.2.0 glob: ^13.0.6 highlight.js: ^11.10.0 + http-proxy-agent: ^7.0.2 + https-proxy-agent: ^7.0.6 lodash: ^4.18.1 markdown-it: ^15.0.0 minimatch: ^10.2.3 @@ -6202,7 +6248,7 @@ __metadata: languageName: node linkType: hard -"https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.5, https-proxy-agent@npm:^7.0.6": +"https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.2, https-proxy-agent@npm:^7.0.5, https-proxy-agent@npm:^7.0.6": version: 7.0.6 resolution: "https-proxy-agent@npm:7.0.6" dependencies: @@ -7857,6 +7903,15 @@ __metadata: languageName: node linkType: hard +"node-addon-api@npm:^8.2.0": + version: 8.9.2 + resolution: "node-addon-api@npm:8.9.2" + dependencies: + node-gyp: latest + checksum: 820b3099b7d27c555fd9d98c986feab52d7eaf2e4dac1bce927857368baa0f2a3f31db5bd5112acd45222fd33a453b3baf8bf78771a0643a4b712e09a33f0fdf + languageName: node + linkType: hard + "node-domexception@npm:^1.0.0": version: 1.0.0 resolution: "node-domexception@npm:1.0.0" @@ -9404,7 +9459,7 @@ __metadata: languageName: node linkType: hard -"socks-proxy-agent@npm:^8.0.5": +"socks-proxy-agent@npm:^8.0.1, socks-proxy-agent@npm:^8.0.5": version: 8.0.5 resolution: "socks-proxy-agent@npm:8.0.5" dependencies: @@ -10340,6 +10395,13 @@ __metadata: languageName: node linkType: hard +"undici@npm:^6.20.1": + version: 6.28.1 + resolution: "undici@npm:6.28.1" + checksum: 25f7398989c7f6d22b4120bb97ac2d8449e5bd30fe0c5eb9265537786a9950c35a0b363a74770729d94084784689f1304744e3e02cff32c614385d5dd4172af7 + languageName: node + linkType: hard + "undici@npm:^7.19.0": version: 7.28.0 resolution: "undici@npm:7.28.0"