Skip to content

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

add 2 essential conditions by default + new warning

Andrey62511f302ad2
diff --git a/docs/documentation/platform/pam/access-requests/auto-approval.mdx b/docs/documentation/platform/pam/access-requests/auto-approval.mdx
index c6b97b1d4b..fc1867f78e 100644
--- a/docs/documentation/platform/pam/access-requests/auto-approval.mdx
+++ b/docs/documentation/platform/pam/access-requests/auto-approval.mdx
@@ -61,7 +61,7 @@ To add rules:
In the **Auto-Approval** card, under **Request Information**, select **Add Field** and choose the record to ask for, such as **Jira ticket** for your Jira connection.
</Step>
<Step>
- Under **Rules**, select **Add Rule**, then replace the rule's default name with one that describes what the rule checks, such as `Approved change ticket`. Approvers see this name on every request the rule approves.
+ Under **Rules**, select **Add Rule**, then replace the rule's default name with one that describes what the rule checks, such as `Approved change ticket`. Approvers see this name on every request the rule approves. A new rule starts with the **hasn't been used before** and **is assigned to the requester** checks on each record the folder asks for.
</Step>
<Step>
Select **Add Condition** and choose a [check](#checks), such as **Jira ticket has status**, then choose its values if it takes any.
@@ -76,7 +76,7 @@ To add rules:
Each condition runs one check on a linked record, and the checks available depend on the record's service. If a check takes values, the record passes when it matches any of them.
<Warning>
- If a record has an **is assigned to the requester** check, add that check to every rule that checks the record. Without it, a requester can link a record that belongs to someone else and still pass the rule.
+ If a record has an **is assigned to the requester** check, add that check to every rule that checks the record. Without it, a requester can link a record that belongs to someone else and still pass the rule. Keep the **hasn't been used before** check too. Without it, one approved record can grant access any number of times.
</Warning>
Every linked record also has a **hasn't been used before** check. It passes only if no earlier approved request in the folder linked the same record. Use it when one approval in the other service should grant access only once.
diff --git a/frontend/src/pages/pam/components/auto-approval/AutoApprovalCard.tsx b/frontend/src/pages/pam/components/auto-approval/AutoApprovalCard.tsx
index 5cfe270c99..466cfcc6fd 100644
--- a/frontend/src/pages/pam/components/auto-approval/AutoApprovalCard.tsx
+++ b/frontend/src/pages/pam/components/auto-approval/AutoApprovalCard.tsx
@@ -28,7 +28,12 @@ import {
ApprovalPolicyType
} from "@app/hooks/api/approvalPolicies";
-import { findSubject, newKey, TAutoApprovalDraft } from "./autoApprovalDraft";
+import {
+ findSubject,
+ getDefaultRuleConditions,
+ newKey,
+ TAutoApprovalDraft
+} from "./autoApprovalDraft";
import { DisabledReason, SectionLabel } from "./AutoApprovalLabels";
import { AutoApprovalRuleCard } from "./AutoApprovalRuleCard";
@@ -92,7 +97,11 @@ export const AutoApprovalCard = ({
...draft,
rules: [
...draft.rules,
- { key: newKey(), name: `Rule ${draft.rules.length + 1}`, conditions: [] }
+ {
+ key: newKey(),
+ name: `Rule ${draft.rules.length + 1}`,
+ conditions: getDefaultRuleConditions(draft.inputs, catalog)
+ }
]
});
diff --git a/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx b/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
index e329f63592..6c3c488165 100644
--- a/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
+++ b/frontend/src/pages/pam/components/auto-approval/AutoApprovalRuleCard.tsx
@@ -26,11 +26,12 @@ import {
findSubject,
getConditionError,
getRuleError,
- getUnboundInputSubjects,
+ getSubjectsMissingCheck,
newKey,
TAutoApprovalDraft,
TDraftCondition,
- TDraftRule
+ TDraftRule,
+ UNUSED_CONSTRAINT
} from "./autoApprovalDraft";
import { DisabledReason, SectionLabel } from "./AutoApprovalLabels";
import { AutoApprovalValuePicker } from "./AutoApprovalValuePicker";
@@ -179,7 +180,22 @@ export const AutoApprovalRuleCard = ({
}: Props) => {
const choices = getSubjectChoices(inputs, catalog);
const ruleError = showErrors ? getRuleError(rule, catalog) : null;
- const unbound = getUnboundInputSubjects(rule, catalog);
+ const missingChecks = [
+ ...getSubjectsMissingCheck(rule, catalog, ASSIGNED_TO_REQUESTER_CONSTRAINT).map(
+ (condition) => ({
+ condition,
+ constraint: ASSIGNED_TO_REQUESTER_CONSTRAINT,
+ message: (label: string) => `Anyone could link someone else's ${label}.`,
+ action: "Add assignee check"
+ })
+ ),
+ ...getSubjectsMissingCheck(rule, catalog, UNUSED_CONSTRAINT).map((condition) => ({
+ condition,
+ constraint: UNUSED_CONSTRAINT,
+ message: (label: string) => `The same ${label} can be reused for any number of requests.`,
+ action: "Add reuse check"
+ }))
+ ];
// Each check appears once per rule, so the menu only offers the ones not added yet
const menuGroups = choices
@@ -277,17 +293,15 @@ export const AutoApprovalRuleCard = ({
</div>
)}
- {unbound.map((condition) => {
+ {missingChecks.map(({ condition, constraint, message, action }) => {
const { subject } = findSubject(catalog, condition.connectionId, condition.subject);
return (
<div
- key={`${condition.connectionId}:${condition.subject}`}
- className="flex max-w-full items-center gap-2 rounded-md border border-warning/20 bg-warning/5 px-2.5 py-1.5 text-xs"
+ key={`${condition.connectionId}:${condition.subject}:${constraint}`}
+ className="flex w-full items-center gap-2 rounded-md border border-warning/20 bg-warning/5 px-2.5 py-1.5 text-xs"
>
<ShieldAlert className="size-3.5 shrink-0 text-warning" />
- <span className="text-muted">
- Anyone could link someone else&apos;s {subject?.label ?? "record"}.
- </span>
+ <span className="flex-1 text-muted">{message(subject?.label ?? "record")}</span>
<Button
type="button"
variant="text"
@@ -297,11 +311,11 @@ export const AutoApprovalRuleCard = ({
addCondition({
connectionId: condition.connectionId,
subject: condition.subject,
- constraint: ASSIGNED_TO_REQUESTER_CONSTRAINT
+ constraint
})
}
>
- Add assignee check
+ {action}
</Button>
</div>
);
diff --git a/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts b/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
index 112498ccc1..86ebad26d4 100644
--- a/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
+++ b/frontend/src/pages/pam/components/auto-approval/autoApprovalDraft.ts
@@ -26,6 +26,9 @@ export type TAutoApprovalDraft = {
// Mirrors the Jira provider's constraint; other providers name theirs the same way
export const ASSIGNED_TO_REQUESTER_CONSTRAINT = "assigned-to-requester";
+// Mirrors the reuse check the engine adds to every record a requester links
+export const UNUSED_CONSTRAINT = "not-used-before";
+
export const newKey = () => crypto.randomUUID();
export const EMPTY_AUTO_APPROVAL_DRAFT: TAutoApprovalDraft = { inputs: [], rules: [] };
@@ -112,10 +115,11 @@ export const getRuleError = (
: null;
};
-// A ticket condition without an assignee check lets anyone link someone else's approved ticket
-export const getUnboundInputSubjects = (
+// The rule checks a record without this check, like an assignee check or the reuse check
+export const getSubjectsMissingCheck = (
rule: TDraftRule,
- catalog: TAutoApprovalCatalogConnection[] | undefined
+ catalog: TAutoApprovalCatalogConnection[] | undefined,
+ constraintId: string
) => {
const linked = new Map<string, TDraftCondition>();
rule.conditions
@@ -126,17 +130,35 @@ export const getUnboundInputSubjects = (
return [...linked.values()].filter((condition) => {
const { subject } = findSubject(catalog, condition.connectionId, condition.subject);
- const offersAssigneeCheck = subject?.constraints.some(
- (constraint) => constraint.id === ASSIGNED_TO_REQUESTER_CONSTRAINT
- );
+ const offersCheck = subject?.constraints.some((constraint) => constraint.id === constraintId);
return (
- offersAssigneeCheck &&
+ offersCheck &&
!rule.conditions.some(
(other) =>
other.connectionId === condition.connectionId &&
other.subject === condition.subject &&
- other.constraint === ASSIGNED_TO_REQUESTER_CONSTRAINT
+ other.constraint === constraintId
)
);
});
};
+
+// A new rule starts single use and bound to the requester for every record the folder asks for
+export const getDefaultRuleConditions = (
+ inputs: TAutoApprovalDraft["inputs"],
+ catalog: TAutoApprovalCatalogConnection[] | undefined
+): TDraftCondition[] =>
+ inputs.flatMap(({ connectionId, subject: subjectId }) => {
+ const { subject } = findSubject(catalog, connectionId, subjectId);
+ return [UNUSED_CONSTRAINT, ASSIGNED_TO_REQUESTER_CONSTRAINT]
+ .filter((constraintId) =>
+ subject?.constraints.some((constraint) => constraint.id === constraintId)
+ )
+ .map((constraint) => ({
+ key: newKey(),
+ connectionId,
+ subject: subjectId,
+ constraint,
+ values: []
+ }));
+ });