Skip to content

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

misc: added wildcard metering

Sheen Capadngane5c2f62ddb14
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 c8864ca9e1..123a253a08 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 { ActiveCerts } from "@app/services/license-client";
+import { ActiveCerts, WildcardCerts } 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";
@@ -2296,6 +2296,7 @@ export const internalCertificateAuthorityServiceFactory = ({
}
usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, WildcardCerts.key);
return {
certificate: leafCert.toString("pem"),
@@ -2772,6 +2773,7 @@ export const internalCertificateAuthorityServiceFactory = ({
}
usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, WildcardCerts.key);
return {
certificate: leafCert,
diff --git a/backend/src/services/certificate/certificate-service.ts b/backend/src/services/certificate/certificate-service.ts
index 81cf19bbeb..639d657a77 100644
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@ -33,7 +33,7 @@ import {
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 { ActiveCerts } from "@app/services/license-client";
+import { ActiveCerts, WildcardCerts } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TUsageCounterDALFactory } from "@app/services/license-client/usage/usage-counter-dal";
import { TPkiAlertV2QueueServiceFactory } from "@app/services/pki-alert-v2/pki-alert-v2-queue";
@@ -476,6 +476,7 @@ export const certificateServiceFactory = ({
});
usageMeteringService.emitForProject(cert.projectId, ActiveCerts.key);
+ usageMeteringService.emitForProject(cert.projectId, WildcardCerts.key);
return {
deletedCert
@@ -625,6 +626,7 @@ export const certificateServiceFactory = ({
);
usageMeteringService.emitForProject(ca.projectId, ActiveCerts.key);
+ usageMeteringService.emitForProject(ca.projectId, WildcardCerts.key);
// Trigger auto sync for PKI syncs connected to this certificate
await triggerAutoSyncForCertificate(cert.id, {
@@ -1037,6 +1039,7 @@ export const certificateServiceFactory = ({
if (isNewQuotaKey) await recordNewCertificateQuotaKey(quotaOrgId, { keyStore }, isWildcard);
usageMeteringService.emitForProject(projectId, ActiveCerts.key);
+ usageMeteringService.emitForProject(projectId, WildcardCerts.key);
return {
certificate: certificatePem,
diff --git a/backend/src/services/license-client/feature-mapping.ts b/backend/src/services/license-client/feature-mapping.ts
index 890887e84a..5893f36c45 100644
--- a/backend/src/services/license-client/feature-mapping.ts
+++ b/backend/src/services/license-client/feature-mapping.ts
@@ -1,4 +1,11 @@
-import { ActiveCerts, AuditRetentionDays, IdentitiesMeter, InternalCas, SsoEnforcement } from "./features";
+import {
+ ActiveCerts,
+ AuditRetentionDays,
+ IdentitiesMeter,
+ InternalCas,
+ SsoEnforcement,
+ WildcardCerts
+} from "./features";
export type TFeatureMapping = {
// Must match a License Server feature registry key (a separate repo); a wrong key means the feature
@@ -312,6 +319,11 @@ const certManagerMappings: TFeatureMapping[] = [
v2Key: ActiveCerts.key,
v1Field: null
},
+ {
+ // Usage meter only; the cap is max_wildcard_certificates, mapped separately below.
+ v2Key: WildcardCerts.key,
+ v1Field: null
+ },
{
// Dedicated cap feature, separate from the `internal_cas` usage meter though both count the same
// set. The per-contract enterprise lever: caps internal CAs, leaves external and ACME unlimited.
diff --git a/backend/src/services/license-client/features.ts b/backend/src/services/license-client/features.ts
index 484f4f5666..b9eb92c544 100644
--- a/backend/src/services/license-client/features.ts
+++ b/backend/src/services/license-client/features.ts
@@ -9,6 +9,7 @@ export const AuditRetentionDays = defineFeature("audit_retention_days", 30);
export const IdentitiesMeter = defineLimitFeature("identities", 0);
export const InternalCas = defineLimitFeature("internal_cas", 0);
export const ActiveCerts = defineLimitFeature("active_certs", 0);
+export const WildcardCerts = defineLimitFeature("wildcard_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/usage/usage-counters.ts b/backend/src/services/license-client/usage/usage-counters.ts
index 0ae44c9555..95adc6d066 100644
--- a/backend/src/services/license-client/usage/usage-counters.ts
+++ b/backend/src/services/license-client/usage/usage-counters.ts
@@ -7,7 +7,8 @@ import {
InternalCas,
PamIdentities,
SecretIdentities,
- UserIdentities
+ UserIdentities,
+ WildcardCerts
} from "../features";
import { TUsageCounterDALFactory } from "./usage-counter-dal";
@@ -26,6 +27,7 @@ export const METERED_DIMENSION_KEYS: string[] = [
IdentitiesMeter,
InternalCas,
ActiveCerts,
+ WildcardCerts,
SecretIdentities,
PamIdentities,
UserIdentities
@@ -57,6 +59,13 @@ export const buildMeteredFeatures = ({
count: (orgId) => usageCounterDAL.countActiveCertificateQuotaKeysByOrg(orgId).then(({ total }) => total),
resolveReportOrgId: (orgId) => usageCounterDAL.resolveRootOrgId(orgId)
},
+ {
+ // The other half of the same query active_certs reads, so the two can never disagree about which
+ // certificates are live. Wildcards also count toward active_certs; this is a priced subset of it.
+ feature: WildcardCerts,
+ count: (orgId) => usageCounterDAL.countActiveCertificateQuotaKeysByOrg(orgId).then(({ wildcard }) => wildcard),
+ resolveReportOrgId: (orgId) => usageCounterDAL.resolveRootOrgId(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 c021b4b761..e64784367f 100644
--- a/backend/src/services/license-client/usage/usage-metering.test.ts
+++ b/backend/src/services/license-client/usage/usage-metering.test.ts
@@ -9,7 +9,8 @@ import {
InternalCas,
PamIdentities,
SecretIdentities,
- UserIdentities
+ UserIdentities,
+ WildcardCerts
} from "../features";
import { buildMeteredFeatures, METERED_DIMENSION_KEYS } from "./usage-counters";
import { usageEventQueueFactory } from "./usage-event-queue";
@@ -251,6 +252,7 @@ describe("buildMeteredFeatures", () => {
IdentitiesMeter.key,
InternalCas.key,
ActiveCerts.key,
+ WildcardCerts.key,
SecretIdentities.key,
PamIdentities.key,
UserIdentities.key
@@ -262,6 +264,8 @@ describe("buildMeteredFeatures", () => {
// Billed on the same unit the cap enforces: distinct quota keys, not certificate rows.
expect(await byKey[ActiveCerts.key](ORG_ID)).toBe(2);
expect(usageCounterDAL.countActiveCertificateQuotaKeysByOrg).toHaveBeenCalledWith(ORG_ID);
+ // Wildcards read the other half of that same result, so the two can never disagree.
+ expect(await byKey[WildcardCerts.key](ORG_ID)).toBe(1);
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);