Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Bitwarden: pass the CA trust settings to bw so a private-CA Vaultwarden connects (#7060)

ARAYN701135a67d44757a
diff --git a/server/host/bitwarden-cli.test.ts b/server/host/bitwarden-cli.test.ts
index 5b2df66c44..947b572ed8 100644
--- a/server/host/bitwarden-cli.test.ts
+++ b/server/host/bitwarden-cli.test.ts
@@ -53,6 +53,24 @@ describe("Bitwarden's command line tool, fetched on first use", () => {
await expect(installBitwardenCli({ dataDir, pin: null })).rejects.toThrow("Bitwarden publishes none");
});
+ it.skipIf(process.platform === "win32")("hands it the server's CA trust settings so a private-CA Vaultwarden connects, and nothing else", async () => {
+ const dir = temp();
+ const tool = join(dir, "bw");
+ writeFileSync(tool, `#!/bin/sh\necho "ca=$NODE_EXTRA_CA_CERTS"\necho "file=$SSL_CERT_FILE"\necho "dir=$SSL_CERT_DIR"\necho "proxy=$OMB_FAKE_SERVER_SECRET"\n`, { mode: 0o755 });
+ const saved = { ca: process.env.NODE_EXTRA_CA_CERTS, file: process.env.SSL_CERT_FILE, dir: process.env.SSL_CERT_DIR };
+ process.env.NODE_EXTRA_CA_CERTS = "/etc/private-ca.pem"; process.env.SSL_CERT_FILE = "/etc/ssl/cert.pem"; delete process.env.SSL_CERT_DIR;
+ process.env.OMB_FAKE_SERVER_SECRET = "never-passed";
+ try {
+ const result = await bitwardenRunner({ executable: async () => tool, appDataDir: join(dir, "account") })(["status"]);
+ expect(result.stdout).toBe("ca=/etc/private-ca.pem\nfile=/etc/ssl/cert.pem\ndir=\nproxy=\n");
+ } finally {
+ delete process.env.OMB_FAKE_SERVER_SECRET;
+ for (const [key, name] of [["ca", "NODE_EXTRA_CA_CERTS"], ["file", "SSL_CERT_FILE"], ["dir", "SSL_CERT_DIR"]] as const) {
+ if (saved[key] === undefined) delete process.env[name]; else process.env[name] = saved[key];
+ }
+ }
+ });
+
it.skipIf(process.platform === "win32")("runs it as a separate process with secrets in its environment only, and none of the server's own", async () => {
const dir = temp();
const tool = join(dir, "bw");
diff --git a/server/host/bitwarden-cli.ts b/server/host/bitwarden-cli.ts
index d773839b01..84bb9b4dcb 100644
--- a/server/host/bitwarden-cli.ts
+++ b/server/host/bitwarden-cli.ts
@@ -95,7 +95,11 @@ export interface BwResult { code: number; stdout: string; stderr: string; timedO
/** One `bw` call: `env` carries every secret (BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD, BW_SESSION). */
export type BwRun = (args: readonly string[], env?: Record<string, string>, timeoutMs?: number) => Promise<BwResult>;
-/** Runs the tool with only what it needs: its own settings folder, no prompts, and nothing of the server's environment. */
+/** The only server settings the tool is given besides its own: which certificate authorities to trust, so a self-hosted
+ * Vaultwarden behind a private CA connects. They name files and folders, never secrets. */
+const TRUST_ENV = ["NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR"] as const;
+
+/** Runs the tool with only what it needs: its own settings folder, no prompts, the CA trust settings, and nothing else of the server's environment. */
export function bitwardenRunner(options: { executable: () => Promise<string>; appDataDir: string }): BwRun {
return async (args, env = {}, timeoutMs = DEFAULT_CALL_TIMEOUT_MS) => {
const file = await options.executable();
@@ -103,7 +107,7 @@ export function bitwardenRunner(options: { executable: () => Promise<string>; ap
return new Promise((resolve) => {
execFile(file, [...args], {
env: {
- PATH: process.env.PATH ?? "", ...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
+ PATH: process.env.PATH ?? "", ...trustEnv(), ...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
HOME: options.appDataDir, BITWARDENCLI_APPDATA_DIR: options.appDataDir, BW_NOINTERACTION: "true", NODE_OPTIONS: "", ...env,
},
timeout: timeoutMs, maxBuffer: OUTPUT_MAX, windowsHide: true, encoding: "utf8",
@@ -116,6 +120,12 @@ export function bitwardenRunner(options: { executable: () => Promise<string>; ap
};
}
+function trustEnv(): Record<string, string> {
+ const out: Record<string, string> = {};
+ for (const name of TRUST_ENV) { const value = process.env[name]; if (value) out[name] = value; }
+ return out;
+}
+
/** Leaves the folder clean when the person disconnects: the tool's own settings and cached vault go with the account. */
export function forgetBitwardenAppData(appDataDir: string): void {
rmSync(appDataDir, { recursive: true, force: true });