Skip to content

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

bot reviews

Andrey90919fb0a065
diff --git a/backend/src/db/migrations/20260928120000_approval-policies-unique-pam-folder-scope.ts b/backend/src/db/migrations/20260928120000_approval-policies-unique-pam-folder-scope.ts
index 8ba46f5cc2..e748b4f2b0 100644
--- a/backend/src/db/migrations/20260928120000_approval-policies-unique-pam-folder-scope.ts
+++ b/backend/src/db/migrations/20260928120000_approval-policies-unique-pam-folder-scope.ts
@@ -12,25 +12,32 @@ export async function up(knex: Knex): Promise<void> {
.select("id", "scopeType", "scopeId", "createdAt")
.orderBy([{ column: "scopeId" }, { column: "createdAt" }]);
- const seen = new Set<string>();
- const staleIds: string[] = [];
+ const survivorByScope = new Map<string, string>();
+ const stale: { id: string; survivorId: string }[] = [];
for (const policy of duplicates) {
const key = `${policy.scopeType as string}:${policy.scopeId as string}`;
- if (seen.has(key)) staleIds.push(policy.id);
- else seen.add(key);
+ const survivorId = survivorByScope.get(key);
+ if (survivorId) stale.push({ id: policy.id, survivorId });
+ else survivorByScope.set(key, policy.id);
}
- if (staleIds.length > 0) {
- await knex(TableName.ApprovalRequests)
- .whereIn("policyId", staleIds)
- .where("status", "pending")
- .update({ status: "cancelled" });
- await knex(TableName.ApprovalPolicies).whereIn("id", staleIds).delete();
+ for (const { id, survivorId } of stale) {
+ // eslint-disable-next-line no-await-in-loop
+ await knex(TableName.ApprovalRequests).where("policyId", id).update({ policyId: survivorId });
+ }
+
+ if (stale.length > 0) {
+ await knex(TableName.ApprovalPolicies)
+ .whereIn(
+ "id",
+ stale.map((s) => s.id)
+ )
+ .delete();
}
await knex.raw(
- `CREATE UNIQUE INDEX IF NOT EXISTS ?? ON ?? ("scopeType", "scopeId") WHERE type = ? AND "scopeId" IS NOT NULL`,
- [INDEX_NAME, TableName.ApprovalPolicies, PAM_ACCESS]
+ `CREATE UNIQUE INDEX IF NOT EXISTS ?? ON ?? ("scopeType", "scopeId") WHERE type = '${PAM_ACCESS}' AND "scopeId" IS NOT NULL`,
+ [INDEX_NAME, TableName.ApprovalPolicies]
);
}
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 d69e809b29..a5595dac15 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
@@ -1063,6 +1063,7 @@ export const pamAccessApprovalResourceFactory = ({
assertCanManagePolicy,
canReadScope,
singlePolicyPerScope: true,
+ scopeType: ApprovalPolicyScope.PamFolder,
verifyPolicyActors,
assertCanCreateRequest,
assertCanReview,
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index 0f5b664102..d4480ba283 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -306,8 +306,13 @@ export const approvalPolicyServiceFactory = ({
const resolveDomainScope = resources[policyType]?.resolveScope;
if (resolveDomainScope) {
+ const expectedScope = resources[policyType]?.scopeType;
+ if (expectedScope && scope !== expectedScope) {
+ throw new BadRequestError({ message: `${policyType} policies must use the ${expectedScope} scope` });
+ }
+
const { projectId } = await resolveDomainScope(scopeId);
- return { projectId, scopeType: scope, scopeId };
+ return { projectId, scopeType: expectedScope ?? scope, scopeId };
}
throw new BadRequestError({ message: `Unsupported scope: ${String(scope)}` });
@@ -1601,6 +1606,15 @@ export const approvalPolicyServiceFactory = ({
const userGroupIds = await ctx.getUserGroupIds();
+ const checkLiveApprover = resources[policyType]?.isLiveApprover;
+ if (
+ checkLiveApprover &&
+ dbScopeId &&
+ !(await checkLiveApprover({ projectId, scopeId: dbScopeId, actor, userGroupIds }))
+ ) {
+ return requests.filter((request) => $isRequester(request, actor));
+ }
+
return requests.filter((request) => {
if ($isRequester(request, actor)) return true;
return request.steps.some((step) =>
diff --git a/backend/src/services/approval-policy/approval-policy-types.ts b/backend/src/services/approval-policy/approval-policy-types.ts
index 9d7535ec47..61b0ba933e 100644
--- a/backend/src/services/approval-policy/approval-policy-types.ts
+++ b/backend/src/services/approval-policy/approval-policy-types.ts
@@ -242,6 +242,9 @@ export type TApprovalResource<
// Set where a scope may carry at most one policy, so creating a second is refused rather than ignored.
singlePolicyPerScope?: boolean;
+
+ // The only scope this type's policies may be created against, paired with resolveScope.
+ scopeType?: ApprovalPolicyScope;
verifyPolicyActors?: (args: {
projectId: string;
scopeId: string | null;