Skip to content

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

feat: review updates

=3d23c779e55b
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.ts
index 31e175a81d..ceee64bb92 100644
--- a/backend/src/ee/routes/v1/license-v2-router.ts
+++ b/backend/src/ee/routes/v1/license-v2-router.ts
@@ -229,6 +229,27 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ method: "POST",
+ url: "/:organizationId/billing/v2/overview/refresh",
+ config: {
+ rateLimit: writeLimit
+ },
+ schema: {
+ params: z.object({ organizationId: z.string().trim() }),
+ response: {
+ 200: z.object({ success: z.boolean() })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ return server.services.licenseV2.refreshEntitlements({
+ orgId: req.params.organizationId,
+ actor: buildActor(req.permission)
+ });
+ }
+ });
+
server.route({
method: "GET",
url: "/:organizationId/billing/v2/catalog",
diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.ts
index bd0fedebac..c358b3910a 100644
--- a/backend/src/ee/services/license-v2/license-v2-service.ts
+++ b/backend/src/ee/services/license-v2/license-v2-service.ts
@@ -43,13 +43,14 @@ import {
} from "./license-v2-types";
type TLicenseV2ServiceFactoryDep = {
- envConfig: Pick<TEnvConfig, "LICENSE_SERVER_V2_MODE" | "LICENSE_KEY">;
+ envConfig: Pick<TEnvConfig, "LICENSE_SERVER_V2_MODE" | "LICENSE_KEY" | "SITE_URL">;
orgDAL: Pick<TOrgDALFactory, "findById">;
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
licenseClient: Pick<
TLicenseClientFactory,
| "getEntitlements"
| "invalidateEntitlements"
+ | "refreshEntitlements"
| "getCatalog"
| "getSubscription"
| "getCloudPlan"
@@ -753,6 +754,14 @@ export const licenseV2ServiceFactory = ({
return { overview };
};
+ // Force-refresh entitlements: ask the license server to recompute and drop the local cache, so the
+ // next overview read pulls the latest and re-populates the cache. Exposed as a manual refresh button.
+ const refreshEntitlements = async ({ orgId, actor }: TGetBillingV2OverviewDTO) => {
+ await ensureBillingRead(orgId, actor);
+ await licenseClient.refreshEntitlements({ id: orgId });
+ return { success: true as const };
+ };
+
const getCatalog = async ({ orgId, actor }: TGetBillingV2CatalogDTO) => {
await ensureBillingRead(orgId, actor);
@@ -765,9 +774,23 @@ export const licenseV2ServiceFactory = ({
return { products };
};
- // Stripe billing portal: manages the existing subscription, payment methods, and billing details.
+ const buildReturnUrl = (orgId: string, returnPath?: string): string => {
+ if (!envConfig.SITE_URL) {
+ throw new InternalServerError({ message: "Failed to build a billing return URL" });
+ }
+ const path = returnPath && returnPath.startsWith("/") ? returnPath : `/organizations/${orgId}/billing`;
+ try {
+ return new URL(path, envConfig.SITE_URL).toString();
+ } catch {
+ throw new InternalServerError({ message: "Failed to build a billing return URL" });
+ }
+ };
+
const openPortal = async (orgId: string, returnPath?: string) => {
- const session = await licenseClient.createPortal(orgId, { returnPath });
+ const session = await licenseClient.createPortal(orgId, {
+ returnPath,
+ returnUrl: buildReturnUrl(orgId, returnPath)
+ });
return { url: session.url };
};
@@ -799,7 +822,12 @@ export const licenseV2ServiceFactory = ({
throw new BadRequestError({ message: "This product is not available for self-serve checkout" });
}
- const result = await licenseClient.createCheckout(orgId, { items, email, returnPath });
+ const result = await licenseClient.createCheckout(orgId, {
+ items,
+ email,
+ returnPath,
+ returnUrl: buildReturnUrl(orgId, returnPath)
+ });
if (result.outcome === "subscription_updated") {
return { outcome: "subscription_updated" as const, subscriptionId: result.subscriptionId };
}
@@ -966,6 +994,7 @@ export const licenseV2ServiceFactory = ({
// Billing surface (portal, checkout, overview) goes live only at full v2 cutover, not during read-compare.
isEnabled: () => envConfig.LICENSE_SERVER_V2_MODE === "on",
getOverview,
+ refreshEntitlements,
getCatalog,
portalSession,
checkoutSession,
diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts
index fa23f060ca..62aa9c0377 100644
--- a/backend/src/ee/services/license/license-types.ts
+++ b/backend/src/ee/services/license/license-types.ts
@@ -107,17 +107,9 @@ 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;
secretsTemporaryAccess: null;
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 07b6e806ad..8402c50091 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -294,15 +294,12 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
);
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."
});
}
- // Windows PAM accounts are an enterprise capability. The `enterprisePamAccount` flag is ignored when
- // null; an explicit boolean enforces it (false blocks Windows / Windows AD account creation).
if (
(accountType === PamAccountType.Windows || accountType === PamAccountType.WindowsAd) &&
typeof plan.enterprisePamAccount === "boolean" &&
diff --git a/backend/src/ee/services/pam-membership/pam-membership-service.ts b/backend/src/ee/services/pam-membership/pam-membership-service.ts
index 1247660d66..260d6f2a19 100644
--- a/backend/src/ee/services/pam-membership/pam-membership-service.ts
+++ b/backend/src/ee/services/pam-membership/pam-membership-service.ts
@@ -13,6 +13,8 @@ import { ms } from "@app/lib/ms";
import { TApprovalPolicyDALFactory } from "@app/services/approval-policy/approval-policy-dal";
import { ApprovalPolicyScope } from "@app/services/approval-policy/approval-policy-enums";
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
+import { PamIdentities } 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";
import { TProjectAccessRequestDALFactory } from "@app/services/project/project-access-request-dal";
@@ -52,6 +54,7 @@ type TPamMembershipServiceFactoryDep = {
groupDAL: Pick<TGroupDALFactory, "findById">;
identityDAL: Pick<TIdentityDALFactory, "findById">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getResourcePermission">;
+ usageMeteringService: Pick<TUsageMeteringServiceFactory, "emitForProject">;
};
export type TPamMembershipServiceFactory = ReturnType<typeof pamMembershipServiceFactory>;
@@ -89,7 +92,8 @@ export const pamMembershipServiceFactory = ({
userDAL,
groupDAL,
identityDAL,
- permissionService
+ permissionService,
+ usageMeteringService
}: TPamMembershipServiceFactoryDep) => {
// Shared helpers
@@ -278,7 +282,7 @@ export const pamMembershipServiceFactory = ({
const { column, id, kind } = await validateActorExists(dto, dto.actorOrgId);
- return membershipDAL.transaction(async (tx) => {
+ const result = await membershipDAL.transaction(async (tx) => {
const existing = await membershipDAL.find(
{ scope: AccessScope.Project, scopeProjectId: projectId, [column]: id },
{ tx }
@@ -316,6 +320,10 @@ export const pamMembershipServiceFactory = ({
createdAt: membership.createdAt
};
});
+
+ // A new PAM project member (user/identity/group) changes the pam_identities meter.
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
+ return result;
};
const addProductUserMembers = async ({
@@ -410,6 +418,11 @@ export const pamMembershipServiceFactory = ({
return results;
});
+ // Only re-meter when project members were actually added.
+ if (memberships.length > 0) {
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
+ }
+
return { memberships, skipped, unresolved };
};
@@ -490,7 +503,7 @@ export const pamMembershipServiceFactory = ({
const { column, id, kind } = resolveActorColumn(dto);
- return membershipDAL.transaction(async (tx) => {
+ const result = await membershipDAL.transaction(async (tx) => {
const [membership] = await membershipDAL.find(
{ scope: AccessScope.Project, scopeProjectId: projectId, [column]: id },
{ tx }
@@ -541,6 +554,9 @@ export const pamMembershipServiceFactory = ({
identityId: kind === PamMemberKind.Identity ? id : undefined
};
});
+
+ usageMeteringService.emitForProject(projectId, PamIdentities.key);
+ return result;
};
// Resource (folder/account) members
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 092843c3af..f4b9bbb566 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1724,7 +1724,8 @@ export const registerRoutes = async (
userDAL,
groupDAL,
identityDAL,
- permissionService
+ permissionService,
+ usageMeteringService
});
const certManagerInstanceService = certManagerInstanceServiceFactory({
diff --git a/backend/src/services/certificate-authority/certificate-authority-service.ts b/backend/src/services/certificate-authority/certificate-authority-service.ts
index a85cecc297..3423e8bf43 100644
--- a/backend/src/services/certificate-authority/certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts
@@ -30,7 +30,7 @@ import {
} from "../certificate-request/certificate-request-types";
import type { THsmConnectorServiceFactory } from "../hsm-connector/hsm-connector-service";
import { TKmsServiceFactory } from "../kms/kms-service";
-import { MaxInternalCas } from "../license-client";
+import { InternalCas } from "../license-client";
import { TUsageMeteringServiceFactory } from "../license-client/usage";
import { TPkiSubscriberDALFactory } from "../pki-subscriber/pki-subscriber-dal";
import { TPkiSyncDALFactory } from "../pki-sync/pki-sync-dal";
@@ -324,9 +324,6 @@ export const certificateAuthorityServiceFactory = ({
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) {
@@ -361,7 +358,7 @@ export const certificateAuthorityServiceFactory = ({
});
}
- usageMeteringService.emitForProject(projectId, MaxInternalCas.key);
+ usageMeteringService.emitForProject(projectId, InternalCas.key);
return {
id: ca.id,
@@ -891,7 +888,7 @@ export const certificateAuthorityServiceFactory = ({
await certificateAuthorityDAL.deleteById(certificateAuthority.id);
if (type === CaType.INTERNAL) {
- usageMeteringService.emitForProject(certificateAuthority.projectId, MaxInternalCas.key);
+ usageMeteringService.emitForProject(certificateAuthority.projectId, InternalCas.key);
return {
id: certificateAuthority.id,
type,
@@ -1123,7 +1120,7 @@ export const certificateAuthorityServiceFactory = ({
await certificateAuthorityDAL.deleteById(certificateAuthority.id);
if (type === CaType.INTERNAL) {
- usageMeteringService.emitForProject(certificateAuthority.projectId, MaxInternalCas.key);
+ usageMeteringService.emitForProject(certificateAuthority.projectId, InternalCas.key);
return {
id: certificateAuthority.id,
type,
diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
index d63642ea8b..4bd461b416 100644
--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts
@@ -34,7 +34,7 @@ import { TCertificateBodyDALFactory } from "@app/services/certificate/certificat
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
import type { THsmConnectorServiceFactory } from "@app/services/hsm-connector/hsm-connector-service";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
-import { MaxActiveCerts } from "@app/services/license-client";
+import { ActiveCerts } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TPkiCollectionDALFactory } from "@app/services/pki-collection/pki-collection-dal";
import { TPkiCollectionItemDALFactory } from "@app/services/pki-collection/pki-collection-item-dal";
@@ -2216,7 +2216,7 @@ export const internalCertificateAuthorityServiceFactory = ({
cert = await certificateDAL.transaction(executeIssueCertOperations);
}
- usageMeteringService.emitForProject(ca.projectId, MaxActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
return {
certificate: leafCert.toString("pem"),
@@ -2679,7 +2679,7 @@ export const internalCertificateAuthorityServiceFactory = ({
cert = await certificateDAL.transaction(createSignedCert);
}
- usageMeteringService.emitForProject(ca.projectId, MaxActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
return {
certificate: leafCert,
diff --git a/backend/src/services/certificate/certificate-service.ts b/backend/src/services/certificate/certificate-service.ts
index ab55eabe8c..7eeef1c60b 100644
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@ -28,7 +28,7 @@ import { TCertificateAuthorityServiceFactory } from "@app/services/certificate-a
import { TCertificateSyncDALFactory } from "@app/services/certificate-sync/certificate-sync-dal";
import type { THsmConnectorServiceFactory } from "@app/services/hsm-connector/hsm-connector-service";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
-import { MaxActiveCerts } from "@app/services/license-client";
+import { ActiveCerts } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TPkiAlertV2QueueServiceFactory } from "@app/services/pki-alert-v2/pki-alert-v2-queue";
import { PkiAlertEventType } from "@app/services/pki-alert-v2/pki-alert-v2-types";
@@ -413,7 +413,7 @@ export const certificateServiceFactory = ({
pkiSyncQueue
});
- usageMeteringService.emitForProject(cert.projectId, MaxActiveCerts.key);
+ usageMeteringService.emitForProject(cert.projectId, ActiveCerts.key);
return {
deletedCert
@@ -562,7 +562,7 @@ export const certificateServiceFactory = ({
}
);
- usageMeteringService.emitForProject(ca.projectId, MaxActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
// Trigger auto sync for PKI syncs connected to this certificate
await triggerAutoSyncForCertificate(cert.id, {
@@ -959,7 +959,7 @@ export const certificateServiceFactory = ({
}
});
- usageMeteringService.emitForProject(projectId, MaxActiveCerts.key);
+ usageMeteringService.emitForProject(projectId, ActiveCerts.key);
return {
certificate: certificatePem,
diff --git a/backend/src/services/identity-v2/identity-service.ts b/backend/src/services/identity-v2/identity-service.ts
index 69ccc954e6..b01461595b 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, PamIdentities, SecretIdentities } from "@app/services/license-client";
+import { IdentitiesMeter, 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";
@@ -298,7 +298,7 @@ export const identityV2ServiceFactory = ({
// A new identity always adds an org membership; a project-scoped one also joins that project, so
// it counts toward the secret-manager and PAM identity meters too.
- usageMeteringService.emit(dto.permission.orgId, MaxIdentities.key);
+ usageMeteringService.emit(dto.permission.orgId, IdentitiesMeter.key);
if (scopeData.scope === AccessScope.Project) {
usageMeteringService.emitForProject(scopeData.projectId, SecretIdentities.key);
usageMeteringService.emitForProject(scopeData.projectId, PamIdentities.key);
@@ -386,7 +386,7 @@ export const identityV2ServiceFactory = ({
await licenseService.updateSubscriptionOrgMemberCount(scopeData.orgId);
// Deleting the identity cascades its org + project + group memberships, so all meters change.
- usageMeteringService.emit(scopeData.orgId, MaxIdentities.key);
+ usageMeteringService.emit(scopeData.orgId, IdentitiesMeter.key);
usageMeteringService.emit(scopeData.orgId, SecretIdentities.key);
usageMeteringService.emit(scopeData.orgId, PamIdentities.key);
diff --git a/backend/src/services/identity/identity-service.ts b/backend/src/services/identity/identity-service.ts
index 74958dea8b..6d8cce18e5 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, PamIdentities, SecretIdentities } from "@app/services/license-client";
+import { IdentitiesMeter, PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
@@ -186,7 +186,7 @@ export const identityServiceFactory = ({
};
});
await licenseService.updateSubscriptionOrgMemberCount(orgId);
- usageMeteringService.emit(orgId, MaxIdentities.key);
+ usageMeteringService.emit(orgId, IdentitiesMeter.key);
return identity;
};
@@ -378,9 +378,7 @@ 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 and PAM
- // identity meters change too.
+ usageMeteringService.emit(identityOrgMembership.scopeOrgId, IdentitiesMeter.key);
usageMeteringService.emit(identityOrgMembership.scopeOrgId, SecretIdentities.key);
usageMeteringService.emit(identityOrgMembership.scopeOrgId, PamIdentities.key);
return { ...deletedIdentity, orgId: identityOrgMembership.scopeOrgId };
@@ -416,7 +414,7 @@ export const identityServiceFactory = ({
});
const deletedIdentity = await requestMemoize(requestMemoKeys.identityFindById(id), () => identityDAL.findById(id));
- usageMeteringService.emit(identityOrgMembership.scopeOrgId, MaxIdentities.key);
+ usageMeteringService.emit(identityOrgMembership.scopeOrgId, IdentitiesMeter.key);
// Deleting the identity cascades its project + group memberships, so the secret-manager and PAM
// identity meters change too.
usageMeteringService.emit(identityOrgMembership.scopeOrgId, SecretIdentities.key);
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 2b9d8732b2..b2d0f0d3f0 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
@@ -1,18 +1,11 @@
-import {
- AuditRetentionDays,
- MaxActiveCerts,
- MaxIdentities,
- MaxInternalCas,
- MaxPamResources,
- SsoEnforcement
-} from "../../features";
+import { ActiveCerts, AuditRetentionDays, IdentitiesMeter, InternalCas, SsoEnforcement } from "../../features";
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,
+ v2Key: IdentitiesMeter.key,
v1Field: null,
extractV1: null
},
@@ -31,17 +24,12 @@ export const existingDescriptorMappings: TFeatureMapping[] = [
{
// 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,
+ v2Key: InternalCas.key,
v1Field: null,
extractV1: null
},
{
- v2Key: MaxActiveCerts.key,
- v1Field: null,
- extractV1: null
- },
- {
- v2Key: MaxPamResources.key,
+ v2Key: ActiveCerts.key,
v1Field: null,
extractV1: null
}
diff --git a/backend/src/services/license-client/features.ts b/backend/src/services/license-client/features.ts
index fd6f4bd2ce..484f4f5666 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("identities", 0);
-export const MaxInternalCas = defineLimitFeature("internal_cas", 0);
-export const MaxActiveCerts = defineLimitFeature("max_active_certs", 0);
-export const MaxPamResources = defineLimitFeature("max_resources", 0);
+export const IdentitiesMeter = defineLimitFeature("identities", 0);
+export const InternalCas = defineLimitFeature("internal_cas", 0);
+export const ActiveCerts = defineLimitFeature("active_certs", 0);
export const SecretIdentities = defineLimitFeature("secret_identities", 0);
export const PamIdentities = defineLimitFeature("pam_identities", 0);
// Human users (org members), excluding machine identities. For legacy per-user plans that count seats.
diff --git a/backend/src/services/license-client/license-client-cache.ts b/backend/src/services/license-client/license-client-cache.ts
index e457107e81..f7dbea3ed2 100644
--- a/backend/src/services/license-client/license-client-cache.ts
+++ b/backend/src/services/license-client/license-client-cache.ts
@@ -62,6 +62,7 @@ export const entitlementResolverFactory = ({ keyStore, backend }: TEntitlementRe
// its Stripe webhook, so a stale read here is what otherwise makes a removed product linger.
const invalidateEntitlements = async (orgId: string): Promise<void> => {
try {
+ await keyStore.deleteItem(KeyStorePrefixes.LicenseCloudPlan(orgId));
await keyStore.deleteItem(KeyStorePrefixes.LicenseEntitlements(orgId));
} catch (error) {
logger.error(error, `license-client: failed to invalidate entitlements [orgId=${orgId}]`);
diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.ts
index acf5a5c728..29dd6b2566 100644
--- a/backend/src/services/license-client/license-client-types.ts
+++ b/backend/src/services/license-client/license-client-types.ts
@@ -367,10 +367,14 @@ export type TAddSubscriptionItemsPayload = {
export type TCreateCheckoutPayload = {
items: TCheckoutLineItem[];
email?: string;
+ // Absolute return URL; its origin must be in the license server's CUSTOMER_PORTAL_ORIGINS allowlist
+ // (the multi-region fix). returnPath is the relative back-compat fallback.
+ returnUrl?: string;
returnPath?: string;
};
export type TCreatePortalPayload = {
+ returnUrl?: string;
returnPath?: string;
};
diff --git a/backend/src/services/license-client/license-client.test.ts b/backend/src/services/license-client/license-client.test.ts
index 0686a29728..ae9cb683bd 100644
--- a/backend/src/services/license-client/license-client.test.ts
+++ b/backend/src/services/license-client/license-client.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, test, vi } from "vitest";
import { featureReaderFactory } from "./feature-reader";
-import { AuditRetentionDays, MaxIdentities, SsoEnforcement } from "./features";
+import { AuditRetentionDays, IdentitiesMeter, SsoEnforcement } from "./features";
import { licenseClientFactory } from "./license-client";
import { entitlementResolverFactory } from "./license-client-cache";
import { TEntitlementsResponse } from "./license-client-types";
@@ -118,7 +118,7 @@ describe("featureReaderFactory", () => {
expect((await reader.getFeature(ORG_ID, SsoEnforcement)).value).toBe(false);
expect((await reader.getFeature(ORG_ID, AuditRetentionDays)).value).toBe(30);
- expect((await reader.getFeature(ORG_ID, MaxIdentities)).value).toBe(0);
+ expect((await reader.getFeature(ORG_ID, IdentitiesMeter)).value).toBe(0);
});
test("returns server-resolved values when present", async () => {
@@ -129,15 +129,15 @@ describe("featureReaderFactory", () => {
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
expect((await reader.getFeature(ORG_ID, SsoEnforcement)).value).toBe(true);
- expect((await reader.getFeature(ORG_ID, MaxIdentities)).value).toBe(100);
+ expect((await reader.getFeature(ORG_ID, IdentitiesMeter)).value).toBe(100);
});
test("canUse enforces the cap against a registered counter", async () => {
const entitlements = makeEntitlements({ identities: { value: 100, source: "plan" } });
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
- reader.registerCounter(MaxIdentities, async () => 99);
+ reader.registerCounter(IdentitiesMeter, async () => 99);
- const limit = await reader.getFeature(ORG_ID, MaxIdentities);
+ const limit = await reader.getFeature(ORG_ID, IdentitiesMeter);
expect(await limit.canUse(1)).toBe(true);
expect(await limit.canUse(2)).toBe(false);
});
@@ -146,7 +146,7 @@ describe("featureReaderFactory", () => {
const entitlements = makeEntitlements({ identities: { value: 100, source: "plan" } });
const reader = featureReaderFactory({ getEntitlements: async () => entitlements });
- const limit = await reader.getFeature(ORG_ID, MaxIdentities);
+ const limit = await reader.getFeature(ORG_ID, IdentitiesMeter);
expect(await limit.canUse(50)).toBe(true);
expect(await limit.canUse(101)).toBe(false);
});
@@ -165,7 +165,7 @@ describe("licenseClientFactory (usage example)", () => {
});
// A metered feature needs its live-count source registered once at init.
- licenseClient.registerCounter(MaxIdentities, async () => 4);
+ licenseClient.registerCounter(IdentitiesMeter, async () => 4);
test("boolean gate", async () => {
const sso = await licenseClient.getFeature(ORG_ID, SsoEnforcement);
@@ -176,7 +176,7 @@ describe("licenseClientFactory (usage example)", () => {
});
test("limit gate via canUse", async () => {
- const identities = await licenseClient.getFeature(ORG_ID, MaxIdentities);
+ const identities = await licenseClient.getFeature(ORG_ID, IdentitiesMeter);
// throw a LimitExceededError here in real code
expect(await identities.canUse(1)).toBe(false); // fallback cap is 0, current is 4
});
diff --git a/backend/src/services/license-client/usage/usage-counters.ts b/backend/src/services/license-client/usage/usage-counters.ts
index 8700b9c57c..01095d6635 100644
--- a/backend/src/services/license-client/usage/usage-counters.ts
+++ b/backend/src/services/license-client/usage/usage-counters.ts
@@ -2,10 +2,9 @@ import { TLicenseDALFactory } from "@app/ee/services/license/license-dal";
import { TFeatureCounterFn, TLimitFeatureDescriptor } from "../feature";
import {
- MaxActiveCerts,
- MaxIdentities,
- MaxInternalCas,
- MaxPamResources,
+ ActiveCerts,
+ IdentitiesMeter,
+ InternalCas,
PamIdentities,
SecretIdentities,
UserIdentities
@@ -31,10 +30,9 @@ export const buildMeteredFeatures = ({
usageCounterDAL,
isCloud
}: TBuildMeteredFeaturesDep): TMeteredFeature[] => [
- { feature: MaxIdentities, count: (orgId) => licenseDAL.countOrgUsersAndIdentities(orgId) },
- { feature: MaxInternalCas, count: (orgId) => usageCounterDAL.countInternalCas(orgId) },
- { feature: MaxActiveCerts, count: (orgId) => usageCounterDAL.countActiveCerts(orgId) },
- { feature: MaxPamResources, count: (orgId) => usageCounterDAL.countPamResources(orgId) },
+ { feature: IdentitiesMeter, count: (orgId) => licenseDAL.countOrgUsersAndIdentities(orgId) },
+ { feature: InternalCas, count: (orgId) => usageCounterDAL.countInternalCas(orgId) },
+ { feature: ActiveCerts, count: (orgId) => usageCounterDAL.countActiveCerts(orgId) },
{
feature: SecretIdentities,
count: (orgId) => usageCounterDAL.countSecretManagementIdentities(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 9b969a86f3..a570d94ee1 100644
--- a/backend/src/services/license-client/usage/usage-metering.test.ts
+++ b/backend/src/services/license-client/usage/usage-metering.test.ts
@@ -4,10 +4,9 @@ import { QueueJobs, QueueName } from "@app/queue";
import { featureReaderFactory } from "../feature-reader";
import {
- MaxActiveCerts,
- MaxIdentities,
- MaxInternalCas,
- MaxPamResources,
+ ActiveCerts,
+ IdentitiesMeter,
+ InternalCas,
PamIdentities,
SecretIdentities,
UserIdentities
@@ -59,7 +58,7 @@ describe("usageMeteringService.emit (org-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "off" }
});
- svc.emit(ORG_ID, MaxIdentities.key);
+ svc.emit(ORG_ID, IdentitiesMeter.key);
await flushAsync();
expect(queue).not.toHaveBeenCalled();
@@ -73,15 +72,15 @@ describe("usageMeteringService.emit (org-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }
});
- svc.emit(ORG_ID, MaxIdentities.key);
+ svc.emit(ORG_ID, IdentitiesMeter.key);
await flushAsync();
expect(queue).toHaveBeenCalledTimes(1);
const [name, job, data, opts] = queue.mock.calls[0] as unknown as TQueueCall;
expect(name).toBe(QueueName.UsageEvent);
expect(job).toBe(QueueJobs.UsageEvent);
- expect(data).toEqual({ orgId: ORG_ID, dimensionKey: MaxIdentities.key });
- expect(opts.deduplication?.id).toBe(`usage-event-${ORG_ID}-${MaxIdentities.key}`);
+ expect(data).toEqual({ orgId: ORG_ID, dimensionKey: IdentitiesMeter.key });
+ expect(opts.deduplication?.id).toBe(`usage-event-${ORG_ID}-${IdentitiesMeter.key}`);
expect(opts.delay).toBe(5000);
});
@@ -95,7 +94,7 @@ describe("usageMeteringService.emit (org-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }
});
- expect(() => svc.emit(ORG_ID, MaxIdentities.key)).not.toThrow();
+ expect(() => svc.emit(ORG_ID, IdentitiesMeter.key)).not.toThrow();
await flushAsync();
});
});
@@ -110,14 +109,14 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }
});
- svc.emitForProject(PROJECT_ID, MaxPamResources.key);
+ svc.emitForProject(PROJECT_ID, PamIdentities.key);
await flushAsync();
expect(findById).toHaveBeenCalledWith(PROJECT_ID);
expect(queue).toHaveBeenCalledTimes(1);
const [, , data, opts] = queue.mock.calls[0] as unknown as TQueueCall;
- expect(data).toEqual({ orgId: ORG_ID, dimensionKey: MaxPamResources.key });
- expect(opts.deduplication?.id).toBe(`usage-event-${ORG_ID}-${MaxPamResources.key}`);
+ expect(data).toEqual({ orgId: ORG_ID, dimensionKey: PamIdentities.key });
+ expect(opts.deduplication?.id).toBe(`usage-event-${ORG_ID}-${PamIdentities.key}`);
});
test("does not enqueue when the project is missing (e.g. soft-deleted)", async () => {
@@ -128,7 +127,7 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "read-compare" }
});
- svc.emitForProject(PROJECT_ID, MaxPamResources.key);
+ svc.emitForProject(PROJECT_ID, PamIdentities.key);
await flushAsync();
expect(queue).not.toHaveBeenCalled();
@@ -143,7 +142,7 @@ describe("usageMeteringService.emitForProject (project-scoped)", () => {
envConfig: { LICENSE_SERVER_V2_MODE: "off" }
});
- svc.emitForProject(PROJECT_ID, MaxPamResources.key);
+ svc.emitForProject(PROJECT_ID, PamIdentities.key);
await flushAsync();
expect(findById).not.toHaveBeenCalled();
@@ -189,20 +188,18 @@ describe("buildMeteredFeatures", () => {
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,
+ IdentitiesMeter.key,
+ InternalCas.key,
+ ActiveCerts.key,
SecretIdentities.key,
PamIdentities.key,
UserIdentities.key
].sort()
);
- expect(await byKey[MaxIdentities.key](ORG_ID)).toBe(7);
- expect(await byKey[MaxInternalCas.key](ORG_ID)).toBe(1);
- expect(await byKey[MaxActiveCerts.key](ORG_ID)).toBe(2);
- expect(await byKey[MaxPamResources.key](ORG_ID)).toBe(3);
+ expect(await byKey[IdentitiesMeter.key](ORG_ID)).toBe(7);
+ expect(await byKey[InternalCas.key](ORG_ID)).toBe(1);
+ expect(await byKey[ActiveCerts.key](ORG_ID)).toBe(2);
expect(await byKey[SecretIdentities.key](ORG_ID)).toBe(4);
expect(await byKey[PamIdentities.key](ORG_ID)).toBe(5);
expect(await byKey[UserIdentities.key](ORG_ID)).toBe(8);
@@ -241,7 +238,7 @@ describe("buildMeteredFeatures", () => {
});
describe("usageEventQueue.handleUsageEvent (worker)", () => {
- const meteredFeatures = [{ feature: MaxIdentities, count: vi.fn(async () => 42) }];
+ const meteredFeatures = [{ feature: IdentitiesMeter, count: vi.fn(async () => 42) }];
const buildQueue = (
overrides: {
@@ -257,7 +254,7 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
const usageReporter = overrides.usageReporter === undefined ? { reportSnapshots } : overrides.usageReporter;
const emit = vi.fn();
const find = overrides.orgFind ?? vi.fn(async () => []);
- const planFeatures = overrides.planFeatures ?? [MaxIdentities.key];
+ const planFeatures = overrides.planFeatures ?? [IdentitiesMeter.key];
const getEntitlements = vi.fn(async () => ({
features: Object.fromEntries(planFeatures.map((key) => [key, { value: 100, source: "plan" }]))
}));
@@ -281,31 +278,31 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
test("no-ops when the reporter is null (v2 disabled)", async () => {
const { queue } = buildQueue({ usageReporter: null });
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
+ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());
expect(meteredFeatures[0].count).not.toHaveBeenCalled();
});
test("reports a snapshot and records the value on first observation", async () => {
const { queue, reportSnapshots, keyStore } = buildQueue();
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
+ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());
expect(reportSnapshots).toHaveBeenCalledTimes(1);
const [orgId, snapshots] = reportSnapshots.mock.calls[0] as unknown as [string, TUsageSnapshot[]];
expect(orgId).toBe(ORG_ID);
expect(snapshots[0]).toMatchObject({
- dimension_key: MaxIdentities.key,
+ dimension_key: IdentitiesMeter.key,
value: 42,
source: "test-region"
});
- expect(keyStore.store.get(`license-usage-last-reported-${ORG_ID}-${MaxIdentities.key}`)).toBe("42");
+ expect(keyStore.store.get(`license-usage-last-reported-${ORG_ID}-${IdentitiesMeter.key}`)).toBe("42");
});
test("skips the report when the count is unchanged", async () => {
const keyStore = createFakeKeyStore();
- keyStore.store.set(`license-usage-last-reported-${ORG_ID}-${MaxIdentities.key}`, "42");
+ keyStore.store.set(`license-usage-last-reported-${ORG_ID}-${IdentitiesMeter.key}`, "42");
const { queue, reportSnapshots } = buildQueue({ keyStore });
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
+ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());
expect(reportSnapshots).not.toHaveBeenCalled();
});
@@ -318,7 +315,7 @@ describe("usageEventQueue.handleUsageEvent (worker)", () => {
test("skips the count and report when the dimension is not in the org's plan", async () => {
// The org's plan has no metered features, so the dimension is absent from entitlements.features.
const { queue, reportSnapshots } = buildQueue({ planFeatures: [] });
- await queue.handleUsageEvent(ORG_ID, MaxIdentities.key, new Date());
+ await queue.handleUsageEvent(ORG_ID, IdentitiesMeter.key, new Date());
expect(meteredFeatures[0].count).not.toHaveBeenCalled();
expect(reportSnapshots).not.toHaveBeenCalled();
});
@@ -375,7 +372,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({ identities: { value: 100 } }, { identities: 99 });
- const identities = await reader.getFeature(ORG_ID, MaxIdentities);
+ const identities = await reader.getFeature(ORG_ID, IdentitiesMeter);
expect(identities.value).toBe(100); // cap comes from the License Server entitlement
expect(await identities.canUse(1)).toBe(true); // 99 + 1 <= 100
expect(await identities.canUse(2)).toBe(false); // 99 + 2 > 100
@@ -385,7 +382,7 @@ describe("canUse enforcement (using the framework from a call site)", () => {
const reader = buildReader({ internal_cas: { value: 1 } }, { internalCas: 1 });
const assertCanCreateInternalCa = async () => {
- const cas = await reader.getFeature(ORG_ID, MaxInternalCas);
+ const cas = await reader.getFeature(ORG_ID, InternalCas);
if (!(await cas.canUse(1))) {
throw new Error(`internal_cas limit reached (cap ${cas.value})`);
}
diff --git a/frontend/src/hooks/api/billingV2/index.tsx b/frontend/src/hooks/api/billingV2/index.tsx
index 3d7dcfe9fc..38a360226b 100644
--- a/frontend/src/hooks/api/billingV2/index.tsx
+++ b/frontend/src/hooks/api/billingV2/index.tsx
@@ -7,6 +7,7 @@ export {
useCreateBillingV2CheckoutSession,
useCreateBillingV2PortalSession,
usePreviewBillingV2Change,
+ useRefreshBillingV2Entitlements,
useRemoveBillingV2Product,
useResumeBillingV2Subscription,
useStartBillingV2Trial
diff --git a/frontend/src/hooks/api/billingV2/mutations.tsx b/frontend/src/hooks/api/billingV2/mutations.tsx
index bceb2439c7..a19f9529cb 100644
--- a/frontend/src/hooks/api/billingV2/mutations.tsx
+++ b/frontend/src/hooks/api/billingV2/mutations.tsx
@@ -20,6 +20,7 @@ import {
TRemoveBillingV2ProductDTO,
TStartBillingV2TrialDTO
} from "./types";
+import { subscriptionQueryKeys } from "../subscriptions/queries";
export const useCreateBillingV2PortalSession = () => {
return useMutation({
@@ -222,3 +223,22 @@ export const useResumeBillingV2Subscription = () => {
}
});
};
+
+// Force the server to recompute entitlements from the license server and drop its cache, then refetch
+// the overview so the freshly-pulled entitlements land in the query cache.
+export const useRefreshBillingV2Entitlements = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async ({ orgId }: TBillingV2LifecycleDTO) => {
+ const { data } = await apiRequest.post<{ success: boolean }>(
+ `/api/v1/organizations/${orgId}/billing/v2/overview/refresh`
+ );
+
+ return data;
+ },
+ onSuccess: (_data, { orgId }) => {
+ queryClient.invalidateQueries({ queryKey: billingV2Keys.overview(orgId) });
+ queryClient.invalidateQueries({ queryKey: subscriptionQueryKeys.getOrgSubsription(orgId) });
+ }
+ });
+};
diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.ts
index 1d1a12d0bd..bedb2ba017 100644
--- a/frontend/src/hooks/api/subscriptions/types.ts
+++ b/frontend/src/hooks/api/subscriptions/types.ts
@@ -84,8 +84,6 @@ 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/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
index 6505febdd3..b01e1b8364 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/cards/ProductsCard.tsx
@@ -1,17 +1,28 @@
import { ReactNode } from "react";
-import { Package } from "lucide-react";
+import { Package, RefreshCw } from "lucide-react";
+import { createNotification } from "@app/components/notifications";
import {
Badge,
Button,
Card,
+ CardAction,
CardContent,
CardDescription,
CardHeader,
- CardTitle
+ CardTitle,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { cn } from "@app/components/v3/utils";
-import { BillingV2CatalogProduct, BillingV2Entitlement, BillingV2Overview } from "@app/hooks/api";
+import { useOrganization } from "@app/context";
+import {
+ BillingV2CatalogProduct,
+ BillingV2Entitlement,
+ BillingV2Overview,
+ useRefreshBillingV2Entitlements
+} from "@app/hooks/api";
import {
byDisplayOrder,
@@ -227,6 +238,20 @@ export const ProductsCard = ({
const active = visible.filter((prod) => overview.entitlements[prod.id]?.entitled);
const available = visible.filter((prod) => !overview.entitlements[prod.id]?.entitled);
+ const { currentOrg } = useOrganization();
+ const refreshEntitlements = useRefreshBillingV2Entitlements();
+
+ // Pull the latest entitlements from the license server (busting the server cache) and refetch the
+ // overview so the freshly-resolved products land in the UI.
+ const handleRefresh = async () => {
+ try {
+ await refreshEntitlements.mutateAsync({ orgId: currentOrg.id });
+ createNotification({ type: "success", text: "Entitlements refreshed." });
+ } catch {
+ createNotification({ type: "error", text: "Failed to refresh entitlements." });
+ }
+ };
+
return (
<Card>
<CardHeader>
@@ -235,6 +260,24 @@ export const ProductsCard = ({
Products
</CardTitle>
<CardDescription>Everything you can run on your subscription.</CardDescription>
+ {!readOnly && (
+ <CardAction>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="outline"
+ size="sm"
+ isDisabled={refreshEntitlements.isPending}
+ onClick={handleRefresh}
+ >
+ <RefreshCw />
+ Refresh
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Plan changes may take a few minutes to take effect.</TooltipContent>
+ </Tooltip>
+ </CardAction>
+ )}
</CardHeader>
<CardContent>
{visible.length === 0 ? (