Skip to content

Commit 6e760da

Browse files
author
Artur Spatari
committed
fix(vault): expand Infisical secret references when listing secrets
A secret in Infisical can reference another one (`${env.folder.KEY}`), which is the only way to keep a value in one place and read it from several folders. The Infisical client fetches `/api/v3/secrets/raw` without `expandSecretReferences`, and that endpoint leaves references untouched by default. The referencing secret therefore arrives as the literal `${...}` string, is written to the generated `.env`, and the deployment still reports success — the service just receives a placeholder instead of its value. This is easy to miss because the single-secret endpoint (`/raw/{name}`) does expand by default, so the Infisical UI and API show the resolved value while only Dokploy sees the literal. Adds the parameter and the first tests for this client: the list request now asserts the flag, a missing secret and an auth failure. Without the fix the new test fails with `expected null to be 'true'`.
1 parent ab87f2d commit 6e760da

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎apps/dokploy/__test__/env/vault.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { azureClient } from "@dokploy/server/utils/vault/azure";
2121
import { dopplerClient } from "@dokploy/server/utils/vault/doppler";
2222
import { hashicorpClient } from "@dokploy/server/utils/vault/hashicorp";
23+
import { infisicalClient } from "@dokploy/server/utils/vault/infisical";
2324
import { phaseClient } from "@dokploy/server/utils/vault/phase";
2425
import { scalewayClient } from "@dokploy/server/utils/vault/scaleway";
2526

@@ -431,6 +432,58 @@ describe("azure client", () => {
431432
});
432433
});
433434

435+
describe("infisical client", () => {
436+
const config = {
437+
providerType: "infisical" as const,
438+
siteUrl: "https://app.infisical.com",
439+
clientId: "client-1",
440+
clientSecret: "client-secret",
441+
projectId: "workspace-1",
442+
environmentSlug: "prod",
443+
secretPath: "/frontend",
444+
};
445+
446+
const loginResponse = () => jsonResponse({ accessToken: "token-1" });
447+
448+
it("asks the list endpoint to expand secret references", async () => {
449+
mockFetch
450+
.mockResolvedValueOnce(loginResponse())
451+
.mockResolvedValueOnce(
452+
jsonResponse({
453+
secrets: [{ secretKey: "DB_URL", secretValue: "postgres://real" }],
454+
}),
455+
);
456+
457+
const result = await infisicalClient.getSecrets(config, ["DB_URL"]);
458+
459+
expect(result).toEqual({ DB_URL: "postgres://real" });
460+
const [listUrl] = mockFetch.mock.calls[1] as [string];
461+
const params = new URL(listUrl).searchParams;
462+
expect(params.get("expandSecretReferences")).toBe("true");
463+
expect(params.get("workspaceId")).toBe("workspace-1");
464+
expect(params.get("environment")).toBe("prod");
465+
expect(params.get("secretPath")).toBe("/frontend");
466+
});
467+
468+
it("throws a clear error for a missing secret", async () => {
469+
mockFetch
470+
.mockResolvedValueOnce(loginResponse())
471+
.mockResolvedValueOnce(jsonResponse({ secrets: [] }));
472+
473+
await expect(
474+
infisicalClient.getSecrets(config, ["ABSENT"]),
475+
).rejects.toThrow('secret "ABSENT" not found in environment "prod"');
476+
});
477+
478+
it("propagates authentication failures with the status code", async () => {
479+
mockFetch.mockResolvedValueOnce(jsonResponse({}, false, 401));
480+
481+
await expect(infisicalClient.getSecrets(config, ["DB_URL"])).rejects.toThrow(
482+
"authentication failed (status 401)",
483+
);
484+
});
485+
});
486+
434487
describe("doppler client", () => {
435488
it("propagates auth errors with the status code", async () => {
436489
mockFetch.mockResolvedValue(jsonResponse({}, false, 401));

‎packages/server/src/utils/vault/infisical.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const fetchSecrets = async (config: InfisicalConfig) => {
3838
workspaceId: config.projectId,
3939
environment: config.environmentSlug,
4040
secretPath: config.secretPath,
41+
// Infisical's list endpoint leaves secret references (`${env.folder.KEY}`)
42+
// unexpanded unless asked, so without this a referencing secret arrives as
43+
// the literal `${...}` string, lands in the generated .env and the deploy
44+
// still reports success. Single secrets read via /raw/{name} expand by
45+
// default, which makes the difference easy to miss in the UI.
46+
expandSecretReferences: "true",
4147
});
4248
const response = await vaultFetch(
4349
`${baseUrl(config)}/api/v3/secrets/raw?${params.toString()}`,

0 commit comments

Comments
 (0)