Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(flags): allow feature_flag:read scope for project secret API keys (#66174)

Phil Haack90c40c1ff77a
diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsx
index 082ab8b71ead..2fe0ac26bfe0 100644
--- a/frontend/src/lib/scopes.tsx
+++ b/frontend/src/lib/scopes.tsx
@@ -170,7 +170,7 @@ export const API_SCOPES: APIScope[] = [
]
API_SCOPES.sort((a, b) => a.objectName.localeCompare(b.objectName))
-export const PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION = ['endpoint:read'] as const
+export const PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION = ['endpoint:read', 'feature_flag:read'] as const
export type ProjectSecretAPIKeyAllowedScope = (typeof PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION)[number]
@@ -263,6 +263,7 @@ export type ProjectSecretAPIKeyScopePreset = {
export const PROJECT_SECRET_API_KEY_SCOPE_PRESETS: ProjectSecretAPIKeyScopePreset[] = [
{ value: 'endpoint_execution', label: 'Endpoint execution', scopes: ['endpoint:read'] },
+ { value: 'local_evaluation', label: 'Local feature flag evaluation', scopes: ['feature_flag:read'] },
{ value: 'llm_gateway', label: 'AI gateway access', scopes: ['llm_gateway:read'] },
]
diff --git a/posthog/api/test/test_project_secret_api_keys.py b/posthog/api/test/test_project_secret_api_keys.py
index 48159e966a90..815b68ec0c84 100644
--- a/posthog/api/test/test_project_secret_api_keys.py
+++ b/posthog/api/test/test_project_secret_api_keys.py
@@ -76,6 +76,14 @@ class TestProjectSecretAPIKeysAPI(APIBaseTest):
assert data["last_used_at"] is None
assert data["value"].startswith("phs_")
+ def test_create_feature_flag_read_scope(self):
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/project_secret_api_keys",
+ {"label": "local eval key", "scopes": ["feature_flag:read"]},
+ )
+ assert response.status_code == 201
+ assert response.json()["scopes"] == ["feature_flag:read"]
+
def test_create_too_many_api_keys(self):
for i in range(0, MAX_PROJECT_SECRET_API_KEYS_PER_TEAM):
self.client.post(
diff --git a/posthog/scopes.py b/posthog/scopes.py
index 1459f4555643..136c03645d9e 100644
--- a/posthog/scopes.py
+++ b/posthog/scopes.py
@@ -152,6 +152,9 @@ OAUTH_HIDDEN_SCOPE_OBJECTS: frozenset[APIScopeObject] = frozenset({"wizard_sessi
# ai-gateway flag in ProjectSecretAPIKeySerializer, not unconditionally like the entries here.
PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION: list[tuple[APIScopeObject, APIScopeActions]] = [
("endpoint", "read"),
+ # SDK local evaluation and remote config. The Rust feature-flags service already
+ # validates feature_flag:read PSAKs on the flag-definitions path; this makes them creatable.
+ ("feature_flag", "read"),
]
# Server-side scope assignment string-set constants (see RFC: server-side scope