Skip to content

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

refactor decision maps on factory

adilson266e2379eba9
diff --git a/CLAUDE.md b/CLAUDE.md
index 0249da637f..47fad38e93 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -230,7 +230,9 @@ paths: removing a member reaps only the privileges that already exist, so one wr
effect if the user were ever added back. Every outcome is audited as
`ACCESS_APPROVAL_REQUEST_DELEGATED_DECISION` with the `PLATFORM` actor, and
product notifications (the access request webhook) go through `decisionNotifiers`, never through the
-consumer itself. ServiceNow stamps an immutable `decision` on its record before it posts the callback, so
+consumer itself. A new delegated policy type adds its `postApprovalTxRoutine` and decision notifier in
+`delegatedApprovalDecisionMapsFactory`, the same way dispatch details get a builder in
+`DELEGATED_APPROVAL_DISPATCH_DETAILS_BUILDER_MAP`. ServiceNow stamps an immutable `decision` on its record before it posts the callback, so
the provider reads that field alone and ignores `state`.
### Object Storage
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 461d807ade..d1c299b417 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -361,6 +361,7 @@ import { delegatedApprovalServiceFactory } from "@app/services/delegated-approva
import { delegatedApprovalDispatchConsumerFactory } from "@app/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer";
import { delegatedApprovalCallbackServiceFactory } from "@app/services/delegated-approval-callback/delegated-approval-callback-service";
import { delegatedApprovalDecisionConsumerFactory } from "@app/services/delegated-approval-decision/delegated-approval-decision-consumer";
+import { delegatedApprovalDecisionMapsFactory } from "@app/services/delegated-approval-decision/delegated-approval-decision-maps";
import { delegatedApprovalDecisionServiceFactory } from "@app/services/delegated-approval-decision/delegated-approval-decision-service";
import { encryptionKeyRotationServiceFactory } from "@app/services/encryption-key-rotation/encryption-key-rotation-service";
import { acmeEnrollmentConfigDALFactory } from "@app/services/enrollment-config/acme-enrollment-config-dal";
@@ -3298,6 +3299,11 @@ export const registerRoutes = async (
secretAccessApprovalGlobalResource
});
+ const delegatedApprovalDecisionMaps = delegatedApprovalDecisionMapsFactory({
+ secretAccessApprovalGlobalResource,
+ secretAccessApprovalGlobalRequestBridgeService
+ });
+
const delegatedApprovalDecisionService = delegatedApprovalDecisionServiceFactory({
delegatedApprovalRequestDAL,
delegatedApprovalPolicyDAL,
@@ -3307,12 +3313,7 @@ export const registerRoutes = async (
membershipDAL,
kmsService,
auditLogService,
- approvalResources: { [ApprovalPolicyType.SecretAccess]: secretAccessApprovalGlobalResource },
- decisionNotifiers: {
- // maybe we can have it in a better place
- [ApprovalPolicyType.SecretAccess]: ({ approvalRequestId }) =>
- secretAccessApprovalGlobalRequestBridgeService.notifyDelegatedDecision({ requestId: approvalRequestId })
- }
+ ...delegatedApprovalDecisionMaps
});
eventOutboxRegistry.register(delegatedApprovalDecisionConsumerFactory({ delegatedApprovalDecisionService }));
diff --git a/backend/src/services/delegated-approval-decision/delegated-approval-decision-maps.ts b/backend/src/services/delegated-approval-decision/delegated-approval-decision-maps.ts
new file mode 100644
index 0000000000..0861c9db3b
--- /dev/null
+++ b/backend/src/services/delegated-approval-decision/delegated-approval-decision-maps.ts
@@ -0,0 +1,31 @@
+import { ApprovalPolicyType } from "@app/services/approval-policy/approval-policy-enums";
+import { TApprovalResource } from "@app/services/approval-policy/approval-policy-types";
+import { TSecretAccessApprovalGlobalResource } from "@app/services/approval-policy/secret-access/secret-access-policy-factory";
+import { DelegatedApprovalSupportedPolicyType } from "@app/services/delegated-approval/delegated-approval-maps";
+import { TSecretAccessApprovalGlobalRequestBridgeServiceFactory } from "@app/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service";
+
+import { TDelegatedApprovalDecisionNotifier } from "./delegated-approval-decision-types";
+
+type TDelegatedApprovalDecisionMapsFactoryDep = {
+ secretAccessApprovalGlobalResource: Pick<TSecretAccessApprovalGlobalResource, "postApprovalTxRoutine">;
+ secretAccessApprovalGlobalRequestBridgeService: Pick<
+ TSecretAccessApprovalGlobalRequestBridgeServiceFactory,
+ "notifyDelegatedDecision"
+ >;
+};
+
+export const delegatedApprovalDecisionMapsFactory = ({
+ secretAccessApprovalGlobalResource,
+ secretAccessApprovalGlobalRequestBridgeService
+}: TDelegatedApprovalDecisionMapsFactoryDep) => {
+ const approvalResources = {
+ [ApprovalPolicyType.SecretAccess]: secretAccessApprovalGlobalResource
+ } satisfies Record<DelegatedApprovalSupportedPolicyType, Pick<TApprovalResource, "postApprovalTxRoutine">>;
+
+ const decisionNotifiers = {
+ [ApprovalPolicyType.SecretAccess]: ({ approvalRequestId }) =>
+ secretAccessApprovalGlobalRequestBridgeService.notifyDelegatedDecision({ requestId: approvalRequestId })
+ } satisfies Record<DelegatedApprovalSupportedPolicyType, TDelegatedApprovalDecisionNotifier>;
+
+ return { approvalResources, decisionNotifiers };
+};
diff --git a/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts b/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
index d99e9d815a..0a73787822 100644
--- a/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
+++ b/backend/src/services/delegated-approval-decision/delegated-approval-decision-service.ts
@@ -409,19 +409,17 @@ export const delegatedApprovalDecisionServiceFactory = ({
);
return $retryLater(delegatedRequestId, message, isFinalAttempt);
}
- if (finalized.kind === "applied") {
- const notify = isDelegatedApprovalSupportedPolicyType(approvalRequest.type)
- ? decisionNotifiers[approvalRequest.type]
- : undefined;
- if (notify) {
- try {
- await notify({ approvalRequestId: approvalRequest.id, decision: decided.decision });
- } catch (error) {
- logger.error(
- error,
- `Failed to notify about the delegated approval decision [delegatedRequestId=${delegatedRequestId}] [approvalRequestId=${approvalRequest.id}]`
- );
- }
+ if (finalized.kind === "applied" && isDelegatedApprovalSupportedPolicyType(approvalRequest.type)) {
+ try {
+ await decisionNotifiers[approvalRequest.type]({
+ approvalRequestId: approvalRequest.id,
+ decision: decided.decision
+ });
+ } catch (error) {
+ logger.error(
+ error,
+ `Failed to notify about the delegated approval decision [delegatedRequestId=${delegatedRequestId}] [approvalRequestId=${approvalRequest.id}]`
+ );
}
}
return { status: EventResultStatus.Delivered };
diff --git a/backend/src/services/delegated-approval-decision/delegated-approval-decision-types.ts b/backend/src/services/delegated-approval-decision/delegated-approval-decision-types.ts
index 921bb201aa..7740c356b7 100644
--- a/backend/src/services/delegated-approval-decision/delegated-approval-decision-types.ts
+++ b/backend/src/services/delegated-approval-decision/delegated-approval-decision-types.ts
@@ -60,7 +60,7 @@ export type TDelegatedApprovalDecisionServiceFactoryDep = {
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
approvalResources: Record<DelegatedApprovalSupportedPolicyType, Pick<TApprovalResource, "postApprovalTxRoutine">>;
- decisionNotifiers: Partial<Record<DelegatedApprovalSupportedPolicyType, TDelegatedApprovalDecisionNotifier>>;
+ decisionNotifiers: Record<DelegatedApprovalSupportedPolicyType, TDelegatedApprovalDecisionNotifier>;
};
export type TDelegatedApprovalDecisionContext = {
diff --git a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-constants.ts b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-constants.ts
index 557216ed88..51bfb7a392 100644
--- a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-constants.ts
+++ b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-constants.ts
@@ -2,4 +2,4 @@ export const DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS = 1_000;
export const DELEGATED_APPROVAL_PROVIDER_RECORD_NUMBER_MAX_CHARS = 64;
export const DELEGATED_APPROVAL_DISPATCH_RETRY_HINT =
- "Infisical will retry automatically. If it keeps failing, send the request again.";
+ "Infisical will retry automatically. If it keeps failing, go into your external approval service and send the approval decision again.";