Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(pki): raise the post-sync command limit to 8192 characters
bernie-ga7efd13eb091
diff --git a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.tsindex d715d6cf53..7298a26103 100644--- a/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts+++ b/backend/src/services/pki-sync/linux-server/linux-server-pki-sync-schemas.test.ts@@ -81,8 +81,8 @@ describe("Linux Server postSyncCommand validation", () => {});test("rejects a command beyond the length limit", () => {- expect(parseCommand("a".repeat(2048)).success).toBe(true);- expect(parseCommand("a".repeat(2049)).success).toBe(false);+ expect(parseCommand("a".repeat(8192)).success).toBe(true);+ expect(parseCommand("a".repeat(8193)).success).toBe(false);});test("is optional", () => {diff --git a/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.ts b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.tsindex 5871b2080b..eb63276703 100644--- a/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.ts+++ b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.test.ts@@ -266,7 +266,8 @@ describe("runPostSyncCommand", () => {execute: async () => ({ stdout: "x".repeat(5000), stderr: "", exitCode: 0 })});- expect(result.output).toHaveLength(1000 + "... (truncated)".length);+ // The suffix counts against the cap, so the cap bounds what actually gets stored.+ expect(result.output).toHaveLength(1000);expect(result.output?.endsWith("... (truncated)")).toBe(true);});diff --git a/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.ts b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.tsindex e48830525b..02bd5be33a 100644--- a/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.ts+++ b/backend/src/services/pki-sync/pki-sync-post-sync-command-fns.ts@@ -39,7 +39,7 @@ export const findSingleCertificatePostSyncCommandVariables = (command?: string):return SINGLE_CERTIFICATE_VARIABLES.filter((variable) => used.has(variable));};-export const POST_SYNC_COMMAND_MAX_LENGTH = 2048;+export const POST_SYNC_COMMAND_MAX_LENGTH = 8192;export const POST_SYNC_COMMAND_TIMEOUT_MS = 30_000;@@ -173,8 +173,13 @@ export const renderPostSyncCommand = (const redactSecrets = (text: string, secrets: Array<string | undefined>): string =>secrets.reduce<string>((acc, secret) => (secret ? acc.split(secret).join(REDACTED_PLACEHOLDER) : acc), text);+const TRUNCATION_SUFFIX = "... (truncated)";++// The suffix counts against maxLength, so the cap bounds what actually gets stored.const truncate = (text: string, maxLength: number): string =>- text.length > maxLength ? `${text.slice(0, maxLength)}... (truncated)` : text;+ text.length > maxLength+ ? `${text.slice(0, Math.max(0, maxLength - TRUNCATION_SUFFIX.length))}${TRUNCATION_SUFFIX}`+ : text;const firstNonEmptyLine = (text?: string): string | undefined =>text@@ -214,12 +219,13 @@ export const runPostSyncCommand = async (args: {logger.warn(`PKI sync post-sync command failed [syncId=${syncId}] [exitCode=${exitCode}] [durationMs=${durationMs}]`);+ const detail = firstNonEmptyLine(redact(stderr));return {status: PkiSyncStatus.Failed,exitCode,durationMs,output,- failureDetail: firstNonEmptyLine(redact(stderr))?.slice(0, MAX_FAILURE_DETAIL_CHARS),+ failureDetail: detail ? truncate(detail, MAX_FAILURE_DETAIL_CHARS) : undefined,error: `Command exited with code ${exitCode}`};} catch (err) {diff --git a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.test.ts b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.test.tsindex f12f5dd192..f45e997d7f 100644--- a/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.test.ts+++ b/backend/src/services/pki-sync/windows-server/windows-server-pki-sync-schemas.test.ts@@ -78,8 +78,15 @@ describe("Windows Server postSyncCommand validation", () => {});test("rejects a command beyond the length limit", () => {- expect(parseCommand("a".repeat(2048)).success).toBe(true);- expect(parseCommand("a".repeat(2049)).success).toBe(false);+ expect(parseCommand("a".repeat(8192)).success).toBe(true);+ expect(parseCommand("a".repeat(8193)).success).toBe(false);+ });++ test("accepts a non-ASCII command", () => {+ // The gateway base64-encodes the script, so the host's console code page cannot alter it on the+ // way in and the operator is not restricted to ASCII.+ expect(parseCommand("Write-Output 'café'").success).toBe(true);+ expect(parseCommand("Restart-Service -Name 'W3SVC'\r\n\tWrite-Output 'ok'").success).toBe(true);});test("is optional", () => {diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdxindex 96360f9cd2..f18b88b3f3 100644--- a/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx+++ b/docs/documentation/platform/pki/applications/certificate-syncs/linux-server.mdx@@ -163,7 +163,7 @@ sequenceDiagram### Length Limit-A command is limited to 2048 characters, counted after the placeholders are substituted. For anything longer, put the logic in a script on the server and call that script.+A command is limited to 8192 characters, counted after the placeholders are substituted. For anything longer, put the logic in a script on the server and call that script.### Post-Sync Command FAQdiff --git a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdxindex ba043cad8c..5d29a23e7c 100644--- a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx+++ b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx@@ -169,7 +169,7 @@ sequenceDiagram### Length Limit-A command is limited to 2048 characters. Windows caps a command line at 8191 characters and the command is sent to PowerShell encoded, which expands it, so the substituted values count against the same budget. If a long command combined with a sync that delivers many certificates does not fit, the sync reports it clearly. Move the logic into a script file on the server and call that script instead.+A command is limited to 8192 characters, counted after the placeholders are substituted. For anything longer, put the logic in a script on the server and call that script.### Post-Sync Command FAQdiff --git a/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts b/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.tsindex eb34d65008..78d85e0d9b 100644--- a/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts+++ b/frontend/src/components/pki-syncs/forms/schemas/base-pki-sync-schema.ts@@ -1,6 +1,6 @@import { AnyZodObject, z } from "zod";-export const POST_SYNC_COMMAND_MAX_LENGTH = 2048;+export const POST_SYNC_COMMAND_MAX_LENGTH = 8192;export const PostSyncCommandSchema = z.string()