🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(api-keys): enable project API key permissions by default (#18950)
Mark Salpeterd9be3b266b44
diff --git a/.env.prod.example b/.env.prod.exampleindex 4788b3bfad..51f93207db 100644--- a/.env.prod.example+++ b/.env.prod.example@@ -265,10 +265,10 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true# LANGFUSE_CACHE_API_KEY_ENABLED=# LANGFUSE_CACHE_API_KEY_TTL_SECONDS=-# Auth migration: legacy (default) | shadow | enforce+# Auth migration: legacy | shadow | enforce (default)# API_AUTH_MIGRATION=-# Expose API key role selection per scope (default false). Only active with API_AUTH_MIGRATION=enforce.-# API_KEY_PROJECT_ROLES_ENABLE=false+# Expose API key role selection per scope. Only active with API_AUTH_MIGRATION=enforce.+# API_KEY_PROJECT_ROLES_ENABLE=true# API_KEY_ORG_ROLES_ENABLE=false# LANGFUSE_CACHE_PROMPT_ENABLED=# LANGFUSE_CACHE_PROMPT_TTL_SECONDS=diff --git a/packages/shared/src/features/rbac/systemRoleAccessRights.ts b/packages/shared/src/features/rbac/systemRoleAccessRights.tsindex 45117bf944..257b04c4ba 100644--- a/packages/shared/src/features/rbac/systemRoleAccessRights.ts+++ b/packages/shared/src/features/rbac/systemRoleAccessRights.ts@@ -149,7 +149,12 @@ export const systemRoleAccessRights: Record<SystemRole, SystemRoleDefinition> =name: "Ingestion",description: "Create scores and traces from application telemetry.",policies: [- allow("project", ["traces:create", "scores:save", "media:create"]),+ allow("project", [+ "traces:create",+ "scores:save",+ "media:create",+ "project:read",+ ]),],tags: ["principal:apiKey"],},diff --git a/web/src/__tests__/server/projects-api.servertest.ts b/web/src/__tests__/server/projects-api.servertest.tsindex c3194e0622..715daf7709 100644--- a/web/src/__tests__/server/projects-api.servertest.ts+++ b/web/src/__tests__/server/projects-api.servertest.ts@@ -1063,10 +1063,6 @@ describe("Projects API", () => {label: "wrong-scope legacy role",body: { role: "LEGACY_ORGANIZATION_API_KEY" },},- { label: "admin role", body: { role: "ADMIN" } },- { label: "viewer role", body: { role: "VIEWER" } },- { label: "ingest role", body: { role: "INGEST" } },- { label: "scores ingest role", body: { role: "SCORES_INGEST" } },{ label: "gateway role", body: { role: "AI_GATEWAY" } },{ label: "role array", body: { role: [] } },])("rejects $label without creating a key", async ({ body }) => {@@ -1082,6 +1078,26 @@ describe("Projects API", () => {expect(await prisma.apiKey.count({ where: { projectId } })).toBe(before);});+ it("provisions a key with a selected role under the default env", async () => {+ const response = await makeAPICall<+ z.infer<typeof ApiKeyCreationResponseSchema>+ >(+ "POST",+ `/api/public/projects/${projectId}/apiKeys`,+ { role: "INGEST" },+ createBasicAuthHeader(orgApiKey, orgSecretKey),+ );+ createdApiKeyId = response.body.id;+ expect(response.status).toBe(201);+ expect(response.body.role).toBe("INGEST");++ const stored = await prisma.apiKey.findUniqueOrThrow({+ where: { id: response.body.id },+ include: { roleAssignments: true },+ });+ expect(stored.roleAssignments).toMatchObject([{ systemRole: "INGEST" }]);+ });+it("should create a new API key with valid organization API key", async () => {const note = `Test API Key ${randomUUID().substring(0, 8)}`;diff --git a/web/src/__tests__/server/shadowAuth.servertest.ts b/web/src/__tests__/server/shadowAuth.servertest.tsindex 6ce0723cc4..6eeacaf32c 100644--- a/web/src/__tests__/server/shadowAuth.servertest.ts+++ b/web/src/__tests__/server/shadowAuth.servertest.ts@@ -280,8 +280,8 @@ describe("shadowAuth maps principals to legacy-identical scopes", () => {apiKeyId: apiKey.id,ownerId: `project/${projectId}`,principalId: `apiKey/${apiKey.id}`,- roleId: "system/INGEST",- systemRole: "INGEST",+ roleId: "system/SCORES_INGEST",+ systemRole: "SCORES_INGEST",},});setMode("enforce");diff --git a/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts b/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.tsindex df7c3ee99a..ac3dfdd38a 100644--- a/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts+++ b/web/src/__tests__/server/unit/public-api/shadowAuth.servertest.ts@@ -746,9 +746,9 @@ describe("the migration-mode gate reads a declared env var", () => {}});- it("defaults the migration mode to legacy", () => {+ it("defaults the migration mode to enforce", () => {expect(source("env.mjs")).toMatch(- /API_AUTH_MIGRATION:\s*z[^;]*?\.default\("legacy"\)/,+ /API_AUTH_MIGRATION:\s*z[^;]*?\.default\("enforce"\)/,);});});diff --git a/web/src/__tests__/server/unit/systemRoleAccessRights.servertest.ts b/web/src/__tests__/server/unit/systemRoleAccessRights.servertest.tsindex 9974a0ded8..e53dc73032 100644--- a/web/src/__tests__/server/unit/systemRoleAccessRights.servertest.ts+++ b/web/src/__tests__/server/unit/systemRoleAccessRights.servertest.ts@@ -93,7 +93,12 @@ describe("systemRoleAccessRights", () => {{resourceKind: "project",effect: "ALLOW",- actions: ["traces:create", "scores:save", "media:create"],+ actions: [+ "traces:create",+ "scores:save",+ "media:create",+ "project:read",+ ],},]);});diff --git a/web/src/env.mjs b/web/src/env.mjsindex 5fe15ac433..1dff56790a 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -412,8 +412,8 @@ export const env = createEnv({API_AUTH_MIGRATION: z.enum(["legacy", "shadow", "enforce"])- .default("legacy"),- API_KEY_PROJECT_ROLES_ENABLE: z.enum(["true", "false"]).default("false"),+ .default("enforce"),+ API_KEY_PROJECT_ROLES_ENABLE: z.enum(["true", "false"]).default("true"),API_KEY_ORG_ROLES_ENABLE: z.enum(["true", "false"]).default("false"),// Multimodal media upload to S3