Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added all the new flags

=e65f07240345
diff --git a/backend/src/db/migrations/utils/env-config.ts b/backend/src/db/migrations/utils/env-config.ts
index 056874f061..5f70b912a5 100644
--- a/backend/src/db/migrations/utils/env-config.ts
+++ b/backend/src/db/migrations/utils/env-config.ts
@@ -32,6 +32,10 @@ const envSchema = z
LICENSE_KEY: zpStr(z.string().optional()),
LICENSE_KEY_OFFLINE: zpStr(z.string().optional()),
LICENSE_SERVER_V2_MODE: z.enum(["off", "read-compare", "on"]).default("off"),
+ DISABLE_LICENSE_V1_CLOUD: z
+ .enum(["true", "false"])
+ .default("false")
+ .transform((val) => val === "true"),
INTERNAL_REGION: zpStr(z.enum(["us", "eu"]).optional()),
SITE_URL: zpStr(z.string().transform((val) => (val ? removeTrailingSlash(val) : val))).optional()
diff --git a/backend/src/ee/services/group/group-fns.ts b/backend/src/ee/services/group/group-fns.ts
index 2ad6c194e6..ca147a03b8 100644
--- a/backend/src/ee/services/group/group-fns.ts
+++ b/backend/src/ee/services/group/group-fns.ts
@@ -3,7 +3,7 @@ import { Knex } from "knex";
import { AccessScope, ProjectVersion, SecretKeyEncoding, TableName, TUsers } from "@app/db/schemas";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, ForbiddenRequestError, NotFoundError, ScimRequestError } from "@app/lib/errors";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import {
TAddIdentitiesToGroup,
@@ -300,8 +300,9 @@ export const addUsersToGroupByUserIds = async ({
);
}
- // These users may now be in a secret-manager project through this group.
+ // These users may now be in a secret-manager or PAM project through this group.
usageMeteringService?.emit(group.orgId, SecretIdentities.key);
+ usageMeteringService?.emit(group.orgId, PamIdentities.key);
return membersToAddToGroupNonPending.concat(membersToAddToGroupPending);
};
@@ -374,8 +375,9 @@ export const addIdentitiesToGroup = async ({
tx
);
- // These identities may now be in a secret-manager project through this group.
+ // These identities may now be in a secret-manager or PAM project through this group.
usageMeteringService?.emit(group.orgId, SecretIdentities.key);
+ usageMeteringService?.emit(group.orgId, PamIdentities.key);
return identityIdsArray.map((identityId) => ({ id: identityId }));
});
};
@@ -527,8 +529,9 @@ export const removeUsersFromGroupByUserIds = async ({
);
}
- // These users may have left a secret-manager project they only reached through this group.
+ // These users may have left a secret-manager or PAM project they only reached through this group.
usageMeteringService?.emit(group.orgId, SecretIdentities.key);
+ usageMeteringService?.emit(group.orgId, PamIdentities.key);
return membersToRemoveFromGroupNonPending.concat(membersToRemoveFromGroupPending);
};
@@ -606,8 +609,9 @@ export const removeIdentitiesFromGroup = async ({
tx
);
- // These identities may have left a secret-manager project they only reached through this group.
+ // These identities may have left a secret-manager or PAM project they only reached through this group.
usageMeteringService?.emit(group.orgId, SecretIdentities.key);
+ usageMeteringService?.emit(group.orgId, PamIdentities.key);
return identityIdsArray.map((identityId) => ({ id: identityId }));
});
};
diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.ts
index 192172bb56..48b9a31c43 100644
--- a/backend/src/ee/services/group/group-service.ts
+++ b/backend/src/ee/services/group/group-service.ts
@@ -17,7 +17,7 @@ import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { TGenericPermission } from "@app/lib/types";
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TMembershipDALFactory } from "@app/services/membership/membership-dal";
import { TMembershipRoleDALFactory } from "@app/services/membership/membership-role-dal";
@@ -609,12 +609,14 @@ export const groupServiceFactory = ({
});
// Removing the group drops its members from any project it was on.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { group: unlinkedGroup, isUnlinked: true };
}
const deletedGroup = await deleteOwnedGroup({ groupId: id, actorOrgId });
// Deleting the group drops its members from any project it was on.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { group: deletedGroup, isUnlinked: false };
};
@@ -958,8 +960,9 @@ export const groupServiceFactory = ({
projectBotDAL
});
- // The user may now be in a secret-manager project through this group.
+ // The user may now be in a secret-manager or PAM project through this group.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { user: users[0], group: groupMembership.group };
};
@@ -1041,8 +1044,9 @@ export const groupServiceFactory = ({
identityGroupMembershipDAL
});
- // The identity may now be in a secret-manager project through this group.
+ // The identity may now be in a secret-manager or PAM project through this group.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { identity: identities[0], group: groupMembership.group };
};
@@ -1135,8 +1139,9 @@ export const groupServiceFactory = ({
identityIds: []
});
- // The user may have left a secret-manager project it only reached through this group.
+ // The user may have left a secret-manager or PAM project it only reached through this group.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { user: users[0], group: groupMembership.group };
};
@@ -1223,8 +1228,9 @@ export const groupServiceFactory = ({
identityIds: [identityId]
});
- // The identity may have left a secret-manager project it only reached through this group.
+ // The identity may have left a secret-manager or PAM project it only reached through this group.
usageMeteringService.emit(actorOrgId, SecretIdentities.key);
+ usageMeteringService.emit(actorOrgId, PamIdentities.key);
return { identity: identities[0], group: groupMembership.group };
};
diff --git a/backend/src/ee/services/license/__mocks__/license-fns.ts b/backend/src/ee/services/license/__mocks__/license-fns.ts
index 73e1f5a5a3..a1c1b2c521 100644
--- a/backend/src/ee/services/license/__mocks__/license-fns.ts
+++ b/backend/src/ee/services/license/__mocks__/license-fns.ts
@@ -5,6 +5,12 @@ export const getDefaultOnPremFeatures = () => {
tier: -1,
workspaceLimit: null,
workspacesUsed: 0,
+ secretSyncLimit: null,
+ maxInternalCas: null,
+ maxPamAccounts: null,
+ pam: null,
+ certManager: null,
+ pkiCodeSigning: null,
memberLimit: null,
membersUsed: 0,
identityLimit: null,
diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.ts
index 007d3a4ad5..1a156556bb 100644
--- a/backend/src/ee/services/license/license-fns.ts
+++ b/backend/src/ee/services/license/license-fns.ts
@@ -68,6 +68,11 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
tier: -1,
workspaceLimit: null,
workspacesUsed: 0,
+ secretSyncLimit: null,
+ maxInternalCas: null,
+ maxPamAccounts: null,
+ pam: null,
+ certManager: null,
memberLimit: null,
membersUsed: 0,
environmentLimit: null,
@@ -112,6 +117,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
pkiAcme: true,
pkiScep: false,
pkiPqc: false,
+ pkiCodeSigning: null,
kmsPqc: false,
enforceMfa: false,
projectTemplates: false,
diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts
index 176e4e2452..d96a2fe7d4 100644
--- a/backend/src/ee/services/license/license-service.ts
+++ b/backend/src/ee/services/license/license-service.ts
@@ -62,6 +62,7 @@ type TLicenseServiceFactoryDep = {
| "SITE_URL"
| "LICENSE_SERVER_V2_MODE"
| "LICENSE_SERVER_V2_SERVICE_KEY"
+ | "DISABLE_LICENSE_V1_CLOUD"
>;
orgDAL: Pick<TOrgDALFactory, "findRootOrgDetails" | "countAllOrgMembers" | "findById">;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
@@ -308,6 +309,7 @@ export const licenseServiceFactory = ({
throw new BadRequestError({ message: "License Server v2 entitlements are unavailable" });
}
currentPlan = projectV2ToFeatureSet(getDefaultOnPremFeatures(), entitlements);
+ console.log("Current plan", currentPlan);
// The entitlement projection only carries feature flags, so set the plan slug from the
// subscription tier; otherwise the org-level plan label can't reflect the real tier. Keep
@@ -517,6 +519,12 @@ export const licenseServiceFactory = ({
actorAuthMethod,
success_url
}: TStartOrgTrialDTO) => {
+ if (envConfig.DISABLE_LICENSE_V1_CLOUD) {
+ throw new BadRequestError({
+ message: "We're currently updating our license system. Please check back again later."
+ });
+ }
+
const { permission } = await permissionService.getOrgPermission({
actorId,
actor,
@@ -850,6 +858,12 @@ export const licenseServiceFactory = ({
success_url,
cancel_url
}: TAddOrgPmtMethodDTO) => {
+ if (envConfig.DISABLE_LICENSE_V1_CLOUD) {
+ throw new BadRequestError({
+ message: "We're currently updating our license system. Please check back again later."
+ });
+ }
+
const { permission } = await permissionService.getOrgPermission({
actorId,
actor,
diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts
index 428472dd17..215321bfb3 100644
--- a/backend/src/ee/services/license/license-types.ts
+++ b/backend/src/ee/services/license/license-types.ts
@@ -84,6 +84,9 @@ export type TFeatureSet = {
pkiAcme: true;
pkiScep: false;
pkiPqc: false;
+ // PKI code signing capability. null (default) is ignored (no restriction); an explicit boolean gates
+ // code signer creation.
+ pkiCodeSigning: null;
kmsPqc: false;
enforceMfa: false;
projectTemplates: false;
@@ -104,6 +107,19 @@ export type TFeatureSet = {
honeyTokens: false;
honeyTokenLimit: 0;
secretsBrokering: true;
+ // Max secret syncs allowed org-wide. null (default) means uncapped; a number enforces the cap at
+ // creation time.
+ secretSyncLimit: null;
+ // Max internal CAs allowed org-wide (external CAs are not capped). null (default) means uncapped; a
+ // number enforces the cap at creation time.
+ maxInternalCas: null;
+ // Max PAM accounts allowed org-wide. null (default) means uncapped; a number enforces the cap at
+ // creation time.
+ maxPamAccounts: null;
+ // Product gate flags. null (default) is ignored; an explicit `true` blocks the product's primary
+ // creation operation (PAM accounts / certificate authorities) and surfaces an upgrade modal.
+ pam: null;
+ certManager: null;
};
export type TOrgPlansTableDTO = {
diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.ts
index b1c5695707..b62f7b7325 100644
--- a/backend/src/ee/services/pam-account/pam-account-dal.ts
+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts
@@ -238,6 +238,17 @@ export const pamAccountDALFactory = (db: TDbClient) => {
return Number(result[0]?.count ?? 0);
};
+ // Total PAM accounts across the org's projects (excluding soft-deleted projects), used to enforce the
+ // plan's maxPamAccounts at creation time.
+ const countByOrgId = async (orgId: string, tx?: Knex): Promise<number> => {
+ const result = await (tx || db.replicaNode())(TableName.PamAccount)
+ .join(TableName.Project, `${TableName.PamAccount}.projectId`, `${TableName.Project}.id`)
+ .where(`${TableName.Project}.orgId`, orgId)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .count<[{ count: string }]>(`${TableName.PamAccount}.id`);
+ return Number(result[0]?.count ?? 0);
+ };
+
const findRotationCandidates = async (
projectId: string,
accessibleFolderIds: string[],
@@ -355,6 +366,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {
findByIdWithDetails,
findAccountsToRotate,
countAccountsToRotate,
+ countByOrgId,
findRotationCandidates,
reconcileRotationScheduleForTemplate,
reconcileRotationScheduleForAccount
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index afbee06b0b..97bb4d5111 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -4,6 +4,7 @@ import { packRules } from "@casl/ability/extra";
import { RESOURCE_SCOPE, ResourceType, TPamAccountTemplates } from "@app/db/schemas";
import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
import { TGatewayV2DALFactory } from "@app/ee/services/gateway-v2/gateway-v2-dal";
+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
ResourcePermissionPamResourceActions,
@@ -78,6 +79,7 @@ type TPamAccountServiceFactoryDep = {
TPamAccessRequestServiceFactory,
"getAccessStatusBatch" | "getFolderPolicyConfigured" | "cleanupAccountResources"
>;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
};
const assertPasswordMeetsRequirements = (credentials: unknown, templateSettings: unknown) => {
@@ -130,7 +132,8 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
membershipDAL,
membershipRoleDAL,
permissionService,
- kmsService
+ kmsService,
+ licenseService
} = deps;
const getProjectCipher = async (projectId: string) =>
@@ -290,6 +293,25 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
ResourcePermissionSub.PamResource
);
+ const plan = await licenseService.getPlan(ctx.actorOrgId);
+ // The `pam` gate flag is ignored when null; an explicit `true` blocks PAM account creation.
+ if (typeof plan.pam === "boolean" && plan.pam) {
+ throw new BadRequestError({
+ message: "PAM is not available on your current plan. Please upgrade to continue."
+ });
+ }
+
+ // maxPamAccounts is uncapped by default (null); only enforce a cap when the plan configures a numeric
+ // limit. Counted org-wide right before creation.
+ if (typeof plan.maxPamAccounts === "number") {
+ const currentPamAccountCount = await pamAccountDAL.countByOrgId(ctx.actorOrgId);
+ if (currentPamAccountCount >= plan.maxPamAccounts) {
+ throw new BadRequestError({
+ message: "Failed to create PAM account due to plan limit reached. Upgrade plan to add more PAM accounts."
+ });
+ }
+ }
+
const folder = await pamFolderDAL.findById(folderId);
if (!folder || folder.projectId !== projectId) {
throw new NotFoundError({ message: `Folder with ID '${folderId}' not found` });
diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.ts
index 9e3bc1b44a..e119665891 100644
--- a/backend/src/lib/config/env.ts
+++ b/backend/src/lib/config/env.ts
@@ -325,6 +325,9 @@ const envSchema = z
LICENSE_SERVER_V2_MODE: z.enum(["off", "read-compare", "on"]).default("off"),
LICENSE_SERVER_V2_URL: zpStr(z.string().optional()),
LICENSE_SERVER_V2_SERVICE_KEY: zpStr(z.string().optional()),
+ // When true, new checkouts (adding a payment method) and trials on License Server v1 cloud are
+ // disallowed, pushing orgs onto License Server v2.
+ DISABLE_LICENSE_V1_CLOUD: zodStrBool.default("false"),
// CROSS-PROJECT SECRET SHARING
CROSS_PROJECT_SECRET_SHARING_ORG_WHITELIST: zpStr(z.string().optional()),
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 746c839c15..39d61136aa 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1913,7 +1913,8 @@ export const registerRoutes = async (
gatewayV2DAL,
gatewayPoolService,
appConnectionDAL,
- pamAccessRequestService
+ pamAccessRequestService,
+ licenseService
});
const pamDiscoverySourceDAL = pamDiscoverySourceDALFactory(db);
@@ -3220,7 +3221,8 @@ export const registerRoutes = async (
gatewayPoolService,
usageMeteringService,
hsmConnectorService,
- certificateAuthoritySecretDAL
+ certificateAuthoritySecretDAL,
+ licenseService
});
const certificateEstService = certificateEstServiceFactory({
@@ -3629,7 +3631,8 @@ export const registerRoutes = async (
approvalRequestGrantsDAL,
membershipDAL,
membershipRoleDAL,
- hsmConnectorService
+ hsmConnectorService,
+ licenseService
});
const signerAutoRenewalQueue = signerAutoRenewalQueueFactory({
diff --git a/backend/src/services/certificate-authority/certificate-authority-dal.ts b/backend/src/services/certificate-authority/certificate-authority-dal.ts
index a02b1b4da4..02cc3013d2 100644
--- a/backend/src/services/certificate-authority/certificate-authority-dal.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-dal.ts
@@ -365,11 +365,33 @@ export const certificateAuthorityDALFactory = (db: TDbClient) => {
}
};
+ // Internal CAs (those with an internal_certificate_authorities row) across all of the org's projects,
+ // excluding soft-deleted projects. Used to enforce the plan's maxInternalCas at creation time; external
+ // CAs are intentionally not counted.
+ const countInternalCasByOrgId = async (orgId: string, tx?: Knex) => {
+ try {
+ const doc = await (tx || db.replicaNode())(TableName.CertificateAuthority)
+ .join(
+ TableName.InternalCertificateAuthority,
+ `${TableName.CertificateAuthority}.id`,
+ `${TableName.InternalCertificateAuthority}.caId`
+ )
+ .join(TableName.Project, `${TableName.CertificateAuthority}.projectId`, `${TableName.Project}.id`)
+ .where(`${TableName.Project}.orgId`, orgId)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .count();
+ return Number(doc?.[0]?.count ?? 0);
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Count Internal CAs By Org ID - Certificate Authority" });
+ }
+ };
+
return {
...caOrm,
findWithAssociatedCa,
buildCertificateChain,
findByIdWithAssociatedCa,
- findByNameAndProjectIdWithAssociatedCa
+ findByNameAndProjectIdWithAssociatedCa,
+ countInternalCasByOrgId
};
};
diff --git a/backend/src/services/certificate-authority/certificate-authority-service.ts b/backend/src/services/certificate-authority/certificate-authority-service.ts
index cc8e6ac85d..c37115d4fe 100644
--- a/backend/src/services/certificate-authority/certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts
@@ -3,6 +3,7 @@ import { ForbiddenError, subject } from "@casl/ability";
import { ActionProjectType, TableName } from "@app/db/schemas";
import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
ProjectPermissionCertificateActions,
@@ -126,6 +127,7 @@ type TCertificateAuthorityServiceFactoryDep = {
| "findByIdWithAssociatedCa"
| "findWithAssociatedCa"
| "findByNameAndProjectIdWithAssociatedCa"
+ | "countInternalCasByOrgId"
>;
externalCertificateAuthorityDAL: Pick<TExternalCertificateAuthorityDALFactory, "create" | "update" | "findOne">;
internalCertificateAuthorityService: TInternalCertificateAuthorityServiceFactory;
@@ -152,6 +154,7 @@ type TCertificateAuthorityServiceFactoryDep = {
usageMeteringService: Pick<TUsageMeteringServiceFactory, "emitForProject">;
hsmConnectorService: Pick<THsmConnectorServiceFactory, "assertAttachPermission">;
certificateAuthoritySecretDAL: Pick<TCertificateAuthoritySecretDALFactory, "findOne">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
};
export type TCertificateAuthorityServiceFactory = ReturnType<typeof certificateAuthorityServiceFactory>;
@@ -178,7 +181,8 @@ export const certificateAuthorityServiceFactory = ({
gatewayPoolService,
usageMeteringService,
hsmConnectorService,
- certificateAuthoritySecretDAL
+ certificateAuthoritySecretDAL,
+ licenseService
}: TCertificateAuthorityServiceFactoryDep) => {
const acmeFns = AcmeCertificateAuthorityFns({
appConnectionDAL,
@@ -308,9 +312,31 @@ export const certificateAuthorityServiceFactory = ({
subject(ProjectPermissionSub.CertificateAuthorities, { name })
);
+ const plan = await licenseService.getPlan(actor.orgId);
+ // The `certManager` gate flag is ignored when null; an explicit `true` blocks creating any CA
+ // (internal or external).
+ if (typeof plan.certManager === "boolean" && plan.certManager) {
+ throw new BadRequestError({
+ message: "Certificate Manager is not available on your current plan. Please upgrade to continue."
+ });
+ }
+
if (type === CaType.INTERNAL) {
const internalConfig = configuration as TCreateInternalCertificateAuthorityDTO["configuration"];
+ // maxInternalCas is uncapped by default (null); only enforce a cap when the plan configures a
+ // numeric limit. Counted org-wide right before creation and scoped to internal CAs (external CAs
+ // are not capped).
+ if (typeof plan.maxInternalCas === "number") {
+ const currentInternalCaCount = await certificateAuthorityDAL.countInternalCasByOrgId(actor.orgId);
+ if (currentInternalCaCount >= plan.maxInternalCas) {
+ throw new BadRequestError({
+ message:
+ "Failed to create internal certificate authority due to plan limit reached. Upgrade plan to add more internal certificate authorities."
+ });
+ }
+ }
+
if (internalConfig.keySource === CertKeySource.Hsm) {
if (!internalConfig.hsmConnectorId) {
throw new BadRequestError({ message: "An HSM Connector is required when the key source is HSM." });
diff --git a/backend/src/services/identity-v2/identity-service.ts b/backend/src/services/identity-v2/identity-service.ts
index c002687f49..69ccc954e6 100644
--- a/backend/src/services/identity-v2/identity-service.ts
+++ b/backend/src/services/identity-v2/identity-service.ts
@@ -30,7 +30,7 @@ import { groupBy } from "@app/lib/fn";
import { ms } from "@app/lib/ms";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
-import { MaxIdentities, SecretIdentities } from "@app/services/license-client";
+import { MaxIdentities, PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TProjectDALFactory } from "@app/services/project/project-dal";
@@ -297,10 +297,11 @@ export const identityV2ServiceFactory = ({
await licenseService.updateSubscriptionOrgMemberCount(dto.permission.orgId);
// A new identity always adds an org membership; a project-scoped one also joins that project, so
- // it counts toward the secret-manager identity meter too.
+ // it counts toward the secret-manager and PAM identity meters too.
usageMeteringService.emit(dto.permission.orgId, MaxIdentities.key);
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
}
return { identity };
@@ -384,9 +385,10 @@ export const identityV2ServiceFactory = ({
await licenseService.updateSubscriptionOrgMemberCount(scopeData.orgId);
- // Deleting the identity cascades its org + project + group memberships, so both meters change.
+ // Deleting the identity cascades its org + project + group memberships, so all meters change.
usageMeteringService.emit(scopeData.orgId, MaxIdentities.key);
usageMeteringService.emit(scopeData.orgId, SecretIdentities.key);
+ usageMeteringService.emit(scopeData.orgId, PamIdentities.key);
return { identity: deletedIdentity };
};
diff --git a/backend/src/services/identity/identity-service.ts b/backend/src/services/identity/identity-service.ts
index 72346bdbdd..74958dea8b 100644
--- a/backend/src/services/identity/identity-service.ts
+++ b/backend/src/services/identity/identity-service.ts
@@ -14,7 +14,7 @@ import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/li
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { TIdentityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";
-import { MaxIdentities, SecretIdentities } from "@app/services/license-client";
+import { MaxIdentities, PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
@@ -379,8 +379,10 @@ export const identityServiceFactory = ({
const deletedIdentity = await identityDAL.deleteById(id);
await licenseService.updateSubscriptionOrgMemberCount(identityOrgMembership.scopeOrgId);
usageMeteringService.emit(identityOrgMembership.scopeOrgId, MaxIdentities.key);
- // Deleting the identity cascades its project + group memberships, so the secret-manager meter changes too.
+ // Deleting the identity cascades its project + group memberships, so the secret-manager and PAM
+ // identity meters change too.
usageMeteringService.emit(identityOrgMembership.scopeOrgId, SecretIdentities.key);
+ usageMeteringService.emit(identityOrgMembership.scopeOrgId, PamIdentities.key);
return { ...deletedIdentity, orgId: identityOrgMembership.scopeOrgId };
}
@@ -415,8 +417,10 @@ export const identityServiceFactory = ({
const deletedIdentity = await requestMemoize(requestMemoKeys.identityFindById(id), () => identityDAL.findById(id));
usageMeteringService.emit(identityOrgMembership.scopeOrgId, MaxIdentities.key);
- // Deleting the identity cascades its project + group memberships, so the secret-manager meter changes too.
+ // Deleting the identity cascades its project + group memberships, so the secret-manager and PAM
+ // identity meters change too.
usageMeteringService.emit(identityOrgMembership.scopeOrgId, SecretIdentities.key);
+ usageMeteringService.emit(identityOrgMembership.scopeOrgId, PamIdentities.key);
return { ...deletedIdentity, orgId: identityOrgMembership.scopeOrgId };
};
diff --git a/backend/src/services/license-client/dual-read/entitlement-comparator.test.ts b/backend/src/services/license-client/dual-read/entitlement-comparator.test.ts
index ea0fdf88b9..6912704af2 100644
--- a/backend/src/services/license-client/dual-read/entitlement-comparator.test.ts
+++ b/backend/src/services/license-client/dual-read/entitlement-comparator.test.ts
@@ -52,16 +52,16 @@ describe("compareEntitlements", () => {
test("v1 null cap normalized to UNLIMITED matches a v2 unlimited representation", () => {
const mappings: TFeatureMapping[] = [
{
- v2Key: "max_identities",
+ v2Key: "identities",
v1Field: "identityLimit",
extractV1: (p) => p.identityLimit,
normalize: unlimitedWhenNull
}
];
const plan = makePlan({ identityLimit: null });
- const entitlements = makeEntitlements({ max_identities: { value: UNLIMITED } });
+ const entitlements = makeEntitlements({ identities: { value: UNLIMITED } });
- const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "max_identities");
+ const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "identities");
expect(diff.kind).toBe(DualReadDiffKind.Match);
expect(diff.v1Value).toBe(UNLIMITED);
expect(diff.v2Value).toBe(UNLIMITED);
@@ -85,11 +85,11 @@ describe("compareEntitlements", () => {
});
test("a mapping with no v1 extractor reports V1Absent", () => {
- const mappings: TFeatureMapping[] = [{ v2Key: "max_internal_cas", v1Field: null, extractV1: null }];
+ const mappings: TFeatureMapping[] = [{ v2Key: "internal_cas", v1Field: null, extractV1: null }];
const plan = makePlan({});
- const entitlements = makeEntitlements({ max_internal_cas: { value: 5 } });
+ const entitlements = makeEntitlements({ internal_cas: { value: 5 } });
- const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "max_internal_cas");
+ const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "internal_cas");
expect(diff.kind).toBe(DualReadDiffKind.V1Absent);
expect(diff.v1Value).toBeNull();
expect(diff.v2Value).toBe(5);
@@ -98,16 +98,16 @@ describe("compareEntitlements", () => {
test("v1 UNLIMITED versus a v2 finite number downgrades to Indeterminate", () => {
const mappings: TFeatureMapping[] = [
{
- v2Key: "max_identities",
+ v2Key: "identities",
v1Field: "identityLimit",
extractV1: (p) => p.identityLimit,
normalize: unlimitedWhenNull
}
];
const plan = makePlan({ identityLimit: null });
- const entitlements = makeEntitlements({ max_identities: { value: 100 } });
+ const entitlements = makeEntitlements({ identities: { value: 100 } });
- const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "max_identities");
+ const diff = findByKey(compareEntitlements(plan, entitlements, mappings), "identities");
expect(diff.kind).toBe(DualReadDiffKind.Indeterminate);
expect(diff.v1Value).toBe(UNLIMITED);
expect(diff.v2Value).toBe(100);
diff --git a/backend/src/services/license-client/dual-read/feature-mapping/core.ts b/backend/src/services/license-client/dual-read/feature-mapping/core.ts
index 1a3447993f..3420e16868 100644
--- a/backend/src/services/license-client/dual-read/feature-mapping/core.ts
+++ b/backend/src/services/license-client/dual-read/feature-mapping/core.ts
@@ -80,5 +80,15 @@ export const coreMappings: TFeatureMapping[] = [
v2Key: "enterprise_app_connections",
v1Field: "enterpriseAppConnections",
extractV1: (p) => p.enterpriseAppConnections
+ },
+ {
+ v2Key: "pam",
+ v1Field: "pam",
+ extractV1: (p) => p.pam
+ },
+ {
+ v2Key: "cert_manager",
+ v1Field: "certManager",
+ extractV1: (p) => p.certManager
}
];
diff --git a/backend/src/services/license-client/dual-read/feature-mapping/existing.ts b/backend/src/services/license-client/dual-read/feature-mapping/existing.ts
index d2faaa45c3..2b9d8732b2 100644
--- a/backend/src/services/license-client/dual-read/feature-mapping/existing.ts
+++ b/backend/src/services/license-client/dual-read/feature-mapping/existing.ts
@@ -6,14 +6,15 @@ import {
MaxPamResources,
SsoEnforcement
} from "../../features";
-import { TFeatureMapping, unlimitedWhenNull } from "../dual-read-types";
+import { TFeatureMapping } from "../dual-read-types";
export const existingDescriptorMappings: TFeatureMapping[] = [
{
+ // v2's `identities` is a usage meter (reported count); the identity cap is a separate v2 feature
+ // (max_identity_limit) mapped in limits.ts, so the meter itself maps to no v1 field.
v2Key: MaxIdentities.key,
- v1Field: "identityLimit",
- extractV1: (p) => p.identityLimit,
- normalize: unlimitedWhenNull
+ v1Field: null,
+ extractV1: null
},
{
v2Key: AuditRetentionDays.key,
@@ -28,6 +29,8 @@ export const existingDescriptorMappings: TFeatureMapping[] = [
extractV1: null
},
{
+ // v2's `internal_cas` is a usage meter; the internal-CA cap is a separate v2 feature
+ // (max_internal_cas) mapped in limits.ts, so the meter itself maps to no v1 field.
v2Key: MaxInternalCas.key,
v1Field: null,
extractV1: null
diff --git a/backend/src/services/license-client/dual-read/feature-mapping/limits.ts b/backend/src/services/license-client/dual-read/feature-mapping/limits.ts
index caa6f44427..c14a25db9c 100644
--- a/backend/src/services/license-client/dual-read/feature-mapping/limits.ts
+++ b/backend/src/services/license-client/dual-read/feature-mapping/limits.ts
@@ -7,6 +7,34 @@ export const limitsMappings: TFeatureMapping[] = [
extractV1: (p) => p.environmentLimit,
normalize: unlimitedWhenNull
},
+ {
+ // Max identities allowed. Dedicated cap feature, separate from the `identities` usage meter.
+ v2Key: "max_identity_limit",
+ v1Field: "identityLimit",
+ extractV1: (p) => p.identityLimit,
+ normalize: unlimitedWhenNull
+ },
+ {
+ // Max internal CAs allowed. Dedicated cap feature, separate from the `internal_cas` usage meter.
+ v2Key: "max_internal_cas",
+ v1Field: "maxInternalCas",
+ extractV1: (p) => p.maxInternalCas,
+ normalize: unlimitedWhenNull
+ },
+ {
+ // Max PAM accounts allowed. null (v1 default) means uncapped, so it normalizes to UNLIMITED.
+ v2Key: "max_pam_accounts",
+ v1Field: "maxPamAccounts",
+ extractV1: (p) => p.maxPamAccounts,
+ normalize: unlimitedWhenNull
+ },
+ {
+ // null (v1 default) means uncapped, so it normalizes to UNLIMITED for the dual-read compare.
+ v2Key: "secret_sync_limit",
+ v1Field: "secretSyncLimit",
+ extractV1: (p) => p.secretSyncLimit,
+ normalize: unlimitedWhenNull
+ },
{
v2Key: "audit_log_stream_limit",
v1Field: "auditLogStreamLimit",
diff --git a/backend/src/services/license-client/dual-read/feature-mapping/pki-security.ts b/backend/src/services/license-client/dual-read/feature-mapping/pki-security.ts
index 2bc61292a1..67e480d6fc 100644
--- a/backend/src/services/license-client/dual-read/feature-mapping/pki-security.ts
+++ b/backend/src/services/license-client/dual-read/feature-mapping/pki-security.ts
@@ -26,6 +26,11 @@ export const pkiSecurityMappings: TFeatureMapping[] = [
v1Field: "pkiPqc",
extractV1: (p) => p.pkiPqc
},
+ {
+ v2Key: "pki_code_signing",
+ v1Field: "pkiCodeSigning",
+ extractV1: (p) => p.pkiCodeSigning
+ },
{
v2Key: "ssh_host_groups",
v1Field: "sshHostGroups",
diff --git a/backend/src/services/license-client/dual-read/unlicensed.test.ts b/backend/src/services/license-client/dual-read/unlicensed.test.ts
index cdfb3df2d5..9a495c10a9 100644
--- a/backend/src/services/license-client/dual-read/unlicensed.test.ts
+++ b/backend/src/services/license-client/dual-read/unlicensed.test.ts
@@ -36,7 +36,7 @@ describe("classifyUnlicensedCompare", () => {
name: "all-default features + paid v1 skips and warns",
features: {
environment_limit: { value: 3, source: "default" },
- max_identities: { value: 5, source: "default" }
+ identities: { value: 5, source: "default" }
},
slug: "enterprise",
wantSkip: true,
diff --git a/backend/src/services/license-client/features.ts b/backend/src/services/license-client/features.ts
index 42c79bed73..d490b79e60 100644
--- a/backend/src/services/license-client/features.ts
+++ b/backend/src/services/license-client/features.ts
@@ -6,10 +6,9 @@ export const SsoEnforcement = defineFeature("sso_enforcement", false);
export const AuditRetentionDays = defineFeature("audit_retention_days", 30);
// Metered limit features. Their key is both the resolved cap and the usage meter (see usage/).
-export const MaxIdentities = defineLimitFeature("max_identities", 0);
-export const MaxInternalCas = defineLimitFeature("max_internal_cas", 0);
+export const MaxIdentities = defineLimitFeature("identities", 0);
+export const MaxInternalCas = defineLimitFeature("internal_cas", 0);
export const MaxActiveCerts = defineLimitFeature("max_active_certs", 0);
export const MaxPamResources = defineLimitFeature("max_resources", 0);
-// Distinct users + machine identities that belong to a Secret Management project (via direct
-// membership or a group). Org-scoped on cloud; whole-instance on self-hosted.
export const SecretIdentities = defineLimitFeature("secret_identities", 0);
+export const PamIdentities = defineLimitFeature("pam_identities", 0);
diff --git a/backend/src/services/license-client/license-client.test.ts b/backend/src/services/license-client/license-client.test.ts
index 43b47526a0..88b6ffbd34 100644
--- a/backend/src/services/license-client/license-client.test.ts
+++ b/backend/src/services/license-client/license-client.test.ts
@@ -65,12 +65,12 @@ describe("entitlementResolverFactory", () => {
test("fetches once then serves subsequent reads from the cache", async () => {
const keyStore = createFakeKeyStore();
const { backend, getCalls } = createStubBackend(
- makeEntitlements({ max_identities: { value: 100, source: "plan" } })
+ makeEntitlements({ identities: { value: 100, source: "plan" } })
);
const resolver = entitlementResolverFactory({ keyStore, backend });
const first = await resolver.getEntitlements({ id: ORG_ID });
- expect(first?.features.max_identities.value).toBe(100);
+ expect(first?.features.identities.value).toBe(100);
expect(getCalls()).toBe(1);
await resolver.getEntitlements({ id: ORG_ID });
@@ -88,7 +88,7 @@ describe("entitlementResolverFactory", () => {
test("forwards org identity to the backend even after an identity-less call seeded the cache", async () => {
const keyStore = createFakeKeyStore();
const { backend, getCalls, getOrgs } = createStubBackend(
- makeEntitlements({ max_identities: { value: 100, source: "plan" } })
+ makeEntitlements({ identities: { value: 100, source: "plan" } })
);
const resolver = entitlementResolverFactory({ keyStore, backend });
@@ -104,7 +104,7 @@ describe("entitlementResolverFactory", () => {
test("syncs org identity once per ttl window then serves from the cache", async () => {
const keyStore = createFakeKeyStore();
const { backend, getCalls } = createStubBackend(
- makeEntitlements({ max_identities: { value: 100, source: "plan" } })
+ makeEntitlements({ identities: { value: 100, source: "plan" } })
);
const resolver = entitlementResolverFactory({ keyStore, backend });
@@ -128,7 +128,7 @@ describe("featureReaderFactory", () => {
test("returns server-resolved values when present", async () => {
const entitlements = makeEntitlements({
sso_enforcement: { value: true, source: "plan", from_product: "boost" },
- max_identities: { value: 100, source: "plan", from_product: "secrets_management" }
+ identities: { value: 100, source: "plan", from_product: "secrets_management" }
});
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
@@ -137,7 +137,7 @@ describe("featureReaderFactory", () => {
});
test("canUse enforces the cap against a registered counter", async () => {
- const entitlements = makeEntitlements({ max_identities: { value: 100, source: "plan" } });
+ const entitlements = makeEntitlements({ identities: { value: 100, source: "plan" } });
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
reader.registerCounter(MaxIdentities, async () => 99);
@@ -147,7 +147,7 @@ describe("featureReaderFactory", () => {
});
test("canUse without a registered counter compares the request against the cap", async () => {
- const entitlements = makeEntitlements({ max_identities: { value: 100, source: "plan" } });
+ const entitlements = makeEntitlements({ identities: { value: 100, source: "plan" } });
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
const limit = await reader.getFeature(ORG_ID, MaxIdentities);
diff --git a/backend/src/services/license-client/usage/usage-counter-dal.ts b/backend/src/services/license-client/usage/usage-counter-dal.ts
index 625e706874..8b82ce589c 100644
--- a/backend/src/services/license-client/usage/usage-counter-dal.ts
+++ b/backend/src/services/license-client/usage/usage-counter-dal.ts
@@ -65,93 +65,103 @@ export const usageCounterDALFactory = (db: TDbClient) => {
}
};
- // Distinct users + machine identities that belong to a Secret Management project, either through a
+ // Distinct users + machine identities that belong to a project of the given type, either through a
// direct membership or through a group assigned to the project. Project memberships (user, identity,
// and group actors) all live in the unified `memberships` table with scope = project; the group's
// members are then resolved through the user/identity group-membership tables. When orgId is given
// the count is scoped to that org (cloud); when omitted it spans the whole instance (self-hosted).
// The four sources are UNION-ed (not UNION ALL) with a per-kind prefix so an identity in several
// projects, or reachable via both a direct and a group membership, is only counted once.
- const countSecretManagementIdentities = async (orgId?: string): Promise<number> => {
- try {
- // The live Secret Management project ids, resolved once per source. Scoping happens here on
- // projects.orgId (indexed via projects_orgid_type_idx) rather than on memberships.scopeOrgId:
- // leading with the org's handful of SM projects lets each source drive off the small project set
- // and probe memberships through the partial (scopeProjectId, actor*) unique indexes as an
- // index-only scan, instead of scanning every project-scope membership row in the org. Self-hosted
- // passes no orgId and counts the whole instance. A fresh builder per call keeps knex from
- // mutating a shared subquery.
- const secretProjectIds = () => {
- const qb = db
- .replicaNode()(TableName.Project)
- .where(`${TableName.Project}.type`, ProjectType.SecretManager)
- .whereNull(`${TableName.Project}.deleteAfter`)
- .select(`${TableName.Project}.id`);
- if (orgId) void qb.where(`${TableName.Project}.orgId`, orgId);
- return qb;
- };
+ const countProjectIdentities = async (projectType: ProjectType, orgId?: string): Promise<number> => {
+ // The live project ids for this type, resolved once per source. Scoping happens here on
+ // projects.orgId (indexed via projects_orgid_type_idx) rather than on memberships.scopeOrgId:
+ // leading with the org's handful of typed projects lets each source drive off the small project set
+ // and probe memberships through the partial (scopeProjectId, actor*) unique indexes as an
+ // index-only scan, instead of scanning every project-scope membership row in the org. Self-hosted
+ // passes no orgId and counts the whole instance. A fresh builder per call keeps knex from
+ // mutating a shared subquery.
+ const typedProjectIds = () => {
+ const qb = db
+ .replicaNode()(TableName.Project)
+ .where(`${TableName.Project}.type`, projectType)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .select(`${TableName.Project}.id`);
+ if (orgId) void qb.where(`${TableName.Project}.orgId`, orgId);
+ return qb;
+ };
- // scope = project + a non-null actor column + whereIn against the SM project ids matches the
- // partial unique indexes exactly; each project-scope row carries exactly one actor column.
- const directUsers = db
- .replicaNode()(TableName.Membership)
- .where(`${TableName.Membership}.scope`, AccessScope.Project)
- .whereNotNull(`${TableName.Membership}.actorUserId`)
- .whereIn(`${TableName.Membership}.scopeProjectId`, secretProjectIds())
- .select(db.raw("'u' as kind"))
- .select(`${TableName.Membership}.actorUserId as entityId`);
+ // scope = project + a non-null actor column + whereIn against the typed project ids matches the
+ // partial unique indexes exactly; each project-scope row carries exactly one actor column.
+ const directUsers = db
+ .replicaNode()(TableName.Membership)
+ .where(`${TableName.Membership}.scope`, AccessScope.Project)
+ .whereNotNull(`${TableName.Membership}.actorUserId`)
+ .whereIn(`${TableName.Membership}.scopeProjectId`, typedProjectIds())
+ .select(db.raw("'u' as kind"))
+ .select(`${TableName.Membership}.actorUserId as entityId`);
- const distinctEntities = directUsers.union(
- [
- (qb) =>
- void qb
- .from(TableName.Membership)
- .where(`${TableName.Membership}.scope`, AccessScope.Project)
- .whereNotNull(`${TableName.Membership}.actorIdentityId`)
- .whereIn(`${TableName.Membership}.scopeProjectId`, secretProjectIds())
- .select(db.raw("'i' as kind"))
- .select(`${TableName.Membership}.actorIdentityId as entityId`),
- // A group assigned to a project (membership with actorGroupId) brings its members into it. A
- // pending group membership (invited, not yet joined) does not occupy a seat.
- (qb) =>
- void qb
- .from(TableName.UserGroupMembership)
- .join(
- TableName.Membership,
- `${TableName.UserGroupMembership}.groupId`,
- `${TableName.Membership}.actorGroupId`
- )
- .where(`${TableName.Membership}.scope`, AccessScope.Project)
- .where(`${TableName.UserGroupMembership}.isPending`, false)
- .whereIn(`${TableName.Membership}.scopeProjectId`, secretProjectIds())
- .select(db.raw("'u' as kind"))
- .select(`${TableName.UserGroupMembership}.userId as entityId`),
- (qb) =>
- void qb
- .from(TableName.IdentityGroupMembership)
- .join(
- TableName.Membership,
- `${TableName.IdentityGroupMembership}.groupId`,
- `${TableName.Membership}.actorGroupId`
- )
- .where(`${TableName.Membership}.scope`, AccessScope.Project)
- .whereIn(`${TableName.Membership}.scopeProjectId`, secretProjectIds())
- .select(db.raw("'i' as kind"))
- .select(`${TableName.IdentityGroupMembership}.identityId as entityId`)
- ],
- true
- );
- // .as() on a union builder is typed as any, so cast the awaited row before counting.
- const row = (await db
- .replicaNode()
- .count("* as count")
- .from(distinctEntities.as("secret_identities"))
- .first()) as { count?: string | number } | undefined;
- return toCount(row);
+ const distinctEntities = directUsers.union(
+ [
+ (qb) =>
+ void qb
+ .from(TableName.Membership)
+ .where(`${TableName.Membership}.scope`, AccessScope.Project)
+ .whereNotNull(`${TableName.Membership}.actorIdentityId`)
+ .whereIn(`${TableName.Membership}.scopeProjectId`, typedProjectIds())
+ .select(db.raw("'i' as kind"))
+ .select(`${TableName.Membership}.actorIdentityId as entityId`),
+ // A group assigned to a project (membership with actorGroupId) brings its members into it. A
+ // pending group membership (invited, not yet joined) does not occupy a seat.
+ (qb) =>
+ void qb
+ .from(TableName.UserGroupMembership)
+ .join(
+ TableName.Membership,
+ `${TableName.UserGroupMembership}.groupId`,
+ `${TableName.Membership}.actorGroupId`
+ )
+ .where(`${TableName.Membership}.scope`, AccessScope.Project)
+ .where(`${TableName.UserGroupMembership}.isPending`, false)
+ .whereIn(`${TableName.Membership}.scopeProjectId`, typedProjectIds())
+ .select(db.raw("'u' as kind"))
+ .select(`${TableName.UserGroupMembership}.userId as entityId`),
+ (qb) =>
+ void qb
+ .from(TableName.IdentityGroupMembership)
+ .join(
+ TableName.Membership,
+ `${TableName.IdentityGroupMembership}.groupId`,
+ `${TableName.Membership}.actorGroupId`
+ )
+ .where(`${TableName.Membership}.scope`, AccessScope.Project)
+ .whereIn(`${TableName.Membership}.scopeProjectId`, typedProjectIds())
+ .select(db.raw("'i' as kind"))
+ .select(`${TableName.IdentityGroupMembership}.identityId as entityId`)
+ ],
+ true
+ );
+ // .as() on a union builder is typed as any, so cast the awaited row before counting.
+ const row = (await db.replicaNode().count("* as count").from(distinctEntities.as("project_identities")).first()) as
+ | { count?: string | number }
+ | undefined;
+ return toCount(row);
+ };
+
+ const countSecretManagementIdentities = async (orgId?: string): Promise<number> => {
+ try {
+ return await countProjectIdentities(ProjectType.SecretManager, orgId);
} catch (error) {
throw new DatabaseError({ error, name: "Count secret management identities for usage" });
}
};
- return { countInternalCas, countActiveCerts, countPamResources, countSecretManagementIdentities };
+ const countPamIdentities = async (orgId?: string): Promise<number> => {
+ try {
+ return await countProjectIdentities(ProjectType.PAM, orgId);
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Count PAM identities for usage" });
+ }
+ };
+
+ return { countInternalCas, countActiveCerts, countPamResources, countSecretManagementIdentities, countPamIdentities };
};
diff --git a/backend/src/services/license-client/usage/usage-counters.ts b/backend/src/services/license-client/usage/usage-counters.ts
index deabf389c1..88b48d2b05 100644
--- a/backend/src/services/license-client/usage/usage-counters.ts
+++ b/backend/src/services/license-client/usage/usage-counters.ts
@@ -1,7 +1,14 @@
import { TLicenseDALFactory } from "@app/ee/services/license/license-dal";
import { TFeatureCounterFn, TLimitFeatureDescriptor } from "../feature";
-import { MaxActiveCerts, MaxIdentities, MaxInternalCas, MaxPamResources, SecretIdentities } from "../features";
+import {
+ MaxActiveCerts,
+ MaxIdentities,
+ MaxInternalCas,
+ MaxPamResources,
+ PamIdentities,
+ SecretIdentities
+} from "../features";
import { TUsageCounterDALFactory } from "./usage-counter-dal";
export type TMeteredFeature = {
@@ -30,5 +37,9 @@ export const buildMeteredFeatures = ({
{
feature: SecretIdentities,
count: (orgId) => usageCounterDAL.countSecretManagementIdentities(isCloud ? orgId : undefined)
+ },
+ {
+ feature: PamIdentities,
+ count: (orgId) => usageCounterDAL.countPamIdentities(isCloud ? orgId : undefined)
}
];
diff --git a/backend/src/services/license-client/usage/usage-metering.test.ts b/backend/src/services/license-client/usage/usage-metering.test.ts
index 7d47011550..1e0f2c82b3 100644
--- a/backend/src/services/license-client/usage/usage-metering.test.ts
+++ b/backend/src/services/license-client/usage/usage-metering.test.ts
@@ -3,7 +3,14 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
import { QueueJobs, QueueName } from "@app/queue";
import { featureReaderFactory } from "../feature-reader";
-import { MaxActiveCerts, MaxIdentities, MaxInternalCas, MaxPamResources, SecretIdentities } from "../features";
+import {
+ MaxActiveCerts,
+ MaxIdentities,
+ MaxInternalCas,
+ MaxPamResources,
+ PamIdentities,
+ SecretIdentities
+} from "../features";
import { buildMeteredFeatures } from "./usage-counters";
import { usageEventQueueFactory } from "./usage-event-queue";
import { usageMeteringServiceFactory } from "./usage-metering-service";
@@ -170,13 +177,21 @@ describe("buildMeteredFeatures", () => {
countInternalCas: vi.fn(async () => 1),
countActiveCerts: vi.fn(async () => 2),
countPamResources: vi.fn(async () => 3),
- countSecretManagementIdentities: vi.fn(async () => 4)
+ countSecretManagementIdentities: vi.fn(async () => 4),
+ countPamIdentities: vi.fn(async () => 5)
};
const metered = buildMeteredFeatures({ licenseDAL, usageCounterDAL, isCloud: true });
const byKey = Object.fromEntries(metered.map((m) => [m.feature.key, m.count]));
expect(Object.keys(byKey).sort()).toEqual(
- [MaxIdentities.key, MaxInternalCas.key, MaxActiveCerts.key, MaxPamResources.key, SecretIdentities.key].sort()
+ [
+ MaxIdentities.key,
+ MaxInternalCas.key,
+ MaxActiveCerts.key,
+ MaxPamResources.key,
+ SecretIdentities.key,
+ PamIdentities.key
+ ].sort()
);
expect(await byKey[MaxIdentities.key](ORG_ID)).toBe(7);
@@ -184,9 +199,11 @@ describe("buildMeteredFeatures", () => {
expect(await byKey[MaxActiveCerts.key](ORG_ID)).toBe(2);
expect(await byKey[MaxPamResources.key](ORG_ID)).toBe(3);
expect(await byKey[SecretIdentities.key](ORG_ID)).toBe(4);
+ expect(await byKey[PamIdentities.key](ORG_ID)).toBe(5);
expect(licenseDAL.countOrgUsersAndIdentities).toHaveBeenCalledWith(ORG_ID);
- // Cloud scopes the secret-identity meter to the org.
+ // Cloud scopes the identity meters to the org.
expect(usageCounterDAL.countSecretManagementIdentities).toHaveBeenCalledWith(ORG_ID);
+ expect(usageCounterDAL.countPamIdentities).toHaveBeenCalledWith(ORG_ID);
});
test("self-hosted meters secret identities across the whole instance (no org scope)", async () => {
@@ -195,13 +212,17 @@ describe("buildMeteredFeatures", () => {
countInternalCas: vi.fn(async () => 0),
countActiveCerts: vi.fn(async () => 0),
countPamResources: vi.fn(async () => 0),
- countSecretManagementIdentities: vi.fn(async () => 9)
+ countSecretManagementIdentities: vi.fn(async () => 9),
+ countPamIdentities: vi.fn(async () => 6)
};
const metered = buildMeteredFeatures({ licenseDAL, usageCounterDAL, isCloud: false });
const secret = metered.find((m) => m.feature.key === SecretIdentities.key);
+ const pam = metered.find((m) => m.feature.key === PamIdentities.key);
expect(await secret?.count(ORG_ID)).toBe(9);
+ expect(await pam?.count(ORG_ID)).toBe(6);
expect(usageCounterDAL.countSecretManagementIdentities).toHaveBeenCalledWith(undefined);
+ expect(usageCounterDAL.countPamIdentities).toHaveBeenCalledWith(undefined);
});
});
@@ -306,7 +327,8 @@ describe("canUse enforcement (using the framework from a call site)", () => {
countInternalCas: async () => counts.internalCas ?? 0,
countActiveCerts: async () => 0,
countPamResources: async () => 0,
- countSecretManagementIdentities: async () => 0
+ countSecretManagementIdentities: async () => 0,
+ countPamIdentities: async () => 0
};
buildMeteredFeatures({ licenseDAL, usageCounterDAL, isCloud: true }).forEach(({ feature, count }) =>
reader.registerCounter(feature, count)
@@ -315,7 +337,7 @@ describe("canUse enforcement (using the framework from a call site)", () => {
};
test("canUse() compares the live count against the cap resolved from entitlements", async () => {
- const reader = buildReader({ max_identities: { value: 100 } }, { identities: 99 });
+ const reader = buildReader({ identities: { value: 100 } }, { identities: 99 });
const identities = await reader.getFeature(ORG_ID, MaxIdentities);
expect(identities.value).toBe(100); // cap comes from the License Server entitlement
@@ -324,15 +346,15 @@ describe("canUse enforcement (using the framework from a call site)", () => {
});
test("a metered create path blocks once the cap is reached", async () => {
- const reader = buildReader({ max_internal_cas: { value: 1 } }, { internalCas: 1 });
+ const reader = buildReader({ internal_cas: { value: 1 } }, { internalCas: 1 });
const assertCanCreateInternalCa = async () => {
const cas = await reader.getFeature(ORG_ID, MaxInternalCas);
if (!(await cas.canUse(1))) {
- throw new Error(`max_internal_cas limit reached (cap ${cas.value})`);
+ throw new Error(`internal_cas limit reached (cap ${cas.value})`);
}
};
- await expect(assertCanCreateInternalCa()).rejects.toThrow("max_internal_cas limit reached (cap 1)");
+ await expect(assertCanCreateInternalCa()).rejects.toThrow("internal_cas limit reached (cap 1)");
});
});
diff --git a/backend/src/services/membership-group/membership-group-service.ts b/backend/src/services/membership-group/membership-group-service.ts
index e2635f2f80..573cf6d926 100644
--- a/backend/src/services/membership-group/membership-group-service.ts
+++ b/backend/src/services/membership-group/membership-group-service.ts
@@ -18,7 +18,7 @@ import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { groupBy } from "@app/lib/fn";
import { ms } from "@app/lib/ms";
import { SearchResourceOperators } from "@app/lib/search-resource/search";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TApplicationMembershipCleanupServiceFactory } from "../membership/application-membership-cleanup-service";
@@ -199,9 +199,10 @@ export const membershipGroupServiceFactory = ({
return doc;
});
- // Assigning a group to a project brings the group's users + identities into it, changing the meter.
+ // Assigning a group to a project brings the group's users + identities into it, changing the meters.
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
}
return { membership, group };
};
@@ -408,9 +409,10 @@ export const membershipGroupServiceFactory = ({
? await performDelete(externalTx)
: await membershipGroupDAL.transaction(performDelete);
- // Removing a group from a project drops its users + identities from it, changing the meter.
+ // Removing a group from a project drops its users + identities from it, changing the meters.
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
}
return { membership: membershipDoc, group };
};
diff --git a/backend/src/services/membership-identity/membership-identity-service.ts b/backend/src/services/membership-identity/membership-identity-service.ts
index 0b45e9968e..d75838654d 100644
--- a/backend/src/services/membership-identity/membership-identity-service.ts
+++ b/backend/src/services/membership-identity/membership-identity-service.ts
@@ -9,7 +9,7 @@ import { groupBy } from "@app/lib/fn";
import { ms } from "@app/lib/ms";
import { SearchResourceOperators } from "@app/lib/search-resource/search";
import { getIdentityActiveLockoutAuthMethods } from "@app/services/identity/identity-fns";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
@@ -190,9 +190,10 @@ export const membershipIdentityServiceFactory = ({
return doc;
});
- // Adding an identity to a project changes the secret-manager identity meter (a direct member).
+ // Adding an identity to a project changes the secret-manager and PAM identity meters (a direct member).
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
}
return { membership };
};
@@ -368,11 +369,13 @@ export const membershipIdentityServiceFactory = ({
: await membershipIdentityDAL.transaction(performDelete);
// Removing an identity from a project drops a direct member; removing it from the org cascades its
- // project + group memberships. Either way the secret-manager identity meter changes.
+ // project + group memberships. Either way the secret-manager and PAM identity meters change.
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
} else {
usageMeteringService.emit(scopeData.orgId, SecretIdentities.key);
+ usageMeteringService.emit(scopeData.orgId, PamIdentities.key);
}
return { membership: membershipDoc };
};
diff --git a/backend/src/services/membership-user/membership-user-service.ts b/backend/src/services/membership-user/membership-user-service.ts
index 496f6082fe..967ecfbbb3 100644
--- a/backend/src/services/membership-user/membership-user-service.ts
+++ b/backend/src/services/membership-user/membership-user-service.ts
@@ -21,7 +21,7 @@ import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { SearchResourceOperators } from "@app/lib/search-resource/search";
import { isDisposableEmail, sanitizeEmail, validateEmail } from "@app/lib/validator";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
@@ -359,9 +359,10 @@ export const membershipUserServiceFactory = ({
const { signUpTokens } = await factory.onCreateMembershipComplete(dto, newMembershipUsers);
- // Adding a user to a project changes the secret-manager identity meter (a direct member).
+ // Adding a user to a project changes the secret-manager and PAM identity meters (a direct member).
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
}
return { memberships: membershipDoc, signUpTokens };
};
@@ -566,11 +567,13 @@ export const membershipUserServiceFactory = ({
: await membershipUserDAL.transaction(performDelete);
// Removing a user from a project drops a direct member; removing them from the org cascades their
- // project + group memberships. Either way the secret-manager identity meter changes.
+ // project + group memberships. Either way the secret-manager and PAM identity meters change.
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
} else {
usageMeteringService.emit(scopeData.orgId, SecretIdentities.key);
+ usageMeteringService.emit(scopeData.orgId, PamIdentities.key);
}
return { membership: membershipDoc };
};
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 15d19c57f7..a65c575674 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -38,7 +38,7 @@ import { logger } from "@app/lib/logger";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { getDefaultOrgMembershipRoleForUpdateOrg } from "@app/services/org/org-role-fns";
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
@@ -1206,8 +1206,9 @@ export const orgServiceFactory = ({
approvalPolicyDAL
});
- // Removing an org member cascades their project + group memberships, changing the meter.
+ // Removing an org member cascades their project + group memberships, changing the identity meters.
usageMeteringService.emit(orgId, SecretIdentities.key);
+ usageMeteringService.emit(orgId, PamIdentities.key);
return deletedMembership;
};
@@ -1247,8 +1248,9 @@ export const orgServiceFactory = ({
approvalPolicyDAL
});
- // Removing org members cascades their project + group memberships, changing the meter.
+ // Removing org members cascades their project + group memberships, changing the identity meters.
usageMeteringService.emit(orgId, SecretIdentities.key);
+ usageMeteringService.emit(orgId, PamIdentities.key);
return deletedMemberships;
};
diff --git a/backend/src/services/project-membership/project-membership-service.ts b/backend/src/services/project-membership/project-membership-service.ts
index 86cc506770..1616fde6dc 100644
--- a/backend/src/services/project-membership/project-membership-service.ts
+++ b/backend/src/services/project-membership/project-membership-service.ts
@@ -11,7 +11,7 @@ import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { groupBy } from "@app/lib/fn";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TAccessApprovalPolicyApproverDALFactory } from "../../ee/services/access-approval-policy/access-approval-policy-approver-dal";
@@ -302,6 +302,7 @@ export const projectMembershipServiceFactory = ({
});
}
usageMeteringService.emitForProject(projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
return orgMembers;
};
@@ -410,6 +411,7 @@ export const projectMembershipServiceFactory = ({
: await membershipUserDAL.transaction(performDelete);
usageMeteringService.emitForProject(projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
return memberships;
};
@@ -491,6 +493,7 @@ export const projectMembershipServiceFactory = ({
}
usageMeteringService.emitForProject(projectId, SecretIdentities.key);
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
return deletedMembership;
};
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index eb5c5a9bb1..4ea17875ba 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -61,7 +61,7 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { OrgServiceActor, TProjectPermission } from "@app/lib/types";
-import { SecretIdentities } from "@app/services/license-client";
+import { PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TPkiSubscriberDALFactory } from "@app/services/pki-subscriber/pki-subscriber-dal";
@@ -785,9 +785,10 @@ export const projectServiceFactory = ({
await keyStore.deleteItem(KeyStorePrefixes.LicenseCloudPlan(actorOrgId));
// A new project seeds its creator (plus any template members/identities); emit so a new
- // secret-manager project's seats are metered. Org-scoped (not emitForProject) to avoid racing the
- // just-committed row; the counter filters by project type.
+ // secret-manager or PAM project's seats are metered. Org-scoped (not emitForProject) to avoid racing
+ // the just-committed row; the counter filters by project type.
usageMeteringService.emit(results.orgId, SecretIdentities.key);
+ usageMeteringService.emit(results.orgId, PamIdentities.key);
return results;
};
@@ -869,8 +870,9 @@ export const projectServiceFactory = ({
// refresh the cached plan so the freed workspace slot is reflected immediately
// (countOfOrgProjects now excludes soft-deleted projects)
await keyStore.deleteItem(KeyStorePrefixes.LicenseCloudPlan(actorOrgId));
- // The soft-deleted project drops out of the meter's count, so its members no longer count.
+ // The soft-deleted project drops out of the meters' counts, so its members no longer count.
usageMeteringService.emit(project.orgId, SecretIdentities.key);
+ usageMeteringService.emit(project.orgId, PamIdentities.key);
return { ...softDeletedProject, slug: project.slug };
} finally {
await lock.release();
diff --git a/backend/src/services/secret-sync/secret-sync-dal.ts b/backend/src/services/secret-sync/secret-sync-dal.ts
index 2771ff811f..b2a2e63ad2 100644
--- a/backend/src/services/secret-sync/secret-sync-dal.ts
+++ b/backend/src/services/secret-sync/secret-sync-dal.ts
@@ -229,6 +229,21 @@ export const secretSyncDALFactory = (
}
};
+ // Total secret syncs across all of the org's projects (excluding soft-deleted projects), used to
+ // enforce the plan's secretSyncLimit at creation time.
+ const countByOrgId = async (orgId: string, tx?: Knex) => {
+ try {
+ const doc = await (tx || db.replicaNode())(TableName.SecretSync)
+ .join(TableName.Project, `${TableName.SecretSync}.projectId`, `${TableName.Project}.id`)
+ .where(`${TableName.Project}.orgId`, orgId)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .count();
+ return Number(doc?.[0]?.count ?? 0);
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Count By Org ID - Secret Sync" });
+ }
+ };
+
const findByDestinationAndOrgId = async (destination: string, orgId: string, tx?: Knex) => {
try {
const response = await (tx || db.replicaNode())(TableName.SecretSync)
@@ -251,6 +266,7 @@ export const secretSyncDALFactory = (
create,
updateById,
updateAndReturnIds,
+ countByOrgId,
findByDestinationAndOrgId
};
};
diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.ts
index dedcdec84a..f1b50361ac 100644
--- a/backend/src/services/secret-sync/secret-sync-service.ts
+++ b/backend/src/services/secret-sync/secret-sync-service.ts
@@ -376,6 +376,18 @@ export const secretSyncServiceFactory = ({
"Failed to create secret sync due to plan restriction. Upgrade plan to access enterprise secret syncs."
);
+ // secretSyncLimit is uncapped by default (null); only enforce a cap when the plan configures a
+ // numeric limit. Counted org-wide right before creation.
+ const plan = await licenseService.getPlan(actor.orgId);
+ if (typeof plan.secretSyncLimit === "number") {
+ const currentSecretSyncCount = await secretSyncDAL.countByOrgId(actor.orgId);
+ if (currentSecretSyncCount >= plan.secretSyncLimit) {
+ throw new BadRequestError({
+ message: "Failed to create secret sync due to plan limit reached. Upgrade plan to add more secret syncs."
+ });
+ }
+ }
+
const { permission: projectPermission } = await permissionService.getProjectPermission({
actor: actor.type,
actorId: actor.id,
diff --git a/backend/src/services/signer/signer-service.ts b/backend/src/services/signer/signer-service.ts
index 2c2675d6d5..1ceb1f9083 100644
--- a/backend/src/services/signer/signer-service.ts
+++ b/backend/src/services/signer/signer-service.ts
@@ -11,6 +11,7 @@ import {
ResourceMembershipRole,
ResourceType
} from "@app/db/schemas";
+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
ProjectPermissionCodeSigningActions,
@@ -148,6 +149,7 @@ type TSignerServiceFactoryDep = {
"create" | "find" | "delete" | "transaction" | "findResourceMembershipsForActor"
>;
membershipRoleDAL: Pick<TMembershipRoleDALFactory, "create" | "delete">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
};
export type TSignerServiceFactory = ReturnType<typeof signerServiceFactory>;
@@ -270,7 +272,8 @@ export const signerServiceFactory = ({
approvalRequestGrantsDAL,
membershipDAL,
membershipRoleDAL,
- hsmConnectorService
+ hsmConnectorService,
+ licenseService
}: TSignerServiceFactoryDep) => {
const hsmCertIssuanceDeps = {
certificateAuthorityDAL,
@@ -361,6 +364,15 @@ export const signerServiceFactory = ({
ProjectPermissionSub.CodeSigners
);
+ // pkiCodeSigning is ignored when null (no restriction); only an explicit boolean gates the feature,
+ // blocking creation when it is explicitly false.
+ const plan = await licenseService.getPlan(dto.actorOrgId);
+ if (typeof plan.pkiCodeSigning === "boolean" && !plan.pkiCodeSigning) {
+ throw new BadRequestError({
+ message: "Failed to create code signer due to plan restriction. Upgrade plan to access PKI code signing."
+ });
+ }
+
const usingExistingCert = Boolean(dto.certificateId);
const usingCa = Boolean(dto.caId);
if (usingExistingCert === usingCa) {
diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.ts
index bf1cb446e0..1d1a12d0bd 100644
--- a/frontend/src/hooks/api/subscriptions/types.ts
+++ b/frontend/src/hooks/api/subscriptions/types.ts
@@ -84,4 +84,8 @@ export type SubscriptionPlan = {
honeyTokens: boolean;
honeyTokenLimit: number;
secretsBrokering: boolean;
+ // Product gate flags. When explicitly true, the product's primary creation flow is blocked and an
+ // upgrade modal is surfaced in the product layout.
+ pam?: boolean | null;
+ certManager?: boolean | null;
};
diff --git a/frontend/src/layouts/PamLayout/PamLayout.tsx b/frontend/src/layouts/PamLayout/PamLayout.tsx
index 66e5652333..1a518156d8 100644
--- a/frontend/src/layouts/PamLayout/PamLayout.tsx
+++ b/frontend/src/layouts/PamLayout/PamLayout.tsx
@@ -1,16 +1,31 @@
+import { useEffect, useState } from "react";
import { Outlet } from "@tanstack/react-router";
-import { useProjectPermission } from "@app/context";
+import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
+import { useProjectPermission, useSubscription } from "@app/context";
import { AssumePrivilegeModeBanner } from "../ProjectLayout/components/AssumePrivilegeModeBanner";
export const PamLayout = () => {
const { assumedPrivilegeDetails } = useProjectPermission();
+ const { subscription } = useSubscription();
+
+ const isPamGated = subscription?.pam === true;
+ const [isUpgradeModalOpen, setIsUpgradeModalOpen] = useState(isPamGated);
+
+ useEffect(() => {
+ if (isPamGated) setIsUpgradeModalOpen(true);
+ }, [isPamGated]);
return (
<>
{assumedPrivilegeDetails && <AssumePrivilegeModeBanner />}
<Outlet />
+ <UpgradePlanModal
+ isOpen={isUpgradeModalOpen}
+ onOpenChange={setIsUpgradeModalOpen}
+ text="PAM is not available on your current plan. Upgrade to continue using it."
+ />
</>
);
};
diff --git a/frontend/src/layouts/PkiManagerLayout/PkiManagerLayout.tsx b/frontend/src/layouts/PkiManagerLayout/PkiManagerLayout.tsx
index 1a4338a59d..6da1d4a4f9 100644
--- a/frontend/src/layouts/PkiManagerLayout/PkiManagerLayout.tsx
+++ b/frontend/src/layouts/PkiManagerLayout/PkiManagerLayout.tsx
@@ -1,15 +1,25 @@
+import { useEffect, useState } from "react";
import { Outlet, useRouterState } from "@tanstack/react-router";
-import { useProjectPermission } from "@app/context";
+import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
+import { useProjectPermission, useSubscription } from "@app/context";
import { AssumePrivilegeModeBanner } from "../ProjectLayout/components/AssumePrivilegeModeBanner";
import { CertManagerInstanceBanner } from "./components/CertManagerInstanceBanner";
export const PkiManagerLayout = () => {
const { assumedPrivilegeDetails } = useProjectPermission();
+ const { subscription } = useSubscription();
const pathname = useRouterState({ select: (s) => s.location.pathname });
const isDashboard = /\/cert-manager\/[^/]+\/overview\/?$/.test(pathname);
+ const isCertManagerGated = subscription?.certManager === true;
+ const [isUpgradeModalOpen, setIsUpgradeModalOpen] = useState(isCertManagerGated);
+
+ useEffect(() => {
+ if (isCertManagerGated) setIsUpgradeModalOpen(true);
+ }, [isCertManagerGated]);
+
return (
<div className="flex h-full w-full flex-col overflow-x-hidden">
{assumedPrivilegeDetails && <AssumePrivilegeModeBanner />}
@@ -17,6 +27,11 @@ export const PkiManagerLayout = () => {
<div className="flex-1 overflow-x-hidden overflow-y-auto bg-bunker-800 px-12 pt-10 pb-4">
<Outlet />
</div>
+ <UpgradePlanModal
+ isOpen={isUpgradeModalOpen}
+ onOpenChange={setIsUpgradeModalOpen}
+ text="Certificate Manager is not available on your current plan. Upgrade to continue using it."
+ />
</div>
);
};