Skip to content

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

chore: new access support

Sheen Capadnganc6809ee7ec49
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
index ab82c51adc..87bd7171ae 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
@@ -158,26 +158,39 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
},
schema: {
description: "Access PAM account",
- body: z.object({
- accountPath: z.string().trim(),
- projectId: z.string().uuid(),
- mfaSessionId: z.string().optional(),
- duration: z
- .string()
- .min(1)
- .transform((val, ctx) => {
- const parsedMs = ms(val);
-
- if (typeof parsedMs !== "number" || parsedMs <= 0) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: "Invalid duration format. Must be a positive duration (e.g., '1h', '30m', '2d')."
- });
- return z.NEVER;
- }
- return parsedMs;
- })
- }),
+ body: z
+ .object({
+ accountPath: z.string().trim().optional(),
+ resourceName: z.string().trim().optional(),
+ accountName: z.string().trim().optional(),
+ projectId: z.string().uuid(),
+ mfaSessionId: z.string().optional(),
+ duration: z
+ .string()
+ .min(1)
+ .transform((val, ctx) => {
+ const parsedMs = ms(val);
+
+ if (typeof parsedMs !== "number" || parsedMs <= 0) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Invalid duration format. Must be a positive duration (e.g., '1h', '30m', '2d')."
+ });
+ return z.NEVER;
+ }
+ return parsedMs;
+ })
+ })
+ .refine(
+ (data) => {
+ const hasResourceAndAccount = data.resourceName && data.accountName;
+ const hasAccountPath = data.accountPath;
+ return hasResourceAndAccount || hasAccountPath;
+ },
+ {
+ message: "Either (resourceName and accountName) or accountPath must be provided"
+ }
+ ),
response: {
200: z.discriminatedUnion("resourceType", [
// Gateway-based resources (Postgres, MySQL, Redis, SSH)
@@ -210,6 +223,8 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
actorName: `${req.auth.user.firstName ?? ""} ${req.auth.user.lastName ?? ""}`.trim(),
actorUserAgent: req.auditLogInfo.userAgent ?? "",
accountPath: req.body.accountPath,
+ resourceName: req.body.resourceName,
+ accountName: req.body.accountName,
projectId: req.body.projectId,
duration: req.body.duration,
mfaSessionId: req.body.mfaSessionId
@@ -226,6 +241,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
metadata: {
accountId: response.account.id,
accountPath: req.body.accountPath,
+ resourceName: req.body.resourceName,
accountName: response.account.name,
duration: req.body.duration ? new Date(req.body.duration).toISOString() : undefined
}
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 6b9dca2101..a814a37e9d 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -4252,7 +4252,8 @@ interface PamAccountAccessEvent {
type: EventType.PAM_ACCOUNT_ACCESS;
metadata: {
accountId: string;
- accountPath: string;
+ accountPath?: string;
+ resourceName?: string;
accountName: string;
duration?: string;
};
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 20c300548d..025b4e5e24 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -611,6 +611,8 @@ export const pamAccountServiceFactory = ({
const access = async (
{
accountPath,
+ resourceName: inputResourceName,
+ accountName: inputAccountName,
projectId,
actorEmail,
actorIp,
@@ -621,39 +623,80 @@ export const pamAccountServiceFactory = ({
}: TAccessAccountDTO,
actor: OrgServiceActor
) => {
- const pathSegments: string[] = accountPath.split("/").filter(Boolean);
- if (pathSegments.length === 0) {
- throw new BadRequestError({ message: "Invalid accountPath. Path must contain at least the account name." });
- }
+ let account;
+ let resource;
+ let folderPath = "/";
+
+ // New approach: Use resourceName + accountName to find the account directly
+ if (inputResourceName && inputAccountName) {
+ // Find resource by name
+ resource = await pamResourceDAL.findOne({ projectId, name: inputResourceName });
+ if (!resource) {
+ throw new NotFoundError({ message: `Resource with name '${inputResourceName}' not found` });
+ }
- const accountName: string = pathSegments[pathSegments.length - 1] ?? "";
- const folderPathSegments: string[] = pathSegments.slice(0, -1);
+ // Find account by name within the resource
+ account = await pamAccountDAL.findOne({
+ projectId,
+ resourceId: resource.id,
+ name: inputAccountName
+ });
- const folderPath: string = folderPathSegments.length > 0 ? `/${folderPathSegments.join("/")}` : "/";
+ if (!account) {
+ throw new NotFoundError({
+ message: `Account with name '${inputAccountName}' not found for resource '${inputResourceName}'`
+ });
+ }
- let folderId: string | null = null;
- if (folderPath !== "/") {
- const folder = await pamFolderDAL.findByPath(projectId, folderPath);
- if (!folder) {
- throw new NotFoundError({ message: `Folder at path '${folderPath}' not found` });
+ // Get folder path if account has a folder
+ if (account.folderId) {
+ folderPath = await getFullPamFolderPath({
+ pamFolderDAL,
+ folderId: account.folderId,
+ projectId
+ });
}
- folderId = folder.id;
}
+ // Legacy approach: Use accountPath to find the account
+ else if (accountPath) {
+ const pathSegments: string[] = accountPath.split("/").filter(Boolean);
+ if (pathSegments.length === 0) {
+ throw new BadRequestError({ message: "Invalid accountPath. Path must contain at least the account name." });
+ }
- const account = await pamAccountDAL.findOne({
- projectId,
- folderId,
- name: accountName
- });
+ const accountName: string = pathSegments[pathSegments.length - 1] ?? "";
+ const folderPathSegments: string[] = pathSegments.slice(0, -1);
+
+ folderPath = folderPathSegments.length > 0 ? `/${folderPathSegments.join("/")}` : "/";
- if (!account) {
- throw new NotFoundError({
- message: `Account with name '${accountName}' not found at path '${accountPath}'`
+ let folderId: string | null = null;
+ if (folderPath !== "/") {
+ const folder = await pamFolderDAL.findByPath(projectId, folderPath);
+ if (!folder) {
+ throw new NotFoundError({ message: `Folder at path '${folderPath}' not found` });
+ }
+ folderId = folder.id;
+ }
+
+ account = await pamAccountDAL.findOne({
+ projectId,
+ folderId,
+ name: accountName
});
- }
- const resource = await pamResourceDAL.findById(account.resourceId);
- if (!resource) throw new NotFoundError({ message: `Resource with ID '${account.resourceId}' not found` });
+ if (!account) {
+ throw new NotFoundError({
+ message: `Account with name '${accountName}' not found at path '${accountPath}'`
+ });
+ }
+
+ resource = await pamResourceDAL.findById(account.resourceId);
+ if (!resource) throw new NotFoundError({ message: `Resource with ID '${account.resourceId}' not found` });
+ } else {
+ throw new BadRequestError({
+ message: "Either (resourceName and accountName) or accountPath must be provided"
+ });
+ }
const fac = APPROVAL_POLICY_FACTORY_MAP[ApprovalPolicyType.PamAccess](ApprovalPolicyType.PamAccess);
diff --git a/backend/src/ee/services/pam-account/pam-account-types.ts b/backend/src/ee/services/pam-account/pam-account-types.ts
index c7a1afae81..205c918886 100644
--- a/backend/src/ee/services/pam-account/pam-account-types.ts
+++ b/backend/src/ee/services/pam-account/pam-account-types.ts
@@ -16,7 +16,9 @@ export type TUpdateAccountDTO = Partial<Omit<TCreateAccountDTO, "folderId" | "re
};
export type TAccessAccountDTO = {
- accountPath: string;
+ accountPath?: string;
+ resourceName?: string;
+ accountName?: string;
projectId: string;
actorEmail: string;
actorIp: string;
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
index c16dc7a66a..e217970778 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx
@@ -10,31 +10,18 @@ import { PamResourceType, TPamAccount } from "@app/hooks/api/pam";
type Props = {
account?: TPamAccount;
- accountPath?: string;
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
projectId: string;
};
-export const PamAccessAccountModal = ({
- isOpen,
- onOpenChange,
- account,
- projectId,
- accountPath
-}: Props) => {
+export const PamAccessAccountModal = ({ isOpen, onOpenChange, account, projectId }: Props) => {
const [duration, setDuration] = useState("4h");
const { protocol, hostname, port } = window.location;
const portSuffix = port && port !== "80" && port !== "443" ? `:${port}` : "";
const siteURL = `${protocol}//${hostname}${portSuffix}`;
- let fullAccountPath = `/${account?.name ?? ""}`;
- if (accountPath) {
- const path = accountPath.replace(/^\/+|\/+$/g, "");
- fullAccountPath = `/${path}/${account?.name ?? ""}`;
- }
-
const isDurationValid = useMemo(() => duration && ms(duration || "1s") > 0, [duration]);
const cliDuration = useMemo(() => {
@@ -82,17 +69,17 @@ export const PamAccessAccountModal = ({
switch (account.resource.resourceType) {
case PamResourceType.Postgres:
case PamResourceType.MySQL:
- return `infisical pam db access-account ${fullAccountPath} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
+ return `infisical pam db access --resource ${account.resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
case PamResourceType.Redis:
- return `infisical pam redis access-account ${fullAccountPath} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
+ return `infisical pam redis access --resource ${account.resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
case PamResourceType.SSH:
- return `infisical pam ssh access-account ${fullAccountPath} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
+ return `infisical pam ssh access --resource ${account.resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
case PamResourceType.Kubernetes:
- return `infisical pam kubernetes access-account ${fullAccountPath} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
+ return `infisical pam kubernetes access --resource ${account.resource.name} --account ${account.name} --project-id ${projectId} --duration ${cliDuration} --domain ${siteURL}`;
default:
return "";
}
- }, [account, fullAccountPath, projectId, cliDuration, siteURL]);
+ }, [account, projectId, cliDuration, siteURL]);
if (!account) return null;