Skip to content

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

fix veria comment

Andreyc12c53eca7c2
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 92158233b8..431a572719 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
@@ -210,9 +210,10 @@ export const pamAccessRequestServiceFactory = ({
const isFolderBreakGlassUser = async (
policyId: string,
userId: string,
- userGroupIds: Set<string>
+ userGroupIds: Set<string>,
+ tx?: Knex
): Promise<boolean> => {
- const bypassers = await approvalPolicyDAL.findBypassersByPolicyId(policyId);
+ const bypassers = await approvalPolicyDAL.findBypassersByPolicyId(policyId, tx);
return bypassers.some(
(b) =>
(b.type === ApproverType.User && b.id === userId) || (b.type === ApproverType.Group && userGroupIds.has(b.id))
@@ -735,6 +736,45 @@ export const pamAccessRequestServiceFactory = ({
};
};
+ const assertBreakGlassEligible = async ({
+ account,
+ folderId,
+ policyId,
+ projectId,
+ userGroupIds,
+ ctx
+ }: {
+ account: { name: string; templatePolicies: unknown };
+ folderId: string;
+ policyId: string;
+ projectId: string;
+ userGroupIds: Set<string>;
+ ctx: TActorContext;
+ }) => {
+ if (ctx.actor !== ActorType.USER) {
+ throw new ForbiddenRequestError({ message: "Only users can break glass on an access request" });
+ }
+
+ const { allowBreakGlass } = resolveAccessControls(account.templatePolicies);
+ if (!allowBreakGlass) {
+ throw new ForbiddenRequestError({
+ message: `Break-glass is not enabled for '${account.name}'. Ask a PAM admin to turn on the Allow Break-Glass policy on its template.`
+ });
+ }
+
+ if (!(await isFolderBreakGlassUser(policyId, ctx.actorId, userGroupIds))) {
+ throw new ForbiddenRequestError({ message: "You are not a break-glass user for this folder" });
+ }
+
+ const activeMemberships = await findActiveFolderMemberships(projectId, folderId);
+ const hasActiveMembership = activeMemberships.some(
+ (m) => m.actorUserId === ctx.actorId || (m.actorGroupId && userGroupIds.has(m.actorGroupId))
+ );
+ if (!hasActiveMembership) {
+ throw new ForbiddenRequestError({ message: "You are not a member of this folder" });
+ }
+ };
+
const notifyOfBreakGlass = async ({
request,
steps,
@@ -868,32 +908,13 @@ export const pamAccessRequestServiceFactory = ({
});
}
- const { allowBreakGlass } = resolveAccessControls(account.templatePolicies);
- if (!allowBreakGlass) {
- throw new ForbiddenRequestError({
- message: `Break-glass is not enabled for '${account.name}'. Ask a PAM admin to turn on the Allow Break-Glass policy on its template.`
- });
- }
-
const policy = await findFolderPolicy(folderId);
if (!policy) {
throw new ForbiddenRequestError({ message: "Approval policy no longer exists for this folder" });
}
const userGroupIds = await getUserGroupIds(ctx.actorId, ctx.actorOrgId);
- if (!(await isFolderBreakGlassUser(policy.id, ctx.actorId, userGroupIds))) {
- throw new ForbiddenRequestError({
- message: "You are not a break-glass user for this folder"
- });
- }
-
- const activeMemberships = await findActiveFolderMemberships(projectId, folderId);
- const hasActiveMembership = activeMemberships.some(
- (m) => m.actorUserId === ctx.actorId || (m.actorGroupId && userGroupIds.has(m.actorGroupId))
- );
- if (!hasActiveMembership) {
- throw new ForbiddenRequestError({ message: "You are not a member of this folder" });
- }
+ await assertBreakGlassEligible({ account, folderId, policyId: policy.id, projectId, userGroupIds, ctx });
// Break-glass skips the approver, not the permission the request itself needed.
const accessType = requestData.requestData.accessType ?? PamAccessType.Session;
@@ -933,6 +954,10 @@ export const pamAccessRequestServiceFactory = ({
)
);
+ if (!(await isFolderBreakGlassUser(policy.id, ctx.actorId, userGroupIds, tx))) {
+ throw new ForbiddenRequestError({ message: "You are not a break-glass user for this folder" });
+ }
+
const currentStep = steps.find((s) => s.stepNumber === locked.currentStep);
if (currentStep) {
await approvalRequestApprovalsDAL.create(
@@ -1085,6 +1110,17 @@ export const pamAccessRequestServiceFactory = ({
throw new BadRequestError({ message: "No approval configuration found for this folder" });
}
+ if (breakGlass) {
+ await assertBreakGlassEligible({
+ account,
+ folderId: account.folderId,
+ policyId: policy.id,
+ projectId,
+ userGroupIds: await getUserGroupIds(ctx.actorId, ctx.actorOrgId),
+ ctx
+ });
+ }
+
const durationMs = parseDurationMs(duration);
const accessDuration = (
policy.constraints as { constraints?: { accessDuration?: { min?: string; max?: string } } } | null
diff --git a/backend/src/services/approval-policy/approval-policy-dal.ts b/backend/src/services/approval-policy/approval-policy-dal.ts
index 46d01f53a3..9b3f044403 100644
--- a/backend/src/services/approval-policy/approval-policy-dal.ts
+++ b/backend/src/services/approval-policy/approval-policy-dal.ts
@@ -63,9 +63,9 @@ export const approvalPolicyDALFactory = (db: TDbClient) => {
}
};
- const findBypassersByPolicyId = async (policyId: string): Promise<PolicyBypasser[]> => {
+ const findBypassersByPolicyId = async (policyId: string, tx?: Knex): Promise<PolicyBypasser[]> => {
try {
- const dbInstance = db.replicaNode();
+ const dbInstance = tx || db.replicaNode();
const rows = (await dbInstance(TableName.ApprovalPolicyBypassers)
.where({ policyId })
.select("userId", "groupId")) as { userId: string | null; groupId: string | null }[];