Repository navigation
feat(agents): integrate Entra identity registration and authorization #43149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
joshua-berri
wants to merge
8
commits into
main
Choose a base branch
from
litellm_agent_entra_identity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
320a688
feat(agents): integrate Entra identity registration and authorization
joshua-berri e53e15c
fix(agents): enforce fresh MCP grants and repair auth fixtures
joshua-berri d8b1882
test(agents): remove duplicate auth import
joshua-berri 1b0162b
refactor(agents): defer optional team selector cleanup
joshua-berri 4ce23d0
fix(agents): enforce actor and target invocation rate limits
joshua-berri 91c331a
fix(agents): reconcile every reserved agent token counter
joshua-berri 485bc29
style(agents): format rate descriptor construction
joshua-berri 080de40
fix(agents): pass rate policy without loop-local Final
joshua-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...-proxy-extras/litellm_proxy_extras/migrations/20260921190000_agent_identity/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "LiteLLM_AgentsTable" ADD COLUMN IF NOT EXISTS "enabled" BOOLEAN NOT NULL DEFAULT true, | ||
| ADD COLUMN IF NOT EXISTS "execution_mode" TEXT NOT NULL DEFAULT 'autonomous', | ||
| ADD COLUMN IF NOT EXISTS "identity_managed" BOOLEAN NOT NULL DEFAULT false; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "LiteLLM_SpendLogs" ADD COLUMN IF NOT EXISTS "billing_agent_id" TEXT; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE IF NOT EXISTS "LiteLLM_AgentIdentity" ( | ||
| "agent_id" TEXT NOT NULL, | ||
| "active" BOOLEAN NOT NULL DEFAULT true, | ||
| "provider" TEXT NOT NULL, | ||
| "issuer" TEXT NOT NULL, | ||
| "tenant_id" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "service_principal_id" TEXT, | ||
| "required_roles" TEXT[] DEFAULT ARRAY[]::TEXT[], | ||
| "required_scopes" TEXT[] DEFAULT ARRAY['user_impersonation']::TEXT[], | ||
| "revision" TEXT NOT NULL, | ||
| "last_authenticated_at" TIMESTAMP(3), | ||
|
|
||
| CONSTRAINT "LiteLLM_AgentIdentity_pkey" PRIMARY KEY ("agent_id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE IF NOT EXISTS "LiteLLM_RetiredAgentIdentity" ( | ||
| "binding_id" TEXT NOT NULL, | ||
| "agent_id" TEXT, | ||
| "provider" TEXT NOT NULL, | ||
| "issuer" TEXT NOT NULL, | ||
| "tenant_id" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
|
|
||
| CONSTRAINT "LiteLLM_RetiredAgentIdentity_pkey" PRIMARY KEY ("binding_id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE IF NOT EXISTS "LiteLLM_RetiredAgent" ( | ||
| "original_agent_id" TEXT NOT NULL, | ||
| "retired_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "LiteLLM_RetiredAgent_pkey" PRIMARY KEY ("original_agent_id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE IF NOT EXISTS "LiteLLM_VerifiedSubject" ( | ||
| "subject_id" TEXT NOT NULL, | ||
| "issuer" TEXT NOT NULL, | ||
| "tenant_id" TEXT NOT NULL, | ||
| "oid" TEXT NOT NULL, | ||
| "kind" TEXT NOT NULL DEFAULT 'human', | ||
| "user_id" TEXT, | ||
| "verified_via" TEXT NOT NULL DEFAULT 'sso_interactive', | ||
| "verified_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "LiteLLM_VerifiedSubject_pkey" PRIMARY KEY ("subject_id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX IF NOT EXISTS "LiteLLM_AgentIdentity_provider_tenant_id_client_id_key" ON "LiteLLM_AgentIdentity"("provider", "tenant_id", "client_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX IF NOT EXISTS "LiteLLM_AgentIdentity_issuer_service_principal_id_key" ON "LiteLLM_AgentIdentity"("issuer", "service_principal_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX IF NOT EXISTS "LiteLLM_RetiredAgentIdentity_provider_tenant_id_client_id_key" ON "LiteLLM_RetiredAgentIdentity"("provider", "tenant_id", "client_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX IF NOT EXISTS "LiteLLM_VerifiedSubject_user_id_idx" ON "LiteLLM_VerifiedSubject"("user_id"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX IF NOT EXISTS "LiteLLM_VerifiedSubject_issuer_tenant_id_oid_key" ON "LiteLLM_VerifiedSubject"("issuer", "tenant_id", "oid"); | ||
|
|
||
| -- AddForeignKey | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'LiteLLM_AgentIdentity_agent_id_fkey') THEN | ||
| ALTER TABLE "LiteLLM_AgentIdentity" ADD CONSTRAINT "LiteLLM_AgentIdentity_agent_id_fkey" FOREIGN KEY ("agent_id") REFERENCES "LiteLLM_AgentsTable"("agent_id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| -- AddForeignKey | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'LiteLLM_RetiredAgentIdentity_agent_id_fkey') THEN | ||
| ALTER TABLE "LiteLLM_RetiredAgentIdentity" ADD CONSTRAINT "LiteLLM_RetiredAgentIdentity_agent_id_fkey" FOREIGN KEY ("agent_id") REFERENCES "LiteLLM_AgentsTable"("agent_id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| -- AddForeignKey | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'LiteLLM_VerifiedSubject_user_id_fkey') THEN | ||
| ALTER TABLE "LiteLLM_VerifiedSubject" ADD CONSTRAINT "LiteLLM_VerifiedSubject_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "LiteLLM_UserTable"("user_id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
| END IF; | ||
| END $$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| from types import MappingProxyType | ||
| from typing import Final | ||
|
|
||
| from litellm.proxy._types import UserAPIKeyAuth | ||
| from litellm.proxy.agent_endpoints.auth.agent_access_groups import resolve_managed_agent_ceilings | ||
| from litellm.proxy.agent_endpoints.managed_identity import raise_identity_failure | ||
| from litellm.types.proxy.agent_identity import AgentIdentityFailure | ||
|
|
||
|
|
||
| async def _delegated_resource_subject(user_id: str) -> UserAPIKeyAuth: | ||
| from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler | ||
|
|
||
| human: Final = await MCPRequestHandler.reload_admitted_user(user_id, requires_fresh_policy=True) | ||
| return human.model_copy(update=MappingProxyType({"mcp_explicit_grants_only": True})) | ||
|
|
||
|
|
||
| async def managed_agent_servers(auth: UserAPIKeyAuth) -> tuple[str, ...]: | ||
| from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler | ||
| from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager | ||
|
|
||
| agent: Final = auth.managed_agent_policy | ||
| if agent is None: | ||
| return () | ||
|
|
||
| try: | ||
| base: Final = frozenset(await MCPRequestHandler.get_allowed_mcp_servers_for_agent(auth)) | ||
| ceilings: Final = await resolve_managed_agent_ceilings(agent) | ||
| expanded: Final = tuple( | ||
| frozenset(global_mcp_server_manager.expand_permission_list(sorted(ceiling.mcp_server_ids))) | ||
| for ceiling in ceilings | ||
| ) | ||
| own: Final = frozenset(server for server in base if all(server in ceiling for ceiling in expanded)) | ||
| context: Final = auth.managed_agent_context | ||
| if context is None or context.mode == "autonomous": | ||
| return tuple(sorted(own)) | ||
| if context.user_id is None: | ||
| return () | ||
| human: Final = await _delegated_resource_subject(context.user_id) | ||
| allowed: Final = await MCPRequestHandler.resolve_admitted_subject_servers(human) | ||
| return tuple(sorted(own.intersection(allowed))) | ||
| except Exception: # noqa: BLE001 # Authorization boundary: every unresolved policy must deny access | ||
| raise_identity_failure( | ||
| AgentIdentityFailure(code="policy_unavailable", message="Agent MCP policy is unavailable") | ||
| ) | ||
|
|
||
|
|
||
| async def managed_agent_tools(server_id: str, auth: UserAPIKeyAuth) -> list[str] | None: | ||
| from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler | ||
|
|
||
| if server_id not in await managed_agent_servers(auth): | ||
| return [] | ||
| try: | ||
| own: Final = await MCPRequestHandler.get_agent_tool_permissions_for_server(server_id, auth) | ||
| context: Final = auth.managed_agent_context | ||
| if context is None or context.mode == "autonomous": | ||
| return own | ||
| if context.user_id is None: | ||
| return [] | ||
| human: Final = await _delegated_resource_subject(context.user_id) | ||
| human_tools: Final = await MCPRequestHandler.resolve_admitted_subject_tools(server_id, human) | ||
| if own is None: | ||
| return human_tools | ||
| return own if human_tools is None else sorted(frozenset(own).intersection(human_tools)) | ||
| except Exception: # noqa: BLE001 # Authorization boundary: every unresolved policy must deny access | ||
| raise_identity_failure( | ||
| AgentIdentityFailure(code="policy_unavailable", message="Agent tool policy is unavailable") | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.