Skip to content

Commit 0c1dfe9

Browse files
Artur Spatariclaude
andcommitted
fix(vault): read Infisical secrets pulled in through an import
Fixes Dokploy#5413. A secret brought into a folder with "Import Secrets" was reported as not found. Two reasons, and the first is easy to miss: The list endpoint takes the flag in **snake_case**. `includeImports` is silently ignored — the request still returns 200, with `imports` present but empty — so the imported secret looked like it simply did not exist. Measured against app.infisical.com with a registered import (confirmed via GET /api/v1/secret-imports): expandSecretReferences=true imports[] empty expandSecretReferences=true&includeImports=true imports[] empty expandSecretReferences=true&include_imports=true imports[] has the secret Second, imported secrets never appear in `secrets` — they come back in a separate `imports` array, one entry per source path, which the client did not read at all. Imported entries are merged before the folder's own, so a name defined in both resolves to the local value, matching how Infisical resolves it. Also measured, for whoever looks next: `/api/v4/secrets` returns imports with no flag at all, and single-secret reads (`/raw/{name}`) never see an imported key — 404 on v3, no such route on v4. So a folder listing is the only way to reach them. vault.test.ts: 57 passed. Reverting the fix fails the new merge test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 88118cd commit 0c1dfe9

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,50 @@ describe("infisical client", () => {
472472
expect(params.get("secretPath")).toBe("/frontend");
473473
});
474474

475+
it("asks for imported secrets and merges them", async () => {
476+
mockFetch.mockResolvedValueOnce(loginResponse()).mockResolvedValueOnce(
477+
jsonResponse({
478+
secrets: [],
479+
imports: [
480+
{
481+
secretPath: "/shared",
482+
secrets: [
483+
{ secretKey: "DB_URL", secretValue: "postgres://imported" },
484+
],
485+
},
486+
],
487+
}),
488+
);
489+
490+
const result = await infisicalClient.getSecrets(config, ["DB_URL"]);
491+
492+
expect(result).toEqual({ DB_URL: "postgres://imported" });
493+
const [listUrl] = mockFetch.mock.calls[1] as [string];
494+
// snake_case on purpose: `includeImports` is silently ignored and the
495+
// response comes back with an empty `imports` array.
496+
expect(new URL(listUrl).searchParams.get("include_imports")).toBe("true");
497+
});
498+
499+
it("lets a folder's own secret win over an imported one of the same name", async () => {
500+
mockFetch.mockResolvedValueOnce(loginResponse()).mockResolvedValueOnce(
501+
jsonResponse({
502+
secrets: [{ secretKey: "DB_URL", secretValue: "postgres://local" }],
503+
imports: [
504+
{
505+
secretPath: "/shared",
506+
secrets: [
507+
{ secretKey: "DB_URL", secretValue: "postgres://imported" },
508+
],
509+
},
510+
],
511+
}),
512+
);
513+
514+
const result = await infisicalClient.getSecrets(config, ["DB_URL"]);
515+
516+
expect(result).toEqual({ DB_URL: "postgres://local" });
517+
});
518+
475519
it("throws a clear error for a missing secret", async () => {
476520
mockFetch
477521
.mockResolvedValueOnce(loginResponse())

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ const readPath = async (
7979
// still reports success. Single secrets read via /raw/{name} expand by
8080
// default, which makes the difference easy to miss in the UI.
8181
expandSecretReferences: "true",
82+
// Secrets pulled in through "Import Secrets" are not part of `secrets`:
83+
// they come back in a separate `imports` array, and only when this is
84+
// asked for. Note the snake_case — `includeImports` is silently ignored
85+
// (the request still returns 200 with an empty `imports`), which is why
86+
// an imported secret looked like it simply did not exist.
87+
include_imports: "true",
8288
});
8389
const response = await vaultFetch(
8490
`${baseUrl(config)}/api/v3/secrets/raw?${params.toString()}`,
@@ -93,9 +99,17 @@ const readPath = async (
9399

94100
const body = (await response.json()) as {
95101
secrets?: { secretKey: string; secretValue: string }[];
102+
imports?: { secrets?: { secretKey: string; secretValue: string }[] }[];
96103
};
97104

98105
const secrets: Record<string, string> = {};
106+
// Imported first, then the folder's own: Infisical resolves a name defined
107+
// in both in favour of the local one, so writing local last preserves that.
108+
for (const imported of body.imports ?? []) {
109+
for (const secret of imported.secrets ?? []) {
110+
secrets[secret.secretKey] = secret.secretValue;
111+
}
112+
}
99113
for (const secret of body.secrets ?? []) {
100114
secrets[secret.secretKey] = secret.secretValue;
101115
}

0 commit comments

Comments
 (0)