Skip to content

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

PR comments

Matheus Nogueiraf15e5b257deb
diff --git a/backend/src/ee/services/secret-approval-policy/secret-approval-policy-fns.ts b/backend/src/ee/services/secret-approval-policy/secret-approval-policy-fns.ts
index bc33d90f04..309cf11910 100644
--- a/backend/src/ee/services/secret-approval-policy/secret-approval-policy-fns.ts
+++ b/backend/src/ee/services/secret-approval-policy/secret-approval-policy-fns.ts
@@ -6,15 +6,26 @@ import { ActorType } from "@app/services/auth/auth-type";
* Returns `false` (skip enforcement) when:
* 1. No policy exists for the path/env (`policy` is `undefined`)
* 2. The actor is a machine identity and the policy allows bypass
+ * 3. The actor is neither a USER nor an IDENTITY (e.g. PLATFORM, SCIM_CLIENT)
*
* Acts as a TypeScript type guard: when it returns `true`, downstream code
* can safely access `policy.id`, `policy.name`, etc.
*/
+/**
+ * Returns the committer ID fields for a secret approval request,
+ * setting the appropriate field based on the actor type.
+ */
+export const getCommitterIds = (actor: ActorType, actorId: string) => ({
+ committerUserId: actor === ActorType.USER ? actorId : undefined,
+ committerIdentityId: actor === ActorType.IDENTITY ? actorId : undefined
+});
+
export const shouldApplyPolicy = <T extends { bypassForMachineIdentities: boolean }>(
policy: T | undefined,
actorType: ActorType
): policy is T => {
if (!policy) return false;
if (actorType === ActorType.IDENTITY && policy.bypassForMachineIdentities) return false;
+ if (actorType !== ActorType.USER && actorType !== ActorType.IDENTITY) return false;
return true;
};
diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts
index f996273b90..d9db0827d3 100644
--- a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts
+++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts
@@ -86,6 +86,7 @@ import {
} from "../permission/project-permission";
import { ProjectEvents, TProjectEventPayload } from "../project-events/project-events-types";
import { TSecretApprovalPolicyDALFactory } from "../secret-approval-policy/secret-approval-policy-dal";
+import { getCommitterIds } from "../secret-approval-policy/secret-approval-policy-fns";
import { scanSecretPolicyViolations } from "../secret-scanning-v2/secret-scanning-v2-fns";
import { TSecretApprovalRequestDALFactory } from "./secret-approval-request-dal";
import { hasSecretUpdateCommitConflict, sendApprovalEmailsFn } from "./secret-approval-request-fns";
@@ -328,6 +329,7 @@ export const secretApprovalRequestServiceFactory = ({
!canReadApprovalRequests &&
!hasRole(ProjectMembershipRole.Admin) &&
secretApprovalRequest.committerUserId !== actorId &&
+ secretApprovalRequest.committerIdentityId !== actorId &&
!policy.approvers.find(({ userId }) => userId === actorId)
) {
throw new ForbiddenRequestError({ message: "User has insufficient privileges" });
@@ -1616,7 +1618,7 @@ export const secretApprovalRequestServiceFactory = ({
policyId: policy.id,
status: "open",
hasMerged: false,
- ...(actor === ActorType.IDENTITY ? { committerIdentityId: actorId } : { committerUserId: actorId })
+ ...getCommitterIds(actor, actorId)
},
tx
);
@@ -1712,7 +1714,8 @@ export const secretApprovalRequestServiceFactory = ({
notification: {
type: TriggerFeature.SECRET_APPROVAL,
payload: {
- userEmail: user?.email ?? "machine-identity",
+ userEmail: user?.email ?? undefined,
+ machineIdentityId: actorId,
environment: env.name,
secretPath,
projectId,
@@ -1752,7 +1755,8 @@ export const secretApprovalRequestServiceFactory = ({
projectId,
environment,
secretPath,
- numberOfCommits: commits.length
+ numberOfCommits: commits.length,
+ actorType: actor as string
}
})
.catch(() => {});
@@ -2133,7 +2137,7 @@ export const secretApprovalRequestServiceFactory = ({
policyId: policy.id,
status: "open",
hasMerged: false,
- ...(actor === ActorType.IDENTITY ? { committerIdentityId: actorId } : { committerUserId: actorId }),
+ ...getCommitterIds(actor, actorId),
commitMessage
},
tx
@@ -2251,7 +2255,8 @@ export const secretApprovalRequestServiceFactory = ({
projectId,
environment,
secretPath,
- numberOfCommits: commits.length
+ numberOfCommits: commits.length,
+ actorType: actor as string
}
})
.catch(() => {});
diff --git a/backend/src/ee/services/secret-replication/secret-replication-service.ts b/backend/src/ee/services/secret-replication/secret-replication-service.ts
index 79367392a1..8f7cb70616 100644
--- a/backend/src/ee/services/secret-replication/secret-replication-service.ts
+++ b/backend/src/ee/services/secret-replication/secret-replication-service.ts
@@ -1,6 +1,6 @@
import { SecretType, TSecrets, TSecretsV2 } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
-import { shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
+import { getCommitterIds, shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
import { TSecretApprovalPolicyServiceFactory } from "@app/ee/services/secret-approval-policy/secret-approval-policy-service";
import { TSecretApprovalRequestDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-dal";
import { TSecretApprovalRequestSecretDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-secret-dal";
@@ -466,7 +466,7 @@ export const secretReplicationServiceFactory = ({
policyId: policy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId,
+ ...getCommitterIds(actor, actorId),
isReplicated: true
},
tx
@@ -729,7 +729,7 @@ export const secretReplicationServiceFactory = ({
destinationFolder.path
);
// this means it should be a approval request rather than direct replication
- if (policy && actor === ActorType.USER) {
+ if (shouldApplyPolicy(policy, actor)) {
const localSecretsLatestVersions = destinationLocalSecrets.map(({ id }) => id);
const latestSecretVersions = await secretVersionDAL.findLatestVersionMany(
destinationReplicationFolderId,
@@ -743,7 +743,7 @@ export const secretReplicationServiceFactory = ({
policyId: policy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId,
+ ...getCommitterIds(actor, actorId),
isReplicated: true
},
tx
diff --git a/backend/src/lib/workflow-integrations/types.ts b/backend/src/lib/workflow-integrations/types.ts
index e155f5c0b2..9932088906 100644
--- a/backend/src/lib/workflow-integrations/types.ts
+++ b/backend/src/lib/workflow-integrations/types.ts
@@ -18,7 +18,8 @@ export type TNotification =
| {
type: TriggerFeature.SECRET_APPROVAL;
payload: {
- userEmail: string;
+ userEmail?: string;
+ machineIdentityId?: string;
environment: string;
secretPath: string;
requestId: string;
diff --git a/backend/src/services/microsoft-teams/microsoft-teams-fns.ts b/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
index 21a91c9b36..280e33dd4e 100644
--- a/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
+++ b/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
@@ -364,6 +364,7 @@ export const buildTeamsPayload = (orgId: string, notification: TNotification) =>
switch (notification.type) {
case TriggerFeature.SECRET_APPROVAL: {
const { payload } = notification;
+ const author = payload.machineIdentityId ? `machine identity ${payload.machineIdentityId}` : (payload.userEmail ?? "unknown");
const adaptiveCard = {
type: "AdaptiveCard",
@@ -378,7 +379,7 @@ export const buildTeamsPayload = (orgId: string, notification: TNotification) =>
},
{
type: "TextBlock",
- text: `A secret approval request has been opened by ${payload.userEmail}.`,
+ text: `A secret approval request has been opened by ${author}.`,
wrap: true
},
{
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
index 6dbbb4871f..54abdd0555 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
@@ -15,7 +15,7 @@ import {
} from "@app/db/schemas";
import { throwIfMissingSecretReadValueOrDescribePermission } from "@app/ee/services/permission/permission-fns";
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
-import { shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
+import { getCommitterIds, shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
import {
InternalMetadataType,
TInternalMetadata
@@ -1718,7 +1718,7 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes
policyId: destinationFolderPolicy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId
+ ...getCommitterIds(actor, actorId)
},
tx
);
@@ -1920,7 +1920,7 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes
policyId: sourceFolderPolicy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId
+ ...getCommitterIds(actor, actorId)
},
tx
);
diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.ts
index e674089055..9d2375fb38 100644
--- a/backend/src/services/secret/secret-service.ts
+++ b/backend/src/services/secret/secret-service.ts
@@ -24,7 +24,7 @@ import {
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { ProjectEvents, TProjectEventPayload } from "@app/ee/services/project-events/project-events-types";
-import { shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
+import { getCommitterIds, shouldApplyPolicy } from "@app/ee/services/secret-approval-policy/secret-approval-policy-fns";
import { TSecretApprovalPolicyServiceFactory } from "@app/ee/services/secret-approval-policy/secret-approval-policy-service";
import { TSecretApprovalRequestDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-dal";
import { TSecretApprovalRequestSecretDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-secret-dal";
@@ -3183,7 +3183,7 @@ export const secretServiceFactory = ({
policyId: destinationFolderPolicy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId
+ ...getCommitterIds(actor, actorId)
},
tx
);
@@ -3308,7 +3308,7 @@ export const secretServiceFactory = ({
policyId: sourceFolderPolicy.id,
status: "open",
hasMerged: false,
- committerUserId: actorId
+ ...getCommitterIds(actor, actorId)
},
tx
);
diff --git a/backend/src/services/slack/slack-fns.ts b/backend/src/services/slack/slack-fns.ts
index e5836fbe61..a351453a50 100644
--- a/backend/src/services/slack/slack-fns.ts
+++ b/backend/src/services/slack/slack-fns.ts
@@ -53,7 +53,8 @@ const buildSlackPayload = (notification: TNotification) => {
switch (notification.type) {
case TriggerFeature.SECRET_APPROVAL: {
const { payload } = notification;
- const messageBody = `A secret approval request has been opened by ${payload.userEmail}.
+ const author = payload.machineIdentityId ? `machine identity ${payload.machineIdentityId}` : (payload.userEmail ?? "unknown");
+ const messageBody = `A secret approval request has been opened by ${author}.
*Project*: ${payload.projectName}
*Environment*: ${payload.environment}
*Secret path*: ${payload.secretPath || "/"}
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index 0a09eb5843..49539720fd 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -768,6 +768,7 @@ export type TSecretApprovalRequestSubmittedEvent = {
environment: string;
secretPath: string;
numberOfCommits: number;
+ actorType: string;
};
};