Skip to content

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

permission updates

x03220548b346f5fd43
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
index 94ba896660..9e85da4b8f 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-account-router.ts
@@ -350,6 +350,47 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ method: "GET",
+ url: "/:accountId/permissions",
+ config: { rateLimit: readLimit },
+ schema: {
+ operationId: "getPamAccountPermissions",
+ description:
+ "Get the caller's effective resource permissions on this account, merging folder-level and direct account-level roles.",
+ tags: [ApiDocsTags.PamAccounts],
+ params: z.object({ accountId: z.string().uuid().describe("The ID of the account") }),
+ response: {
+ 200: z.object({
+ data: z.object({
+ permissions: z.any().array(),
+ memberships: z
+ .object({
+ id: z.string(),
+ actorUserId: z.string().nullish(),
+ actorIdentityId: z.string().nullish(),
+ actorGroupId: z.string().nullish(),
+ roles: z.object({ role: z.string(), customRoleSlug: z.string().nullish() }).array()
+ })
+ .array()
+ })
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ const data = await server.services.pamAccount.getAccountPermissions({
+ accountId: req.params.accountId,
+ projectId: req.internalPamProjectId,
+ actorId: req.permission.id,
+ actor: req.permission.type,
+ actorOrgId: req.permission.orgId,
+ actorAuthMethod: req.permission.authMethod
+ });
+ return { data };
+ }
+ });
+
server.route({
method: "GET",
url: "/:accountId",
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-folder-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-folder-router.ts
index bf82fec214..fe235333d4 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-folder-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-folder-router.ts
@@ -55,6 +55,48 @@ export const registerPamFolderRouter = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ method: "GET",
+ url: "/:folderId/permissions",
+ config: { rateLimit: readLimit },
+ schema: {
+ operationId: "getPamFolderPermissions",
+ description: "Get the caller's effective resource permissions on this folder.",
+ tags: [ApiDocsTags.PamFolders],
+ params: z.object({
+ folderId: z.string().uuid().describe("The ID of the folder")
+ }),
+ response: {
+ 200: z.object({
+ data: z.object({
+ permissions: z.any().array(),
+ memberships: z
+ .object({
+ id: z.string(),
+ actorUserId: z.string().nullish(),
+ actorIdentityId: z.string().nullish(),
+ actorGroupId: z.string().nullish(),
+ roles: z.object({ role: z.string(), customRoleSlug: z.string().nullish() }).array()
+ })
+ .array()
+ })
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ const data = await server.services.pamFolder.getFolderPermissions({
+ folderId: req.params.folderId,
+ projectId: req.internalPamProjectId,
+ actorId: req.permission.id,
+ actor: req.permission.type,
+ actorOrgId: req.permission.orgId,
+ actorAuthMethod: req.permission.authMethod
+ });
+ return { data };
+ }
+ });
+
server.route({
method: "GET",
url: "/:folderId",
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 4ba346cf32..ccd32a58e3 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -1,4 +1,5 @@
-import { ForbiddenError } from "@casl/ability";
+import { createMongoAbility, ForbiddenError, MongoAbility, MongoQuery, RawRuleOf } from "@casl/ability";
+import { packRules } from "@casl/ability/extra";
import { RESOURCE_SCOPE, ResourceType } from "@app/db/schemas";
import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
@@ -6,12 +7,14 @@ import { TGatewayV2DALFactory } from "@app/ee/services/gateway-v2/gateway-v2-dal
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
ResourcePermissionPamResourceActions,
+ ResourcePermissionSet,
ResourcePermissionSub
} from "@app/ee/services/permission/resource-permission";
+import { conditionsMatcher } from "@app/lib/casl";
import { createSshKeyPair } from "@app/ee/services/ssh/ssh-certificate-authority-fns";
import { SshCertKeyAlgorithm } from "@app/ee/services/ssh-certificate/ssh-certificate-types";
import { DatabaseErrorCode } from "@app/lib/error-codes";
-import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";
+import { BadRequestError, DatabaseError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsDataKey } from "@app/services/kms/kms-types";
@@ -395,13 +398,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
membershipDAL,
membershipRoleDAL,
projectId,
- {
- allOf: [ResourcePermissionPamResourceActions.ReadAccounts],
- anyOf: [
- ResourcePermissionPamResourceActions.LaunchSessions,
- ResourcePermissionPamResourceActions.ViewCredentials
- ]
- },
+ { allOf: [ResourcePermissionPamResourceActions.ReadAccounts] },
ctx
);
if (folderIds.length === 0 && accountIds.length === 0) return { accounts: [], totalCount: 0 };
@@ -489,5 +486,71 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
return { publicKey: metadata.caPublicKey };
};
- return { list, listAccessible, getById, create, update, deleteAccount, getOrCreateSshCa, getSshCaPublicKey };
+ const getAccountPermissions = async ({ accountId, projectId, ...ctx }: TGetPamAccountDTO & TActorContext) => {
+ const account = await pamAccountDAL.findById(accountId);
+ if (!account || account.projectId !== projectId) {
+ throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });
+ }
+
+ const allRules: RawRuleOf<MongoAbility<ResourcePermissionSet, MongoQuery>>[] = [];
+ const allMemberships: Awaited<ReturnType<typeof permissionService.getResourcePermission>>["memberships"] = [];
+
+ if (account.folderId) {
+ try {
+ const folderResult = await permissionService.getResourcePermission({
+ actor: ctx.actor,
+ actorId: ctx.actorId,
+ projectId,
+ resourceType: ResourceType.PamFolder,
+ resourceId: account.folderId,
+ actorAuthMethod: ctx.actorAuthMethod,
+ actorOrgId: ctx.actorOrgId
+ });
+ allRules.push(...folderResult.permission.rules);
+ allMemberships.push(...folderResult.memberships);
+ } catch (err) {
+ if (!(err instanceof ForbiddenRequestError)) throw err;
+ }
+ }
+
+ try {
+ const accountResult = await permissionService.getResourcePermission({
+ actor: ctx.actor,
+ actorId: ctx.actorId,
+ projectId,
+ resourceType: ResourceType.PamAccount,
+ resourceId: accountId,
+ actorAuthMethod: ctx.actorAuthMethod,
+ actorOrgId: ctx.actorOrgId
+ });
+ allRules.push(...accountResult.permission.rules);
+ allMemberships.push(...accountResult.memberships);
+ } catch (err) {
+ if (!(err instanceof ForbiddenRequestError)) throw err;
+ }
+
+ const mergedPermission = createMongoAbility<ResourcePermissionSet>(allRules, { conditionsMatcher });
+
+ ForbiddenError.from(mergedPermission).throwUnlessCan(
+ ResourcePermissionPamResourceActions.ReadAccounts,
+ ResourcePermissionSub.PamResource
+ );
+
+ return {
+ permissions: packRules(mergedPermission.rules),
+ memberships: allMemberships
+ };
+ };
+
+ return {
+ list,
+ listAccessible,
+ getById,
+ create,
+ update,
+ deleteAccount,
+ getOrCreateSshCa,
+ getSshCaPublicKey,
+ getAccountPermissions
+ };
};
diff --git a/backend/src/ee/services/pam-folder/pam-folder-service.ts b/backend/src/ee/services/pam-folder/pam-folder-service.ts
index 4933917c3a..9b0ab4c554 100644
--- a/backend/src/ee/services/pam-folder/pam-folder-service.ts
+++ b/backend/src/ee/services/pam-folder/pam-folder-service.ts
@@ -1,4 +1,5 @@
import { ForbiddenError } from "@casl/ability";
+import { packRules } from "@casl/ability/extra";
import { RESOURCE_SCOPE, ResourceType } from "@app/db/schemas";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
@@ -76,7 +77,7 @@ export const pamFolderServiceFactory = ({
membershipDAL,
membershipRoleDAL,
projectId,
- { allOf: [ResourcePermissionPamResourceActions.ReadFolder] },
+ { anyOf: [ResourcePermissionPamResourceActions.ReadFolder, ResourcePermissionPamResourceActions.ReadAccounts] },
ctx
);
if (folderIds.length === 0 && accountIds.length === 0) return [];
@@ -190,5 +191,32 @@ export const pamFolderServiceFactory = ({
});
};
- return { list, getById, create, update, deleteFolder };
+ const getFolderPermissions = async ({ folderId, projectId, ...ctx }: TGetPamFolderDTO & TActorContext) => {
+ const folder = await pamFolderDAL.findById(folderId);
+ if (!folder || folder.projectId !== projectId) {
+ throw new NotFoundError({ message: `Folder with ID '${folderId}' not found` });
+ }
+
+ const { permission, memberships } = await permissionService.getResourcePermission({
+ actor: ctx.actor,
+ actorId: ctx.actorId,
+ projectId,
+ resourceType: ResourceType.PamFolder,
+ resourceId: folderId,
+ actorAuthMethod: ctx.actorAuthMethod,
+ actorOrgId: ctx.actorOrgId
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(
+ ResourcePermissionPamResourceActions.ReadFolder,
+ ResourcePermissionSub.PamResource
+ );
+
+ return {
+ permissions: packRules(permission.rules),
+ memberships
+ };
+ };
+
+ return { list, getById, create, update, deleteFolder, getFolderPermissions };
};
diff --git a/frontend/src/hooks/api/pam/enums.ts b/frontend/src/hooks/api/pam/enums.ts
index be581dbf1c..21a40da8af 100644
--- a/frontend/src/hooks/api/pam/enums.ts
+++ b/frontend/src/hooks/api/pam/enums.ts
@@ -54,3 +54,27 @@ export enum PamAccountView {
Flat = "flat",
Nested = "nested"
}
+
+export enum PamResourcePermissionSub {
+ PamResource = "pam-resource"
+}
+
+export enum PamResourcePermissionActions {
+ ReadFolder = "read-folder",
+ EditFolder = "edit-folder",
+ DeleteFolder = "delete-folder",
+ ReadAccounts = "read-accounts",
+ CreateAccounts = "create-accounts",
+ EditAccounts = "edit-accounts",
+ DeleteAccounts = "delete-accounts",
+ LaunchSessions = "launch-sessions",
+ ViewSessions = "view-sessions",
+ TerminateSessions = "terminate-sessions",
+ ViewCredentials = "view-credentials",
+ RequestAccess = "request-access",
+ ApproveRequests = "approve-requests",
+ ManagePolicies = "manage-policies",
+ ManageRotation = "manage-rotation",
+ ManageMembers = "manage-members",
+ ViewAuditLogs = "view-audit-logs"
+}
diff --git a/frontend/src/hooks/api/pam/queries.tsx b/frontend/src/hooks/api/pam/queries.tsx
index d08b529661..1ca19ed585 100644
--- a/frontend/src/hooks/api/pam/queries.tsx
+++ b/frontend/src/hooks/api/pam/queries.tsx
@@ -7,8 +7,13 @@ import {
} from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
+import {
+ createResourcePermissionQueryHook,
+ ResourcePermissionResponse
+} from "@app/helpers/resourcePermissions";
import {
+ PamFolderPermissionSet,
TAccessiblePamAccount,
TListAccessiblePamAccountsDTO,
TListPamAccountsDTO,
@@ -35,9 +40,36 @@ export const pamKeys = {
],
getAccount: (accountId: string) => [...pamKeys.account(), "get", accountId],
getSession: (sessionId: string) => [...pamKeys.session(), "get", sessionId],
- listSessions: (projectId: string) => [...pamKeys.session(), "list", projectId]
+ listSessions: (projectId: string) => [...pamKeys.session(), "list", projectId],
+ folderPermissions: (folderId: string) => [...pamKeys.all, "folder-permissions", folderId] as const,
+ accountPermissions: (accountId: string) =>
+ [...pamKeys.all, "account-permissions", accountId] as const
+};
+
+const fetchFolderPermissions = async (folderId: string) => {
+ const { data } = await apiRequest.get<{
+ data: ResourcePermissionResponse<PamFolderPermissionSet>;
+ }>(`/api/v1/pam/folders/${folderId}/permissions`);
+ return data.data;
};
+export const usePamFolderPermission = createResourcePermissionQueryHook<PamFolderPermissionSet>({
+ queryKey: (folderId) => pamKeys.folderPermissions(folderId),
+ fetchFn: fetchFolderPermissions
+});
+
+const fetchAccountPermissions = async (accountId: string) => {
+ const { data } = await apiRequest.get<{
+ data: ResourcePermissionResponse<PamFolderPermissionSet>;
+ }>(`/api/v1/pam/accounts/${accountId}/permissions`);
+ return data.data;
+};
+
+export const usePamAccountPermission = createResourcePermissionQueryHook<PamFolderPermissionSet>({
+ queryKey: (accountId) => pamKeys.accountPermissions(accountId),
+ fetchFn: fetchAccountPermissions
+});
+
// Accessible Accounts (user-facing)
type TListAccessiblePamAccountsResponse = {
accounts: TAccessiblePamAccount[];
diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.ts
index 65e5748b91..a71e54e26a 100644
--- a/frontend/src/hooks/api/pam/types/index.ts
+++ b/frontend/src/hooks/api/pam/types/index.ts
@@ -3,11 +3,18 @@ import {
PamAccountOrderBy,
PamAccountType,
PamAccountView,
+ PamResourcePermissionActions,
+ PamResourcePermissionSub,
PamResourceType,
PamSessionStatus,
SessionChannelType
} from "../enums";
+export type PamFolderPermissionSet = [
+ PamResourcePermissionActions,
+ PamResourcePermissionSub.PamResource
+];
+
// New model types
export type TPamAccount = {
diff --git a/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx b/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
index 51ab574730..b236eb2d57 100644
--- a/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
+++ b/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
@@ -1,7 +1,13 @@
import { Rocket } from "lucide-react";
-import { Badge, Button } from "@app/components/v3";
-import { PAM_ACCOUNT_TYPE_MAP, TAccessiblePamAccount } from "@app/hooks/api/pam";
+import { Badge, Button, Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3";
+import {
+ PAM_ACCOUNT_TYPE_MAP,
+ PamResourcePermissionActions,
+ PamResourcePermissionSub,
+ TAccessiblePamAccount
+} from "@app/hooks/api/pam";
+import { usePamAccountPermission } from "@app/hooks/api/pam/queries";
import { AccountPlatformIcon } from "./AccountPlatformIcon";
@@ -13,6 +19,12 @@ type Props = {
export const AccountRow = ({ account, onLaunch }: Props) => {
const typeName = PAM_ACCOUNT_TYPE_MAP[account.accountType]?.name ?? account.accountType;
+ const { data: accountPermission } = usePamAccountPermission(account.id);
+ const canLaunch = accountPermission?.permission.can(
+ PamResourcePermissionActions.LaunchSessions,
+ PamResourcePermissionSub.PamResource
+ );
+
return (
<div className="flex items-center gap-3 border-b border-border px-4 py-2 last:border-b-0">
<AccountPlatformIcon accountType={account.accountType} size={24} />
@@ -20,10 +32,26 @@ export const AccountRow = ({ account, onLaunch }: Props) => {
<Badge variant="info">{typeName}</Badge>
<span className="flex-1" />
<div className="flex shrink-0 items-center gap-2">
- <Button variant="pam" size="xs" onClick={() => onLaunch(account)}>
- <Rocket className="size-3" />
- Launch
- </Button>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <div>
+ <Button
+ variant="pam"
+ size="xs"
+ onClick={() => onLaunch(account)}
+ isDisabled={!canLaunch}
+ >
+ <Rocket className="size-3" />
+ Launch
+ </Button>
+ </div>
+ </TooltipTrigger>
+ {!canLaunch && (
+ <TooltipContent>
+ You don&apos;t have permission to launch sessions for this account
+ </TooltipContent>
+ )}
+ </Tooltip>
</div>
</div>
);