Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(rbac): restrict organization API key management to OWNER (#13539)

Steffen Schmitz351a5aefad57
diff --git a/web/src/__tests__/server/organizations-api-key-trpc.servertest.ts b/web/src/__tests__/server/organizations-api-key-trpc.servertest.ts
index 8693269e85..cd67172911 100644
--- a/web/src/__tests__/server/organizations-api-key-trpc.servertest.ts
+++ b/web/src/__tests__/server/organizations-api-key-trpc.servertest.ts
@@ -59,12 +59,41 @@ describe("organization API keys trpc", () => {
environment: {} as any,
};
+ const adminSession: Session = {
+ expires: "1",
+ user: {
+ id: "user-3",
+ canCreateOrganizations: true,
+ name: "Admin User",
+ organizations: [
+ {
+ id: organizationId,
+ name: "Test Organization",
+ role: "ADMIN",
+ plan: "cloud:hobby",
+ cloudConfig: undefined,
+ metadata: {},
+ projects: [],
+ },
+ ],
+ featureFlags: {
+ excludeClickhouseRead: false,
+ templateFlag: true,
+ },
+ admin: false,
+ },
+ environment: {} as any,
+ };
+
const ownerCtx = createInnerTRPCContext({ session: ownerSession });
const ownerCaller = appRouter.createCaller({ ...ownerCtx, prisma });
const memberCtx = createInnerTRPCContext({ session: memberSession });
const memberCaller = appRouter.createCaller({ ...memberCtx, prisma });
+ const adminCtx = createInnerTRPCContext({ session: adminSession });
+ const adminCaller = appRouter.createCaller({ ...adminCtx, prisma });
+
const unAuthedCtx = createInnerTRPCContext({ session: null });
const unAuthedCaller = appRouter.createCaller({ ...unAuthedCtx, prisma });
@@ -100,6 +129,14 @@ describe("organization API keys trpc", () => {
).rejects.toThrow(TRPCError);
});
+ it("admin cannot fetch organization API keys", async () => {
+ await expect(
+ adminCaller.organizationApiKeys.byOrganizationId({
+ orgId: organizationId,
+ }),
+ ).rejects.toThrow(TRPCError);
+ });
+
it("unauthenticated user cannot fetch organization API keys", async () => {
await expect(
unAuthedCaller.organizationApiKeys.byOrganizationId({
@@ -131,6 +168,15 @@ describe("organization API keys trpc", () => {
).rejects.toThrow(TRPCError);
});
+ it("admin cannot create organization API keys", async () => {
+ await expect(
+ adminCaller.organizationApiKeys.create({
+ orgId: organizationId,
+ note: "Test API Key",
+ }),
+ ).rejects.toThrow(TRPCError);
+ });
+
it("unauthenticated user cannot create organization API keys", async () => {
await expect(
unAuthedCaller.organizationApiKeys.create({
@@ -182,6 +228,23 @@ describe("organization API keys trpc", () => {
}),
).rejects.toThrow(TRPCError);
});
+
+ it("admin cannot update API key note", async () => {
+ // Create a key as owner
+ const apiKeyResult = await ownerCaller.organizationApiKeys.create({
+ orgId: organizationId,
+ note: "Original Note",
+ });
+
+ // Try to update as admin
+ await expect(
+ adminCaller.organizationApiKeys.updateNote({
+ orgId: organizationId,
+ keyId: apiKeyResult.id,
+ note: "Updated Note",
+ }),
+ ).rejects.toThrow(TRPCError);
+ });
});
describe("organizationApiKeys.delete", () => {
@@ -222,5 +285,21 @@ describe("organization API keys trpc", () => {
}),
).rejects.toThrow(TRPCError);
});
+
+ it("admin cannot delete API key", async () => {
+ // Create a key as owner
+ const apiKeyResult = await ownerCaller.organizationApiKeys.create({
+ orgId: organizationId,
+ note: "To Be Deleted",
+ });
+
+ // Try to delete as admin
+ await expect(
+ adminCaller.organizationApiKeys.delete({
+ orgId: organizationId,
+ id: apiKeyResult.id,
+ }),
+ ).rejects.toThrow(TRPCError);
+ });
});
});
diff --git a/web/src/features/rbac/constants/organizationAccessRights.ts b/web/src/features/rbac/constants/organizationAccessRights.ts
index 8dff526d4f..2b3f27b11c 100644
--- a/web/src/features/rbac/constants/organizationAccessRights.ts
+++ b/web/src/features/rbac/constants/organizationAccessRights.ts
@@ -32,7 +32,6 @@ export const organizationRoleAccessRights: Record<Role, OrganizationScope[]> = {
ADMIN: [
"projects:create",
"projects:transfer_org",
- "organization:CRUD_apiKeys",
"organization:update",
"organizationMembers:CUD",
"organizationMembers:read",