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
add time units to secret scanning env variables
Matheus Nogueirac927d04fc774
diff --git a/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-fns.ts b/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-fns.tsindex 7e814985cb..0be4a22c59 100644--- a/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-fns.ts+++ b/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-fns.ts@@ -150,7 +150,7 @@ export const cloneRepository = async ({ cloneUrl, repoPath }: TCloneRepository):await execFileBounded("git", [...getGitThreadLimitArgs(), "clone", cloneUrl, repoPath, "--bare"], {phase: SecretScanningExecPhase.Clone,- timeoutMs: getConfig().SECRET_SCANNING_CLONE_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_CLONE_TIMEOUT,env: GIT_PROCESS_ENV});};@@ -164,7 +164,7 @@ export async function scanDirectory(inputPath: string, outputPath: string, confiawait execFileBounded("infisical", args, {phase: SecretScanningExecPhase.Scan,cwd: inputPath,- timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT,env: getScannerProcessEnv(),successExitCodes: [0, SCAN_FINDINGS_EXIT_CODE]});@@ -179,7 +179,7 @@ export async function scanFile(inputPath: string, configPath?: string): Promise<try {await execFileBounded("infisical", args, {phase: SecretScanningExecPhase.Scan,- timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT,env: getScannerProcessEnv(),successExitCodes: [0]});diff --git a/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-queue.ts b/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-queue.tsindex 2c500a4320..2efc0c8848 100644--- a/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-queue.ts+++ b/backend/src/ee/services/secret-scanning-v2/secret-scanning-v2-queue.ts@@ -13,7 +13,7 @@ import {scanGitRepositoryAndGetFindings} from "@app/ee/services/secret-scanning-v2/secret-scanning-v2-fns";import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";-import { getConfig, SECRET_SCANNING_SCAN_OVERHEAD_MS } from "@app/lib/config/env";+import { getConfig, SECRET_SCANNING_SCAN_OVERHEAD } from "@app/lib/config/env";import { CronJobName, TCronJobFactory } from "@app/lib/cron/cron-job";import { BadRequestError, InternalServerError } from "@app/lib/errors";import { logger } from "@app/lib/logger";@@ -72,9 +72,7 @@ const STUCK_SCAN_STATUS_MESSAGE =// shorter can expire mid-scan and let a second scan of the same resource start alongside the first.const getFullScanLockTtlMs = () => {const appCfg = getConfig();- return (- appCfg.SECRET_SCANNING_CLONE_TIMEOUT_MS + appCfg.SECRET_SCANNING_SCAN_TIMEOUT_MS + SECRET_SCANNING_SCAN_OVERHEAD_MS- );+ return appCfg.SECRET_SCANNING_CLONE_TIMEOUT + appCfg.SECRET_SCANNING_SCAN_TIMEOUT + SECRET_SCANNING_SCAN_OVERHEAD;};export const secretScanningV2QueueServiceFactory = ({@@ -837,10 +835,10 @@ export const secretScanningV2QueueServiceFactory = ({pattern: "*/10 * * * *",runHashTtlS: 60 * 60,handler: async () => {- const { SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS } = getConfig();+ const { SECRET_SCANNING_STUCK_SCAN_TIMEOUT } = getConfig();const stuckScans = await secretScanningV2DAL.scans.findStuck(- new Date(Date.now() - SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS),+ new Date(Date.now() - SECRET_SCANNING_STUCK_SCAN_TIMEOUT),STUCK_SCAN_REAP_BATCH_SIZE);diff --git a/backend/src/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns.ts b/backend/src/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns.tsindex b817072431..e8f307ae7e 100644--- a/backend/src/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns.ts+++ b/backend/src/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns.ts@@ -46,7 +46,7 @@ export async function cloneRepo(await execFileBounded("git", [...getGitThreadLimitArgs(), "clone", cloneUrl, repoPath, "--bare"], {phase: SecretScanningExecPhase.Clone,- timeoutMs: getConfig().SECRET_SCANNING_CLONE_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_CLONE_TIMEOUT,env: GIT_PROCESS_ENV});}@@ -55,7 +55,7 @@ export async function runInfisicalScanOnRepo(repoPath: string, outputPath: strinawait execFileBounded("infisical", ["scan", "--exit-code=77", "-r", outputPath], {phase: SecretScanningExecPhase.Scan,cwd: repoPath,- timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT,env: getScannerProcessEnv(),successExitCodes: [0, SCAN_FINDINGS_EXIT_CODE]});@@ -69,7 +69,7 @@ export async function runInfisicalScan(inputPath: string, outputPath: string, coawait execFileBounded("infisical", args, {phase: SecretScanningExecPhase.Scan,- timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT_MS,+ timeoutMs: getConfig().SECRET_SCANNING_SCAN_TIMEOUT,env: getScannerProcessEnv(),successExitCodes: [0, SCAN_FINDINGS_EXIT_CODE]});diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.tsindex 5c69295a71..eb9f1337e7 100644--- a/backend/src/lib/config/env.ts+++ b/backend/src/lib/config/env.ts@@ -63,7 +63,44 @@ export const runModesSchema = zpStr(z.string().optional())* headroom when validating the stuck-scan threshold so the reaper can't reach a healthy scan, and* as the scan lock TTL headroom so the lock outlives any scan the reaper would consider healthy.*/-export const SECRET_SCANNING_SCAN_OVERHEAD_MS = 5 * 60 * 1000;+export const SECRET_SCANNING_SCAN_OVERHEAD = ms("5m");++// The `_MS` counterpart of each of these variables was the numeric form of the same timeout, and is+// still honoured for instances that set it. `ms` reads a bare number as milliseconds, so a legacy+// value needs no parsing of its own.+const zodTimeoutMs = ({+ description,+ defaultValue,+ legacyMsEnvVar+}: {+ description: string;+ defaultValue: string;+ legacyMsEnvVar: string;+}) =>+ zpStr(+ z+ .string()+ .optional()+ .describe(description)+ .transform((val, ctx) => {+ const legacyValue = process.env[legacyMsEnvVar]?.trim() || undefined;+ const raw = val ?? legacyValue ?? defaultValue;++ const duration = ms(raw);+ if (duration === undefined || duration < 1) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message:+ val === undefined+ ? `Invalid value "${raw}" in ${legacyMsEnvVar}. Expected a positive number of milliseconds.`+ : `Invalid duration "${raw}". Expected a positive duration string such as "30s", "10m" or "6h".`+ });+ return z.NEVER;+ }++ return duration;+ })+ );const databaseReadReplicaSchema = z.object({@@ -371,18 +408,16 @@ const envSchema = zSECRET_SCANNING_PRIVATE_KEY: zpStr(z.string().optional()),SECRET_SCANNING_ORG_WHITELIST: zpStr(z.string().optional()),SECRET_SCANNING_GIT_APP_SLUG: zpStr(z.string().default("infisical-radar")),- SECRET_SCANNING_SCAN_TIMEOUT_MS: z.coerce- .number()- .int()- .min(1)- .default(10 * 60 * 1000)- .describe("Wall-clock ceiling for a single `infisical scan` invocation before its process group is killed"),- SECRET_SCANNING_CLONE_TIMEOUT_MS: z.coerce- .number()- .int()- .min(1)- .default(10 * 60 * 1000)- .describe("Wall-clock ceiling for a single `git clone` invocation before its process group is killed"),+ SECRET_SCANNING_SCAN_TIMEOUT: zodTimeoutMs({+ description: "Wall-clock ceiling for a single `infisical scan` invocation before its process group is killed",+ defaultValue: "10m",+ legacyMsEnvVar: "SECRET_SCANNING_SCAN_TIMEOUT_MS"+ }),+ SECRET_SCANNING_CLONE_TIMEOUT: zodTimeoutMs({+ description: "Wall-clock ceiling for a single `git clone` invocation before its process group is killed",+ defaultValue: "10m",+ legacyMsEnvVar: "SECRET_SCANNING_CLONE_TIMEOUT_MS"+ }),SECRET_SCANNING_MEMORY_LIMIT_MB: z.coerce.number().int()@@ -405,14 +440,12 @@ const envSchema = z.min(0).default(5120).describe("Repositories larger than this are rejected before/after cloning. Set to 0 to disable."),- SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS: z.coerce- .number()- .int()- .min(1)- .default(60 * 60 * 1000)- .describe(- "A scan left in the `scanning` state for longer than this is marked failed by the reaper. Must exceed clone + scan timeouts combined."- ),+ SECRET_SCANNING_STUCK_SCAN_TIMEOUT: zodTimeoutMs({+ description:+ "A scan left in the `scanning` state for longer than this is marked failed by the reaper. Must exceed clone + scan timeouts combined.",+ defaultValue: "1h",+ legacyMsEnvVar: "SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS"+ }),// LICENSE// The License Server host. Serves both the self-hosted token endpoint and the entitlement API.LICENSE_SERVER_URL: zpStr(z.string().optional().default("https://portal.infisical.com")),@@ -634,12 +667,12 @@ const envSchema = z});const scanBudgetMs =- data.SECRET_SCANNING_CLONE_TIMEOUT_MS + data.SECRET_SCANNING_SCAN_TIMEOUT_MS + SECRET_SCANNING_SCAN_OVERHEAD_MS;- if (data.SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS <= scanBudgetMs) {+ data.SECRET_SCANNING_CLONE_TIMEOUT + data.SECRET_SCANNING_SCAN_TIMEOUT + SECRET_SCANNING_SCAN_OVERHEAD;+ if (data.SECRET_SCANNING_STUCK_SCAN_TIMEOUT <= scanBudgetMs) {ctx.addIssue({code: z.ZodIssueCode.custom,- path: ["SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS"],- message: `SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS (${data.SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS}ms) must exceed SECRET_SCANNING_CLONE_TIMEOUT_MS + SECRET_SCANNING_SCAN_TIMEOUT_MS plus ${SECRET_SCANNING_SCAN_OVERHEAD_MS}ms of measurement and bookkeeping (${scanBudgetMs}ms), otherwise healthy in-flight scans are reaped as stuck.`+ path: ["SECRET_SCANNING_STUCK_SCAN_TIMEOUT"],+ message: `SECRET_SCANNING_STUCK_SCAN_TIMEOUT (${data.SECRET_SCANNING_STUCK_SCAN_TIMEOUT}ms) must exceed SECRET_SCANNING_CLONE_TIMEOUT + SECRET_SCANNING_SCAN_TIMEOUT plus ${SECRET_SCANNING_SCAN_OVERHEAD}ms of measurement and bookkeeping (${scanBudgetMs}ms), otherwise healthy in-flight scans are reaped as stuck.`});}})diff --git a/docs/self-hosting/configuration/envars.mdx b/docs/self-hosting/configuration/envars.mdxindex f4fc56c9e3..e7891a367a 100644--- a/docs/self-hosting/configuration/envars.mdx+++ b/docs/self-hosting/configuration/envars.mdx@@ -1008,26 +1008,18 @@ You can configure third-party app connections for re-use across Infisical Projec{" "}-<ParamField- query="SECRET_SCANNING_SCAN_TIMEOUT_MS"- type="number"- default="600000"- optional->- How long, in milliseconds, a single scan may run before it is cancelled and- the scan is marked failed. Defaults to `600000` (10 minutes).+<ParamField query="SECRET_SCANNING_SCAN_TIMEOUT" type="string" default="10m" optional>+ How long a single scan may run before it is cancelled and the scan is marked+ failed. Takes a duration string such as `90s`, `10m`, or `2h`. Defaults to+ `10m`.</ParamField>{" "}-<ParamField- query="SECRET_SCANNING_CLONE_TIMEOUT_MS"- type="number"- default="600000"- optional->- How long, in milliseconds, cloning a repository may take before it is- cancelled and the scan is marked failed. Defaults to `600000` (10 minutes).+<ParamField query="SECRET_SCANNING_CLONE_TIMEOUT" type="string" default="10m" optional>+ How long cloning a repository may take before it is cancelled and the scan is+ marked failed. Takes a duration string such as `90s`, `10m`, or `2h`. Defaults+ to `10m`.</ParamField>{" "}@@ -1069,11 +1061,11 @@ You can configure third-party app connections for re-use across Infisical ProjecDefaults to `5120` (5 GB). Set to `0` to disable.</ParamField>- <ParamField query="SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS" type="number" default="3600000" optional>- How long, in milliseconds, a scan may stay in progress before it is assumed dead — its worker- was killed — and marked failed. Defaults to `3600000` (1 hour). Must exceed the clone and scan- timeouts plus the time a scan spends measuring the repository and writing its results; the- server refuses to start otherwise.+ <ParamField query="SECRET_SCANNING_STUCK_SCAN_TIMEOUT" type="string" default="1h" optional>+ How long a scan may stay in progress before it is assumed dead — its worker was killed — and+ marked failed. Takes a duration string such as `90s`, `10m`, or `2h`. Defaults to `1h`. Must+ exceed the clone and scan timeouts plus the time a scan spends measuring the repository and+ writing its results; the server refuses to start otherwise.</ParamField></Accordion>