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.

fix(experiments): show experiment:read in the project key scope picker (#94502)

leonhardprinz24ad933bd4f1
diff --git a/.agents/skills/adding-project-secret-api-key-auth/SKILL.md b/.agents/skills/adding-project-secret-api-key-auth/SKILL.md
index c1a557c9792c..33d19e8ca3fe 100644
--- a/.agents/skills/adding-project-secret-api-key-auth/SKILL.md
+++ b/.agents/skills/adding-project-secret-api-key-auth/SKILL.md
@@ -29,6 +29,8 @@ PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION: list[tuple[APIScopeObject, APIS
If your product isn't listed, key creation rejects the scope before auth is ever attempted. Add your `(scope_object, action)` tuple here first.
+Add the same scope to `PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION` in `frontend/src/lib/scopes.tsx`. The scope picker in project settings builds its checkboxes from that list, so a backend-only change leaves users with no way to grant the scope. `posthog/test/test_scopes.py` compares the two lists.
+
### 2. Add the authenticator and opt in actions
```python
diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsx
index 19a9030b8e40..301c287c3f54 100644
--- a/frontend/src/lib/scopes.tsx
+++ b/frontend/src/lib/scopes.tsx
@@ -282,11 +282,14 @@ export const API_SCOPES_OMITTED_FROM_MODAL: Partial<Record<APIScopeObject, strin
external_data_schema: 'Pending removal: covered by external_data_source; no viewset uses it.',
}
+// Keep in sync with PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION in posthog/scopes.py.
+// posthog/test/test_scopes.py compares the two lists.
export const PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION = [
'endpoint:read',
'feature_flag:read',
'account:read',
'loop:write',
+ 'experiment:read',
] as const
export type ProjectSecretAPIKeyAllowedScope = (typeof PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION)[number]
diff --git a/posthog/test/test_scopes.py b/posthog/test/test_scopes.py
index 0f5d0a783679..dcfa11c34898 100644
--- a/posthog/test/test_scopes.py
+++ b/posthog/test/test_scopes.py
@@ -1,3 +1,4 @@
+import re
import runpy
from pathlib import Path
@@ -477,3 +478,20 @@ class TestFilterToUnprivilegedScopes(SimpleTestCase):
"insight:read",
"query:read",
]
+
+
+class TestProjectSecretAPIKeyScopeParity(SimpleTestCase):
+ # The settings scope picker builds its checkboxes from the frontend copy of this list,
+ # so a scope added on the backend alone is allowed by the API but has no UI to grant it.
+ def test_frontend_list_matches_backend(self) -> None:
+ tsx = (Path(__file__).resolve().parents[2] / "frontend" / "src" / "lib" / "scopes.tsx").read_text()
+ match = re.search(
+ r"export const PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION = \[(.*?)\] as const",
+ tsx,
+ re.DOTALL,
+ )
+ assert match, "Could not find PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION in scopes.tsx"
+
+ frontend_scopes = set(re.findall(r"'([a-z_]+:[a-z]+)'", match.group(1)))
+ backend_scopes = {f"{obj}:{action}" for obj, action in PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION}
+ assert frontend_scopes == backend_scopes