Skip to content

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

address reviews

Andrey60d081190a79
diff --git a/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts b/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts
index 3bcecc3160..d69e809b29 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts
@@ -138,6 +138,7 @@ type TBreakGlassSubject = {
projectId: string;
accountId?: string;
folderId?: string;
+ accessType?: PamAccessType;
actor: TApprovalActor;
};
@@ -251,8 +252,12 @@ export const pamAccessApprovalResourceFactory = ({
);
};
- const matchesInputs: NonNullable<TPamAccessApprovalResource["matchesInputs"]> = (payload, inputs) =>
- matchesPamAccessSubject(payload, inputs as TPamAccessPolicyInputs);
+ const matchesInputs: NonNullable<TPamAccessApprovalResource["matchesInputs"]> = (payload, inputs) => {
+ const target = inputs as TPamAccessPolicyInputs;
+ if (target.accessType) return matchesPamAccessSubject(payload, target);
+
+ return (payload as { accountId?: string } | null)?.accountId === target.accountId;
+ };
const validateConstraints: TPamAccessApprovalResource["validateConstraints"] = (policy, requestData) => {
const requestedMs = parsePamAccessDuration(requestData.duration);
@@ -531,6 +536,7 @@ export const pamAccessApprovalResourceFactory = ({
projectId,
accountId,
folderId,
+ accessType,
bypassers,
actor,
userGroupIds
@@ -564,10 +570,31 @@ export const pamAccessApprovalResourceFactory = ({
return new ForbiddenRequestError({ message: "You are not a member of this folder" });
}
+ try {
+ await checkAccountAccess(
+ permissionService,
+ account.id,
+ folderId,
+ projectId,
+ accessType === PamAccessType.Credential
+ ? ResourcePermissionPamResourceActions.ViewCredentials
+ : ResourcePermissionPamResourceActions.LaunchSessions,
+ toActorContext(actor)
+ );
+ } catch (err) {
+ return err as Error;
+ }
+
return null;
};
- const assertBreakGlassEligible = async ({ projectId, accountId, folderId, actor }: TBreakGlassSubject) => {
+ const assertBreakGlassEligible = async ({
+ projectId,
+ accountId,
+ folderId,
+ accessType,
+ actor
+ }: TBreakGlassSubject) => {
const policy = folderId ? await $findFolderPolicy(projectId, folderId) : null;
if (!policy) {
throw new ForbiddenRequestError({ message: "Approval policy no longer exists for this folder" });
@@ -582,6 +609,7 @@ export const pamAccessApprovalResourceFactory = ({
projectId,
accountId,
folderId,
+ accessType,
actor,
bypassers,
userGroupIds: new Set(userGroupMemberships.map((g) => g.groupId))
@@ -600,6 +628,7 @@ export const pamAccessApprovalResourceFactory = ({
projectId: request.projectId,
accountId: inputs?.accountId,
folderId: inputs?.folderId,
+ accessType: inputs?.accessType,
actor,
bypassers,
userGroupIds
@@ -1033,6 +1062,7 @@ export const pamAccessApprovalResourceFactory = ({
noMatchingPolicyMessage: "No approval configuration found for this folder",
assertCanManagePolicy,
canReadScope,
+ singlePolicyPerScope: true,
verifyPolicyActors,
assertCanCreateRequest,
assertCanReview,
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
index aa36c56387..ff09c756f2 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
@@ -323,23 +323,13 @@ export const pamAccessRequestServiceFactory = ({
});
}
- // Break-glass skips the approver, not the permission the request itself needed.
const accessType = requestData.requestData.accessType ?? PamAccessType.Session;
- await checkAccountAccess(
- permissionService,
- account.id,
- account.folderId,
- projectId,
- accessType === PamAccessType.Credential
- ? ResourcePermissionPamResourceActions.ViewCredentials
- : ResourcePermissionPamResourceActions.LaunchSessions,
- ctx
- );
await pamAccessApprovalResource.assertBreakGlassEligible({
projectId,
accountId,
folderId,
+ accessType,
actor: toApprovalActor(ctx)
});
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index 8d23b8729a..fa60c269a3 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -3,6 +3,7 @@ import { Knex } from "knex";
import {
ActionProjectType,
+ OrganizationActionScope,
ProjectMembershipRole,
RESOURCE_SCOPE,
ResourceType,
@@ -616,6 +617,19 @@ export const approvalPolicyServiceFactory = ({
});
}
+ if (resources[policyType]?.singlePolicyPerScope && dbScopeId) {
+ const existing = await approvalPolicyDAL.findOne({
+ type: policyType,
+ scopeType: dbScopeType,
+ scopeId: dbScopeId
+ });
+ if (existing) {
+ throw new BadRequestError({
+ message: `An approval policy named '${existing.name}' already governs this scope. Update it instead of creating another.`
+ });
+ }
+ }
+
await $verifyPolicyActors({
policyType,
projectId,
@@ -1083,12 +1097,24 @@ export const approvalPolicyServiceFactory = ({
return { request: decorated };
};
+ const $assertOrgMember = (organizationId: string, actor: TApprovalActor) =>
+ permissionService.getOrgPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ orgId: organizationId,
+ actorOrgId: actor.orgId,
+ scope: OrganizationActionScope.Any,
+ actorAuthMethod: actor.authMethod
+ });
+
const getRequestById = async (requestId: string, actor: TApprovalActor) => {
const request = await approvalRequestDAL.findById(requestId);
if (!request) {
throw new ForbiddenRequestError({ message: "Request not found" });
}
+ await $assertOrgMember(request.organizationId, actor);
+
const steps = await approvalRequestDAL.findStepsByRequestId(requestId);
const isRequester = $isRequester(request, actor);
@@ -1179,6 +1205,8 @@ export const approvalPolicyServiceFactory = ({
});
}
+ await $assertOrgMember(request.organizationId, actor);
+
const supportsBreakGlass = Boolean(resources[policyType]?.isBreakGlassEligible);
if (bypassReason !== undefined && !supportsBreakGlass) {
throw new BadRequestError({
@@ -1402,6 +1430,8 @@ export const approvalPolicyServiceFactory = ({
});
}
+ await $assertOrgMember(request.organizationId, actor);
+
if (request.status !== ApprovalRequestStatus.Pending) {
throw new BadRequestError({ message: "Request is not pending" });
}
diff --git a/backend/src/services/approval-policy/approval-policy-types.ts b/backend/src/services/approval-policy/approval-policy-types.ts
index 9c410e5e09..9d7535ec47 100644
--- a/backend/src/services/approval-policy/approval-policy-types.ts
+++ b/backend/src/services/approval-policy/approval-policy-types.ts
@@ -239,6 +239,9 @@ export type TApprovalResource<
// Whether the actor may read a scope's requests and grants, for a type whose read authority is the
// scope rather than the project.
canReadScope?: (args: { projectId: string; scopeId: string | null; actor: TApprovalActor }) => Promise<boolean>;
+
+ // Set where a scope may carry at most one policy, so creating a second is refused rather than ignored.
+ singlePolicyPerScope?: boolean;
verifyPolicyActors?: (args: {
projectId: string;
scopeId: string | null;