diff --git a/litellm/proxy/_lazy_openapi_snapshot.json b/litellm/proxy/_lazy_openapi_snapshot.json index 06e157498aa..833deffd659 100644 --- a/litellm/proxy/_lazy_openapi_snapshot.json +++ b/litellm/proxy/_lazy_openapi_snapshot.json @@ -5203,7 +5203,7 @@ }, "/v1/skills/{skill_id}/archive": { "get": { - "description": "Stored skill upload, repacked so SKILL.md sits at the archive root.", + "description": "Stored skill upload, repacked so SKILL.md sits at the archive root.\n\nAnonymous while the public index is on; otherwise needs a LiteLLM key\nwith access to the skill's owner scope.", "operationId": "agent_skills_archive_v1_skills__skill_id__archive_get", "parameters": [ { diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index d24e451cfc1..9584c62b3ef 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -519,6 +519,7 @@ class LiteLLMRoutes(enum.Enum): "/claude_code_gateway/v1/messages/count_tokens", "/v1/skills", "/v1/skills/{skill_id}", + "/v1/skills/{skill_id}/archive", "/claude-code/marketplace.json", "/claude-code/plugins", "/claude-code/plugins/{plugin_name}", diff --git a/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py b/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py index 3084cbfd84f..b7cd5268a47 100644 --- a/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py +++ b/litellm/proxy/discovery_endpoints/agent_skills_endpoints.py @@ -1,9 +1,11 @@ """Serve skills stored on the proxy as an Agent Skills well-known discovery index. ``npx skills add -a `` reads ``/.well-known/agent-skills/index.json`` -and downloads each entry's archive. Discovery clients send no credentials, so both -routes are unauthenticated and stay off until ``litellm_settings.public_skills_index`` +and downloads each entry's archive. Discovery clients send no credentials, so the +index routes are unauthenticated and stay off until ``litellm_settings.public_skills_index`` is enabled, which publishes every stored skill to anyone who can reach the proxy. +The archive route stays anonymous while the index is public; with the index off it +requires a LiteLLM key and stays scoped to the skill's owner. """ import asyncio @@ -20,6 +22,7 @@ import litellm from litellm._logging import verbose_proxy_logger from litellm.caching.in_memory_cache import InMemoryCache from litellm.models.skills import LiteLLM_SkillsTable +from litellm.proxy._types import SpecialHeaders, UserAPIKeyAuth from litellm.proxy.discovery_endpoints.agent_skills_archive import SkillArchive, build_skill_archive from litellm.types.proxy.discovery_endpoints.agent_skills_endpoints import ( MAX_SKILL_DESCRIPTION_LENGTH, @@ -62,11 +65,30 @@ async def stored_skills() -> Sequence[LiteLLM_SkillsTable]: return await LiteLLMSkillsHandler.list_skills(limit=MAX_INDEXED_SKILLS) -async def stored_skill(skill_id: str) -> LiteLLM_SkillsTable | None: +async def archive_caller(request: Request) -> UserAPIKeyAuth | None: + if litellm.public_skills_index is True: + return None + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + + return await user_api_key_auth( + request=request, + api_key=request.headers.get(SpecialHeaders.openai_authorization.value, ""), + azure_api_key_header=request.headers.get(SpecialHeaders.azure_authorization.value), + anthropic_api_key_header=request.headers.get(SpecialHeaders.anthropic_authorization.value), + google_ai_studio_api_key_header=request.headers.get(SpecialHeaders.google_ai_studio_authorization.value), + azure_apim_header=request.headers.get(SpecialHeaders.azure_apim_authorization.value), + custom_litellm_key_header=request.headers.get(SpecialHeaders.custom_litellm_api_key.value), + ) + + +async def stored_skill( + skill_id: str, + caller: UserAPIKeyAuth | None = Depends(archive_caller), # noqa: B008 # FastAPI dependency injection +) -> LiteLLM_SkillsTable | None: from litellm.llms.litellm_proxy.skills.handler import LiteLLMSkillsHandler try: - return await LiteLLMSkillsHandler.get_skill(skill_id) + return await LiteLLMSkillsHandler.get_skill(skill_id, user_api_key_dict=caller) except ValueError: return None @@ -111,14 +133,17 @@ async def agent_skills_index( @router.get( "/v1/skills/{skill_id}/archive", - dependencies=(Depends(ensure_index_enabled),), response_class=ZipArchiveResponse, ) async def agent_skills_archive( skill_id: str, skill: LiteLLM_SkillsTable | None = Depends(stored_skill), ) -> ZipArchiveResponse: - """Stored skill upload, repacked so SKILL.md sits at the archive root.""" + """Stored skill upload, repacked so SKILL.md sits at the archive root. + + Anonymous while the public index is on; otherwise needs a LiteLLM key + with access to the skill's owner scope. + """ archive: Final = await _archive_for(skill) if skill is not None else None if archive is None: raise HTTPException(status_code=404, detail=f"No installable skill archive for: {skill_id}") diff --git a/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py b/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py index e538c50cde8..7f2feefb0bf 100644 --- a/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py +++ b/tests/test_litellm/llms/litellm_proxy/test_skills_ownership.py @@ -336,6 +336,27 @@ async def test_should_hide_skill_from_different_owner(monkeypatch): ) +@pytest.mark.asyncio +async def test_should_return_skill_to_its_owner(monkeypatch): + table = AsyncMock() + table.find_unique.return_value = _skill("litellm_skill_mine", "user-1") + prisma_client = type( + "Prisma", (), {"db": type("DB", (), {"litellm_skillstable": table})()} + )() + monkeypatch.setattr( + LiteLLMSkillsHandler, + "_get_prisma_client", + AsyncMock(return_value=prisma_client), + ) + + skill = await LiteLLMSkillsHandler.get_skill( + "litellm_skill_mine", + user_api_key_dict=UserAPIKeyAuth(user_id="user-1"), + ) + + assert skill.skill_id == "litellm_skill_mine" + + @pytest.mark.asyncio async def test_should_hide_unowned_skill_by_default(monkeypatch): table = AsyncMock() diff --git a/tests/test_litellm/proxy/discovery_endpoints/test_agent_skills_endpoints.py b/tests/test_litellm/proxy/discovery_endpoints/test_agent_skills_endpoints.py index ea889e75ae8..420302360f4 100644 --- a/tests/test_litellm/proxy/discovery_endpoints/test_agent_skills_endpoints.py +++ b/tests/test_litellm/proxy/discovery_endpoints/test_agent_skills_endpoints.py @@ -4,12 +4,14 @@ import zipfile from datetime import datetime, timezone import pytest -from fastapi import FastAPI +from fastapi import Depends, FastAPI from fastapi.testclient import TestClient import litellm from litellm.models.skills import LiteLLM_SkillsTable +from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.discovery_endpoints.agent_skills_endpoints import ( + archive_caller, router, stored_skill, stored_skills, @@ -80,7 +82,6 @@ def test_discovery_is_absent_until_public_skills_index_is_enabled(monkeypatch): for path in WELL_KNOWN_PATHS: assert client.get(path).status_code == 404 - assert client.get("/v1/skills/litellm_skill_1/archive").status_code == 404 @pytest.mark.parametrize("path", WELL_KNOWN_PATHS) @@ -167,6 +168,72 @@ def test_archive_route_404s_for_a_skill_that_does_not_exist(index_enabled): assert client.get("/v1/skills/litellm_skill_missing/archive").status_code == 404 +def authenticated_client_for( + *skills: LiteLLM_SkillsTable, caller: UserAPIKeyAuth | None = None +) -> tuple[TestClient, list[UserAPIKeyAuth | None]]: + from litellm.proxy._types import ProxyException + + app = FastAPI() + + @app.exception_handler(ProxyException) + async def _proxy_exception(request, exc: ProxyException): + from fastapi.responses import JSONResponse + + return JSONResponse(status_code=int(exc.code), content={"error": exc.to_dict()}) + + app.include_router(router) + + seen: list[UserAPIKeyAuth | None] = [] # mutable-ok: test spy recording the resolved caller + + def _skill( + skill_id: str, + resolved: UserAPIKeyAuth | None = Depends(archive_caller), + ) -> LiteLLM_SkillsTable | None: + seen.append(resolved) + return next((candidate for candidate in skills if candidate.skill_id == skill_id), None) + + app.dependency_overrides[stored_skill] = _skill + if caller is not None: + app.dependency_overrides[archive_caller] = lambda: caller + return TestClient(app), seen + + +def test_archive_route_rejects_keyless_requests_when_the_index_is_private(monkeypatch): + monkeypatch.setattr(litellm, "public_skills_index", False) + from litellm.proxy import proxy_server + + monkeypatch.setattr(proxy_server, "master_key", "sk-master") + client, seen = authenticated_client_for(skill("litellm_skill_1")) + + assert client.get("/v1/skills/litellm_skill_1/archive").status_code == 401 + assert seen == [] + + +def test_archive_route_serves_an_authenticated_key_when_the_index_is_private(monkeypatch): + monkeypatch.setattr(litellm, "public_skills_index", False) + client, seen = authenticated_client_for(skill("litellm_skill_1"), caller=UserAPIKeyAuth(user_id="user-1")) + + downloaded = client.get( + "/v1/skills/litellm_skill_1/archive", + headers={"Authorization": "Bearer sk-test"}, + ) + + assert downloaded.status_code == 200 + assert downloaded.headers["content-type"] == "application/zip" + assert seen[0] is not None and seen[0].user_id == "user-1" + with zipfile.ZipFile(io.BytesIO(downloaded.content)) as archive: + assert "SKILL.md" in archive.namelist() + + +def test_archive_route_stays_anonymous_while_the_index_is_public(index_enabled): + client, seen = authenticated_client_for(skill("litellm_skill_1")) + + downloaded = client.get("/v1/skills/litellm_skill_1/archive") + + assert downloaded.status_code == 200 + assert seen == [None] + + def test_a_stored_skill_is_repacked_once_per_version(index_enabled): stamp = datetime(2026, 9, 6, 9, 0, tzinfo=timezone.utc) first = client_for(skill("litellm_skill_cached", files={"s/SKILL.md": MANIFEST}, updated_at=stamp)) diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.ts index 57ff2fe9d87..e6b304d7d93 100644 --- a/ui/litellm-dashboard/src/lib/http/schema.d.ts +++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts @@ -20566,6 +20566,9 @@ export interface paths { /** * Agent Skills Archive * @description Stored skill upload, repacked so SKILL.md sits at the archive root. + * + * Anonymous while the public index is on; otherwise needs a LiteLLM key + * with access to the skill's owner scope. */ get: operations["agent_skills_archive_v1_skills__skill_id__archive_get"]; put?: never;