feat(mongodb): add TLS connection options in connection tab (#2515)
Add MongoDB TLS options (`tlsAllowInvalidCertificates`, `retryWrites`, `tlsCAFile`) to the connection form with backend URL normalization and DocumentDB/SSH tunnel guidance, while preserving legacy `tlsCAFile` in `url_params` for existing DocumentDB users, hardening auth failure hint matching, and clarifying TLS bypass security labels.
This commit is contained in:
1 parent
f826cb5d38
commit
b60f8b2039
11 files changed
+270
-6
No files matched your search
@@ -14,7 +14,42 @@ export function setMongoUrlParam(urlParams: string | undefined, key: string, val
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
export function mongoUrlParamIsTrue(urlParams: string | undefined, key: string, defaultValue = false): boolean {
|
||||
const value = mongoUrlParam(urlParams, key);
|
||||
if (!value) return defaultValue;
|
||||
return ["true", "1", "yes"].includes(value.toLowerCase());
|
||||
}
|
||||
|
||||
export function setMongoUrlParamBoolean(urlParams: string | undefined, key: string, value: boolean, defaultWhenEnabled = false): string {
|
||||
if (value === defaultWhenEnabled) {
|
||||
return setMongoUrlParam(urlParams, key, "");
|
||||
}
|
||||
return setMongoUrlParam(urlParams, key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
export function normalizeMongoTlsFormState(ssl: boolean, urlParams: string | undefined, caCertPath: string | undefined): { urlParams: string; caCertPath: string } {
|
||||
if (ssl) {
|
||||
const nextCaCertPath = caCertPath?.trim() || "";
|
||||
let nextUrlParams = urlParams || "";
|
||||
if (nextCaCertPath) {
|
||||
nextUrlParams = setMongoUrlParam(nextUrlParams, "tlsCAFile", "");
|
||||
}
|
||||
return { urlParams: nextUrlParams, caCertPath: nextCaCertPath };
|
||||
}
|
||||
const next = setMongoUrlParam(setMongoUrlParam(setMongoUrlParam(urlParams, "tlsAllowInvalidCertificates", ""), "tlsAllowInvalidHostnames", ""), "tlsCAFile", "");
|
||||
return { urlParams: next, caCertPath: "" };
|
||||
}
|
||||
|
||||
export function mongodbAuthFailureHint(message: string): string {
|
||||
const normalizedMessage = message.toLowerCase();
|
||||
if (normalizedMessage.includes("tlsallowinvalidhostnames is an invalid option")) {
|
||||
return `${message}\n\nDBX uses the Rust MongoDB driver (rustls), which does not accept tlsAllowInvalidHostnames in the connection string. Use tlsAllowInvalidCertificates=true instead. This is commonly required for AWS DocumentDB over an SSH tunnel because the local endpoint is 127.0.0.1 while the server certificate is issued for the DocumentDB hostname.`;
|
||||
}
|
||||
|
||||
if (message.includes('certificate not valid for name "127.0.0.1"') || (message.includes("invalid peer certificate") && message.includes("127.0.0.1") && message.includes("docdb"))) {
|
||||
return `${message}\n\nTLS hostname verification failed because the SSH tunnel connects to 127.0.0.1, but the DocumentDB certificate is issued for the cluster hostname. Add tlsAllowInvalidCertificates=true to URL params. Keep tlsCAFile configured so the certificate chain is still trusted when possible.`;
|
||||
}
|
||||
|
||||
if (message.includes("cannot specify multiple seeds with directConnection=true")) {
|
||||
return `${message}\n\nMongoDB directConnection=true can only be used with a single host. Remove directConnection=true when using a multi-host replica set URL, or keep only one reachable host if you need a direct connection.`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user