diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts index 5a74236a9..c39f07b5c 100644 --- a/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts +++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts @@ -121,7 +121,7 @@ export const dynamicSecretServiceFactory = ({ if (inputs && typeof inputs === "object" && "gatewayId" in inputs && inputs.gatewayId) { const gatewayId = inputs.gatewayId as string; - const [gateway] = await gatewayDAL.find({ id: gatewayId }); + const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: actorOrgId }); if (!gateway) { throw new NotFoundError({ @@ -275,7 +275,7 @@ export const dynamicSecretServiceFactory = ({ if (updatedInput && typeof updatedInput === "object" && "gatewayId" in updatedInput && updatedInput?.gatewayId) { const gatewayId = updatedInput.gatewayId as string; - const [gateway] = await gatewayDAL.find({ id: gatewayId }); + const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: actorOrgId }); if (!gateway) { throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found` diff --git a/backend/src/ee/services/gateway/gateway-dal.ts b/backend/src/ee/services/gateway/gateway-dal.ts index b51c781ee..31b4b727b 100644 --- a/backend/src/ee/services/gateway/gateway-dal.ts +++ b/backend/src/ee/services/gateway/gateway-dal.ts @@ -8,11 +8,14 @@ export type TGatewayDALFactory = ReturnType; export const gatewayDALFactory = (db: TDbClient) => { const orm = ormify(db, TableName.Gateway); - const find = async (filter: TFindFilter, { offset, limit, sort, tx }: TFindOpt = {}) => { + const find = async ( + filter: TFindFilter & { orgId?: string }, + { offset, limit, sort, tx }: TFindOpt = {} + ) => { try { const query = (tx || db)(TableName.Gateway) // eslint-disable-next-line @typescript-eslint/no-misused-promises - .where(buildFindFilter(filter, TableName.Gateway)) + .where(buildFindFilter(filter, TableName.Gateway, ["orgId"])) .join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.Gateway}.identityId`) .join( TableName.IdentityOrgMembership, @@ -22,6 +25,10 @@ export const gatewayDALFactory = (db: TDbClient) => { .select(selectAllTableCols(TableName.Gateway)) .select(db.ref("orgId").withSchema(TableName.IdentityOrgMembership).as("identityOrgId")) .select(db.ref("name").withSchema(TableName.Identity).as("identityName")); + + if (filter.orgId) { + void query.where(`${TableName.IdentityOrgMembership}.orgId`, filter.orgId); + } if (limit) void query.limit(limit); if (offset) void query.offset(offset); if (sort) { diff --git a/backend/src/lib/knex/index.ts b/backend/src/lib/knex/index.ts index b1e011709..2e17bff20 100644 --- a/backend/src/lib/knex/index.ts +++ b/backend/src/lib/knex/index.ts @@ -32,13 +32,13 @@ export const buildFindFilter = ( { $in, $notNull, $search, $complex, ...filter }: TFindFilter, tableName?: TableName, - excludeKeys?: Array + excludeKeys?: string[] ) => (bd: Knex.QueryBuilder) => { const processedFilter = tableName ? Object.fromEntries( Object.entries(filter) - .filter(([key]) => !excludeKeys || !excludeKeys.includes(key as keyof R)) + .filter(([key]) => !excludeKeys || !excludeKeys.includes(key)) .map(([key, value]) => [`${tableName}.${key}`, value]) ) : filter; diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts index 32855d3cb..2da7c3881 100644 --- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts +++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts @@ -350,7 +350,7 @@ export const identityKubernetesAuthServiceFactory = ({ }); if (gatewayId) { - const [gateway] = await gatewayDAL.find({ id: gatewayId }); + const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: identityMembershipOrg.orgId }); if (!gateway) { throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found` @@ -466,7 +466,7 @@ export const identityKubernetesAuthServiceFactory = ({ }); if (gatewayId) { - const [gateway] = await gatewayDAL.find({ id: gatewayId }); + const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: identityMembershipOrg.orgId }); if (!gateway) { throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found`