Skip to content

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

fix: repair dual-read unlicensed detection and drop wrong free baseline

Tre Dubrava255b87c97f12
diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts
index f2f195d7c1..176e4e2452 100644
--- a/backend/src/ee/services/license/license-service.ts
+++ b/backend/src/ee/services/license/license-service.ts
@@ -370,7 +370,7 @@ export const licenseServiceFactory = ({
// read-compare bake: serve v1 but shadow-compare against v2 in the background ahead of the cutover.
if (envConfig.LICENSE_SERVER_V2_MODE === "read-compare") {
- licenseDualRead?.compareInBackground(rootOrgId, currentPlan, getDefaultOnPremFeatures);
+ licenseDualRead?.compareInBackground(rootOrgId, currentPlan);
}
return currentPlan;
diff --git a/backend/src/services/license-client/dual-read/dual-read-service.ts b/backend/src/services/license-client/dual-read/dual-read-service.ts
index 666bcade25..3d10436ef3 100644
--- a/backend/src/services/license-client/dual-read/dual-read-service.ts
+++ b/backend/src/services/license-client/dual-read/dual-read-service.ts
@@ -7,6 +7,7 @@ import { TLicenseClientFactory } from "@app/services/license-client/license-clie
import { DualReadDiffKind } from "./dual-read-types";
import { compareEntitlements } from "./entitlement-comparator";
import { FEATURE_MAPPINGS } from "./feature-mapping";
+import { classifyUnlicensedCompare } from "./unlicensed";
export type TDualReadServiceFactory = ReturnType<typeof dualReadServiceFactory>;
@@ -19,7 +20,7 @@ export const dualReadServiceFactory = ({ licenseClient, envConfig }: TDualReadSe
// Fire-and-forget shadow compare against the already-resolved v1 plan. Never awaited, never throws into
// the request path; inert unless mode is read-compare. Reads v2 through the real client SDK so the
// production read path is exercised under real traffic ahead of the cutover.
- const compareInBackground = (orgId: string, planV1: TFeatureSet, getFreeTierPlan: () => TFeatureSet) => {
+ const compareInBackground = (orgId: string, planV1: TFeatureSet) => {
if (!envConfig.isLicenseDualReadEnabled) {
return;
}
@@ -32,23 +33,15 @@ export const dualReadServiceFactory = ({ licenseClient, envConfig }: TDualReadSe
return;
}
- // A v2 resolution with every feature at its default (a license that contributes nothing above
- // defaults) is effectively the free tier; comparing that against the org's real v1 plan is noise,
- // so compare v2 against the v1 free baseline instead.
- const featureValues = Object.values(entitlements.features);
- const isV2Unlicensed = featureValues.length > 0 && featureValues.every((f) => f.source === "default");
- let planForCompare = planV1;
- if (isV2Unlicensed) {
- planForCompare = getFreeTierPlan();
- }
-
- // A paid v1 org that resolves to all-defaults in v2 is a cutover downgrade risk; the swap above
- // would otherwise mask it as identical telemetry to a genuinely free org.
- if (isV2Unlicensed && planV1.slug && planV1.slug !== "starter") {
- logger.warn(`license-dual-read: paid v1 org unlicensed in v2 [orgId=${orgId}] [v1Slug=${planV1.slug}]`);
+ const { skip, warnPaid } = classifyUnlicensedCompare(entitlements, planV1);
+ if (skip) {
+ if (warnPaid) {
+ logger.warn(`license-dual-read: paid v1 org unlicensed in v2 [orgId=${orgId}] [v1Slug=${planV1.slug}]`);
+ }
+ return;
}
- const discrepancies = compareEntitlements(planForCompare, entitlements, FEATURE_MAPPINGS);
+ const discrepancies = compareEntitlements(planV1, entitlements, FEATURE_MAPPINGS);
const diffs = discrepancies.filter((d) => d.kind !== DualReadDiffKind.Match);
for (const d of diffs) {
diff --git a/backend/src/services/license-client/dual-read/unlicensed.test.ts b/backend/src/services/license-client/dual-read/unlicensed.test.ts
new file mode 100644
index 0000000000..cdfb3df2d5
--- /dev/null
+++ b/backend/src/services/license-client/dual-read/unlicensed.test.ts
@@ -0,0 +1,71 @@
+import { describe, expect, test } from "vitest";
+
+import { TFeatureSet } from "@app/ee/services/license/license-types";
+
+import { TEntitlementsResponse } from "../license-client-types";
+import { classifyUnlicensedCompare } from "./unlicensed";
+
+const makePlan = (slug: string | null): TFeatureSet => ({ slug }) as TFeatureSet;
+const makeEntitlements = (features: TEntitlementsResponse["features"]): TEntitlementsResponse =>
+ ({ features }) as TEntitlementsResponse;
+
+describe("classifyUnlicensedCompare", () => {
+ const cases: {
+ name: string;
+ features: TEntitlementsResponse["features"];
+ slug: string | null;
+ wantSkip: boolean;
+ wantWarn: boolean;
+ }[] = [
+ { name: "empty features + paid v1 skips and warns", features: {}, slug: "pro", wantSkip: true, wantWarn: true },
+ {
+ name: "empty features + free v1 skips without warning",
+ features: {},
+ slug: "starter",
+ wantSkip: true,
+ wantWarn: false
+ },
+ {
+ name: "empty features + null slug skips without warning",
+ features: {},
+ slug: null,
+ wantSkip: true,
+ wantWarn: false
+ },
+ {
+ name: "all-default features + paid v1 skips and warns",
+ features: {
+ environment_limit: { value: 3, source: "default" },
+ max_identities: { value: 5, source: "default" }
+ },
+ slug: "enterprise",
+ wantSkip: true,
+ wantWarn: true
+ },
+ {
+ name: "mixed sources runs the compare",
+ features: {
+ environment_limit: { value: 3, source: "default" },
+ sso_enforcement: { value: true, source: "plan" }
+ },
+ slug: "pro",
+ wantSkip: false,
+ wantWarn: false
+ },
+ {
+ name: "licensed features run the compare",
+ features: { sso_enforcement: { value: true, source: "plan" } },
+ slug: "enterprise",
+ wantSkip: false,
+ wantWarn: false
+ }
+ ];
+
+ for (const tc of cases) {
+ test(tc.name, () => {
+ const result = classifyUnlicensedCompare(makeEntitlements(tc.features), makePlan(tc.slug));
+ expect(result.skip).toBe(tc.wantSkip);
+ expect(result.warnPaid).toBe(tc.wantWarn);
+ });
+ }
+});
diff --git a/backend/src/services/license-client/dual-read/unlicensed.ts b/backend/src/services/license-client/dual-read/unlicensed.ts
new file mode 100644
index 0000000000..700ef01873
--- /dev/null
+++ b/backend/src/services/license-client/dual-read/unlicensed.ts
@@ -0,0 +1,14 @@
+import { TFeatureSet } from "@app/ee/services/license/license-types";
+
+import { TEntitlementsResponse } from "../license-client-types";
+
+// An unlicensed org resolves to all-default features (vacuously true on the empty map v2 returns today),
+// so there is nothing to compare. Paid v1 orgs are still flagged since they get downgraded at cutover.
+export const classifyUnlicensedCompare = (
+ entitlements: TEntitlementsResponse,
+ planV1: TFeatureSet
+): { skip: boolean; warnPaid: boolean } => {
+ const skip = Object.values(entitlements.features).every((f) => f.source === "default");
+ const warnPaid = skip && Boolean(planV1.slug) && planV1.slug !== "starter";
+ return { skip, warnPaid };
+};