Skip to content

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

fix(api): allow machine identities on approval policy routes (#7755)

Saif Ur Rahmane7b29a4c7c21
diff --git a/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts b/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
index 3706a14c4b..72ed808124 100644
--- a/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
+++ b/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
@@ -81,7 +81,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { policy } = await server.services.approvalPolicy.create(
policyType,
@@ -138,7 +138,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { policies, projectId } = await server.services.approvalPolicy.list(
policyType,
@@ -182,7 +182,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { policy } = await server.services.approvalPolicy.getById(req.params.policyId, req.permission);
@@ -223,7 +223,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { policy } = await server.services.approvalPolicy.updateById(
req.params.policyId,
@@ -280,7 +280,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { policyId, projectId } = await server.services.approvalPolicy.deleteById(
req.params.policyId,
@@ -337,7 +337,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
handler: async (req) => {
const { requests, projectId } = await server.services.approvalPolicy.listRequests(
policyType,
@@ -462,7 +462,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
handler: async (req) => {
const { request } = await server.services.approvalPolicy.getRequestById(req.params.requestId, req.permission);
@@ -642,7 +642,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const { request } = await server.services.approvalPolicy.cancelRequest(req.params.requestId, req.permission);
@@ -683,7 +683,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
handler: async (req) => {
const { grants, projectId } = await server.services.approvalPolicy.listGrants(
policyType,
@@ -727,7 +727,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
handler: async (req) => {
const { grant } = await server.services.approvalPolicy.getGrantById(req.params.grantId, req.permission);
@@ -809,7 +809,7 @@ export const registerApprovalPolicyEndpoints = ({
200: checkPolicyMatchResponseSchema
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const result = await server.services.approvalPolicy.checkPolicyMatch(policyType, req.body, req.permission);
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index 74b99dc4c0..0e195e61c3 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -151,6 +151,20 @@ export const approvalPolicyServiceFactory = ({
};
};
+ // A request attributes its requester to exactly one column: a user or a machine identity.
+ // Actor ids are unique across orgs but an actor can hold tokens for several, and a requester
+ // match skips the permission check, so the token's org has to match too.
+ const $isRequester = (
+ request: { organizationId: string; requesterId?: string | null; machineIdentityId?: string | null },
+ actor: OrgServiceActor
+ ) => {
+ if (request.organizationId !== actor.orgId) return false;
+
+ return actor.type === ActorType.IDENTITY
+ ? request.machineIdentityId === actor.id
+ : request.requesterId === actor.id;
+ };
+
const $decorateRequest = async <
R extends {
id: string;
@@ -1022,7 +1036,7 @@ export const approvalPolicyServiceFactory = ({
const steps = await approvalRequestDAL.findStepsByRequestId(requestId);
- const isRequester = request.requesterId === actor.id;
+ const isRequester = $isRequester(request, actor);
// Check if user is an eligible approver for any step
const userGroups = await userGroupMembershipDAL.findGroupMembershipsByUserIdInOrg(actor.id, actor.orgId);
@@ -1403,7 +1417,7 @@ export const approvalPolicyServiceFactory = ({
const userGroupIds = await ctx.getUserGroupIds();
return requests.filter((request) => {
- if (request.requesterId === actor.id) return true;
+ if ($isRequester(request, actor)) return true;
return request.steps.some((step) =>
step.approvers.some(
(approver) =>
@@ -1457,7 +1471,7 @@ export const approvalPolicyServiceFactory = ({
throw new BadRequestError({ message: "Request is not pending" });
}
- if (request.requesterId !== actor.id) {
+ if (!$isRequester(request, actor)) {
throw new ForbiddenRequestError({ message: "You are not the requester of this request" });
}