Skip to content

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

improve UX when missing grant

Thiago Araujo da Silvafff1e88747f5
diff --git a/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts b/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
index 89ccb445a0..390a98e479 100644
--- a/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
+++ b/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
@@ -298,17 +298,18 @@ describe("Privilege boundary on org membership downgrade", () => {
asIdentity(actor.token)
);
expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("more privileged org member");
+ expect(res.json().message).toContain("Failed to change the roles or attributes of this org member");
});
- test("deactivating a more privileged member follows the removal boundary", async () => {
- // Deactivation keys on member:delete, so it lands where a removal lands rather than where a role
- // change does. Own target, because it succeeds on one of the two runs.
+ test("deactivating a more privileged member is bounded on the legacy system only", async () => {
+ // Deactivation keys on member:edit, which the route's own permission check already demanded, so
+ // the new system has nothing further to ask. Own target, because it succeeds on one of the two runs.
const target = await createAdminTarget();
const res = await patchMembership(target.membershipId, { isActive: false }, asIdentity(actor.token));
expect(res.statusCode).toBe(newSystem ? 200 : 403);
- if (!newSystem) expect(res.json().message).toContain("more privileged org member");
+ if (!newSystem)
+ expect(res.json().message).toContain("Failed to change the activation status of this org member");
});
});
diff --git a/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts b/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
index 5a5d165327..d72e08c394 100644
--- a/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
+++ b/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
@@ -362,13 +362,13 @@ describe("Privilege boundary on org membership removal", () => {
test("a member:delete-only role cannot remove an org Admin", async () => {
const res = await deleteOrgMembership(adminTarget.membershipId, asIdentity(actor.token));
expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("more privileged member");
+ expect(res.json().message).toContain("Failed to remove this member from the organization");
});
test("the bulk route is bounded too, so it is not a way around the single-member route", async () => {
const res = await bulkDeleteOrgMemberships([adminTarget.membershipId], asIdentity(actor.token));
expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("more privileged member");
+ expect(res.json().message).toContain("Failed to remove this member from the organization");
});
test("an admin can still remove an org Admin", async () => {
diff --git a/backend/src/services/membership-user/org/org-membership-user-factory.ts b/backend/src/services/membership-user/org/org-membership-user-factory.ts
index 361664279d..278fe26dd6 100644
--- a/backend/src/services/membership-user/org/org-membership-user-factory.ts
+++ b/backend/src/services/membership-user/org/org-membership-user-factory.ts
@@ -125,7 +125,7 @@ export const newOrgMembershipUserFactory = ({
opSubject: OrgPermissionSubjects.Member,
actorPermission: permission,
targetPermissions: permissionRoles,
- baseMessage: "Cannot grant a role exceeding your own privileges to a new org member"
+ baseMessage: "Failed to assign the requested role to a new org member"
});
}
@@ -343,12 +343,12 @@ export const newOrgMembershipUserFactory = ({
if (dto.data.roles.length || dto.data.metadata !== undefined)
targetOps.push({
opAction: OrgPermissionMemberActions.GrantPrivileges,
- baseMessage: "Failed to change the roles or attributes of a more privileged org member"
+ baseMessage: "Failed to change the roles or attributes of this org member"
});
if (dto.data.isActive !== undefined)
targetOps.push({
opAction: OrgPermissionMemberActions.Edit,
- baseMessage: "Failed to change the activation status of a more privileged org member"
+ baseMessage: "Failed to change the activation status of this org member"
});
if (targetOps.length) {
@@ -386,7 +386,7 @@ export const newOrgMembershipUserFactory = ({
opSubject: OrgPermissionSubjects.Member,
actorPermission: permission,
targetPermissions: permissionRoles,
- baseMessage: "Cannot grant a role exceeding your own privileges to an existing org member"
+ baseMessage: "Failed to assign the requested role to an existing org member"
});
}
};
@@ -421,7 +421,7 @@ export const newOrgMembershipUserFactory = ({
opSubject: OrgPermissionSubjects.Member,
actorPermission: permission,
targetPermissions,
- baseMessage: "Failed to remove a more privileged member from the organization"
+ baseMessage: "Failed to remove this member from the organization"
});
};
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 4581018a37..dab663ff5e 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -875,12 +875,12 @@ export const orgServiceFactory = ({
if (role !== undefined || metadata !== undefined)
targetOps.push({
opAction: OrgPermissionMemberActions.GrantPrivileges,
- baseMessage: "Failed to change the roles or attributes of a more privileged org member"
+ baseMessage: "Failed to change the roles or attributes of this org member"
});
if (isActive !== undefined)
targetOps.push({
opAction: OrgPermissionMemberActions.Edit,
- baseMessage: "Failed to change the activation status of a more privileged org member"
+ baseMessage: "Failed to change the activation status of this org member"
});
if (targetOps.length) {
@@ -926,7 +926,7 @@ export const orgServiceFactory = ({
opSubject: OrgPermissionSubjects.Member,
actorPermission: permission,
targetPermissions: permissionRoles,
- baseMessage: "Cannot assign a role exceeding your own privileges to an org member"
+ baseMessage: "Failed to assign the requested role to an org member"
});
}
@@ -1239,7 +1239,7 @@ export const orgServiceFactory = ({
opSubject: OrgPermissionSubjects.Member,
actorPermission: permission,
targetPermissions,
- baseMessage: "Failed to remove a more privileged member from the organization"
+ baseMessage: "Failed to remove this member from the organization"
});
};
diff --git a/frontend/src/hooks/api/reactQuery.tsx b/frontend/src/hooks/api/reactQuery.tsx
index 29ea9b9fdc..d100866a28 100644
--- a/frontend/src/hooks/api/reactQuery.tsx
+++ b/frontend/src/hooks/api/reactQuery.tsx
@@ -87,6 +87,53 @@ function ValidationErrorModal({
);
}
+type TPermissionConditions = Record<
+ string,
+ string | { [K in PermissionConditionOperators]: string | string[] }
+>;
+
+function PermissionConditionsList({
+ conditions,
+ keyPrefix
+}: {
+ conditions?: unknown;
+ keyPrefix: string;
+}) {
+ const fields = Object.keys((conditions as TPermissionConditions) || {});
+ if (!fields.length) return null;
+
+ return (
+ <ul className="mt-2 flex list-disc flex-col gap-1.5 pl-5 marker:text-muted">
+ {fields.flatMap((field, fieldIndex) => {
+ const operators = (conditions as TPermissionConditions)[field];
+ const formattedFieldName = camelCaseToSpaces(field).toLowerCase();
+
+ if (typeof operators === "string") {
+ return (
+ <li key={`${keyPrefix}-${fieldIndex + 1}`}>
+ <span className="font-medium capitalize">{formattedFieldName}</span>{" "}
+ <span className="text-muted">equal to</span>{" "}
+ <Badge variant="neutral">{operators}</Badge>
+ </li>
+ );
+ }
+
+ return Object.keys(operators).map((operator, operatorIndex) => (
+ <li key={`${keyPrefix}-${fieldIndex + 1}-${operatorIndex + 1}`}>
+ <span className="font-medium capitalize">{formattedFieldName}</span>{" "}
+ <span className="text-muted">
+ {formatedConditionsOperatorNames[operator as PermissionConditionOperators]}
+ </span>{" "}
+ <Badge variant="neutral">
+ {operators[operator as PermissionConditionOperators].toString()}
+ </Badge>
+ </li>
+ ));
+ })}
+ </ul>
+ );
+}
+
export const onRequestError = (
error: unknown,
_variables?: unknown,
@@ -191,51 +238,10 @@ export const onRequestError = (
<span>{el.subject.toString()}</span>
{hasConditions && <span className="text-muted">with conditions:</span>}
</div>
- {hasConditions && (
- <ul className="mt-2 flex list-disc flex-col gap-1.5 pl-5 marker:text-muted">
- {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {
- const operators = (
- el.conditions as Record<
- string,
- string | { [K in PermissionConditionOperators]: string | string[] }
- >
- )[field];
-
- const formattedFieldName = camelCaseToSpaces(field).toLowerCase();
- if (typeof operators === "string") {
- return (
- <li key={`Forbidden-error-details-${index + 1}-${fieldIndex + 1}`}>
- <span className="font-medium capitalize">
- {formattedFieldName}
- </span>{" "}
- <span className="text-muted">equal to</span>{" "}
- <Badge variant="neutral">{operators}</Badge>
- </li>
- );
- }
-
- return Object.keys(operators).map((operator, operatorIndex) => (
- <li
- key={`Forbidden-error-details-${index + 1}-${
- fieldIndex + 1
- }-${operatorIndex + 1}`}
- >
- <span className="font-medium capitalize">{formattedFieldName}</span>{" "}
- <span className="text-muted">
- {
- formatedConditionsOperatorNames[
- operator as PermissionConditionOperators
- ]
- }
- </span>{" "}
- <Badge variant="neutral">
- {operators[operator as PermissionConditionOperators].toString()}
- </Badge>
- </li>
- ));
- })}
- </ul>
- )}
+ <PermissionConditionsList
+ conditions={el.conditions}
+ keyPrefix={`Forbidden-error-details-${index + 1}`}
+ />
</div>
);
})}
@@ -253,6 +259,67 @@ export const onRequestError = (
});
return;
}
+ if (serverResponse?.error === ApiErrorTypes.PermissionBoundaryError) {
+ const missingPermissions = serverResponse.details?.missingPermissions ?? [];
+ const toastIdRef: { current: string | number | undefined } = { current: undefined };
+ toastIdRef.current = createNotification({
+ title: "Permission Denied",
+ type: "error",
+ text: `${serverResponse.message}${serverResponse.message.endsWith(".") ? "" : "."}`,
+ callToAction: missingPermissions.length ? (
+ <Dialog
+ onOpenChange={(open) => {
+ if (!open && toastIdRef.current !== undefined) {
+ dismissNotification(toastIdRef.current);
+ }
+ }}
+ >
+ <DialogTrigger asChild>
+ <Button variant="outline" size="xs">
+ Show more
+ </Button>
+ </DialogTrigger>
+ <DialogContent className="z-[70] sm:max-w-2xl" overlayClassName="z-[70]">
+ <DialogHeader>
+ <DialogTitle>Missing Permissions</DialogTitle>
+ <DialogDescription>
+ Your role needs the permissions below to perform this action.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="flex flex-col gap-2">
+ {missingPermissions.map((el, index) => (
+ <div
+ key={`Permission-boundary-details-${index + 1}`}
+ className="rounded-md border border-border bg-card p-4 text-sm"
+ >
+ <div className="flex flex-wrap items-center gap-x-1.5 gap-y-1">
+ <span>Can</span>
+ <Badge variant="danger">{el.action}</Badge>
+ <span>{el.subject}</span>
+ {Boolean(Object.keys(el.conditions || {}).length) && (
+ <span className="text-muted">with conditions:</span>
+ )}
+ </div>
+ <PermissionConditionsList
+ conditions={el.conditions}
+ keyPrefix={`Permission-boundary-details-${index + 1}`}
+ />
+ </div>
+ ))}
+ </div>
+ </DialogContent>
+ </Dialog>
+ ) : undefined,
+ copyActions: [
+ {
+ value: serverResponse.reqId,
+ name: "Request ID",
+ label: `Request ID: ${serverResponse.reqId}`
+ }
+ ]
+ });
+ return;
+ }
const errorMessage =
serverResponse?.message || "An unexpected error occurred. Please try again.";