Skip to content

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

feat: add folder permission on the UI

adilson6dff1cdc4f54
diff --git a/backend/e2e-test/routes/v1/identity-folder-access.spec.ts b/backend/e2e-test/routes/v1/identity-folder-access.spec.ts
index 5bae1264b9..d74e390a66 100644
--- a/backend/e2e-test/routes/v1/identity-folder-access.spec.ts
+++ b/backend/e2e-test/routes/v1/identity-folder-access.spec.ts
@@ -522,4 +522,105 @@ describe("Identity folder access CRUD", () => {
});
});
});
+
+ describe("actor grant listing", () => {
+ const listTarget = { environmentSlug: seedData1.environment.slug, secretPath: "/identity-folder-access-list" };
+ let listFolder: { id: string; name: string };
+ let listIdentityId: string;
+
+ beforeAll(async () => {
+ listFolder = await createFolder({ path: "/", name: "identity-folder-access-list" });
+ const listIdentity = await createProjectIdentity(ProjectMembershipRole.Member);
+ listIdentityId = listIdentity.identityId;
+ });
+
+ afterAll(async () => {
+ await deleteFolder({ path: "/", id: listFolder.id });
+ await deleteProjectIdentity(listIdentityId);
+ });
+
+ test("returns an empty list for an identity with no grants", async () => {
+ const res = await testServer.inject({
+ method: "GET",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders()
+ });
+ expect(res.statusCode).toBe(200);
+ expect(res.json()).toEqual({ folderAccess: [] });
+ });
+
+ test("lists every folder grant for the identity across the project, sorted by path", async () => {
+ const temporaryAccessStartTime = new Date().toISOString();
+ const firstRes = await testServer.inject({
+ method: "POST",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders(),
+ body: { ...folderTarget, permission: SecretFolderRole.List }
+ });
+ expect(firstRes.statusCode).toBe(200);
+
+ const secondRes = await testServer.inject({
+ method: "POST",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders(),
+ body: {
+ ...listTarget,
+ permission: SecretFolderRole.Manage,
+ type: {
+ isTemporary: true,
+ temporaryMode: TemporaryPermissionMode.Relative,
+ temporaryRange: "4h",
+ temporaryAccessStartTime
+ }
+ }
+ });
+ expect(secondRes.statusCode).toBe(200);
+
+ try {
+ const listRes = await testServer.inject({
+ method: "GET",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders()
+ });
+ expect(listRes.statusCode).toBe(200);
+ const { folderAccess } = listRes.json();
+ expect(folderAccess).toHaveLength(2);
+ expect(folderAccess[0]).toEqual(
+ expect.objectContaining({
+ identityId: listIdentityId,
+ projectId,
+ permission: SecretFolderRole.List,
+ environment: seedData1.environment.slug,
+ secretPath: folderTarget.secretPath,
+ isTemporary: false,
+ temporaryRange: null
+ })
+ );
+ expect(folderAccess[1]).toEqual(
+ expect.objectContaining({
+ identityId: listIdentityId,
+ permission: SecretFolderRole.Manage,
+ secretPath: listTarget.secretPath,
+ isTemporary: true,
+ temporaryMode: TemporaryPermissionMode.Relative,
+ temporaryRange: "4h"
+ })
+ );
+ expect(new Date(folderAccess[1].temporaryAccessStartTime).toISOString()).toBe(temporaryAccessStartTime);
+ } finally {
+ await testServer.inject({
+ method: "DELETE",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders(),
+ body: { ...folderTarget }
+ });
+ await testServer.inject({
+ method: "DELETE",
+ url: folderAccessUrl(listIdentityId),
+ headers: authHeaders(),
+ body: { ...listTarget }
+ });
+ }
+ });
+ });
});
diff --git a/backend/e2e-test/routes/v1/user-folder-access.spec.ts b/backend/e2e-test/routes/v1/user-folder-access.spec.ts
index 62e7c60bc9..335546a994 100644
--- a/backend/e2e-test/routes/v1/user-folder-access.spec.ts
+++ b/backend/e2e-test/routes/v1/user-folder-access.spec.ts
@@ -879,6 +879,118 @@ describe("User folder access CRUD", () => {
});
expect(createRes.statusCode).toBe(403);
});
+
+ test("cannot list a user's folder grants", async () => {
+ const res = await testServer.inject({
+ method: "GET",
+ url: folderAccessUrl(),
+ headers: outsiderHeaders()
+ });
+ expect(res.statusCode).toBe(403);
+ });
+ });
+
+ describe("actor grant listing", () => {
+ const listTarget = { environmentSlug: seedData1.environment.slug, secretPath: "/user-folder-access-list" };
+ let listFolder: { id: string; name: string };
+ let listUserId: string;
+
+ beforeAll(async () => {
+ listFolder = await createFolder({ path: "/", name: "user-folder-access-list" });
+ const listUser = await createProjectUser(ProjectMembershipRole.Member);
+ listUserId = listUser.userId;
+ });
+
+ afterAll(async () => {
+ await deleteFolder({ path: "/", id: listFolder.id });
+ await deleteProjectUser(listUserId);
+ });
+
+ test("returns an empty list for a user with no grants", async () => {
+ const res = await testServer.inject({
+ method: "GET",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders()
+ });
+ expect(res.statusCode).toBe(200);
+ expect(res.json()).toEqual({ folderAccess: [] });
+ });
+
+ test("lists every folder grant for the user across the project, sorted by path", async () => {
+ const temporaryAccessStartTime = new Date().toISOString();
+ const firstRes = await testServer.inject({
+ method: "POST",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders(),
+ body: { ...folderTarget, permission: SecretFolderRole.Read }
+ });
+ expect(firstRes.statusCode).toBe(200);
+
+ const secondRes = await testServer.inject({
+ method: "POST",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders(),
+ body: {
+ ...listTarget,
+ permission: SecretFolderRole.Edit,
+ type: {
+ isTemporary: true,
+ temporaryMode: TemporaryPermissionMode.Relative,
+ temporaryRange: "30m",
+ temporaryAccessStartTime
+ }
+ }
+ });
+ expect(secondRes.statusCode).toBe(200);
+
+ try {
+ const listRes = await testServer.inject({
+ method: "GET",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders()
+ });
+ expect(listRes.statusCode).toBe(200);
+ const { folderAccess } = listRes.json();
+ expect(folderAccess).toHaveLength(2);
+ expect(folderAccess[0]).toEqual(
+ expect.objectContaining({
+ userId: listUserId,
+ projectId,
+ permission: SecretFolderRole.Read,
+ environment: seedData1.environment.slug,
+ secretPath: folderTarget.secretPath,
+ isTemporary: false,
+ temporaryRange: null
+ })
+ );
+ expect(folderAccess[1]).toEqual(
+ expect.objectContaining({
+ userId: listUserId,
+ permission: SecretFolderRole.Edit,
+ secretPath: listTarget.secretPath,
+ isTemporary: true,
+ temporaryMode: TemporaryPermissionMode.Relative,
+ temporaryRange: "30m"
+ })
+ );
+ expect(new Date(folderAccess[1].temporaryAccessStartTime).toISOString()).toBe(temporaryAccessStartTime);
+ expect(folderAccess[0]).not.toHaveProperty("name");
+ expect(folderAccess[0]).not.toHaveProperty("permissions");
+ } finally {
+ await testServer.inject({
+ method: "DELETE",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders(),
+ body: { ...folderTarget }
+ });
+ await testServer.inject({
+ method: "DELETE",
+ url: folderAccessUrl(listUserId),
+ headers: authHeaders(),
+ body: { ...listTarget }
+ });
+ }
+ });
});
describe("group removal reaps folder grants", () => {
diff --git a/backend/e2e-test/routes/v2/secret-folder-rbac.spec.ts b/backend/e2e-test/routes/v2/secret-folder-rbac.spec.ts
index 57b15f7c1c..f02afe8876 100644
--- a/backend/e2e-test/routes/v2/secret-folder-rbac.spec.ts
+++ b/backend/e2e-test/routes/v2/secret-folder-rbac.spec.ts
@@ -43,6 +43,10 @@ let memberMembershipId: string;
let memberJwtToken: string;
const memberSessionId = randomUUID();
+// grants in most specs belong to a third user so the acting member's own ability stays on the
+// base member role; only the tier-specific specs grant to the acting member
+let grantHolderUserId: string;
+
let permissionArg: {
actor: ActorType;
actorId: string;
@@ -86,6 +90,18 @@ beforeAll(async () => {
.returning("*");
memberUserId = user.id;
+ const holderUsername = `folder-rbac-holder-${alphaNumericNanoId(8)}@example.com`.toLowerCase();
+ const [grantHolder] = await testDb(TableName.Users)
+ .insert({
+ username: holderUsername,
+ email: holderUsername,
+ isGhost: false,
+ isAccepted: true,
+ authMethods: [AuthMethod.EMAIL]
+ })
+ .returning("*");
+ grantHolderUserId = grantHolder.id;
+
const [orgMembership] = await testDb(TableName.Membership)
.insert({
scope: AccessScope.Organization,
@@ -163,7 +179,7 @@ afterAll(async () => {
await testRedis.del(permissionDataKey, permissionMarkerKey, folderDataKey, folderMarkerKey);
await testDb(TableName.AuthTokenSession).where({ id: memberSessionId }).del();
await testDb(TableName.Membership).where({ actorUserId: memberUserId }).del();
- await testDb(TableName.Users).where({ id: memberUserId }).del();
+ await testDb(TableName.Users).whereIn("id", [memberUserId, grantHolderUserId]).del();
});
const clearMemberPermissionCaches = () =>
@@ -420,7 +436,7 @@ describe("Folder deletion reaps folder-scoped privileges", () => {
});
});
-describe("Folder deletion requires manage-access on RBAC-granted folders", () => {
+describe("Folder deletion succeeds despite folder-scoped grants", () => {
const deleteFolderAs = async (token: string, dto: { path: string; id: string; forceDelete?: boolean }) =>
testServer.inject({
method: "DELETE",
@@ -438,61 +454,44 @@ describe("Folder deletion requires manage-access on RBAC-granted folders", () =>
await clearMemberPermissionCaches();
});
- test("blocks a member without manage-access from deleting a folder that has a grant", async () => {
+ test("lets a member with delete permission delete a folder that has a grant, reaping the grant", async () => {
const folder = await createFolder({ path: "/", name: "rbac-guard-direct" });
await testDb(TableName.AdditionalPrivilege).insert({
name: "e2e-rbac-guard-direct",
- actorUserId: memberUserId,
+ actorUserId: grantHolderUserId,
projectId,
folderId: folder.id,
role: SecretFolderRole.Read,
permissions: null,
isTemporary: false
});
- await clearMemberPermissionCaches();
const res = await deleteFolderAs(memberJwtToken, { path: "/", id: folder.id });
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
- expect(await testDb(TableName.AdditionalPrivilege).where({ folderId: folder.id })).toHaveLength(1);
-
- await deleteFolder({ path: "/", id: folder.id });
- await clearMemberPermissionCaches();
+ expect(res.statusCode).toBe(200);
+ expect(await testDb(TableName.AdditionalPrivilege).where({ folderId: folder.id })).toEqual([]);
});
- test("blocks deleting a parent when a descendant folder has a grant", async () => {
+ test("lets a member delete a parent whose descendant folder has a grant", async () => {
const parent = await createFolder({ path: "/", name: "rbac-guard-parent" });
const child = await createFolder({ path: "/rbac-guard-parent", name: "rbac-guard-child" });
await testDb(TableName.AdditionalPrivilege).insert({
name: "e2e-rbac-guard-child",
- actorUserId: memberUserId,
+ actorUserId: grantHolderUserId,
projectId,
folderId: child.id,
role: SecretFolderRole.Read,
permissions: null,
isTemporary: false
});
- await clearMemberPermissionCaches();
const res = await deleteFolderAs(memberJwtToken, { path: "/", id: parent.id, forceDelete: true });
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("/rbac-guard-parent/rbac-guard-child");
-
- await deleteFolder({ path: "/", id: parent.id, forceDelete: true });
- await clearMemberPermissionCaches();
- });
-
- test("allows a member to delete a folder with no grants", async () => {
- const folder = await createFolder({ path: "/", name: "rbac-guard-free" });
- await clearMemberPermissionCaches();
-
- const res = await deleteFolderAs(memberJwtToken, { path: "/", id: folder.id });
expect(res.statusCode).toBe(200);
+ expect(await testDb(TableName.AdditionalPrivilege).where({ folderId: child.id })).toEqual([]);
});
- test("allows deletion when the member holds the full-access tier on the granted folder", async () => {
+ test("lets a member holding the full-access tier delete their granted folder", async () => {
const folder = await createFolder({ path: "/", name: "rbac-guard-full" });
await testDb(TableName.AdditionalPrivilege).insert({
@@ -512,33 +511,7 @@ describe("Folder deletion requires manage-access on RBAC-granted folders", () =>
await clearMemberPermissionCaches();
});
- test("allows deletion when the only grant on the folder has expired", async () => {
- const folder = await createFolder({ path: "/", name: "rbac-guard-expired" });
-
- // nothing reaps expired rows, and permission evaluation drops them, so the guard must too
- await testDb(TableName.AdditionalPrivilege).insert({
- name: "e2e-rbac-guard-expired",
- actorUserId: memberUserId,
- projectId,
- folderId: folder.id,
- role: SecretFolderRole.Read,
- permissions: null,
- isTemporary: true,
- temporaryAccessStartTime: new Date(Date.now() - 7_200_000),
- temporaryAccessEndTime: new Date(Date.now() - 3_600_000)
- });
-
- try {
- await clearMemberPermissionCaches();
- const res = await deleteFolderAs(memberJwtToken, { path: "/", id: folder.id });
- expect(res.statusCode).toBe(200);
- } finally {
- await testDb(TableName.AdditionalPrivilege).where({ name: "e2e-rbac-guard-expired" }).del();
- await clearMemberPermissionCaches();
- }
- });
-
- test("blocks an identity without manage-access from deleting a folder that has a grant", async () => {
+ test("lets an identity with delete permission delete a folder that has a grant", async () => {
const identityName = `rbac-guard-identity-${alphaNumericNanoId(8)}`.toLowerCase();
const [identity] = await testDb(TableName.Identity).insert({ name: identityName, orgId }).returning("*");
const [orgMembership] = await testDb(TableName.Membership)
@@ -585,7 +558,7 @@ describe("Folder deletion requires manage-access on RBAC-granted folders", () =>
const folder = await createFolder({ path: "/", name: "rbac-guard-identity" });
await testDb(TableName.AdditionalPrivilege).insert({
name: "e2e-rbac-guard-identity",
- actorIdentityId: identity.id,
+ actorUserId: grantHolderUserId,
projectId,
folderId: folder.id,
role: SecretFolderRole.Read,
@@ -595,10 +568,11 @@ describe("Folder deletion requires manage-access on RBAC-granted folders", () =>
try {
const res = await deleteFolderAs(identityJwt, { path: "/", id: folder.id });
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
+ expect(res.statusCode).toBe(200);
+ expect(await testDb(TableName.AdditionalPrivilege).where({ folderId: folder.id })).toEqual([]);
} finally {
- await deleteFolder({ path: "/", id: folder.id });
+ // no assertion: the folder is already gone when the deletion under test succeeded
+ await deleteFolderAs(jwtAuthToken, { path: "/", id: folder.id, forceDelete: true });
await testDb(TableName.IdentityAccessToken).where({ id: identityTokenId }).del();
await testDb(TableName.Membership).where({ actorIdentityId: identity.id }).del();
await testDb(TableName.Identity).where({ id: identity.id }).del();
@@ -606,7 +580,7 @@ describe("Folder deletion requires manage-access on RBAC-granted folders", () =>
});
});
-describe("Folder move and rename require manage-access on RBAC-granted folders", () => {
+describe("Folder move and rename succeed despite folder-scoped grants", () => {
const moveFolderAs = (token: string, dto: { folderId: string; destinationPath: string }) =>
testServer.inject({
method: "POST",
@@ -620,6 +594,16 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
}
});
+ // cleanup for folders that may or may not still exist at the given path, depending on
+ // whether the operation under test succeeded
+ const tryDeleteFolder = (dto: { path: string; id: string }) =>
+ testServer.inject({
+ method: "DELETE",
+ url: `/api/v2/folders/${dto.id}`,
+ headers: { authorization: `Bearer ${jwtAuthToken}` },
+ body: { projectId, environment: seedData1.environment.slug, path: dto.path, forceDelete: true }
+ });
+
const renameFolderAs = (token: string, dto: { id: string; path: string; name: string; description?: string }) =>
testServer.inject({
method: "PATCH",
@@ -645,10 +629,10 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
}
});
- const grantFolderRole = (dto: { name: string; folderId: string; role: SecretFolderRole }) =>
+ const grantFolderRole = (dto: { name: string; folderId: string; role: SecretFolderRole; actorUserId?: string }) =>
testDb(TableName.AdditionalPrivilege).insert({
name: dto.name,
- actorUserId: memberUserId,
+ actorUserId: dto.actorUserId ?? grantHolderUserId,
projectId,
folderId: dto.folderId,
role: dto.role,
@@ -660,112 +644,88 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
await clearMemberPermissionCaches();
});
- test("blocks a member without manage-access from moving a folder that has a grant", async () => {
+ test("lets a member move a folder that has a grant, repointing the grant", async () => {
const folder = await createFolder({ path: "/", name: "rbac-move-src" });
const destination = await createFolder({ path: "/", name: "rbac-move-dest" });
try {
await grantFolderRole({ name: "e2e-rbac-move", folderId: folder.id, role: SecretFolderRole.Read });
- await clearMemberPermissionCaches();
const res = await moveFolderAs(memberJwtToken, { folderId: folder.id, destinationPath: "/rbac-move-dest" });
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
+ expect(res.statusCode).toBe(200);
+ // the moved folder is recreated under a new id and the grant must follow it
const [privilege] = await testDb(TableName.AdditionalPrivilege).where({ name: "e2e-rbac-move" });
- expect(privilege.folderId).toBe(folder.id);
+ expect(privilege).toBeDefined();
+ expect(privilege.folderId).not.toBe(folder.id);
} finally {
- await deleteFolder({ path: "/", id: folder.id, forceDelete: true });
+ await tryDeleteFolder({ path: "/", id: folder.id });
await deleteFolder({ path: "/", id: destination.id, forceDelete: true });
- await clearMemberPermissionCaches();
}
});
- test("blocks a member without manage-access from moving a parent whose descendant has a grant", async () => {
+ test("lets a member move a parent whose descendant folder has a grant", async () => {
const parent = await createFolder({ path: "/", name: "rbac-move-parent" });
const child = await createFolder({ path: "/rbac-move-parent", name: "rbac-move-child" });
const destination = await createFolder({ path: "/", name: "rbac-move-parent-dest" });
try {
await grantFolderRole({ name: "e2e-rbac-move-child", folderId: child.id, role: SecretFolderRole.Read });
- await clearMemberPermissionCaches();
const res = await moveFolderAs(memberJwtToken, {
folderId: parent.id,
destinationPath: "/rbac-move-parent-dest"
});
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
- } finally {
- await deleteFolder({ path: "/", id: parent.id, forceDelete: true });
- await deleteFolder({ path: "/", id: destination.id, forceDelete: true });
- await clearMemberPermissionCaches();
- }
- });
-
- test("allows a member to move a folder with no grants", async () => {
- const folder = await createFolder({ path: "/", name: "rbac-move-free" });
- const destination = await createFolder({ path: "/", name: "rbac-move-free-dest" });
-
- try {
- await clearMemberPermissionCaches();
- const res = await moveFolderAs(memberJwtToken, {
- folderId: folder.id,
- destinationPath: "/rbac-move-free-dest"
- });
expect(res.statusCode).toBe(200);
+
+ const [privilege] = await testDb(TableName.AdditionalPrivilege).where({ name: "e2e-rbac-move-child" });
+ expect(privilege).toBeDefined();
+ expect(privilege.folderId).not.toBe(child.id);
} finally {
+ await tryDeleteFolder({ path: "/", id: parent.id });
await deleteFolder({ path: "/", id: destination.id, forceDelete: true });
- await clearMemberPermissionCaches();
}
});
- test("blocks a member without manage-access from renaming a folder that has a grant", async () => {
+ test("lets a member rename a folder that has a grant", async () => {
const folder = await createFolder({ path: "/", name: "rbac-rename-src" });
try {
await grantFolderRole({ name: "e2e-rbac-rename", folderId: folder.id, role: SecretFolderRole.Read });
- await clearMemberPermissionCaches();
const res = await renameFolderAs(memberJwtToken, {
id: folder.id,
path: "/",
name: "rbac-rename-src-renamed"
});
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
+ expect(res.statusCode).toBe(200);
} finally {
await deleteFolder({ path: "/", id: folder.id, forceDelete: true });
- await clearMemberPermissionCaches();
}
});
- test("blocks the batch route from renaming a folder that has a grant", async () => {
+ test("lets the batch route rename a folder that has a grant", async () => {
const folder = await createFolder({ path: "/", name: "rbac-rename-batch" });
try {
await grantFolderRole({ name: "e2e-rbac-rename-batch", folderId: folder.id, role: SecretFolderRole.Read });
- await clearMemberPermissionCaches();
const res = await renameFolderBatchAs(memberJwtToken, {
id: folder.id,
path: "/",
name: "rbac-rename-batch-renamed"
});
- expect(res.statusCode).toBe(403);
- expect(res.json().message).toContain("manage folder access");
+ expect(res.statusCode).toBe(200);
} finally {
await deleteFolder({ path: "/", id: folder.id, forceDelete: true });
- await clearMemberPermissionCaches();
}
});
- test("allows a description-only update on a granted folder, since no path moves", async () => {
+ test("lets a member update the description of a granted folder", async () => {
const folder = await createFolder({ path: "/", name: "rbac-rename-desc" });
try {
await grantFolderRole({ name: "e2e-rbac-rename-desc", folderId: folder.id, role: SecretFolderRole.Read });
- await clearMemberPermissionCaches();
const res = await renameFolderAs(memberJwtToken, {
id: folder.id,
@@ -776,11 +736,10 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
expect(res.statusCode).toBe(200);
} finally {
await deleteFolder({ path: "/", id: folder.id, forceDelete: true });
- await clearMemberPermissionCaches();
}
});
- test("lets the full-access tier rename its own granted folder but not move it elsewhere", async () => {
+ test("lets a full-access grant holder rename and move their granted folder", async () => {
const folder = await createFolder({ path: "/", name: "rbac-relocate-full" });
const destination = await createFolder({ path: "/", name: "rbac-relocate-full-dest" });
@@ -788,11 +747,11 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
await grantFolderRole({
name: "e2e-rbac-relocate-full",
folderId: folder.id,
- role: SecretFolderRole.FullAccess
+ role: SecretFolderRole.FullAccess,
+ actorUserId: memberUserId
});
await clearMemberPermissionCaches();
- // the tier confers manage-access at the folder's own path, which is the only scope a rename changes
const renamed = await renameFolderAs(memberJwtToken, {
id: folder.id,
path: "/",
@@ -800,16 +759,18 @@ describe("Folder move and rename require manage-access on RBAC-granted folders",
});
expect(renamed.statusCode).toBe(200);
- // a move needs manage-access at the destination too, which the tier does not confer
await clearMemberPermissionCaches();
const moved = await moveFolderAs(memberJwtToken, {
folderId: folder.id,
destinationPath: "/rbac-relocate-full-dest"
});
- expect(moved.statusCode).toBe(403);
- expect(moved.json().message).toContain("manage folder access");
+ expect(moved.statusCode).toBe(200);
+
+ const [privilege] = await testDb(TableName.AdditionalPrivilege).where({ name: "e2e-rbac-relocate-full" });
+ expect(privilege).toBeDefined();
+ expect(privilege.folderId).not.toBe(folder.id);
} finally {
- await deleteFolder({ path: "/", id: folder.id, forceDelete: true });
+ await tryDeleteFolder({ path: "/", id: folder.id });
await deleteFolder({ path: "/", id: destination.id, forceDelete: true });
await clearMemberPermissionCaches();
}
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 44355111d2..e4be934a99 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -1844,6 +1844,14 @@ export const FOLDER_ACCESS = {
limit: "The number of machine identities to return.",
search: "The text string that machine identity names will be filtered by."
},
+ LIST_USER_GRANTS: {
+ projectId: "The ID of the project to list the user's folder access grants in.",
+ userId: "The ID of the user whose folder access grants to list."
+ },
+ LIST_IDENTITY_GRANTS: {
+ projectId: "The ID of the project to list the machine identity's folder access grants in.",
+ identityId: "The ID of the machine identity whose folder access grants to list."
+ },
PERMISSION_AUDIT: {
includeFolderPermissions: "Whether to include folder-scoped access grants in the returned permission sources."
}
diff --git a/backend/src/server/routes/v1/identity-project-membership-router.ts b/backend/src/server/routes/v1/identity-project-membership-router.ts
index 78e051f3cd..070003e91a 100644
--- a/backend/src/server/routes/v1/identity-project-membership-router.ts
+++ b/backend/src/server/routes/v1/identity-project-membership-router.ts
@@ -729,6 +729,44 @@ export const registerIdentityProjectMembershipRouter = async (server: FastifyZod
}
});
+ server.route({
+ method: "GET",
+ url: "/identities/:identityId/secret-folder-access",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ hide: true,
+ operationId: "listIdentityFolderAccess",
+ tags: [ApiDocsTags.FolderAccess],
+ description: "List every folder a machine identity has been granted access on in a project.",
+ security: [
+ {
+ bearerAuth: []
+ }
+ ],
+ params: z.object({
+ projectId: z.string().trim().min(1).max(64).describe(FOLDER_ACCESS.LIST_IDENTITY_GRANTS.projectId),
+ identityId: z.string().uuid().describe(FOLDER_ACCESS.LIST_IDENTITY_GRANTS.identityId)
+ }),
+ response: {
+ 200: z.object({
+ folderAccess: identityFolderAccessResponseSchema.array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ const { folderAccess } = await server.services.folderPermission.listActorFolderGrants({
+ permission: req.permission,
+ projectId: req.params.projectId,
+ target: { actorId: req.params.identityId, actorType: ActorType.IDENTITY }
+ });
+
+ return { folderAccess: folderAccess.map((grant) => ({ ...grant, identityId: req.params.identityId })) };
+ }
+ });
+
server.route({
method: "GET",
url: "/secret-folder-access/identities",
diff --git a/backend/src/server/routes/v1/project-membership-router.ts b/backend/src/server/routes/v1/project-membership-router.ts
index 966113a8b9..c0b7a9b6d1 100644
--- a/backend/src/server/routes/v1/project-membership-router.ts
+++ b/backend/src/server/routes/v1/project-membership-router.ts
@@ -856,6 +856,44 @@ export const registerProjectMembershipRouter = async (server: FastifyZodProvider
}
});
+ server.route({
+ method: "GET",
+ url: "/:projectId/users/:userId/secret-folder-access",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ hide: true,
+ operationId: "listUserFolderAccess",
+ tags: [ApiDocsTags.FolderAccess],
+ description: "List every folder a user has been granted access on in a project.",
+ security: [
+ {
+ bearerAuth: []
+ }
+ ],
+ params: z.object({
+ projectId: z.string().trim().min(1).max(64).describe(FOLDER_ACCESS.LIST_USER_GRANTS.projectId),
+ userId: z.string().uuid().describe(FOLDER_ACCESS.LIST_USER_GRANTS.userId)
+ }),
+ response: {
+ 200: z.object({
+ folderAccess: userFolderAccessResponseSchema.array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ const { folderAccess } = await server.services.folderPermission.listActorFolderGrants({
+ permission: req.permission,
+ projectId: req.params.projectId,
+ target: { actorId: req.params.userId, actorType: ActorType.USER }
+ });
+
+ return { folderAccess: folderAccess.map((grant) => ({ ...grant, userId: req.params.userId })) };
+ }
+ });
+
server.route({
method: "GET",
url: "/:projectId/secret-folder-access/users",
diff --git a/backend/src/services/folder-permission/folder-permission-fns.ts b/backend/src/services/folder-permission/folder-permission-fns.ts
index 520de32c7e..d15e2eb48a 100644
--- a/backend/src/services/folder-permission/folder-permission-fns.ts
+++ b/backend/src/services/folder-permission/folder-permission-fns.ts
@@ -3,6 +3,8 @@ import { ForbiddenError, subject } from "@casl/ability";
import { ActionProjectType, SecretFolderRole, TAdditionalPrivileges, TemporaryPermissionMode } from "@app/db/schemas";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import {
+ ProjectPermissionIdentityActions,
+ ProjectPermissionMemberActions,
ProjectPermissionSecretFolderActions,
ProjectPermissionSub
} from "@app/ee/services/permission/project-permission";
@@ -83,6 +85,23 @@ export const getFolderAccessPermission = async (
return callerPermission;
};
+export const assertReadActorGrantsAccess = (
+ callerPermission: Awaited<ReturnType<typeof getFolderAccessPermission>>,
+ target: TFolderGrantActor
+) => {
+ if (target.actorType === ActorType.USER) {
+ ForbiddenError.from(callerPermission).throwUnlessCan(
+ ProjectPermissionMemberActions.Read,
+ ProjectPermissionSub.Member
+ );
+ } else {
+ ForbiddenError.from(callerPermission).throwUnlessCan(
+ ProjectPermissionIdentityActions.Read,
+ ProjectPermissionSub.Identity
+ );
+ }
+};
+
export const assertManageFolderAccess = (
callerPermission: Awaited<ReturnType<typeof getFolderAccessPermission>>,
folder: TResolvedFolder
diff --git a/backend/src/services/folder-permission/folder-permission-service.ts b/backend/src/services/folder-permission/folder-permission-service.ts
index 929f678743..de785f8c23 100644
--- a/backend/src/services/folder-permission/folder-permission-service.ts
+++ b/backend/src/services/folder-permission/folder-permission-service.ts
@@ -13,6 +13,7 @@ import {
assertFullAccessIsPermanent,
assertGrantTargetEligible,
assertManageFolderAccess,
+ assertReadActorGrantsAccess,
computeTemporaryFields,
getFolderAccessPermission,
resolveFolder,
@@ -23,6 +24,7 @@ import {
import {
TCreateFolderGrantDTO,
TDeleteFolderGrantDTO,
+ TListActorFolderGrantsDTO,
TListFolderAccessActorsDTO,
TUpdateFolderGrantDTO
} from "./folder-permission-types";
@@ -30,9 +32,9 @@ import {
type TFolderPermissionServiceFactoryDep = {
additionalPrivilegeDAL: Pick<
TAdditionalPrivilegeDALFactory,
- "findOne" | "create" | "updateById" | "deleteById" | "transaction"
+ "findOne" | "find" | "create" | "updateById" | "deleteById" | "transaction"
>;
- secretFolderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath">;
+ secretFolderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findSecretPathByFolderIds">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "invalidateProjectFolderPermissionCache">;
folderPermissionDAL: Pick<
TFolderPermissionDALFactory,
@@ -209,11 +211,45 @@ export const folderPermissionServiceFactory = ({
};
};
+ const listActorFolderGrants = async (dto: TListActorFolderGrantsDTO) => {
+ const { projectId, target } = dto;
+ const callerPermission = await getFolderAccessPermission(dto.permission, projectId, permissionService);
+ assertReadActorGrantsAccess(callerPermission, target);
+
+ const rows = await additionalPrivilegeDAL.find({
+ projectId,
+ [targetActorField(target)]: target.actorId,
+ $notNull: ["folderId"]
+ });
+ const grantRows = rows.filter((row) => row.role);
+ if (!grantRows.length) return { folderAccess: [] };
+
+ const folders = await secretFolderDAL.findSecretPathByFolderIds(
+ projectId,
+ grantRows.map((row) => row.folderId as string)
+ );
+
+ // a grant whose folder no longer resolves (soft-deleted environment) is omitted, matching how
+ // the permission layer treats it
+ const folderAccess = grantRows
+ .flatMap((row, idx) => {
+ const folder = folders[idx];
+ if (!folder) return [];
+ return [
+ toFolderGrant(row, projectId, { id: folder.id, path: folder.path, environmentSlug: folder.environmentSlug })
+ ];
+ })
+ .sort((a, b) => a.environment.localeCompare(b.environment) || a.secretPath.localeCompare(b.secretPath));
+
+ return { folderAccess };
+ };
+
return {
createFolderGrant,
updateFolderGrant,
deleteFolderGrant,
listFolderAccessUsers,
- listFolderAccessIdentities
+ listFolderAccessIdentities,
+ listActorFolderGrants
};
};
diff --git a/backend/src/services/folder-permission/folder-permission-types.ts b/backend/src/services/folder-permission/folder-permission-types.ts
index bb20b3cad2..7d7ae71ccc 100644
--- a/backend/src/services/folder-permission/folder-permission-types.ts
+++ b/backend/src/services/folder-permission/folder-permission-types.ts
@@ -54,6 +54,12 @@ export type TDeleteFolderGrantDTO = {
target: TFolderGrantActor;
};
+export type TListActorFolderGrantsDTO = {
+ permission: OrgServiceActor;
+ projectId: string;
+ target: TFolderGrantActor;
+};
+
export type TListFolderAccessActorsDTO = {
permission: OrgServiceActor;
projectId: string;
diff --git a/frontend/src/hooks/api/folderAccess/index.ts b/frontend/src/hooks/api/folderAccess/index.ts
index 9110ccd172..2bd8ea0a43 100644
--- a/frontend/src/hooks/api/folderAccess/index.ts
+++ b/frontend/src/hooks/api/folderAccess/index.ts
@@ -9,7 +9,9 @@ export {
export {
folderAccessKeys,
useListFolderAccessIdentities,
- useListFolderAccessUsers
+ useListFolderAccessUsers,
+ useListIdentityFolderAccess,
+ useListUserFolderAccess
} from "./queries";
export type {
TCreateIdentityFolderAccessDTO,
@@ -20,8 +22,12 @@ export type {
TFolderAccessIdentity,
TFolderAccessUser,
TFolderGrantType,
+ TIdentityFolderAccess,
TListFolderAccessActorsDTO,
+ TListIdentityFolderAccessDTO,
+ TListUserFolderAccessDTO,
TUpdateIdentityFolderAccessDTO,
- TUpdateUserFolderAccessDTO
+ TUpdateUserFolderAccessDTO,
+ TUserFolderAccess
} from "./types";
export { SecretFolderRole } from "./types";
diff --git a/frontend/src/hooks/api/folderAccess/mutations.tsx b/frontend/src/hooks/api/folderAccess/mutations.tsx
index d069e3f21c..2d99d5355c 100644
--- a/frontend/src/hooks/api/folderAccess/mutations.tsx
+++ b/frontend/src/hooks/api/folderAccess/mutations.tsx
@@ -24,6 +24,9 @@ const invalidateFolderAccess = (
queryClient.invalidateQueries({
predicate: (query) => {
const label = query.queryKey[1];
+ if (label === "user-folder-access" || label === "identity-folder-access") {
+ return (query.queryKey[0] as { projectId?: string })?.projectId === projectId;
+ }
if (label !== "folder-access-users" && label !== "folder-access-identities") return false;
const params = query.queryKey[0] as {
projectId?: string;
diff --git a/frontend/src/hooks/api/folderAccess/queries.tsx b/frontend/src/hooks/api/folderAccess/queries.tsx
index 60887c8c6e..df352c2c25 100644
--- a/frontend/src/hooks/api/folderAccess/queries.tsx
+++ b/frontend/src/hooks/api/folderAccess/queries.tsx
@@ -2,7 +2,15 @@ import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
-import { TFolderAccessIdentity, TFolderAccessUser, TListFolderAccessActorsDTO } from "./types";
+import {
+ TFolderAccessIdentity,
+ TFolderAccessUser,
+ TIdentityFolderAccess,
+ TListFolderAccessActorsDTO,
+ TListIdentityFolderAccessDTO,
+ TListUserFolderAccessDTO,
+ TUserFolderAccess
+} from "./types";
const DEFAULT_LIMIT = 50;
@@ -30,7 +38,11 @@ export const folderAccessKeys = {
[
{ projectId, environmentSlug, secretPath, offset, limit, search },
"folder-access-identities"
- ] as const
+ ] as const,
+ listUserGrants: ({ projectId, userId }: TListUserFolderAccessDTO) =>
+ [{ projectId, userId }, "user-folder-access"] as const,
+ listIdentityGrants: ({ projectId, identityId }: TListIdentityFolderAccessDTO) =>
+ [{ projectId, identityId }, "identity-folder-access"] as const
};
export const useListFolderAccessUsers = ({
@@ -62,6 +74,33 @@ export const useListFolderAccessUsers = ({
enabled: Boolean(projectId) && Boolean(environmentSlug) && Boolean(secretPath)
});
+export const useListUserFolderAccess = ({ projectId, userId }: TListUserFolderAccessDTO) =>
+ useQuery({
+ queryKey: folderAccessKeys.listUserGrants({ projectId, userId }),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ folderAccess: TUserFolderAccess[] }>(
+ `/api/v1/projects/${projectId}/users/${userId}/secret-folder-access`
+ );
+ return data.folderAccess;
+ },
+ enabled: Boolean(projectId) && Boolean(userId)
+ });
+
+export const useListIdentityFolderAccess = ({
+ projectId,
+ identityId
+}: TListIdentityFolderAccessDTO) =>
+ useQuery({
+ queryKey: folderAccessKeys.listIdentityGrants({ projectId, identityId }),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ folderAccess: TIdentityFolderAccess[] }>(
+ `/api/v1/projects/${projectId}/memberships/identities/${identityId}/secret-folder-access`
+ );
+ return data.folderAccess;
+ },
+ enabled: Boolean(projectId) && Boolean(identityId)
+ });
+
export const useListFolderAccessIdentities = ({
projectId,
environmentSlug,
diff --git a/frontend/src/hooks/api/folderAccess/types.ts b/frontend/src/hooks/api/folderAccess/types.ts
index 9b0cd4239c..7d75f963bb 100644
--- a/frontend/src/hooks/api/folderAccess/types.ts
+++ b/frontend/src/hooks/api/folderAccess/types.ts
@@ -47,6 +47,20 @@ export type TFolderAccessIdentity = {
folderRBACAccess: TFolderAccess | null;
};
+export type TUserFolderAccess = TFolderAccess & { userId: string };
+
+export type TIdentityFolderAccess = TFolderAccess & { identityId: string };
+
+export type TListUserFolderAccessDTO = {
+ projectId: string;
+ userId: string;
+};
+
+export type TListIdentityFolderAccessDTO = {
+ projectId: string;
+ identityId: string;
+};
+
export type TListFolderAccessActorsDTO = {
projectId: string;
environmentSlug: string;
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
index 561fd04dc3..ff892f8d74 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
@@ -54,6 +54,7 @@ import { ActorType } from "@app/hooks/api/auditLogs/enums";
import { useRemovePamProductIdentityMember } from "@app/hooks/api/pam";
import { projectIdentityQuery, useDeleteProjectIdentity } from "@app/hooks/api/projectIdentity";
import { ProjectType } from "@app/hooks/api/projects/types";
+import { FolderAccessSection } from "@app/pages/project/components/FolderAccessSection";
import { ProjectIdentityAuthenticationSection } from "@app/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAuthSection";
import { ProjectIdentityDetailsSection } from "@app/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection";
import { ProjectAccessControlTabs } from "@app/types/project";
@@ -371,6 +372,15 @@ const Page = () => {
identityMembershipDetails={identityMembershipDetails}
/>
)}
+ {currentProject.type === ProjectType.SecretManager && (
+ <FolderAccessSection
+ actor={{
+ type: "identity",
+ id: identityMembershipDetails.identity.id,
+ name: identityMembershipDetails.identity.name
+ }}
+ />
+ )}
</div>
</div>
<IdentityActionConfirmationDialog
diff --git a/frontend/src/pages/project/MemberDetailsByIDPage/MemberDetailsByIDPage.tsx b/frontend/src/pages/project/MemberDetailsByIDPage/MemberDetailsByIDPage.tsx
index 71c5450790..fb01efe19a 100644
--- a/frontend/src/pages/project/MemberDetailsByIDPage/MemberDetailsByIDPage.tsx
+++ b/frontend/src/pages/project/MemberDetailsByIDPage/MemberDetailsByIDPage.tsx
@@ -49,6 +49,7 @@ import { usePopUp } from "@app/hooks";
import { useDeleteUserFromWorkspace, useGetWorkspaceUserDetails } from "@app/hooks/api";
import { ActorType } from "@app/hooks/api/auditLogs/enums";
import { ProjectType } from "@app/hooks/api/projects/types";
+import { FolderAccessSection } from "@app/pages/project/components/FolderAccessSection";
import { ProjectAccessControlTabs } from "@app/types/project";
import { MemberPermissionAuditSheet } from "./components/MemberPermissionAuditSheet";
@@ -283,6 +284,20 @@ export const Page = () => {
{!isCertManager && currentProject.isLegacyAdditionalPrivilegesEnabled && (
<MemberProjectAdditionalPrivilegeSection membershipDetails={membershipDetails} />
)}
+ {currentProject.type === ProjectType.SecretManager && (
+ <FolderAccessSection
+ actor={{
+ type: "user",
+ id: membershipDetails.user.id,
+ membershipId: membershipDetails.id,
+ username: membershipDetails.user.username,
+ email: membershipDetails.user.email,
+ firstName: membershipDetails.user.firstName,
+ lastName: membershipDetails.user.lastName
+ }}
+ hideActions={isOwnProjectMembershipDetails}
+ />
+ )}
</div>
</div>
<DeleteConfirmDialog
diff --git a/frontend/src/pages/project/components/FolderAccessSection/EditFolderAccessSheet.tsx b/frontend/src/pages/project/components/FolderAccessSection/EditFolderAccessSheet.tsx
new file mode 100644
index 0000000000..2d51a8012e
--- /dev/null
+++ b/frontend/src/pages/project/components/FolderAccessSection/EditFolderAccessSheet.tsx
@@ -0,0 +1,264 @@
+import { useState } from "react";
+import { ChevronDownIcon, ClockIcon, FolderIcon, InfoIcon } from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Badge,
+ Button,
+ Input,
+ Label,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ Sheet,
+ SheetContent,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
+import {
+ SecretFolderRole,
+ TFolderAccess,
+ TFolderGrantType,
+ useUpdateIdentityFolderAccess,
+ useUpdateUserFolderAccess
+} from "@app/hooks/api/folderAccess";
+import {
+ DEFAULT_TEMPORARY_RANGE,
+ TEMPORARY_RANGE_PRESETS
+} from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.const";
+import {
+ expiryOf,
+ formatExpiryFull,
+ isValidTemporaryRange
+} from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils";
+import { FolderTierRadioGroup } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderTierRadioGroup";
+
+import { TFolderAccessSectionActor } from "./types";
+
+type Props = {
+ access: TFolderAccess | null;
+ actor: TFolderAccessSectionActor;
+ environmentName: string;
+ onOpenChange: (isOpen: boolean) => void;
+};
+
+type FormProps = {
+ access: TFolderAccess;
+ actor: TFolderAccessSectionActor;
+ environmentName: string;
+ onClose: () => void;
+};
+
+const EditFolderAccessForm = ({ access, actor, environmentName, onClose }: FormProps) => {
+ const [tier, setTier] = useState(access.permission);
+ const [isTemporary, setIsTemporary] = useState(access.isTemporary);
+ const [range, setRange] = useState(access.temporaryRange ?? DEFAULT_TEMPORARY_RANGE);
+ const [rangeTouched, setRangeTouched] = useState(false);
+ const [isTemporaryOpen, setIsTemporaryOpen] = useState(false);
+ const [draftRange, setDraftRange] = useState(range);
+
+ const updateUserAccess = useUpdateUserFolderAccess();
+ const updateIdentityAccess = useUpdateIdentityFolderAccess();
+
+ const currentExpiry = expiryOf(access);
+ const isRangeValid = !isTemporary || isValidTemporaryRange(range);
+ const isDraftRangeValid = isValidTemporaryRange(draftRange);
+ const tierChanged = tier !== access.permission;
+ const temporalChanged = isTemporary !== access.isTemporary || (isTemporary && rangeTouched);
+ const isFullAccessTemporary = tier === SecretFolderRole.FullAccess && isTemporary;
+ const isSaveDisabled =
+ (!tierChanged && !temporalChanged) || !isRangeValid || isFullAccessTemporary;
+
+ let temporaryLabel = "No expiration";
+ if (isTemporary) {
+ if (rangeTouched) temporaryLabel = `Expires in ${range}`;
+ else if (currentExpiry) temporaryLabel = `Expires ${formatExpiryFull(currentExpiry)}`;
+ }
+
+ const openTemporary = (nextOpen: boolean) => {
+ if (nextOpen) setDraftRange(isTemporary ? range : DEFAULT_TEMPORARY_RANGE);
+ setIsTemporaryOpen(nextOpen);
+ };
+
+ const handleSave = async () => {
+ // an untouched temporal state is omitted entirely so a tier-only edit does not restart the
+ // expiry window; a touched range always restarts it from now, same as the roster's Apply
+ let type: TFolderGrantType | undefined;
+ if (temporalChanged) {
+ type = isTemporary
+ ? {
+ isTemporary: true,
+ temporaryMode: "relative",
+ temporaryRange: range,
+ temporaryAccessStartTime: new Date().toISOString()
+ }
+ : { isTemporary: false };
+ }
+
+ const payload = {
+ projectId: access.projectId,
+ environmentSlug: access.environment,
+ secretPath: access.secretPath,
+ permission: tierChanged ? tier : undefined,
+ type
+ };
+
+ if (actor.type === "user") {
+ await updateUserAccess.mutateAsync({ ...payload, userId: actor.id });
+ } else {
+ await updateIdentityAccess.mutateAsync({ ...payload, identityId: actor.id });
+ }
+ createNotification({ type: "success", text: "Folder access updated" });
+ onClose();
+ };
+
+ return (
+ <>
+ <SheetHeader>
+ <SheetTitle className="flex items-center gap-2">
+ Edit Folder Access
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <InfoIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-72">
+ Permissions granted here apply within this folder. The folder itself can still be
+ moved, edited, or deleted by anyone with folder edit or delete permissions.
+ </TooltipContent>
+ </Tooltip>
+ </SheetTitle>
+ <div className="mt-2 flex min-w-0 items-center gap-2 text-xs">
+ <FolderIcon className="size-3.5 shrink-0 text-folder" />
+ <span className="truncate font-mono text-accent">{access.secretPath}</span>
+ <Badge variant="project" className="shrink-0">
+ {environmentName}
+ </Badge>
+ </div>
+ </SheetHeader>
+
+ <div className="thin-scrollbar flex-1 space-y-5 overflow-y-auto p-4">
+ <div className="space-y-2">
+ <Label>Permission</Label>
+ <FolderTierRadioGroup value={tier} onValueChange={setTier} />
+ {isFullAccessTemporary && (
+ <p className="text-xs text-danger">
+ Full Access cannot be temporary. Remove the expiration or choose a lower tier.
+ </p>
+ )}
+ </div>
+
+ <div className="space-y-2">
+ <Label>Temporary access</Label>
+ <Popover open={isTemporaryOpen} onOpenChange={openTemporary}>
+ <PopoverTrigger asChild>
+ <Button variant="outline" size="sm" className="w-full justify-between">
+ <span className="flex items-center gap-2">
+ <ClockIcon className="size-3.5" />
+ {temporaryLabel}
+ </span>
+ <ChevronDownIcon />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ align="start"
+ className="w-72 space-y-3 p-4"
+ onFocusOutside={(e) => e.preventDefault()}
+ >
+ <div className="space-y-1">
+ <p className="text-sm font-medium text-foreground">Temporary access</p>
+ <p className="text-xs text-muted">
+ Access is revoked automatically once the duration elapses.
+ {access.isTemporary && " Applying a new duration restarts the window from now."}
+ </p>
+ </div>
+ <Input
+ value={draftRange}
+ onChange={(e) => setDraftRange(e.target.value)}
+ placeholder={DEFAULT_TEMPORARY_RANGE}
+ />
+ <div className="flex gap-1.5">
+ {TEMPORARY_RANGE_PRESETS.map((preset) => (
+ <Button
+ key={preset}
+ variant="outline"
+ size="xs"
+ onClick={() => setDraftRange(preset)}
+ >
+ {preset}
+ </Button>
+ ))}
+ </div>
+ {!isDraftRangeValid && (
+ <p className="text-xs text-danger">Enter a duration such as 30m, 4h or 1d.</p>
+ )}
+ <div className="flex justify-between gap-2">
+ {isTemporary ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-danger"
+ onClick={() => {
+ setIsTemporary(false);
+ setIsTemporaryOpen(false);
+ }}
+ >
+ Remove expiration
+ </Button>
+ ) : (
+ <span />
+ )}
+ <Button
+ variant="project"
+ size="sm"
+ isDisabled={!isDraftRangeValid}
+ onClick={() => {
+ setRange(draftRange);
+ setRangeTouched(true);
+ setIsTemporary(true);
+ setIsTemporaryOpen(false);
+ }}
+ >
+ Apply
+ </Button>
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ </div>
+
+ <SheetFooter className="border-t">
+ <Button variant="outline" onClick={onClose}>
+ Cancel
+ </Button>
+ <Button
+ variant="project"
+ isDisabled={isSaveDisabled}
+ isPending={updateUserAccess.isPending || updateIdentityAccess.isPending}
+ onClick={handleSave}
+ >
+ Save Changes
+ </Button>
+ </SheetFooter>
+ </>
+ );
+};
+
+export const EditFolderAccessSheet = ({ access, actor, environmentName, onOpenChange }: Props) => (
+ <Sheet open={Boolean(access)} onOpenChange={onOpenChange}>
+ <SheetContent className="gap-y-0 sm:max-w-[600px]">
+ {access && (
+ <EditFolderAccessForm
+ key={access.id}
+ access={access}
+ actor={actor}
+ environmentName={environmentName}
+ onClose={() => onOpenChange(false)}
+ />
+ )}
+ </SheetContent>
+ </Sheet>
+);
diff --git a/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx b/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx
new file mode 100644
index 0000000000..3640989b9c
--- /dev/null
+++ b/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx
@@ -0,0 +1,323 @@
+import { useState } from "react";
+import { subject } from "@casl/ability";
+import { format, formatDistance } from "date-fns";
+import {
+ CircleAlertIcon,
+ ClockAlertIcon,
+ ClockIcon,
+ FolderIcon,
+ RefreshCwIcon,
+ Trash2Icon,
+ UsersIcon
+} from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ Badge,
+ Button,
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Empty,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyTitle,
+ IconButton,
+ PageLoader,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
+import {
+ ProjectPermissionSecretFolderActions,
+ ProjectPermissionSub,
+ useProject,
+ useProjectPermission
+} from "@app/context";
+import {
+ TFolderAccess,
+ useDeleteIdentityFolderAccess,
+ useDeleteUserFolderAccess,
+ useListIdentityFolderAccess,
+ useListUserFolderAccess
+} from "@app/hooks/api/folderAccess";
+import { FOLDER_ROLE_TIER_LABELS } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.const";
+import {
+ toIdentityActor,
+ toUserActor
+} from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils";
+import { RemoveFolderAccessDialog } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/RemoveFolderAccessDialog";
+
+import { EditFolderAccessSheet } from "./EditFolderAccessSheet";
+import { TFolderAccessSectionActor } from "./types";
+
+type Props = {
+ actor: TFolderAccessSectionActor;
+ hideActions?: boolean;
+};
+
+export const FolderAccessSection = ({ actor, hideActions = false }: Props) => {
+ const { projectId, currentProject } = useProject();
+ const { permission } = useProjectPermission();
+
+ const [editTarget, setEditTarget] = useState<TFolderAccess | null>(null);
+ const [deleteTarget, setDeleteTarget] = useState<TFolderAccess | null>(null);
+
+ const userAccess = useListUserFolderAccess({
+ projectId,
+ userId: actor.type === "user" ? actor.id : ""
+ });
+ const identityAccess = useListIdentityFolderAccess({
+ projectId,
+ identityId: actor.type === "identity" ? actor.id : ""
+ });
+ const {
+ data: folderAccess,
+ isPending,
+ isError,
+ refetch
+ } = actor.type === "user" ? userAccess : identityAccess;
+
+ const deleteUserAccess = useDeleteUserFolderAccess();
+ const deleteIdentityAccess = useDeleteIdentityFolderAccess();
+
+ const environmentNameOf = (slug: string) =>
+ currentProject?.environments.find((env) => env.slug === slug)?.name ?? slug;
+
+ const canManageAccessOn = (row: TFolderAccess) =>
+ permission.can(
+ ProjectPermissionSecretFolderActions.ManageAccess,
+ subject(ProjectPermissionSub.SecretFolders, {
+ environment: row.environment,
+ secretPath: row.secretPath
+ })
+ );
+
+ const actorNoun = actor.type === "user" ? "user" : "machine identity";
+
+ const dialogActor = (() => {
+ if (!deleteTarget) return null;
+ if (actor.type === "user") {
+ return toUserActor({
+ userId: actor.id,
+ membershipId: actor.membershipId,
+ username: actor.username,
+ email: actor.email,
+ firstName: actor.firstName,
+ lastName: actor.lastName,
+ folderRBACAccess: deleteTarget
+ });
+ }
+ return toIdentityActor({
+ identityId: actor.id,
+ name: actor.name,
+ folderRBACAccess: deleteTarget
+ });
+ })();
+
+ const handleDelete = async () => {
+ if (!deleteTarget) return;
+ const target = {
+ projectId,
+ environmentSlug: deleteTarget.environment,
+ secretPath: deleteTarget.secretPath
+ };
+ if (actor.type === "user") {
+ await deleteUserAccess.mutateAsync({ ...target, userId: actor.id });
+ } else {
+ await deleteIdentityAccess.mutateAsync({ ...target, identityId: actor.id });
+ }
+ createNotification({ type: "success", text: "Folder access removed" });
+ setDeleteTarget(null);
+ };
+
+ return (
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>Folder Access</CardTitle>
+ <CardDescription>
+ Folder-level access for this {actorNoun}. Overrides{" "}
+ {actor.type === "user" ? "their" : "its"} project roles within each folder.
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ {isError && (
+ <Alert variant="danger">
+ <CircleAlertIcon />
+ <AlertTitle>Could not load folder access</AlertTitle>
+ <AlertDescription>
+ <span>Retry to load this {actorNoun}&apos;s folder access.</span>
+ <Button size="xs" variant="danger" onClick={() => refetch().catch(() => undefined)}>
+ <RefreshCwIcon />
+ Retry
+ </Button>
+ </AlertDescription>
+ </Alert>
+ )}
+ {!isError && isPending && (
+ <div className="h-40 w-full">
+ <PageLoader lottieClassName="w-16" />
+ </div>
+ )}
+ {!isError &&
+ !isPending &&
+ (folderAccess?.length ? (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-2/5">Folder</TableHead>
+ <TableHead>Environment</TableHead>
+ <TableHead>Access</TableHead>
+ <TableHead>Duration</TableHead>
+ {!hideActions && <TableHead variant="action" />}
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {folderAccess.map((row) => {
+ const isExpired =
+ row.isTemporary && new Date() > new Date(row.temporaryAccessEndTime || "");
+
+ let text = "Permanent";
+ let toolTipText = "Non-Expiring Access";
+ if (row.isTemporary) {
+ if (isExpired) {
+ text = "Access Expired";
+ toolTipText = "Timed Access Expired";
+ } else {
+ text = formatDistance(
+ new Date(row.temporaryAccessEndTime || ""),
+ new Date()
+ );
+ toolTipText = `Until ${format(
+ new Date(row.temporaryAccessEndTime || ""),
+ "yyyy-MM-dd hh:mm:ss aaa"
+ )}`;
+ }
+ }
+
+ const canManage = canManageAccessOn(row);
+
+ return (
+ <TableRow key={`folder-access-${row.id}`}>
+ <TableCell>
+ <div className="flex min-w-0 items-center gap-2">
+ <FolderIcon className="size-3.5 shrink-0 text-folder" />
+ <span className="truncate font-mono">{row.secretPath}</span>
+ </div>
+ </TableCell>
+ <TableCell>{environmentNameOf(row.environment)}</TableCell>
+ <TableCell>{FOLDER_ROLE_TIER_LABELS[row.permission]}</TableCell>
+ <TableCell>
+ {row.isTemporary ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Badge
+ className="capitalize"
+ variant={isExpired ? "danger" : "warning"}
+ >
+ {isExpired ? <ClockAlertIcon /> : <ClockIcon />}
+ {text}
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent>{toolTipText}</TooltipContent>
+ </Tooltip>
+ ) : (
+ text
+ )}
+ </TableCell>
+ {!hideActions && (
+ <TableCell variant="action">
+ <div className="flex items-center justify-end">
+ <Tooltip disableHoverableContent>
+ <TooltipTrigger>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ aria-label="Manage folder access"
+ isDisabled={!canManage}
+ onClick={(e) => {
+ setEditTarget(row);
+ e.stopPropagation();
+ }}
+ >
+ <UsersIcon />
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>
+ {canManage ? "Manage Access" : "Access Restricted"}
+ </TooltipContent>
+ </Tooltip>
+ <Tooltip disableHoverableContent>
+ <TooltipTrigger>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ aria-label="Remove folder access"
+ className="hover:text-danger"
+ isDisabled={!canManage}
+ onClick={(e) => {
+ setDeleteTarget(row);
+ e.stopPropagation();
+ }}
+ >
+ <Trash2Icon />
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>
+ {canManage ? "Remove Folder Access" : "Access Restricted"}
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </TableCell>
+ )}
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ ) : (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>This {actorNoun} has no folder access</EmptyTitle>
+ <EmptyDescription>
+ Grant folder-level access from the Secrets overview using a folder&apos;s Manage
+ Access action
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ ))}
+ </CardContent>
+ </Card>
+ <EditFolderAccessSheet
+ access={editTarget}
+ actor={actor}
+ environmentName={editTarget ? environmentNameOf(editTarget.environment) : ""}
+ onOpenChange={(isOpen) => {
+ if (!isOpen) setEditTarget(null);
+ }}
+ />
+ <RemoveFolderAccessDialog
+ actor={dialogActor}
+ onOpenChange={(isOpen) => {
+ if (!isOpen) setDeleteTarget(null);
+ }}
+ onConfirm={() => handleDelete()}
+ isPending={deleteUserAccess.isPending || deleteIdentityAccess.isPending}
+ folderPath={deleteTarget?.secretPath ?? ""}
+ environmentName={deleteTarget ? environmentNameOf(deleteTarget.environment) : ""}
+ />
+ </>
+ );
+};
diff --git a/frontend/src/pages/project/components/FolderAccessSection/index.tsx b/frontend/src/pages/project/components/FolderAccessSection/index.tsx
new file mode 100644
index 0000000000..94d265b2dd
--- /dev/null
+++ b/frontend/src/pages/project/components/FolderAccessSection/index.tsx
@@ -0,0 +1,2 @@
+export { FolderAccessSection } from "./FolderAccessSection";
+export type { TFolderAccessSectionActor } from "./types";
diff --git a/frontend/src/pages/project/components/FolderAccessSection/types.ts b/frontend/src/pages/project/components/FolderAccessSection/types.ts
new file mode 100644
index 0000000000..b9aff93923
--- /dev/null
+++ b/frontend/src/pages/project/components/FolderAccessSection/types.ts
@@ -0,0 +1,15 @@
+export type TFolderAccessSectionActor =
+ | {
+ type: "user";
+ id: string;
+ membershipId: string | null;
+ username: string;
+ email: string | null;
+ firstName: string | null;
+ lastName: string | null;
+ }
+ | {
+ type: "identity";
+ id: string;
+ name: string;
+ };
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/AddFolderAccessSheet.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/AddFolderAccessSheet.tsx
index 0547d7c029..18a0f75870 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/AddFolderAccessSheet.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/AddFolderAccessSheet.tsx
@@ -8,8 +8,6 @@ import {
FilterableSelect,
Input,
Label,
- RadioGroup,
- RadioGroupItem,
Sheet,
SheetContent,
SheetFooter,
@@ -25,17 +23,14 @@ import {
useListFolderAccessUsers
} from "@app/hooks/api/folderAccess";
-import {
- DEFAULT_TEMPORARY_RANGE,
- FOLDER_ROLE_TIERS,
- TEMPORARY_RANGE_PRESETS
-} from "./folder-access.const";
+import { DEFAULT_TEMPORARY_RANGE, TEMPORARY_RANGE_PRESETS } from "./folder-access.const";
import {
isValidTemporaryRange,
TFolderAccessActor,
toIdentityActor,
toUserActor
} from "./folder-access.utils";
+import { FolderTierRadioGroup } from "./FolderTierRadioGroup";
const CANDIDATE_LIMIT = 100;
@@ -182,33 +177,7 @@ export const AddFolderAccessSheet = ({
<div className="space-y-2">
<Label>Permission</Label>
- <RadioGroup value={tier} onValueChange={(value) => setTier(value as SecretFolderRole)}>
- {FOLDER_ROLE_TIERS.map((option) => (
- <Label
- key={option.value}
- htmlFor={`folder-tier-${option.value}`}
- className={`flex cursor-pointer items-start gap-3 rounded-lg border p-3 ${
- tier === option.value
- ? "border-project/35 bg-project/5"
- : "border-border bg-card"
- }`}
- >
- <RadioGroupItem
- id={`folder-tier-${option.value}`}
- value={option.value}
- className="mt-0.5"
- />
- <span className="space-y-0.5">
- <span className="block text-sm font-medium text-foreground">
- {option.label}
- </span>
- <span className="block text-xs leading-relaxed text-muted">
- {option.description}
- </span>
- </span>
- </Label>
- ))}
- </RadioGroup>
+ <FolderTierRadioGroup value={tier} onValueChange={setTier} />
</div>
<div className="space-y-2">
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderAccessSheet.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderAccessSheet.tsx
index 9576872202..98911f876b 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderAccessSheet.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderAccessSheet.tsx
@@ -1,5 +1,5 @@
import { useMemo, useState } from "react";
-import { FolderIcon, SearchIcon, UsersIcon } from "lucide-react";
+import { FolderIcon, InfoIcon, SearchIcon, UsersIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
@@ -18,7 +18,10 @@ import {
SheetContent,
SheetHeader,
SheetTitle,
- Skeleton
+ Skeleton,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
} from "@app/components/v3";
import { useDebounce } from "@app/hooks";
import {
@@ -156,7 +159,18 @@ export const FolderAccessSheet = ({
<Sheet open={isOpen} onOpenChange={onOpenChange}>
<SheetContent className="gap-y-0 sm:max-w-[640px]">
<SheetHeader>
- <SheetTitle>Manage Permissions</SheetTitle>
+ <SheetTitle className="flex items-center gap-2">
+ Manage Permissions
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <InfoIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-72">
+ Permissions granted here apply within this folder. The folder itself can still be
+ moved, edited, or deleted by anyone with folder edit or delete permissions.
+ </TooltipContent>
+ </Tooltip>
+ </SheetTitle>
<div className="mt-2 flex min-w-0 items-center gap-2 text-xs">
<FolderIcon className="size-3.5 shrink-0 text-folder" />
<span className="truncate font-mono text-accent">{folderPath}</span>
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderTierRadioGroup.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderTierRadioGroup.tsx
new file mode 100644
index 0000000000..a21fbc7bf5
--- /dev/null
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderTierRadioGroup.tsx
@@ -0,0 +1,33 @@
+import { Label, RadioGroup, RadioGroupItem } from "@app/components/v3";
+import { SecretFolderRole } from "@app/hooks/api/folderAccess";
+
+import { FOLDER_ROLE_TIERS } from "./folder-access.const";
+
+type Props = {
+ value: SecretFolderRole;
+ onValueChange: (value: SecretFolderRole) => void;
+};
+
+export const FolderTierRadioGroup = ({ value, onValueChange }: Props) => (
+ <RadioGroup value={value} onValueChange={(next) => onValueChange(next as SecretFolderRole)}>
+ {FOLDER_ROLE_TIERS.map((option) => (
+ <Label
+ key={option.value}
+ htmlFor={`folder-tier-${option.value}`}
+ className={`flex cursor-pointer items-start gap-3 rounded-lg border p-3 ${
+ value === option.value ? "border-project/35 bg-project/5" : "border-border bg-card"
+ }`}
+ >
+ <RadioGroupItem
+ id={`folder-tier-${option.value}`}
+ value={option.value}
+ className="mt-0.5"
+ />
+ <span className="space-y-0.5">
+ <span className="block text-sm font-medium text-foreground">{option.label}</span>
+ <span className="block text-xs leading-relaxed text-muted">{option.description}</span>
+ </span>
+ </Label>
+ ))}
+ </RadioGroup>
+);