Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_/vibrant-booth-d4258b

Yuneng Jiangd46ef9aeb4b4
diff --cc ui/litellm-dashboard/src/components/leftnav.test.tsx
index 3c2047b8d75,04aae64c768..f074624dcf2
--- a/ui/litellm-dashboard/src/components/leftnav.test.tsx
+++ b/ui/litellm-dashboard/src/components/leftnav.test.tsx
@@@ -3,11 -3,10 +3,12 @@@ import { afterEach, describe, expect, i
import { renderWithProviders } from "../../tests/test-utils";
import Sidebar, { menuGroups, getBreadcrumb } from "./leftnav";
-vi.mock("../utils/roles", () => {
+vi.mock("../utils/roles", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("../utils/roles")>();
return {
+ ...actual,
all_admin_roles: ["admin", "admin_viewer"],
+ old_admin_roles: ["admin", "admin_viewer"],
internalUserRoles: ["internal"],
rolesWithWriteAccess: ["admin", "internal"],
rolesAllowedToViewWriteScopedPages: ["admin", "internal", "admin_viewer"],
diff --cc ui/litellm-dashboard/src/utils/capabilities.test.ts
index 5a248c09200,3492223c5e8..d53b450c730
--- a/ui/litellm-dashboard/src/utils/capabilities.test.ts
+++ b/ui/litellm-dashboard/src/utils/capabilities.test.ts
@@@ -37,36 -38,32 +38,69 @@@ describe("hasCapability", () =>
});
});
+const SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES = "Internal User";
+
+const ORG_ADMIN_BACKEND_ACCESS: ReadonlyArray<readonly [Capability, string, boolean]> = [
+ ["viewDeletedTeams", "GET /v2/team/list?status=deleted -> 200 (scoped to their orgs)", true],
+ ["viewToolPolicies", "GET /v1/tool/list -> 401", false],
+ ["viewPolicies", "GET /policies/list -> 401", false],
+ ["viewPrompts", "GET /prompts/list -> 401", false],
+ ["viewAuditLogs", "GET /audit -> 401", false],
+];
+
+describe("hasCapability for organization admins", () => {
+ it.each(ORG_ADMIN_BACKEND_ACCESS)("%s matches the backend: %s", (capability, _endpoint, isEntitled) => {
+ expect(hasCapability(SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES, capability, true)).toBe(isEntitled);
+ });
+
+ it.each(NON_ADMIN_ROLES)("grants viewDeletedTeams to an org admin whose session role is %s", (role) => {
+ expect(hasCapability(role, "viewDeletedTeams", true)).toBe(true);
+ });
+
+ it.each(ADMIN_ONLY_CAPABILITIES)("leaves %s denied when the caller is not an org admin", (capability) => {
+ expect(hasCapability(SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES, capability, false)).toBe(false);
+ expect(hasCapability(SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES, capability)).toBe(false);
+ });
+
+ it("keeps the org-admin allowance opt-in per capability", () => {
+ const orgAdminCapabilities = ADMIN_ONLY_CAPABILITIES.filter((capability) =>
+ hasCapability(SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES, capability, true),
+ );
+ expect(orgAdminCapabilities).toEqual(["viewDeletedTeams"]);
+ });
++
++ it("does not let the org-admin allowance reopen the proxy-admin-only viewGlobalSpend gate", () => {
++ expect(hasCapability(SESSION_ROLE_AN_ORG_ADMIN_ACTUALLY_CARRIES, "viewGlobalSpend", true)).toBe(false);
++ expect(hasCapability("Org Admin", "viewGlobalSpend", true)).toBe(false);
++ });
++});
++
+ describe("hasCapability - viewGlobalSpend", () => {
+ it.each(ADMIN_ROLES)("should grant it to %s", (role) => {
+ expect(hasCapability(role, "viewGlobalSpend")).toBe(true);
+ });
+
+ it.each([...NON_ADMIN_ROLES, "internal_user_viewer", "org_admin"])("should deny it to %s", (role) => {
+ expect(hasCapability(role, "viewGlobalSpend")).toBe(false);
+ });
+
+ it("should deny it to every role an org admin or team admin can present at runtime", () => {
+ const orgAdminSessionRole = effectiveSessionRole("internal_user");
+ const teamAdminSessionRole = effectiveSessionRole("internal_user");
+
+ expect(orgAdminSessionRole).toBe("Internal User");
+ expect(hasCapability(orgAdminSessionRole, "viewGlobalSpend")).toBe(false);
+ expect(hasCapability(teamAdminSessionRole, "viewGlobalSpend")).toBe(false);
+ });
+
+ it.each([
+ ["proxy_admin", true],
+ ["proxy_admin_viewer", true],
+ ["internal_user", false],
+ ["internal_user_viewer", false],
+ ] as const)("should match the backend for a %s session", (rawRole, expected) => {
+ expect(hasCapability(effectiveSessionRole(rawRole), "viewGlobalSpend")).toBe(expected);
+ });
});
describe("rolesWithCapability", () => {
diff --cc ui/litellm-dashboard/src/utils/roles.test.ts
index 3fe3a1a0f0b,6430b8277f1..b2d7c2c75e5
--- a/ui/litellm-dashboard/src/utils/roles.test.ts
+++ b/ui/litellm-dashboard/src/utils/roles.test.ts
@@@ -1,20 -1,17 +1,22 @@@
import { describe, it, expect } from "vitest";
import {
+ all_admin_roles,
effectiveSessionRole,
isAdminRole,
+ isOrgAdminForAnyOrg,
+ isOrgAdminSessionRole,
isProxyAdminRole,
isUserTeamAdminForAnyTeam,
isUserTeamAdminForSingleTeam,
isViewOnlySessionRole,
rolesAllowedToViewWriteScopedPages,
rolesWithWriteAccess,
+ teamListScopeUserId,
} from "./roles";
-import { Team } from "@/components/networking";
+import { Organization, Team } from "@/components/networking";
+
+const orgWithMembers = (members: { user_id: string; user_role: string }[]): Organization =>
+ ({ organization_id: "org-1", members }) as unknown as Organization;
describe("roles", () => {
describe("isAdminRole", () => {