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: added lock for project create
=e40b4a0a4b3f
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex a7eec10783..c6ec5dccbe 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -10,7 +10,8 @@ export const PgSqlLock = {KmsRootKeyInit: 2025,OrgGatewayRootCaInit: (orgId: string) => pgAdvisoryLockHashText(`org-gateway-root-ca:${orgId}`),OrgGatewayCertExchange: (orgId: string) => pgAdvisoryLockHashText(`org-gateway-cert-exchange:${orgId}`),- SecretRotationV2Creation: (folderId: string) => pgAdvisoryLockHashText(`secret-rotation-v2-creation:${folderId}`)+ SecretRotationV2Creation: (folderId: string) => pgAdvisoryLockHashText(`secret-rotation-v2-creation:${folderId}`),+ CreateProject: (orgId: string) => pgAdvisoryLockHashText(`create-project:${orgId}`)} as const;export type TKeyStoreFactory = ReturnType<typeof keyStoreFactory>;diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.tsindex 6b132f654c..1ca5eb7547 100644--- a/backend/src/services/project/project-service.ts+++ b/backend/src/services/project/project-service.ts@@ -30,7 +30,7 @@ import { TSshCertificateDALFactory } from "@app/ee/services/ssh-certificate/ssh-import { TSshCertificateTemplateDALFactory } from "@app/ee/services/ssh-certificate-template/ssh-certificate-template-dal";import { TSshHostDALFactory } from "@app/ee/services/ssh-host/ssh-host-dal";import { TSshHostGroupDALFactory } from "@app/ee/services/ssh-host-group/ssh-host-group-dal";-import { TKeyStoreFactory } from "@app/keystore/keystore";+import { PgSqlLock, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";@@ -259,16 +259,17 @@ export const projectServiceFactory = ({);ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Workspace);- const plan = await licenseService.getPlan(organization.id);- if (plan.workspaceLimit !== null && plan.workspacesUsed >= plan.workspaceLimit) {- // case: limit imposed on number of workspaces allowed- // case: number of workspaces used exceeds the number of workspaces allowed- throw new BadRequestError({- message: "Failed to create workspace due to plan limit reached. Upgrade plan to add more workspaces."- });- }-const results = await (trx || projectDAL).transaction(async (tx) => {+ await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.CreateProject(organization.id)]);++ const plan = await licenseService.getPlan(organization.id);+ if (plan.workspaceLimit !== null && plan.workspacesUsed >= plan.workspaceLimit) {+ // case: limit imposed on number of workspaces allowed+ // case: number of workspaces used exceeds the number of workspaces allowed+ throw new BadRequestError({+ message: "Failed to create workspace due to plan limit reached. Upgrade plan to add more workspaces."+ });+ }const ghostUser = await orgService.addGhostUser(organization.id, tx);if (kmsKeyId) {