Skip to content

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

address bernie's reviews

Andrey8720ff2c4759
diff --git a/backend/src/ee/services/scim/scim-service.ts b/backend/src/ee/services/scim/scim-service.ts
index 66a18768e6..27f0c50f5b 100644
--- a/backend/src/ee/services/scim/scim-service.ts
+++ b/backend/src/ee/services/scim/scim-service.ts
@@ -810,8 +810,9 @@ export const scimServiceFactory = ({
);
if (!scimUser.active) {
+ const childOrgs = await orgDAL.find({ rootOrgId: orgId }, { tx });
sendPamCancellations = await terminatePamSessionsForUsers({
- orgIds: [orgId],
+ orgIds: [orgId, ...childOrgs.map((el) => el.id)],
userIds: [membership.actorUserId as string],
pamSessionDAL,
gatewayV2Service,
@@ -941,8 +942,9 @@ export const scimServiceFactory = ({
);
if (!active) {
+ const childOrgs = await orgDAL.find({ rootOrgId: orgId }, { tx });
sendPamCancellations = await terminatePamSessionsForUsers({
- orgIds: [orgId],
+ orgIds: [orgId, ...childOrgs.map((el) => el.id)],
userIds: [membership.actorUserId as string],
pamSessionDAL,
gatewayV2Service,
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 5734f23717..5e3e87ce99 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1359,7 +1359,9 @@ export const registerRoutes = async (
mfaRecoveryCodeService,
usageMeteringService,
alertChannelRecipientDAL,
- emailDomainDAL
+ emailDomainDAL,
+ pamSessionDAL,
+ gatewayV2Service: deferredGatewayV2Service
});
const totpService = totpServiceFactory({
@@ -1585,7 +1587,9 @@ export const registerRoutes = async (
membershipRoleDAL,
membershipUserDAL,
usageMeteringService,
- alertChannelRecipientDAL
+ alertChannelRecipientDAL,
+ pamSessionDAL,
+ gatewayV2Service: deferredGatewayV2Service
});
const offlineUsageReportService = offlineUsageReportServiceFactory({
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 83d87704a2..f33363cfdd 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -1005,8 +1005,9 @@ export const orgServiceFactory = ({
}
if (isActive === false && updatedOrgMembership.actorUserId) {
+ const childOrgs = await orgDAL.find({ rootOrgId: orgId }, { tx });
sendPamCancellations = await terminatePamSessionsForUsers({
- orgIds: [orgId],
+ orgIds: [orgId, ...childOrgs.map((el) => el.id)],
userIds: [updatedOrgMembership.actorUserId],
pamSessionDAL,
gatewayV2Service,
diff --git a/backend/src/services/super-admin/super-admin-service.ts b/backend/src/services/super-admin/super-admin-service.ts
index 5cdd4e0d39..fc0edce43b 100644
--- a/backend/src/services/super-admin/super-admin-service.ts
+++ b/backend/src/services/super-admin/super-admin-service.ts
@@ -11,8 +11,11 @@ import {
} from "@app/db/schemas";
import { TEmailDomainDALFactory } from "@app/ee/services/email-domain/email-domain-dal";
import { EmailDomainStatus } from "@app/ee/services/email-domain/email-domain-types";
+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { getEnforcedIdentityLimit } from "@app/ee/services/license/license-fns";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
+import { terminatePamSessionsForUsers } from "@app/ee/services/pam-session/pam-session-access-fns";
+import { TPamSessionDALFactory } from "@app/ee/services/pam-session/pam-session-dal";
import { KeyStorePrefixes, KeyStoreTtls, PgSqlLock, TKeyStoreFactory } from "@app/keystore/keystore";
import { withCache } from "@app/lib/cache/with-cache";
import {
@@ -93,6 +96,8 @@ type TSuperAdminServiceFactoryDep = {
membershipIdentityDAL: TMembershipIdentityDALFactory;
membershipRoleDAL: TMembershipRoleDALFactory;
alertChannelRecipientDAL: Pick<TAlertChannelRecipientDALFactory, "pruneOutOfScopeRecipients" | "deleteByPrincipals">;
+ pamSessionDAL: Pick<TPamSessionDALFactory, "findLiveByOrgAndUserIds" | "update">;
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPAMConnectionDetails">;
userAliasDAL: Pick<TUserAliasDALFactory, "findOne">;
emailDomainDAL: TEmailDomainDALFactory;
authService: Pick<TAuthLoginFactory, "generateUserTokens">;
@@ -172,7 +177,9 @@ export const superAdminServiceFactory = ({
membershipUserDAL,
membershipRoleDAL,
usageMeteringService,
- alertChannelRecipientDAL
+ alertChannelRecipientDAL,
+ pamSessionDAL,
+ gatewayV2Service
}: TSuperAdminServiceFactoryDep) => {
const initServerCfg = async () => {
// TODO(akhilmhdh): bad pattern time less change this later to me itself
@@ -760,7 +767,17 @@ export const superAdminServiceFactory = ({
actorUserId: userId
});
+ let sendPamCancellations = () => {};
+
const user = await userDAL.transaction(async (tx) => {
+ sendPamCancellations = await terminatePamSessionsForUsers({
+ orgIds: orgMemberships.map((m) => m.scopeOrgId),
+ userIds: [userId],
+ pamSessionDAL,
+ gatewayV2Service,
+ tx
+ });
+
const deletedUser = await userDAL.deleteById(userId, tx);
// principalId carries no FK, so the user row going away leaves recipient rows behind.
await alertChannelRecipientDAL.deleteByPrincipals(
@@ -770,6 +787,8 @@ export const superAdminServiceFactory = ({
return deletedUser;
});
+ sendPamCancellations();
+
emitUserDeletionMeterEvents(orgMemberships);
return user;
};
@@ -790,7 +809,17 @@ export const superAdminServiceFactory = ({
$in: { actorUserId: userIds }
});
+ let sendPamCancellations = () => {};
+
const users = await userDAL.transaction(async (tx) => {
+ sendPamCancellations = await terminatePamSessionsForUsers({
+ orgIds: orgMemberships.map((m) => m.scopeOrgId),
+ userIds,
+ pamSessionDAL,
+ gatewayV2Service,
+ tx
+ });
+
const deletedUsers = await userDAL.delete(
{
$in: {
@@ -806,6 +835,8 @@ export const superAdminServiceFactory = ({
return deletedUsers;
});
+ sendPamCancellations();
+
emitUserDeletionMeterEvents(orgMemberships);
return users;
};
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index 0d72de18a2..a9a5f3975d 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -4,6 +4,9 @@ import { Knex } from "knex";
import { AccessScope, OrganizationActionScope, TUsers } from "@app/db/schemas";
import { TEmailDomainDALFactory } from "@app/ee/services/email-domain/email-domain-dal";
import { EmailDomainStatus } from "@app/ee/services/email-domain/email-domain-types";
+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
+import { terminatePamSessionsForUsers } from "@app/ee/services/pam-session/pam-session-access-fns";
+import { TPamSessionDALFactory } from "@app/ee/services/pam-session/pam-session-dal";
import { OrgPermissionMemberActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { getConfig } from "@app/lib/config/env";
@@ -83,6 +86,8 @@ type TUserServiceFactoryDep = {
mfaRecoveryCodeService: Pick<TMfaRecoveryCodeServiceFactory, "rotateRecoveryCodes" | "deleteRecoveryCodes">;
usageMeteringService: Pick<TUsageMeteringServiceFactory, "emit">;
alertChannelRecipientDAL: Pick<TAlertChannelRecipientDALFactory, "deleteByPrincipals">;
+ pamSessionDAL: Pick<TPamSessionDALFactory, "findLiveByOrgAndUserIds" | "update">;
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPAMConnectionDetails">;
emailDomainDAL: Pick<TEmailDomainDALFactory, "find">;
};
@@ -102,7 +107,9 @@ export const userServiceFactory = ({
mfaRecoveryCodeService,
usageMeteringService,
alertChannelRecipientDAL,
- emailDomainDAL
+ emailDomainDAL,
+ pamSessionDAL,
+ gatewayV2Service
}: TUserServiceFactoryDep) => {
const sendEmailVerificationCode = async (token: string) => {
const config = getConfig();
@@ -614,7 +621,17 @@ export const userServiceFactory = ({
actorUserId: userId
});
+ let sendPamCancellations = () => {};
+
const user = await userDAL.transaction(async (tx) => {
+ sendPamCancellations = await terminatePamSessionsForUsers({
+ orgIds: orgMemberships.map((m) => m.scopeOrgId),
+ userIds: [userId],
+ pamSessionDAL,
+ gatewayV2Service,
+ tx
+ });
+
const deletedUser = await userDAL.deleteById(userId, tx);
await alertChannelRecipientDAL.deleteByPrincipals(
@@ -628,6 +645,8 @@ export const userServiceFactory = ({
return deletedUser;
});
+ sendPamCancellations();
+
// Deleting the user cascades its org, project, and group memberships, so every identity meter changes.
const orgIds = [...new Set(orgMemberships.map((m) => m.scopeOrgId).filter((id): id is string => Boolean(id)))];
orgIds.forEach((orgId) => {