Skip to content

Commit

Permalink
feat: add coder.tlsAltHost option (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb authored Nov 5, 2024
1 parent d4ccfa7 commit 44f4f08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"type": "string",
"default": ""
},
"coder.tlsAltHost": {
"markdownDescription": "Alternative hostname to use for TLS verification. This is useful when the hostname in the certificate does not match the hostname used to connect.",
"type": "string",
"default": ""
},
"coder.proxyLogDirectory": {
"markdownDescription": "If set, the Coder CLI will output extra SSH information into this directory, which can be helpful for debugging connectivity issues.",
"type": "string",
Expand Down
5 changes: 4 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function createHttpAgent(): Promise<ProxyAgent> {
const certFile = expandPath(String(cfg.get("coder.tlsCertFile") ?? "").trim())
const keyFile = expandPath(String(cfg.get("coder.tlsKeyFile") ?? "").trim())
const caFile = expandPath(String(cfg.get("coder.tlsCaFile") ?? "").trim())
const altHost = expandPath(String(cfg.get("coder.tlsAltHost") ?? "").trim())

return new ProxyAgent({
// Called each time a request is made.
Expand All @@ -41,6 +42,7 @@ async function createHttpAgent(): Promise<ProxyAgent> {
cert: certFile === "" ? undefined : await fs.readFile(certFile),
key: keyFile === "" ? undefined : await fs.readFile(keyFile),
ca: caFile === "" ? undefined : await fs.readFile(caFile),
servername: altHost === "" ? undefined : altHost,
// rejectUnauthorized defaults to true, so we need to explicitly set it to
// false if we want to allow self-signed certificates.
rejectUnauthorized: !insecure,
Expand All @@ -66,7 +68,8 @@ async function getHttpAgent(): Promise<ProxyAgent> {
e.affectsConfiguration("coder.insecure") ||
e.affectsConfiguration("coder.tlsCertFile") ||
e.affectsConfiguration("coder.tlsKeyFile") ||
e.affectsConfiguration("coder.tlsCaFile")
e.affectsConfiguration("coder.tlsCaFile") ||
e.affectsConfiguration("coder.tlsAltHost")
) {
agent = createHttpAgent()
}
Expand Down

0 comments on commit 44f4f08

Please sign in to comment.