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
greptile review comments + backfill for some missing schema items related to TLS
x032205e61efc54d06e
diff --git a/backend/src/db/migrations/20260321035221_pam-tls-config-defaults.ts b/backend/src/db/migrations/20260321035221_pam-tls-config-defaults.tsnew file mode 100644index 0000000000..c8616580fe--- /dev/null+++ b/backend/src/db/migrations/20260321035221_pam-tls-config-defaults.ts@@ -0,0 +1,111 @@+import { Knex } from "knex";++import { inMemoryKeyStore } from "@app/keystore/memory";+import { initLogger } from "@app/lib/logger";+import { kmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";+import { KmsDataKey } from "@app/services/kms/kms-types";+import { superAdminDALFactory } from "@app/services/super-admin/super-admin-dal";++import { TableName } from "../schemas";+import { getMigrationEnvConfig, getMigrationHsmConfig } from "./utils/env-config";+import { getMigrationEncryptionServices, getMigrationHsmService } from "./utils/services";++const BATCH_SIZE = 500;++export async function up(knex: Knex): Promise<void> {+ // Backfill discovery sources+ await knex(TableName.PamDiscoverySource)+ .whereRaw(`"discoveryConfiguration" IS NOT NULL AND ("discoveryConfiguration"::jsonb ->> 'useLdaps') IS NULL`)+ .update({+ discoveryConfiguration: knex.raw(+ `"discoveryConfiguration"::jsonb || '{+ "ldapPort": 636,+ "useLdaps": true,+ "ldapRejectUnauthorized": true,+ "winrmPort": 5986,+ "useWinrmHttps": true,+ "winrmRejectUnauthorized": true,+ "discoverDependencies": false+ }'::jsonb`+ )+ });++ // Backfill encrypted resource connection details+ const hasPamResourceTable = await knex.schema.hasTable(TableName.PamResource);+ if (!hasPamResourceTable) return;++ const resources = await knex(TableName.PamResource)+ .whereIn("resourceType", ["active-directory", "windows"])+ .whereNotNull("encryptedConnectionDetails")+ .select("id", "projectId", "resourceType", "encryptedConnectionDetails");++ if (!resources.length) return;++ initLogger();+ const { hsmService } = await getMigrationHsmService({ envConfig: getMigrationHsmConfig() });+ const superAdminDAL = superAdminDALFactory(knex);+ const kmsRootConfigDAL = kmsRootConfigDALFactory(knex);+ const envConfig = await getMigrationEnvConfig(superAdminDAL, hsmService, kmsRootConfigDAL);+ const keyStore = inMemoryKeyStore();+ const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });++ const updates: { id: string; encryptedConnectionDetails: Buffer }[] = [];++ for (const resource of resources) {+ try {+ // eslint-disable-next-line no-await-in-loop+ const { decryptor, encryptor } = await kmsService.createCipherPairWithDataKey(+ { type: KmsDataKey.SecretManager, projectId: resource.projectId },+ knex+ );++ const decrypted = JSON.parse(decryptor({ cipherTextBlob: resource.encryptedConnectionDetails }).toString());++ let modified = false;++ if (resource.resourceType === "active-directory") {+ if (decrypted.useLdaps === undefined) {+ decrypted.useLdaps = true;+ modified = true;+ }+ if (decrypted.ldapRejectUnauthorized === undefined) {+ decrypted.ldapRejectUnauthorized = true;+ modified = true;+ }+ }++ if (resource.resourceType === "windows") {+ if (decrypted.winrmPort === undefined) {+ decrypted.winrmPort = 5986;+ modified = true;+ }+ if (decrypted.useWinrmHttps === undefined) {+ decrypted.useWinrmHttps = true;+ modified = true;+ }+ if (decrypted.winrmRejectUnauthorized === undefined) {+ decrypted.winrmRejectUnauthorized = true;+ modified = true;+ }+ }++ if (modified) {+ const encrypted = encryptor({ plainText: Buffer.from(JSON.stringify(decrypted)) }).cipherTextBlob;+ updates.push({ id: resource.id, encryptedConnectionDetails: encrypted });+ }+ } catch {+ // Skip resources that fail to decrypt+ }+ }++ for (let i = 0; i < updates.length; i += BATCH_SIZE) {+ const batch = updates.slice(i, i + BATCH_SIZE);++ // eslint-disable-next-line no-await-in-loop+ await Promise.all(batch.map((u) => knex(TableName.PamResource).where("id", u.id).update(u)));+ }+}++export async function down(): Promise<void> {+ // No down migration needed+}diff --git a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.tsindex de81a0e798..114c61cf78 100644--- a/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts+++ b/backend/src/ee/services/pam-resource/active-directory/active-directory-resource-schemas.ts@@ -26,8 +26,8 @@ export const ActiveDirectoryResourceConnectionDetailsSchema = z.object({domain: z.string().trim().min(1).max(255),dcAddress: z.string().trim().min(1).max(255),port: z.coerce.number().int().min(1).max(65535),- useLdaps: z.boolean(),- ldapRejectUnauthorized: z.boolean(),+ useLdaps: z.boolean().optional(),+ ldapRejectUnauthorized: z.boolean().optional(),ldapCaCert: z.string().trim()diff --git a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.tsindex 90b902fd24..565523caa7 100644--- a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts+++ b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts@@ -54,8 +54,6 @@ export const buildDependencySyncScript = (const escapedName = escapePowershellSingleQuote(dep.name);const escapedUsername = escapePowershellSingleQuote(accountUsername);- validateWindowsName(escapedName, "Dependency name");-switch (dep.dependencyType) {case PamAccountDependencyType.WindowsService:return [@@ -68,7 +66,6 @@ export const buildDependencySyncScript = (const taskPath = taskData?.TaskPath ?? "\\";validateWindowsPath(taskPath, "Task path");const escapedPath = escapePowershellSingleQuote(taskPath);- validateWindowsPath(escapedPath, "Task path");return `schtasks.exe /Change /TN '${escapedPath}${escapedName}' /RU '${escapedUsername}' /RP '${escapedPassword}'`;}diff --git a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-factory.ts b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-factory.tsindex bf1b8adde0..8d356e65fb 100644--- a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-factory.ts+++ b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-factory.ts@@ -169,7 +169,7 @@ export const windowsResourceFactory: TPamResourceFactory<rotationAccountCredentials.password,proxyPort,useWinrmHttps,- useWinrmHttps ? (connectionDetails.winrmRejectUnauthorized ?? false) : undefined,+ useWinrmHttps ? connectionDetails.winrmRejectUnauthorized : undefined,connectionDetails.winrmCaCert);diff --git a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.tsindex 6de30c11bb..c2a78b7e79 100644--- a/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts+++ b/backend/src/ee/services/pam-resource/windows-server/windows-server-resource-schemas.ts@@ -28,9 +28,9 @@ export const WindowsResourceConnectionDetailsSchema = z.object({port: z.coerce.number().int().min(1).max(65535),// WinRM config — used for rotation only, configured in the rotation policy modal- winrmPort: z.coerce.number().int().min(1).max(65535).optional(),- useWinrmHttps: z.boolean().optional(),- winrmRejectUnauthorized: z.boolean().optional(),+ winrmPort: z.coerce.number().int().min(1).max(65535),+ useWinrmHttps: z.boolean(),+ winrmRejectUnauthorized: z.boolean(),winrmCaCert: z.string().trim()