Skip to content

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

address reviews

Andrey23c62df326d4
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 05fb305e23..a0207fcb76 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
@@ -2,6 +2,7 @@ import { z } from "zod";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { BadRequestError } from "@app/lib/errors";
+import { logger } from "@app/lib/logger";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { isUserSessionAuth } from "@app/server/plugins/auth/inject-identity";
@@ -31,7 +32,7 @@ import {
UpdatePamAccessPolicySchema
} from "@app/services/approval-policy/pam-access/pam-access-policy-schemas";
import { AuthMode } from "@app/services/auth/auth-type";
-import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
+import { PostHogEventTypes, TPostHogEvent } from "@app/services/telemetry/telemetry-types";
type TCreatePolicySchema =
| typeof CreatePamAccessPolicySchema
@@ -73,6 +74,14 @@ export const registerApprovalPolicyEndpoints = ({
// whose requests are raised and reviewed by delegated tokens widens this.
requestAuthModes?: AuthMode[];
}) => {
+ const sendTelemetry = async (event: TPostHogEvent) => {
+ try {
+ await server.services.telemetry.sendPostHogEvents(event);
+ } catch (err) {
+ logger.error(err, `Failed to send ${policyType} approval telemetry`);
+ }
+ };
+
// Policies
server.route({
method: "POST",
@@ -112,7 +121,7 @@ export const registerApprovalPolicyEndpoints = ({
});
if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
+ await sendTelemetry({
event: PostHogEventTypes.PkiApprovalPolicyCreated,
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
@@ -255,7 +264,7 @@ export const registerApprovalPolicyEndpoints = ({
});
if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
+ await sendTelemetry({
event: PostHogEventTypes.PkiApprovalPolicyUpdated,
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
@@ -310,7 +319,7 @@ export const registerApprovalPolicyEndpoints = ({
});
if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
+ await sendTelemetry({
event: PostHogEventTypes.PkiApprovalPolicyDeleted,
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
@@ -444,7 +453,7 @@ export const registerApprovalPolicyEndpoints = ({
});
if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
+ await sendTelemetry({
event: PostHogEventTypes.PkiApprovalRequestCreated,
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
@@ -565,7 +574,7 @@ export const registerApprovalPolicyEndpoints = ({
distinctId: getTelemetryDistinctId(req),
decision: "approved"
});
- if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
+ if (telemetry) await sendTelemetry(telemetry);
return { request };
}
@@ -597,7 +606,8 @@ export const registerApprovalPolicyEndpoints = ({
const { request } = await server.services.approvalPolicy.rejectRequest(
req.params.requestId,
req.body,
- req.permission
+ req.permission,
+ policyType
);
await server.services.auditLog.createAuditLog({
@@ -628,7 +638,7 @@ export const registerApprovalPolicyEndpoints = ({
distinctId: getTelemetryDistinctId(req),
decision: "rejected"
});
- if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
+ if (telemetry) await sendTelemetry(telemetry);
return { request };
}
@@ -788,7 +798,8 @@ export const registerApprovalPolicyEndpoints = ({
const { grant, request } = await server.services.approvalPolicy.revokeGrant(
req.params.grantId,
req.body,
- req.permission
+ req.permission,
+ policyType
);
await server.services.auditLog.createAuditLog({
@@ -817,7 +828,7 @@ export const registerApprovalPolicyEndpoints = ({
request,
distinctId: getTelemetryDistinctId(req)
});
- if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
+ if (telemetry) await sendTelemetry(telemetry);
}
return { grant };
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index 808bdc2ca6..be9edf7b63 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -1097,7 +1097,7 @@ export const approvalPolicyServiceFactory = ({
const userGroups = await userGroupMembershipDAL.findGroupMembershipsByUserIdInOrg(actor.id, actor.orgId);
const userGroupIds = new Set(userGroups.map((g) => g.groupId));
- const isApprover = steps.some((step) =>
+ const isSnapshotApprover = steps.some((step) =>
step.approvers.some(
(approver) =>
(approver.type === ApproverType.User && approver.id === actor.id) ||
@@ -1105,6 +1105,18 @@ export const approvalPolicyServiceFactory = ({
)
);
+ const checkLiveApprover = resources[request.type as ApprovalPolicyType]?.isLiveApprover;
+ const isApprover =
+ isSnapshotApprover &&
+ (!checkLiveApprover ||
+ !request.scopeId ||
+ (await checkLiveApprover({
+ projectId: request.projectId,
+ scopeId: request.scopeId,
+ actor,
+ userGroupIds
+ })));
+
// If user is requester or approver, allow access regardless of role permission
if (!isRequester && !isApprover) {
if (request.scopeType === ApprovalPolicyScope.PkiApplication && request.scopeId) {
@@ -1368,12 +1380,23 @@ export const approvalPolicyServiceFactory = ({
return { request: decorated };
};
- const rejectRequest = async (requestId: string, { comment }: { comment?: string }, actor: TApprovalActor) => {
+ const rejectRequest = async (
+ requestId: string,
+ { comment }: { comment?: string },
+ actor: TApprovalActor,
+ policyType: ApprovalPolicyType
+ ) => {
const request = await approvalRequestDAL.findById(requestId);
if (!request) {
throw new ForbiddenRequestError({ message: "Request not found" });
}
+ if (request.type !== policyType) {
+ throw new BadRequestError({
+ message: `Request type mismatch: expected ${policyType}, got ${request.type}`
+ });
+ }
+
if (request.status !== ApprovalRequestStatus.Pending) {
throw new BadRequestError({ message: "Request is not pending" });
}
@@ -1689,7 +1712,8 @@ export const approvalPolicyServiceFactory = ({
const revokeGrant = async (
grantId: string,
{ revocationReason }: { revocationReason?: string },
- actor: TApprovalActor
+ actor: TApprovalActor,
+ policyType: ApprovalPolicyType
) => {
const grant = await approvalRequestGrantsDAL.findById(grantId);
if (!grant) {
@@ -1697,6 +1721,12 @@ export const approvalPolicyServiceFactory = ({
}
const grantPolicyType = grant.type as ApprovalPolicyType;
+ if (grantPolicyType !== policyType) {
+ throw new BadRequestError({
+ message: `Grant type mismatch: expected ${policyType}, got ${grantPolicyType}`
+ });
+ }
+
const request = grant.requestId ? await approvalRequestDAL.findById(grant.requestId) : null;
const assertDomainCanRevoke = resources[grantPolicyType]?.assertCanRevokeGrant;