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
Address greptile comments
Carlos Monastyrski59e78c9afe36
diff --git a/backend/src/services/signer/signer-issuance-job-dal.ts b/backend/src/services/signer/signer-issuance-job-dal.tsindex 7a09abcc5f..40667b59e6 100644--- a/backend/src/services/signer/signer-issuance-job-dal.ts+++ b/backend/src/services/signer/signer-issuance-job-dal.ts@@ -25,6 +25,19 @@ export const signerIssuanceJobDALFactory = (db: TDbClient) => {}};+ const findPendingForSignerForUpdate = async (+ signerId: string,+ tx: Knex+ ): Promise<TPkiSignerCertificateIssuanceJobs[]> => {+ try {+ return (await tx(TableName.PkiSignerCertificateIssuanceJobs)+ .where({ signerId, status: SignerIssuanceJobStatus.Pending })+ .forUpdate()) as TPkiSignerCertificateIssuanceJobs[];+ } catch (error) {+ throw new DatabaseError({ error, name: "FindPendingSignerIssuanceJobsForUpdate" });+ }+ };+const cancelOpenForSigner = async (signerId: string, reason: string, tx?: Knex) => {try {await (tx || db)(TableName.PkiSignerCertificateIssuanceJobs)@@ -97,5 +110,13 @@ export const signerIssuanceJobDALFactory = (db: TDbClient) => {}};- return { ...orm, findDuePending, cancelOpenForSigner, completeIfPending, claimForAttempt, findLatestForSigner };+ return {+ ...orm,+ findDuePending,+ findPendingForSignerForUpdate,+ cancelOpenForSigner,+ completeIfPending,+ claimForAttempt,+ findLatestForSigner+ };};diff --git a/backend/src/services/signer/signer-issuance-service.ts b/backend/src/services/signer/signer-issuance-service.tsindex 10f5c94c63..7068107ef4 100644--- a/backend/src/services/signer/signer-issuance-service.ts+++ b/backend/src/services/signer/signer-issuance-service.ts@@ -38,6 +38,7 @@ import { SignerExternalCaConfigSchema } from "./signer-types";const POLL_INTERVAL_PATTERN = "*/15 * * * *"; // every 15 minutesconst POLL_BATCH = 25;const RETRY_BACKOFF_MS = 15 * 60_000;+const IN_FLIGHT_ATTEMPT_MS = 5 * 60_000;// DigiCert CS orders can sit pending for up to 3 business days while DigiCert validates the org and// waits for the verified-contact email click, so they get a longer window than synchronous CAs.@@ -653,7 +654,8 @@ export const signerIssuanceServiceFactory = ({orderId,certificateId,lastStatus: CodeSigningOrderStatus.Pending,- lastCheckedAt: new Date().toISOString()+ lastCheckedAt: new Date().toISOString(),+ lifecycle}}});@@ -740,7 +742,8 @@ export const signerIssuanceServiceFactory = ({orderId: existingOrderId,certificateId: info.certificateId,lastStatus: info.status,- lastCheckedAt: new Date().toISOString()+ lastCheckedAt: new Date().toISOString(),+ lifecycle}}});@@ -854,8 +857,28 @@ export const signerIssuanceServiceFactory = ({};};- const cancelOpenJobs = async (signerId: string, reason: string, tx?: Knex) =>- signerIssuanceJobDAL.cancelOpenForSigner(signerId, reason, tx);+ const cancelOpenJobs = async (signerId: string, orderId: number, tx: Knex) => {+ const openJobs = await signerIssuanceJobDAL.findPendingForSignerForUpdate(signerId, tx);+ const now = Date.now();+ const reissueInProgress = openJobs.some((job) => {+ const digicert = (job.externalOrderRef as TDigiCertExternalOrderRef | null)?.digicert;+ if (digicert?.orderId === orderId) return true;+ if (digicert?.lifecycle?.previousOrderId !== orderId) return false;+ const isAttemptInFlight =+ Boolean(job.lastAttemptAt) && now - new Date(job.lastAttemptAt as Date).getTime() < IN_FLIGHT_ATTEMPT_MS;+ return Boolean(digicert.orderId) || isAttemptInFlight;+ });+ if (reissueInProgress) {+ throw new ConflictError({+ message: `A certificate request into DigiCert order ${orderId} is already in progress for this signer, and it would revoke the order's current certificate. Wait for it to finish, then try again.`+ });+ }+ await signerIssuanceJobDAL.cancelOpenForSigner(+ signerId,+ "Superseded by an existing DigiCert certificate attached to the signer.",+ tx+ );+ };const runPendingJobNow = async (signerId: string): Promise<void> => {const job = await signerIssuanceJobDAL.transaction((tx) => signerIssuanceJobDAL.findLatestForSigner(signerId, tx));diff --git a/backend/src/services/signer/signer-service.ts b/backend/src/services/signer/signer-service.tsindex daf73da35b..3214b3aa8f 100644--- a/backend/src/services/signer/signer-service.ts+++ b/backend/src/services/signer/signer-service.ts@@ -527,6 +527,9 @@ export const signerServiceFactory = ({message: `The certificate in DigiCert order ${imported.orderId} is already used by signer '${signerUsingCertificate.name}'.`});}+ await tx.raw("SELECT pg_advisory_xact_lock(hashtext(?))", [+ `signer-hsm-key:${imported.hsm.hsmPublicKeySpki.toString("hex")}`+ ]);const signerUsingKey = await signerDAL.findOneInOrgByCurrentHsmPublicKey(imported.projectId,imported.hsm.hsmPublicKeySpki,@@ -698,6 +701,16 @@ export const signerServiceFactory = ({}): null;+ if (+ importedCertificate &&+ dto.certificateRenewBeforeDays != null &&+ dto.certificateRenewBeforeDays >= importedCertificate.certificateTtlDays+ ) {+ throw new BadRequestError({+ message: `Renew before (${dto.certificateRenewBeforeDays}d) must be less than the validity of the certificate in DigiCert order ${importOrderId} (${importedCertificate.certificateTtlDays}d).`+ });+ }+const keyAlgorithm: CertKeyAlgorithm =importedCertificate?.keyAlgorithm ?? (dto.keyAlgorithm as CertKeyAlgorithm) ?? CertKeyAlgorithm.RSA_2048;@@ -1477,13 +1490,17 @@ export const signerServiceFactory = ({actor: { type: dto.actor, id: dto.actorId, authMethod: dto.actorAuthMethod, orgId: dto.actorOrgId },signerId: signer.id});+ if (+ signer.certificateRenewBeforeDays != null &&+ signer.certificateRenewBeforeDays >= imported.certificateTtlDays+ ) {+ throw new BadRequestError({+ message: `The certificate in DigiCert order ${importOrderId} is valid for ${imported.certificateTtlDays}d, which is not more than the signer's renew before (${signer.certificateRenewBeforeDays}d). Lower the renew-before window first.`+ });+ }return signerDAL.transaction(async (tx) => {- await signerIssuanceService.cancelOpenJobs(- signer.id,- "Superseded by an existing DigiCert certificate attached to the signer.",- tx- );+ await signerIssuanceService.cancelOpenJobs(signer.id, importOrderId, tx);const importedCertificateId = await $attachImportedCertificate(imported, signer.id, tx);return signerDAL.updateById(signer.id,diff --git a/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx b/frontend/src/pages/cert-manager/components/SignerKeyStep.tsxindex b4938b6331..29edac78eb 100644--- a/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx+++ b/frontend/src/pages/cert-manager/components/SignerKeyStep.tsx@@ -151,9 +151,7 @@ export const SignerKeyStep = ({hsmKeyLookupProblem = "No private key with this label in the connector's slot.";}- const visibleHsmKeyLabelError = ((hsmKeyLabelField.value as string) ?? "").trim()- ? undefined- : hsmKeyLabelError;+ const visibleHsmKeyLabelError = typedKeyLabel ? undefined : hsmKeyLabelError;const visibleHsmKeyIdError = hsmKeyIdField.value ? undefined : hsmKeyIdError;const isAlgorithmAllowed = (algo: SignerKeyAlgorithm): boolean => {