Skip to content

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

one app connection + input pair per rule

Andrey0d544fc83d05
diff --git a/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts b/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts
index 98756d015d..27c67b37ed 100644
--- a/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts
+++ b/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts
@@ -164,6 +164,7 @@ export const autoApprovalServiceFactory = ({
const rules = config.rules.map((rule) => {
const name = rule.name.trim();
+ const connectionIdByKind = new Map<string, string>();
const conditions = rule.conditions.map((condition) => {
const isRequester = condition.subject === AUTO_APPROVAL_REQUESTER_SUBJECT;
@@ -181,6 +182,15 @@ export const autoApprovalServiceFactory = ({
});
}
+ const kind = `${connection?.app}:${condition.subject}`;
+ const otherConnectionId = connectionIdByKind.get(kind);
+ if (otherConnectionId && otherConnectionId !== condition.connectionId) {
+ throw new BadRequestError({
+ message: `Rule '${name}' checks the ${subject.label} from both '${appByConnectionId.get(otherConnectionId)?.name ?? otherConnectionId}' and '${connectionName}'. A rule can only check the ${subject.label} from one connection.`
+ });
+ }
+ connectionIdByKind.set(kind, condition.connectionId);
+
const constraint = getConstraintDefinition(subject, condition.constraint);
if (!constraint) {
throw new BadRequestError({
diff --git a/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx b/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
index a2e94f62e9..54f0ea9e26 100644
--- a/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
+++ b/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
@@ -29,6 +29,7 @@ import {
AUTO_APPROVAL_LIMITS,
findSubject,
getConditionError,
+ getRecordKind,
getRuleError,
getSubjectDisplayLabel,
getSubjectsMissingCheck,
@@ -222,8 +223,21 @@ export const AutoApprovalRuleCard = ({
}))
];
- // Each check appears once per rule, so the menu only offers the ones not added yet
+ const connectionIdByKind = new Map(
+ rule.conditions.map((condition) => [
+ getRecordKind(catalog, condition.connectionId, condition.subject),
+ condition.connectionId
+ ])
+ );
+
+ // Each check appears once per rule, and a field kind comes from one connection, so the menu skips both
const menuGroups = choices
+ .filter((choice) => {
+ const usedConnectionId = connectionIdByKind.get(
+ getRecordKind(catalog, choice.connectionId, choice.subject)
+ );
+ return !usedConnectionId || usedConnectionId === choice.connectionId;
+ })
.map((choice) => ({
choice,
constraints:
diff --git a/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts b/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
index 66f00cf51a..acfff46005 100644
--- a/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
+++ b/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
@@ -178,12 +178,24 @@ export const getSubjectsMissingCheck = (
});
};
-// A new rule starts single use and bound to the requester for every record the folder asks for
+// A rule checks one connection per kind of record, so its conditions on the same field kind share a connection
+export const getRecordKind = (
+ catalog: TAutoApprovalCatalogConnection[] | undefined,
+ connectionId: string,
+ subjectId: string
+) => `${findSubject(catalog, connectionId, subjectId).connection?.app}:${subjectId}`;
+
+// A new rule starts single use and bound to the requester for each kind of record the folder asks for
export const getDefaultRuleConditions = (
inputs: TAutoApprovalDraft["inputs"],
catalog: TAutoApprovalCatalogConnection[] | undefined
-): TDraftCondition[] =>
- inputs.flatMap(({ connectionId, subject: subjectId }) => {
+): TDraftCondition[] => {
+ const seenKinds = new Set<string>();
+ return inputs.flatMap(({ connectionId, subject: subjectId }) => {
+ const kind = getRecordKind(catalog, connectionId, subjectId);
+ if (seenKinds.has(kind)) return [];
+ seenKinds.add(kind);
+
const { subject } = findSubject(catalog, connectionId, subjectId);
return [UNUSED_CONSTRAINT, ASSIGNED_TO_REQUESTER_CONSTRAINT]
.filter((constraintId) =>
@@ -197,3 +209,4 @@ export const getDefaultRuleConditions = (
values: []
}));
});
+};