Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Start adding identity based pricing logic
Tuan Dangafee158b95ca
diff --git a/backend/src/ee/services/license/__mocks__/licence-fns.ts b/backend/src/ee/services/license/__mocks__/licence-fns.tsindex ddbffba457..a8b3b351dc 100644--- a/backend/src/ee/services/license/__mocks__/licence-fns.ts+++ b/backend/src/ee/services/license/__mocks__/licence-fns.ts@@ -7,6 +7,8 @@ export const getDefaultOnPremFeatures = () => {workspacesUsed: 0,memberLimit: null,membersUsed: 0,+ identityLimit: null,+ identitiesUsed: 0,environmentLimit: null,environmentsUsed: 0,secretVersioning: true,diff --git a/backend/src/ee/services/license/licence-fns.ts b/backend/src/ee/services/license/licence-fns.tsindex 9d2c5a4724..45325d414d 100644--- a/backend/src/ee/services/license/licence-fns.ts+++ b/backend/src/ee/services/license/licence-fns.ts@@ -15,6 +15,8 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({membersUsed: 0,environmentLimit: null,environmentsUsed: 0,+ identityLimit: null,+ identitiesUsed: 0,dynamicSecret: false,secretVersioning: true,pitRecovery: false,diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.tsindex 46931468fd..0819c461b1 100644--- a/backend/src/ee/services/license/license-service.ts+++ b/backend/src/ee/services/license/license-service.ts@@ -155,6 +155,7 @@ export const licenseServiceFactory = ({LICENSE_SERVER_CLOUD_PLAN_TTL,JSON.stringify(currentPlan));+return currentPlan;}} catch (error) {diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.tsindex e23ff2c841..565387296c 100644--- a/backend/src/ee/services/license/license-types.ts+++ b/backend/src/ee/services/license/license-types.ts@@ -31,6 +31,8 @@ export type TFeatureSet = {dynamicSecret: false;memberLimit: null;membersUsed: 0;+ identityLimit: null;+ identitiesUsed: 0;environmentLimit: null;environmentsUsed: 0;secretVersioning: true;diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 326fbafa61..f20a622aba 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -801,7 +801,8 @@ export const registerRoutes = async (const identityService = identityServiceFactory({permissionService,identityDAL,- identityOrgMembershipDAL+ identityOrgMembershipDAL,+ licenseService});const identityAccessTokenService = identityAccessTokenServiceFactory({identityAccessTokenDAL,diff --git a/backend/src/services/identity/identity-service.ts b/backend/src/services/identity/identity-service.tsindex 2863bf23eb..f5db1e9013 100644--- a/backend/src/services/identity/identity-service.ts+++ b/backend/src/services/identity/identity-service.ts@@ -1,6 +1,7 @@import { ForbiddenError } from "@casl/ability";import { OrgMembershipRole, TOrgRoles } from "@app/db/schemas";+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";import { isAtLeastAsPrivileged } from "@app/lib/casl";@@ -16,6 +17,7 @@ type TIdentityServiceFactoryDep = {identityDAL: TIdentityDALFactory;identityOrgMembershipDAL: TIdentityOrgDALFactory;permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getOrgPermissionByRole">;+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;};export type TIdentityServiceFactory = ReturnType<typeof identityServiceFactory>;diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.tsindex 68d2b8cda2..248bab5680 100644--- a/backend/src/services/org/org-service.ts+++ b/backend/src/services/org/org-service.ts@@ -420,13 +420,20 @@ export const orgServiceFactory = ({}const plan = await licenseService.getPlan(orgId);- if (plan.memberLimit !== null && plan.membersUsed >= plan.memberLimit) {- // case: limit imposed on number of members allowed- // case: number of members used exceeds the number of members allowed+ if (plan?.memberLimit && plan.membersUsed >= plan.memberLimit) {+ // limit imposed on number of members allowed / number of members used exceeds the number of members allowedthrow new BadRequestError({message: "Failed to invite member due to member limit reached. Upgrade plan to invite more members."});}++ if (plan?.identityLimit && plan.identitiesUsed >= plan.identityLimit) {+ // limit imposed on number of identities allowed / number of identities used exceeds the number of identities allowed+ throw new BadRequestError({+ message: "Failed to invite member due to member limit reached. Upgrade plan to invite more members."+ });+ }+const invitee = await orgDAL.transaction(async (tx) => {const inviteeUser = await userDAL.findUserByUsername(inviteeEmail, tx);if (inviteeUser) {diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex 422fe43f3c..89e36e91a9 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -87,7 +87,7 @@ services:- 4000:4000environment:- NODE_ENV=development- - DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable+ # - DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable- TELEMETRY_ENABLED=falsevolumes:- ./backend/src:/app/srcdiff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.tsindex 66959ad1bc..3d4a6dc36b 100644--- a/frontend/src/hooks/api/subscriptions/types.ts+++ b/frontend/src/hooks/api/subscriptions/types.ts@@ -2,6 +2,8 @@ export type SubscriptionPlan = {id: string;membersUsed: number;memberLimit: number;+ identitiesUsed: number;+ identityLimit: number;auditLogs: boolean;dynamicSecret: boolean;auditLogsRetentionDays: number;diff --git a/frontend/src/layouts/AppLayout/AppLayout.tsx b/frontend/src/layouts/AppLayout/AppLayout.tsxindex 72351df88e..d4b1f17f44 100644--- a/frontend/src/layouts/AppLayout/AppLayout.tsx+++ b/frontend/src/layouts/AppLayout/AppLayout.tsx@@ -652,19 +652,19 @@ export const AppLayout = ({ children }: LayoutProps) => {</MenuItem></a></Link>- {(window.location.origin.includes("https://app.infisical.com") ||- window.location.origin.includes("https://gamma.infisical.com")) && (- <Link href={`/org/${currentOrg?.id}/billing`} passHref>- <a>- <MenuItem- isSelected={router.asPath === `/org/${currentOrg?.id}/billing`}- icon="system-outline-103-coin-cash-monetization"- >- Usage & Billing- </MenuItem>- </a>- </Link>- )}+ {/* {(window.location.origin.includes("https://app.infisical.com") ||+ window.location.origin.includes("https://gamma.infisical.com")) && ( */}+ <Link href={`/org/${currentOrg?.id}/billing`} passHref>+ <a>+ <MenuItem+ isSelected={router.asPath === `/org/${currentOrg?.id}/billing`}+ icon="system-outline-103-coin-cash-monetization"+ >+ Usage & Billing+ </MenuItem>+ </a>+ </Link>+ {/* )} */}<Link href={`/org/${currentOrg?.id}/settings`} passHref><a><MenuItemdiff --git a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsxindex c5ebf7c55b..b8b1f1708c 100644--- a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx+++ b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx@@ -4,8 +4,13 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { createNotification } from "@app/components/notifications";import { OrgPermissionCan } from "@app/components/permissions";-import { Button, DeleteActionModal } from "@app/components/v2";-import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";+import { Button, DeleteActionModal, UpgradePlanModal } from "@app/components/v2";+import {+ OrgPermissionActions,+ OrgPermissionSubjects,+ useOrganization,+ useSubscription+} from "@app/context";import { withPermission } from "@app/hoc";import { useDeleteIdentity } from "@app/hooks/api";import { usePopUp } from "@app/hooks/usePopUp";@@ -17,10 +22,10 @@ import { IdentityUniversalAuthClientSecretModal } from "./IdentityUniversalAuthCexport const IdentitySection = withPermission(() => {+ const { subscription } = useSubscription();const { currentOrg } = useOrganization();const orgId = currentOrg?.id || "";-const { mutateAsync: deleteMutateAsync } = useDeleteIdentity();const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp(["identity",@@ -31,6 +36,10 @@ export const IdentitySection = withPermission("upgradePlan"] as const);+ const isMoreIdentitiesAllowed = subscription?.identityLimit+ ? subscription.identitiesUsed < subscription.identityLimit+ : true;+const onDeleteIdentitySubmit = async (identityId: string) => {try {await deleteMutateAsync({@@ -81,7 +90,15 @@ export const IdentitySection = withPermission(colorSchema="primary"type="submit"leftIcon={<FontAwesomeIcon icon={faPlus} />}- onClick={() => handlePopUpOpen("identity")}+ onClick={() => {+ if (!isMoreIdentitiesAllowed) {+ handlePopUpOpen("upgradePlan", {+ description: "You can add more identities if you upgrade your Infisical plan."+ });+ return;+ }+ handlePopUpOpen("identity");+ }}isDisabled={!isAllowed}>Create identity@@ -118,6 +135,11 @@ export const IdentitySection = withPermission()}/>+ <UpgradePlanModal+ isOpen={popUp.upgradePlan.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}+ text={(popUp.upgradePlan?.data as { description: string })?.description}+ /></div>);},diff --git a/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx b/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsxindex 17f32369c5..8943f29402 100644--- a/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx+++ b/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx@@ -23,7 +23,6 @@ import { AddOrgMemberModal } from "./AddOrgMemberModal";import { OrgMembersTable } from "./OrgMembersTable";export const OrgMembersSection = () => {-const { subscription } = useSubscription();const { currentOrg } = useOrganization();const orgId = currentOrg?.id ?? "";@@ -39,9 +38,13 @@ export const OrgMembersSection = () => {const { mutateAsync: deleteMutateAsync } = useDeleteOrgMembership();- const isMoreUsersNotAllowed = subscription?.memberLimit- ? subscription.membersUsed >= subscription.memberLimit- : false;+ const isMoreUsersAllowed = subscription?.memberLimit+ ? subscription.membersUsed < subscription.memberLimit+ : true;++ const isMoreIdentitiesAllowed = subscription?.identityLimit+ ? subscription.identitiesUsed < subscription.identityLimit+ : true;const handleAddMemberModal = () => {if (currentOrg?.authEnforced) {@@ -52,13 +55,14 @@ export const OrgMembersSection = () => {return;}- if (isMoreUsersNotAllowed) {+ if (!isMoreUsersAllowed || !isMoreIdentitiesAllowed) {handlePopUpOpen("upgradePlan", {description: "You can add more members if you upgrade your Infisical plan."});- } else {- handlePopUpOpen("addMember");+ return;}++ handlePopUpOpen("addMember");};const onRemoveMemberSubmit = async (orgMembershipId: string) => {