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
chore: minor patches
Sheen Capadngan6cdf91e5c097
diff --git a/backend/src/db/migrations/20260413000001_gateway-enrollment-tokens.ts b/backend/src/db/migrations/20260413000001_gateway-enrollment-tokens.tsindex e3913b2e4b..375a3e5a78 100644--- a/backend/src/db/migrations/20260413000001_gateway-enrollment-tokens.ts+++ b/backend/src/db/migrations/20260413000001_gateway-enrollment-tokens.ts@@ -4,10 +4,17 @@ import { TableName } from "../schemas";import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";export async function up(knex: Knex): Promise<void> {+ const hasTokenVersionColumn = await knex.schema.hasColumn(TableName.GatewayV2, "tokenVersion");+ const hasIdentityIdColumn = await knex.schema.hasColumn(TableName.GatewayV2, "identityId");+// Make identityId nullable and add tokenVersion to support enrollment-token-based gatewaysawait knex.schema.alterTable(TableName.GatewayV2, (t) => {- t.uuid("identityId").nullable().alter();- t.integer("tokenVersion").notNullable().defaultTo(0);+ if (hasIdentityIdColumn) {+ t.uuid("identityId").nullable().alter();+ }+ if (!hasTokenVersionColumn) {+ t.integer("tokenVersion").notNullable().defaultTo(0);+ }});if (!(await knex.schema.hasTable(TableName.GatewayEnrollmentTokens))) {diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-dal.ts b/backend/src/ee/services/gateway-v2/gateway-v2-dal.tsindex 68898b00cf..9c03e50e1f 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-dal.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-dal.ts@@ -76,5 +76,14 @@ export const gatewayV2DalFactory = (db: TDbClient) => {}};- return { ...orm, find, findById };+ const countByOrgId = async (orgId: string, tx?: Knex) => {+ try {+ const result = await (tx || db.replicaNode())(TableName.GatewayV2).where({ orgId }).count("id").first();+ return parseInt(String(result?.count || "0"), 10);+ } catch (error) {+ throw new DatabaseError({ error, name: `${TableName.GatewayV2}: Count by org id` });+ }+ };++ return { ...orm, find, findById, countByOrgId };};diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.tsindex d6cc2cfe3d..ed2d525d14 100644--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts@@ -46,6 +46,9 @@ import { TGatewayV2DALFactory } from "./gateway-v2-dal";import { GatewayHealthCheckStatus, TGatewayV2ConnectionDetails } from "./gateway-v2-types";import { TOrgGatewayConfigV2DALFactory } from "./org-gateway-config-v2-dal";+// Temporary limit until gateway limiting is implemented at the relay level+const MAX_GATEWAYS_PER_ORG = 50;+type TGatewayV2ServiceFactoryDep = {orgGatewayConfigV2DAL: Pick<TOrgGatewayConfigV2DALFactory, "findOne" | "create" | "transaction" | "findById">;kmsService: TKmsServiceFactory;@@ -1223,15 +1226,32 @@ export const gatewayV2ServiceFactory = ({OrgPermissionSubjects.Gateway);- try {- const gateway = await gatewayV2DAL.create({ orgId, name });- return gateway;- } catch (err) {- if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {- throw new BadRequestError({ message: `A gateway named "${name}" already exists` });+ const gateway = await gatewayV2DAL.transaction(async (tx) => {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call+ await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.CreateGateway(orgId)]);++ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment+ const existingGatewayCount = await gatewayV2DAL.countByOrgId(orgId, tx);+ if (existingGatewayCount >= MAX_GATEWAYS_PER_ORG) {+ throw new BadRequestError({+ message: `Organization has reached the maximum limit of ${MAX_GATEWAYS_PER_ORG} gateways`+ });}- throw err;- }++ try {+ return await gatewayV2DAL.create({ orgId, name }, tx);+ } catch (err) {+ if (+ err instanceof DatabaseError &&+ (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation+ ) {+ throw new BadRequestError({ message: `A gateway named "${name}" already exists` });+ }+ throw err;+ }+ });++ return gateway;};const configureTokenAuth = async ({diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 74fe5d786f..6247c90a2a 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -31,6 +31,7 @@ export const PgSqlLock = {IdentityLogin: (identityId: string, nonce: string) => pgAdvisoryLockHashText(`identity-login:${identityId}:${nonce}`),PamResourceSshCaInit: (resourceId: string) => pgAdvisoryLockHashText(`pam-resource-ssh-ca-init:${resourceId}`),CreateIdentity: (orgId: string) => pgAdvisoryLockHashText(`create-identity:${orgId}`),+ CreateGateway: (orgId: string) => pgAdvisoryLockHashText(`create-gateway:${orgId}`),AccessSharedSecret: (sharedSecretId: string) => pgAdvisoryLockHashText(`access-shared-secret:${sharedSecretId}`),KmsOrgKeyCreation: (orgId: string) => pgAdvisoryLockHashText(`kms-org-key:${orgId}`),KmsOrgDataKeyCreation: (orgId: string) => pgAdvisoryLockHashText(`kms-org-data-key:${orgId}`),diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsxindex b30d5c49c9..27fb2e00bc 100644--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/GatewayTab.tsx@@ -136,9 +136,10 @@ export const GatewayTab = withPermission(id: string;name: string;} | null>(null);- const { data: gateways, isPending: isGatewaysLoading } = useQuery(- gatewaysQueryKeys.listWithTokens()- );+ const { data: gateways, isPending: isGatewaysLoading } = useQuery({+ ...gatewaysQueryKeys.listWithTokens(),+ refetchInterval: 15_000+ });const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["deployGateway",