Skip to content

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

fix(pam): add AttachGateways RBAC check for direct gateway attachment

Saif17e4dcdd45a4
diff --git a/backend/src/ee/services/pam-domain/pam-domain-service.ts b/backend/src/ee/services/pam-domain/pam-domain-service.ts
index 54cdd76d86..105c1ab49d 100644
--- a/backend/src/ee/services/pam-domain/pam-domain-service.ts
+++ b/backend/src/ee/services/pam-domain/pam-domain-service.ts
@@ -1,6 +1,7 @@
import { ForbiddenError, subject } from "@casl/ability";
-import { ActionProjectType, TPamDomains } from "@app/db/schemas";
+import { ActionProjectType, OrganizationActionScope, TPamDomains } from "@app/db/schemas";
+import { OrgPermissionGatewayActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { DatabaseErrorCode } from "@app/lib/error-codes";
import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";
@@ -117,6 +118,19 @@ export const pamDomainServiceFactory = ({
);
if (gatewayId) {
+ const { permission: orgPermission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId
+ });
+ ForbiddenError.from(orgPermission).throwUnlessCan(
+ OrgPermissionGatewayActions.AttachGateways,
+ OrgPermissionSubjects.Gateway
+ );
+
const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });
if (!gateway) {
throw new NotFoundError({ message: "Gateway not found" });
@@ -239,6 +253,19 @@ export const pamDomainServiceFactory = ({
}
if (gatewayId && gatewayId !== domain.gatewayId) {
+ const { permission: orgPermission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId
+ });
+ ForbiddenError.from(orgPermission).throwUnlessCan(
+ OrgPermissionGatewayActions.AttachGateways,
+ OrgPermissionSubjects.Gateway
+ );
+
const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });
if (!gateway) {
throw new NotFoundError({ message: "Gateway not found" });
diff --git a/backend/src/ee/services/pam-domain/pam-domain-types.ts b/backend/src/ee/services/pam-domain/pam-domain-types.ts
index 92b181b088..6bcc0a1de9 100644
--- a/backend/src/ee/services/pam-domain/pam-domain-types.ts
+++ b/backend/src/ee/services/pam-domain/pam-domain-types.ts
@@ -67,7 +67,7 @@ export type TDeleteDomainDTO = {
export type TPamDomainServiceFactoryDep = {
pamDomainDAL: TPamDomainDALFactory;
pamResourceDAL: Pick<TPamResourceDALFactory, "find" | "findById">;
- permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
+ permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getOrgPermission">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
gatewayV2DAL: Pick<TGatewayV2DALFactory, "findOne">;
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
diff --git a/backend/src/ee/services/pam-resource/pam-resource-service.ts b/backend/src/ee/services/pam-resource/pam-resource-service.ts
index 358804d160..78b0da7c82 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-service.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-service.ts
@@ -1,7 +1,11 @@
import { ForbiddenError, subject } from "@casl/ability";
import { ActionProjectType, OrganizationActionScope, TPamResources } from "@app/db/schemas";
-import { OrgPermissionAppConnectionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
+import {
+ OrgPermissionAppConnectionActions,
+ OrgPermissionGatewayActions,
+ OrgPermissionSubjects
+} from "@app/ee/services/permission/org-permission";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
ProjectPermissionActions,
@@ -213,6 +217,19 @@ export const pamResourceServiceFactory = ({
);
if (gatewayId) {
+ const { permission: orgPermission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId
+ });
+ ForbiddenError.from(orgPermission).throwUnlessCan(
+ OrgPermissionGatewayActions.AttachGateways,
+ OrgPermissionSubjects.Gateway
+ );
+
const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });
if (!gateway) {
throw new NotFoundError({ message: "Gateway not found" });
@@ -372,6 +389,19 @@ export const pamResourceServiceFactory = ({
}
if (gatewayId && gatewayId !== resource.gatewayId) {
+ const { permission: orgPermission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId
+ });
+ ForbiddenError.from(orgPermission).throwUnlessCan(
+ OrgPermissionGatewayActions.AttachGateways,
+ OrgPermissionSubjects.Gateway
+ );
+
const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });
if (!gateway) {
throw new NotFoundError({ message: "Gateway not found" });