Skip to content

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

address bot reviews

Andrey62c3ca16bbaf
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
index 30a72fa05d..0af07ff8ff 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-access-request-router.ts
@@ -87,7 +87,11 @@ export const registerPamAccessRequestRouter = async (server: FastifyZodProvider)
metadata: {
requestId: result.request.id,
accountId: result.accountId,
+ accountName: result.accountName,
folderId: result.folderId,
+ folderName: result.folderName ?? undefined,
+ requesterName: result.request.requesterName,
+ requesterEmail: result.request.requesterEmail,
duration: req.body.duration,
accessType: result.accessType,
reason: req.body.reason
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index e3fec98b9b..e1b4f5decc 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -6586,7 +6586,11 @@ interface PamAccessRequestCreateEvent {
metadata: {
requestId: string;
accountId: string;
+ accountName?: string;
folderId: string;
+ folderName?: string;
+ requesterName?: string;
+ requesterEmail?: string;
duration: string;
accessType: string;
reason?: string;
@@ -6598,7 +6602,11 @@ interface PamAccessRequestReviewEvent {
metadata: {
requestId: string;
accountId?: string;
+ accountName?: string;
folderId?: string;
+ folderName?: string;
+ requesterName?: string;
+ requesterEmail?: string;
status: string;
comment?: string;
};
@@ -6610,7 +6618,11 @@ interface PamAccessGrantRevokeEvent {
requestId: string;
grantId: string;
accountId?: string;
+ accountName?: string;
folderId?: string;
+ folderName?: string;
+ granteeName?: string;
+ granteeEmail?: string;
};
}
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 ee4f49cd0c..d6d7c68cc9 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
@@ -1,6 +1,6 @@
import { Knex } from "knex";
-import { RESOURCE_SCOPE, ResourceType, TApprovalRequestGrants, TApprovalRequests } from "@app/db/schemas";
+import { RESOURCE_SCOPE, ResourceType, TApprovalRequestGrants } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";
@@ -48,6 +48,7 @@ import { TMembershipDALFactory } from "@app/services/membership/membership-dal";
import { TMembershipRoleDALFactory } from "@app/services/membership/membership-role-dal";
import { NotificationType } from "@app/services/notification/notification-types";
import { SmtpTemplates } from "@app/services/smtp/smtp-service";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { TUserDALFactory } from "@app/services/user/user-dal";
import {
@@ -112,7 +113,7 @@ export type TPamAccessApprovalResource = TApprovalResource<
TPamAccessPolicy,
TPamAccessRequestData
> & {
- assertBreakGlassEligible: (args: { request: TApprovalRequests; actor: TApprovalActor }) => Promise<void>;
+ assertBreakGlassEligible: (args: TBreakGlassSubject) => Promise<void>;
decorateRequests: <T extends { requestData?: unknown }>(requests: T[]) => Promise<(T & TPamRequestDecoration)[]>;
findActiveFolderMemberships: (
projectId: string,
@@ -133,11 +134,11 @@ const toActorContext = (actor: TApprovalActor): TActorContext => ({
actorAuthMethod: actor.authMethod
});
-type TBreakGlassArgs = {
- request: TApprovalRequests;
- bypassers: PolicyBypasser[];
+type TBreakGlassSubject = {
+ projectId: string;
+ accountId?: string;
+ folderId?: string;
actor: TApprovalActor;
- userGroupIds: Set<string>;
};
const requestDataOf = (request: { requestData?: unknown }) =>
@@ -509,22 +510,23 @@ export const pamAccessApprovalResourceFactory = ({
};
const $refuseBreakGlass = async ({
- request,
+ projectId,
+ accountId,
+ folderId,
bypassers,
actor,
userGroupIds
- }: TBreakGlassArgs): Promise<Error | null> => {
+ }: TBreakGlassSubject & { bypassers: PolicyBypasser[]; userGroupIds: Set<string> }): Promise<Error | null> => {
if (actor.type !== ActorType.USER) {
return new ForbiddenRequestError({ message: "Only users can break glass on an access request" });
}
- const inputs = requestDataOf(request);
- if (!inputs?.accountId || !inputs.folderId) {
+ if (!accountId || !folderId) {
return new BadRequestError({ message: "This request is missing the account it was raised for" });
}
- const account = await pamAccountDAL.findByIdWithDetails(inputs.accountId);
- if (!account || account.projectId !== request.projectId || account.folderId !== inputs.folderId) {
+ const account = await pamAccountDAL.findByIdWithDetails(accountId);
+ if (!account || account.projectId !== projectId || account.folderId !== folderId) {
return new BadRequestError({
message: "This request is no longer valid because the account has moved or been removed"
});
@@ -540,22 +542,15 @@ export const pamAccessApprovalResourceFactory = ({
return new ForbiddenRequestError({ message: "You are not a break-glass user for this folder" });
}
- if (!(await $holdsActiveFolderMembership(request.projectId, inputs.folderId, actor.id, userGroupIds))) {
+ if (!(await $holdsActiveFolderMembership(projectId, folderId, actor.id, userGroupIds))) {
return new ForbiddenRequestError({ message: "You are not a member of this folder" });
}
return null;
};
- const assertBreakGlassEligible = async ({
- request,
- actor
- }: {
- request: TApprovalRequests;
- actor: TApprovalActor;
- }) => {
- const folderId = requestDataOf(request)?.folderId;
- const policy = folderId ? await $findFolderPolicy(request.projectId, folderId) : null;
+ const assertBreakGlassEligible = async ({ projectId, accountId, folderId, actor }: TBreakGlassSubject) => {
+ const policy = folderId ? await $findFolderPolicy(projectId, folderId) : null;
if (!policy) {
throw new ForbiddenRequestError({ message: "Approval policy no longer exists for this folder" });
}
@@ -566,7 +561,9 @@ export const pamAccessApprovalResourceFactory = ({
]);
const refusal = await $refuseBreakGlass({
- request,
+ projectId,
+ accountId,
+ folderId,
actor,
bypassers,
userGroupIds: new Set(userGroupMemberships.map((g) => g.groupId))
@@ -574,8 +571,22 @@ export const pamAccessApprovalResourceFactory = ({
if (refusal) throw refusal;
};
- const isBreakGlassEligible: NonNullable<TPamAccessApprovalResource["isBreakGlassEligible"]> = async (args) =>
- !(await $refuseBreakGlass(args));
+ const isBreakGlassEligible: NonNullable<TPamAccessApprovalResource["isBreakGlassEligible"]> = async ({
+ request,
+ bypassers,
+ actor,
+ userGroupIds
+ }) => {
+ const inputs = requestDataOf(request);
+ return !(await $refuseBreakGlass({
+ projectId: request.projectId,
+ accountId: inputs?.accountId,
+ folderId: inputs?.folderId,
+ actor,
+ bypassers,
+ userGroupIds
+ }));
+ };
const assertCanRevokeGrant: NonNullable<TPamAccessApprovalResource["assertCanRevokeGrant"]> = async ({
grant,
@@ -837,6 +848,38 @@ export const pamAccessApprovalResourceFactory = ({
});
};
+ const buildTelemetryEvent: NonNullable<TPamAccessApprovalResource["buildTelemetryEvent"]> = async ({
+ action,
+ request,
+ distinctId,
+ decision
+ }) => {
+ const orgId = request.organizationId;
+ const base = { distinctId, organizationId: orgId };
+
+ if (action === ApprovalAuditAction.RequestReviewed) {
+ return {
+ ...base,
+ event: PostHogEventTypes.PamAccessRequestReviewed,
+ properties: { orgId, status: decision ?? "" }
+ };
+ }
+
+ if (action === ApprovalAuditAction.GrantRevoked) {
+ return { ...base, event: PostHogEventTypes.PamAccessGrantRevoked, properties: { orgId } };
+ }
+
+ if (action !== ApprovalAuditAction.RequestBypassed) return null;
+
+ const accountId = requestDataOf(request)?.accountId;
+ const account = accountId ? await pamAccountDAL.findByIdWithDetails(accountId) : null;
+ return {
+ ...base,
+ event: PostHogEventTypes.PamAccessRequestBrokeGlass,
+ properties: { orgId, accountType: account?.accountType ?? "" }
+ };
+ };
+
const buildAuditEvent: NonNullable<TPamAccessApprovalResource["buildAuditEvent"]> = async ({
action,
request,
@@ -846,16 +889,26 @@ export const pamAccessApprovalResourceFactory = ({
bypassReason
}) => {
const inputs = requestDataOf(request);
- const scope = { accountId: inputs?.accountId, folderId: inputs?.folderId };
+ const account = inputs?.accountId ? await pamAccountDAL.findByIdWithDetails(inputs.accountId) : null;
+ const folder = inputs?.folderId ? await pamFolderDAL.findById(inputs.folderId) : null;
+ const scope = {
+ accountId: inputs?.accountId,
+ accountName: account?.name,
+ folderId: inputs?.folderId,
+ folderName: folder?.name
+ };
if (action === ApprovalAuditAction.RequestCreated) {
if (!inputs?.accountId || !inputs.folderId) return null;
return {
type: EventType.PAM_ACCESS_REQUEST_CREATE,
metadata: {
- requestId: request.id,
+ ...scope,
accountId: inputs.accountId,
folderId: inputs.folderId,
+ requestId: request.id,
+ requesterName: request.requesterName,
+ requesterEmail: request.requesterEmail,
duration: inputs.duration,
accessType: inputs.accessType ?? PamAccessType.Session,
reason: inputs.reason
@@ -866,21 +919,32 @@ export const pamAccessApprovalResourceFactory = ({
if (action === ApprovalAuditAction.RequestReviewed) {
return {
type: EventType.PAM_ACCESS_REQUEST_REVIEW,
- metadata: { requestId: request.id, ...scope, status: request.status, comment }
+ metadata: {
+ ...scope,
+ requestId: request.id,
+ requesterName: request.requesterName,
+ requesterEmail: request.requesterEmail,
+ status: request.status,
+ comment
+ }
};
}
if (action === ApprovalAuditAction.GrantRevoked && grantId) {
return {
type: EventType.PAM_ACCESS_GRANT_REVOKE,
- metadata: { requestId: request.id, grantId, ...scope }
+ metadata: {
+ ...scope,
+ requestId: request.id,
+ grantId,
+ granteeName: request.requesterName,
+ granteeEmail: request.requesterEmail
+ }
};
}
if (action !== ApprovalAuditAction.RequestBypassed || !grantId) return null;
- const account = inputs?.accountId ? await pamAccountDAL.findByIdWithDetails(inputs.accountId) : null;
- const folder = inputs?.folderId ? await pamFolderDAL.findById(inputs.folderId) : null;
const policy = request.policyId ? await approvalPolicyDAL.findById(request.policyId) : null;
const steps = request.policyId ? await approvalPolicyDAL.findStepsByPolicyId(request.policyId) : [];
@@ -896,9 +960,7 @@ export const pamAccessApprovalResourceFactory = ({
granteeName: request.requesterName ?? undefined,
granteeEmail: request.requesterEmail ?? undefined,
...scope,
- folderName: folder?.name,
resourceName: folder?.name,
- accountName: account?.name,
accessDuration: inputs?.duration ?? "",
bypassReason: bypassReason ?? "",
approverCount: new Set(steps.flatMap((step) => step.approvers.map((a) => `${a.type}:${a.id}`))).size
@@ -943,6 +1005,7 @@ export const pamAccessApprovalResourceFactory = ({
matchesInputs,
buildNotification,
buildAuditEvent,
+ buildTelemetryEvent,
decorateRequests,
filterActiveApprovers,
isLiveApprover,
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 05d8ceba44..aa36c56387 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
@@ -336,7 +336,12 @@ export const pamAccessRequestServiceFactory = ({
ctx
);
- await pamAccessApprovalResource.assertBreakGlassEligible({ request, actor: toApprovalActor(ctx) });
+ await pamAccessApprovalResource.assertBreakGlassEligible({
+ projectId,
+ accountId,
+ folderId,
+ actor: toApprovalActor(ctx)
+ });
const policy = request.policyId ? await approvalPolicyDAL.findById(request.policyId) : null;
@@ -404,6 +409,15 @@ export const pamAccessRequestServiceFactory = ({
throw new BadRequestError({ message: "Account must be in a folder to require approval" });
}
+ if (breakGlass) {
+ await pamAccessApprovalResource.assertBreakGlassEligible({
+ projectId,
+ accountId: account.id,
+ folderId: account.folderId,
+ actor: toApprovalActor(ctx)
+ });
+ }
+
const requester = await resolveRequesterDisplay(ctx);
const { request } = await approvalPolicyService.createRequest(
@@ -419,6 +433,7 @@ export const pamAccessRequestServiceFactory = ({
accessType
},
justification: trimmedReason,
+ skipApproverNotification: breakGlass,
machineIdentityId: ctx.actor === ActorType.IDENTITY ? ctx.actorId : undefined,
requesterName: requester.name,
requesterEmail: requester.email
@@ -436,7 +451,9 @@ export const pamAccessRequestServiceFactory = ({
return {
request: result.request,
accountId: account.id,
+ accountName: account.name,
folderId: account.folderId,
+ folderName: account.folderName,
accountType: account.accountType,
accessType,
brokeGlass: true as const,
@@ -447,7 +464,9 @@ export const pamAccessRequestServiceFactory = ({
return {
request,
accountId: account.id,
+ accountName: account.name,
folderId: account.folderId,
+ folderName: account.folderName,
accountType: account.accountType,
accessType,
brokeGlass: false as const,
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 aea550eec3..05fb305e23 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
@@ -53,7 +53,8 @@ export const registerApprovalPolicyEndpoints = ({
grantResponseSchema,
inputsSchema,
checkPolicyMatchResponseSchema,
- allowRequestCreation = true
+ allowRequestCreation = true,
+ requestAuthModes = [AuthMode.JWT]
}: {
server: FastifyZodProvider;
policyType: ApprovalPolicyType;
@@ -68,6 +69,9 @@ export const registerApprovalPolicyEndpoints = ({
// Whether callers may open an approval request directly. Policy types whose requests are
// only ever created server-side, as part of the flow being gated, must leave this off.
allowRequestCreation?: boolean;
+ // Auth modes the request actions accept. Policy administration stays JWT-only regardless; a type
+ // whose requests are raised and reviewed by delegated tokens widens this.
+ requestAuthModes?: AuthMode[];
}) => {
// Policies
server.route({
@@ -522,7 +526,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth(requestAuthModes),
handler: async (req) => {
const { request, bypassMetadata } = await server.services.approvalPolicy.approveRequest(
req.params.requestId,
@@ -555,18 +559,13 @@ export const registerApprovalPolicyEndpoints = ({
}
});
- if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
- event: PostHogEventTypes.PkiApprovalRequestReviewed,
- distinctId: getTelemetryDistinctId(req),
- organizationId: req.permission.orgId,
- properties: {
- decision: "approved",
- orgId: req.permission.orgId,
- projectId: request.projectId
- }
- });
- }
+ const telemetry = await server.services.approvalPolicy.buildTelemetryEvent({
+ action: bypassMetadata ? ApprovalAuditAction.RequestBypassed : ApprovalAuditAction.RequestReviewed,
+ request,
+ distinctId: getTelemetryDistinctId(req),
+ decision: "approved"
+ });
+ if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
return { request };
}
@@ -593,7 +592,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth(requestAuthModes),
handler: async (req) => {
const { request } = await server.services.approvalPolicy.rejectRequest(
req.params.requestId,
@@ -623,18 +622,13 @@ export const registerApprovalPolicyEndpoints = ({
}
});
- if (policyType === ApprovalPolicyType.CertRequest || policyType === ApprovalPolicyType.CertCodeSigning) {
- await server.services.telemetry.sendPostHogEvents({
- event: PostHogEventTypes.PkiApprovalRequestReviewed,
- distinctId: getTelemetryDistinctId(req),
- organizationId: req.permission.orgId,
- properties: {
- decision: "rejected",
- orgId: req.permission.orgId,
- projectId: request.projectId
- }
- });
- }
+ const telemetry = await server.services.approvalPolicy.buildTelemetryEvent({
+ action: ApprovalAuditAction.RequestReviewed,
+ request,
+ distinctId: getTelemetryDistinctId(req),
+ decision: "rejected"
+ });
+ if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
return { request };
}
@@ -789,7 +783,7 @@ export const registerApprovalPolicyEndpoints = ({
})
}
},
- onRequest: verifyAuth([AuthMode.JWT]),
+ onRequest: verifyAuth(requestAuthModes),
handler: async (req) => {
const { grant, request } = await server.services.approvalPolicy.revokeGrant(
req.params.grantId,
@@ -817,6 +811,15 @@ export const registerApprovalPolicyEndpoints = ({
}
});
+ if (request) {
+ const telemetry = await server.services.approvalPolicy.buildTelemetryEvent({
+ action: ApprovalAuditAction.GrantRevoked,
+ request,
+ distinctId: getTelemetryDistinctId(req)
+ });
+ if (telemetry) await server.services.telemetry.sendPostHogEvents(telemetry);
+ }
+
return { grant };
}
});
diff --git a/backend/src/server/routes/v1/approval-policy-routers/index.ts b/backend/src/server/routes/v1/approval-policy-routers/index.ts
index a78c8418d3..b2150a144d 100644
--- a/backend/src/server/routes/v1/approval-policy-routers/index.ts
+++ b/backend/src/server/routes/v1/approval-policy-routers/index.ts
@@ -27,6 +27,7 @@ import {
PamAccessRequestSchema,
UpdatePamAccessPolicySchema
} from "@app/services/approval-policy/pam-access/pam-access-policy-schemas";
+import { AuthMode } from "@app/services/auth/auth-type";
import { registerApprovalPolicyEndpoints } from "./approval-policy-endpoints";
@@ -44,7 +45,8 @@ export const APPROVAL_POLICY_REGISTER_ROUTER_MAP: Partial<
requestResponseSchema: PamAccessRequestSchema,
grantResponseSchema: PamAccessRequestGrantSchema,
inputsSchema: PamAccessPolicyInputsSchema,
- checkPolicyMatchResponseSchema: PamAccessCheckPolicyMatchResponseSchema
+ checkPolicyMatchResponseSchema: PamAccessCheckPolicyMatchResponseSchema,
+ requestAuthModes: [AuthMode.JWT, AuthMode.OAUTH]
});
},
[ApprovalPolicyType.CertRequest]: async (server: FastifyZodProvider) => {
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index 33ad6c39cf..808bdc2ca6 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -432,7 +432,7 @@ export const approvalPolicyServiceFactory = ({
throw new BadRequestError({ message: "Request has expired" });
}
- const requestSteps = await approvalRequestDAL.findStepsByRequestId(requestId);
+ const requestSteps = await approvalRequestDAL.findStepsByRequestId(requestId, tx);
await Promise.all(
requestSteps.map((step) =>
approvalRequestStepsDAL.updateById(
@@ -483,10 +483,11 @@ export const approvalPolicyServiceFactory = ({
approverCount: bypassedApproverCount
};
+ const livePolicySteps = await approvalPolicyDAL.findStepsByPolicyId(policy.id);
await $notify({
event: ApprovalNotificationEvent.Bypassed,
request: finalRequest,
- approvers: steps.flatMap((step) => step.approvers),
+ approvers: livePolicySteps.flatMap((step) => step.approvers),
actorId: actor.id,
bypassReason: bypassReason.trim()
});
@@ -930,6 +931,7 @@ export const approvalPolicyServiceFactory = ({
machineIdentityId,
requesterName,
requesterEmail,
+ skipApproverNotification,
tx
}: TCreateRequestFromPolicyDTO) => {
const requestWithSteps = await createApprovalRequestWithSteps(
@@ -957,11 +959,13 @@ export const approvalPolicyServiceFactory = ({
tx
);
- await $notify({
- event: ApprovalNotificationEvent.Requested,
- request: requestWithSteps,
- approvers: requestWithSteps.steps[0]?.approvers ?? []
- });
+ if (!skipApproverNotification) {
+ await $notify({
+ event: ApprovalNotificationEvent.Requested,
+ request: requestWithSteps,
+ approvers: requestWithSteps.steps[0]?.approvers ?? []
+ });
+ }
return {
request: requestWithSteps
@@ -978,7 +982,8 @@ export const approvalPolicyServiceFactory = ({
justification,
requesterName,
requesterEmail,
- machineIdentityId
+ machineIdentityId,
+ skipApproverNotification
}: TCreateRequestDTO & {
requesterName: string;
requesterEmail: string;
@@ -1070,7 +1075,8 @@ export const approvalPolicyServiceFactory = ({
requesterUserId: actor.type === ActorType.IDENTITY ? undefined : actor.id,
machineIdentityId,
requesterName,
- requesterEmail
+ requesterEmail,
+ skipApproverNotification
});
const decorated = await $decorateRequest(created.request, actor);
@@ -2247,8 +2253,16 @@ export const approvalPolicyServiceFactory = ({
bypassReason?: string;
}) => (await $resource(args.request.type as ApprovalPolicyType).buildAuditEvent?.(args)) ?? null;
+ const buildTelemetryEvent = async (args: {
+ action: ApprovalAuditAction;
+ request: TApprovalRequests;
+ distinctId: string;
+ decision?: string;
+ }) => (await $resource(args.request.type as ApprovalPolicyType).buildTelemetryEvent?.(args)) ?? null;
+
return {
buildAuditEvent,
+ buildTelemetryEvent,
matchPolicy: (policyType: ApprovalPolicyType, projectId: string, inputs: TApprovalPolicyInputs) =>
$resource(policyType).matchPolicy(projectId, inputs),
getActiveGrant,
diff --git a/backend/src/services/approval-policy/approval-policy-types.ts b/backend/src/services/approval-policy/approval-policy-types.ts
index 0fd4b23382..01f5ae1ba7 100644
--- a/backend/src/services/approval-policy/approval-policy-types.ts
+++ b/backend/src/services/approval-policy/approval-policy-types.ts
@@ -7,6 +7,7 @@ import { OrgServiceActor } from "@app/lib/types";
import { TNotification } from "@app/lib/workflow-integrations/types";
import { NotificationType } from "@app/services/notification/notification-types";
import { SmtpTemplates } from "@app/services/smtp/smtp-service";
+import { TPostHogEvent } from "@app/services/telemetry/telemetry-types";
import {
ApprovalAuditAction,
@@ -127,6 +128,9 @@ export interface TCreateRequestDTO {
requestData: TApprovalRequest["requestData"]["requestData"];
justification?: TApprovalRequest["justification"];
requestDuration?: string | null;
+ // Set by a caller that decides the request in the same breath (break-glass), so approvers are not
+ // asked to act on something that is already resolved
+ skipApproverNotification?: boolean;
}
export interface TCreateRequestFromPolicyDTO {
@@ -140,6 +144,7 @@ export interface TCreateRequestFromPolicyDTO {
machineIdentityId?: string | null;
requesterName: string;
requesterEmail: string;
+ skipApproverNotification?: boolean;
tx?: Knex;
}
@@ -174,6 +179,15 @@ export type TApprovalResource<
// Without it the access-status and reaping helpers have nothing to match on.
matchesInputs?: (payload: unknown, inputs: TApprovalPolicyInputs) => boolean;
+ // The product analytics a lifecycle action owes, so the shared route does not have to know which
+ // products it is serving. Returning nothing records nothing.
+ buildTelemetryEvent?: (args: {
+ action: ApprovalAuditAction;
+ request: TApprovalRequests;
+ distinctId: string;
+ decision?: string;
+ }) => Promise<TPostHogEvent | null>;
+
// Whether the actor is still an approver for the scope, for a type where the request's creation-time
// approver snapshot can outlive the membership behind it.
isLiveApprover?: (args: {
diff --git a/backend/src/services/approval-policy/approval-request-dal.ts b/backend/src/services/approval-policy/approval-request-dal.ts
index 3267f41705..7728745812 100644
--- a/backend/src/services/approval-policy/approval-request-dal.ts
+++ b/backend/src/services/approval-policy/approval-request-dal.ts
@@ -17,9 +17,9 @@ export type TApprovalRequestDALFactory = ReturnType<typeof approvalRequestDALFac
export const approvalRequestDALFactory = (db: TDbClient) => {
const orm = ormify(db, TableName.ApprovalRequests);
- const findStepsByRequestId = async (requestId: string) => {
+ const findStepsByRequestId = async (requestId: string, tx?: Knex) => {
try {
- const dbInstance = db.replicaNode();
+ const dbInstance = tx || db.replicaNode();
const steps = await dbInstance(TableName.ApprovalRequestSteps).where({ requestId }).orderBy("stepNumber", "asc");
if (!steps.length) {
diff --git a/backend/src/services/approval-policy/cert-request/cert-request-policy-factory.ts b/backend/src/services/approval-policy/cert-request/cert-request-policy-factory.ts
index a188cd9c8e..60f73bc352 100644
--- a/backend/src/services/approval-policy/cert-request/cert-request-policy-factory.ts
+++ b/backend/src/services/approval-policy/cert-request/cert-request-policy-factory.ts
@@ -5,9 +5,15 @@ import { CertificateRequestStatus } from "@app/services/certificate-request/cert
import { TCertificateApprovalService } from "@app/services/certificate-v3/certificate-approval-fns";
import { NotificationType } from "@app/services/notification/notification-types";
import { SmtpTemplates } from "@app/services/smtp/smtp-service";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { TApprovalPolicyDALFactory } from "../approval-policy-dal";
-import { ApprovalNotificationEvent, ApprovalPolicyScope, ApprovalPolicyType } from "../approval-policy-enums";
+import {
+ ApprovalAuditAction,
+ ApprovalNotificationEvent,
+ ApprovalPolicyScope,
+ ApprovalPolicyType
+} from "../approval-policy-enums";
import { TApprovalResource } from "../approval-policy-types";
import { TCertRequestPolicy, TCertRequestPolicyInputs, TCertRequestRequestData } from "./cert-request-policy-types";
@@ -76,6 +82,16 @@ export const certRequestApprovalResourceFactory = ({
};
},
+ buildTelemetryEvent: async ({ action, request, distinctId, decision }) =>
+ action === ApprovalAuditAction.RequestReviewed
+ ? {
+ event: PostHogEventTypes.PkiApprovalRequestReviewed,
+ distinctId,
+ organizationId: request.organizationId,
+ properties: { decision: decision ?? "", orgId: request.organizationId, projectId: request.projectId }
+ }
+ : null,
+
postApprovalRoutine: async (request) => {
const certReqId = (request.requestData.requestData as TCertRequestRequestData).certificateRequestId;
diff --git a/backend/src/services/approval-policy/code-signing/code-signing-policy-factory.ts b/backend/src/services/approval-policy/code-signing/code-signing-policy-factory.ts
index f81485ec6e..12a04ca806 100644
--- a/backend/src/services/approval-policy/code-signing/code-signing-policy-factory.ts
+++ b/backend/src/services/approval-policy/code-signing/code-signing-policy-factory.ts
@@ -2,9 +2,15 @@ import { getConfig } from "@app/lib/config/env";
import { ms } from "@app/lib/ms";
import { NotificationType } from "@app/services/notification/notification-types";
import { SmtpTemplates } from "@app/services/smtp/smtp-service";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { TApprovalPolicyDALFactory } from "../approval-policy-dal";
-import { ApprovalNotificationEvent, ApprovalPolicyType, ApprovalRequestGrantStatus } from "../approval-policy-enums";
+import {
+ ApprovalAuditAction,
+ ApprovalNotificationEvent,
+ ApprovalPolicyType,
+ ApprovalRequestGrantStatus
+} from "../approval-policy-enums";
import { TApprovalResource } from "../approval-policy-types";
import { TApprovalRequestGrantsDALFactory } from "../approval-request-dal";
import { normalizeCodeSigningScope } from "./code-signing-policy-fns";
@@ -119,6 +125,16 @@ export const codeSigningApprovalResourceFactory = ({
return { valid: errors.length === 0, errors: errors.length > 0 ? errors : undefined };
},
+ buildTelemetryEvent: async ({ action, request, distinctId, decision }) =>
+ action === ApprovalAuditAction.RequestReviewed
+ ? {
+ event: PostHogEventTypes.PkiApprovalRequestReviewed,
+ distinctId,
+ organizationId: request.organizationId,
+ properties: { decision: decision ?? "", orgId: request.organizationId, projectId: request.projectId }
+ }
+ : null,
+
postApprovalTxRoutine: async (request, tx) => {
const requestData = request.requestData.requestData as TCodeSigningRequestData & {
requestedWindowStart?: string;