Skip to content

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

dont allow org identity manage on sub org to have alerts

Thiago Araujo da Silvaa25da631a914
diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts
index b0ce398cc4..c413340a39 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts
@@ -81,6 +81,18 @@ describe("identity credential alert dal", () => {
expect(calls.where.some((args) => args[0] === "projectMembership.scope")).toBe(false);
});
+ test("a scan only returns identities the alert's organization owns", async () => {
+ const { dal, calls } = buildDAL();
+
+ await dal.findExpiringUaClientSecrets(scanArgs);
+
+ // Org membership alone is not enough: a root-org identity added to a sub-organization is a
+ // member there, but the sub-organization cannot see its credentials, so an org-wide alert in
+ // the sub-organization must not surface them.
+ expect(calls.where).toContainEqual([`${TableName.Membership}.scopeOrgId`, "org-1"]);
+ expect(calls.where).toContainEqual([`${TableName.Identity}.orgId`, "org-1"]);
+ });
+
test("every bound `asOf` timestamp is explicitly cast", async () => {
const { dal, calls } = buildDAL();
diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.ts
index b4694211b6..8573e14712 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-dal.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.ts
@@ -53,6 +53,7 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {
.join(TableName.Identity, `${TableName.IdentityUniversalAuth}.identityId`, `${TableName.Identity}.id`)
.where(`${TableName.Membership}.scope`, AccessScope.Organization)
.where(`${TableName.Membership}.scopeOrgId`, orgId)
+ .where(`${TableName.Identity}.orgId`, orgId)
.where(`${TableName.IdentityUaClientSecret}.isClientSecretRevoked`, false)
.where(`${TableName.IdentityUaClientSecret}.clientSecretTTL`, ">", 0)
.whereRaw(`${expiresAtSql} > ?::timestamptz`, [asOf])
@@ -103,15 +104,15 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {
identityId: string,
orgId: string,
tx?: Knex
- ): Promise<{ projectId: string | null } | undefined> => {
+ ): Promise<{ orgId: string; projectId: string | null } | undefined> => {
try {
const row = (await (tx || db.replicaNode())(TableName.Membership)
.join(TableName.Identity, `${TableName.Membership}.actorIdentityId`, `${TableName.Identity}.id`)
.where(`${TableName.Membership}.actorIdentityId`, identityId)
.where(`${TableName.Membership}.scopeOrgId`, orgId)
.where(`${TableName.Membership}.scope`, AccessScope.Organization)
- .select(db.ref("projectId").withSchema(TableName.Identity))
- .first()) as { projectId: string | null } | undefined;
+ .select(db.ref("orgId").withSchema(TableName.Identity), db.ref("projectId").withSchema(TableName.Identity))
+ .first()) as { orgId: string; projectId: string | null } | undefined;
return row;
} catch (error) {
throw new DatabaseError({ error, name: "FindIdentityInOrg" });
diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts
index 7cf1cbae46..219a724f8a 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts
@@ -64,6 +64,9 @@ const buildProvider = (opts?: {
abilityRules?: { action: string; subject: string; conditions?: Record<string, unknown> }[];
inOrg?: boolean;
inProject?: boolean;
+ // Organization that owns the bound identity. Differs from the alert's org when a root-org
+ // identity has been added to a sub-organization.
+ ownerOrgId?: string;
// Owning project of the bound identity: null for an org-level identity, a project id when the
// identity was created in project scope.
ownerProjectId?: string | null;
@@ -86,7 +89,10 @@ const buildProvider = (opts?: {
opts?.onFind?.(args);
return opts?.secrets ?? [];
},
- findIdentityInOrg: async () => ((opts?.inOrg ?? true) ? { projectId: opts?.ownerProjectId ?? null } : undefined),
+ findIdentityInOrg: async () =>
+ (opts?.inOrg ?? true)
+ ? { orgId: opts?.ownerOrgId ?? "org-1", projectId: opts?.ownerProjectId ?? null }
+ : undefined,
isIdentityInProject: async () => opts?.inProject ?? true,
getProjectType: async () => opts?.projectType ?? null
};
@@ -650,6 +656,23 @@ describe("identity credential alert provider", () => {
await expect(provider.assertResourceInScope({ orgId: "org-1", resourceId: "foreign" })).rejects.toThrow();
});
+ // A root-org identity added to a sub-organization is a member there, but the sub-organization
+ // cannot see or change its auth methods, and auth-method events carry the owning org. An alert
+ // created in the sub-organization would never match and would leak credential metadata.
+ test("assertResourceInScope rejects a parent-org identity on a sub-organization's alert", async () => {
+ const provider = buildProvider({ inOrg: true, ownerOrgId: "root-org" });
+ await expect(provider.assertResourceInScope({ orgId: "sub-org", resourceId: "ident-1" })).rejects.toThrow(
+ /belongs to the parent organization/
+ );
+ });
+
+ test("assertResourceInScope rejects a parent-org identity on a sub-organization project's alert", async () => {
+ const provider = buildProvider({ inOrg: true, inProject: true, ownerOrgId: "root-org" });
+ await expect(
+ provider.assertResourceInScope({ orgId: "sub-org", projectId: "proj-1", resourceId: "ident-1" })
+ ).rejects.toThrow(/belongs to the parent organization/);
+ });
+
test("assertResourceInScope rejects an identity not in the project when project-scoped", async () => {
const provider = buildProvider({ inOrg: true, inProject: false });
await expect(
diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
index 265c901181..2995e1c83a 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
@@ -395,6 +395,12 @@ export const identityCredentialAlertProviderFactory = ({
throw new NotFoundError({ message: `Identity '${input.resourceId}' was not found in this organization` });
}
+ if (identity.orgId !== input.orgId) {
+ throw new ForbiddenRequestError({
+ message: `Identity '${input.resourceId}' belongs to the parent organization. Create this alert in that organization, where the identity's authentication is managed.`
+ });
+ }
+
if (identity.projectId && identity.projectId !== input.projectId) {
throw new ForbiddenRequestError({
message: `Identity '${input.resourceId}' belongs to a project. Create this alert within that project so its identity permissions are enforced.`