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(auth): sync PAK scope modal with backend scope list (#70339)

Yasend5569fa659a8
diff --git a/frontend/src/lib/scopes.test.ts b/frontend/src/lib/scopes.test.ts
index dc5604364e98..9ab900ef9adb 100644
--- a/frontend/src/lib/scopes.test.ts
+++ b/frontend/src/lib/scopes.test.ts
@@ -1,5 +1,13 @@
import { AGENT_USE_CASE_SCOPES } from 'lib/agentScopes.generated'
-import { AGENT_CLI_API_KEY_SCOPES, API_KEY_SCOPE_PRESETS, API_SCOPES, getScopeDescription } from 'lib/scopes'
+import {
+ AGENT_CLI_API_KEY_SCOPES,
+ API_KEY_SCOPE_PRESETS,
+ API_SCOPES,
+ API_SCOPES_OMITTED_FROM_MODAL,
+ getScopeDescription,
+} from 'lib/scopes'
+
+import { API_SCOPE_OBJECTS } from '~/types'
const getRenderableKeyCreationScopes = (): Set<string> =>
new Set(
@@ -28,6 +36,23 @@ describe('getScopeDescription', () => {
})
})
+describe('API_SCOPES modal coverage', () => {
+ const offered = new Set(API_SCOPES.map(({ key }) => key))
+ const omitted = new Set(Object.keys(API_SCOPES_OMITTED_FROM_MODAL))
+
+ it('offers or explicitly omits every scope object', () => {
+ // Guards the drift where a scope object is added to API_SCOPE_OBJECTS (mirroring a new
+ // backend scope) but its key-creation modal row is forgotten, silently hiding a grantable scope.
+ const uncovered = API_SCOPE_OBJECTS.filter((obj) => !offered.has(obj) && !omitted.has(obj))
+ expect(uncovered).toEqual([])
+ })
+
+ it('never both offers and omits the same scope', () => {
+ const overlap = [...omitted].filter((obj) => offered.has(obj as (typeof API_SCOPE_OBJECTS)[number]))
+ expect(overlap).toEqual([])
+ })
+})
+
describe('API_KEY_SCOPE_PRESETS', () => {
const findPreset = (value: string): (typeof API_KEY_SCOPE_PRESETS)[number] => {
const preset = API_KEY_SCOPE_PRESETS.find((p) => p.value === value)
diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsx
index 282bf09fc619..4342d2a8cdfb 100644
--- a/frontend/src/lib/scopes.tsx
+++ b/frontend/src/lib/scopes.tsx
@@ -45,7 +45,6 @@ export const API_SCOPES: APIScope[] = [
{ key: 'approvals', objectName: 'Approvals', objectPlural: 'approvals' },
{ key: 'batch_export', objectName: 'Batch export', objectPlural: 'batch exports' },
{ key: 'business_knowledge', objectName: 'Business knowledge', objectPlural: 'business knowledge' },
- // `clickhouse_test_cluster_perf` is omitted — see `INTERNAL_API_SCOPE_OBJECTS` in posthog/scopes.py.
{ key: 'cohort', objectName: 'Cohort', objectPlural: 'cohorts' },
{ key: 'comment', objectName: 'Comment', objectPlural: 'comments' },
{
@@ -79,6 +78,7 @@ export const API_SCOPES: APIScope[] = [
{ key: 'endpoint', objectName: 'Endpoint', objectPlural: 'endpoints' },
{ key: 'engineering_analytics', objectName: 'Engineering analytics', objectPlural: 'engineering analytics' },
{ key: 'event_definition', objectName: 'Event definition', objectPlural: 'event definitions' },
+ { key: 'event_filter', objectName: 'Event filter', objectPlural: 'event filters' },
{ key: 'error_tracking', objectName: 'Error tracking', objectPlural: 'error tracking' },
{ key: 'evaluation', objectName: 'Evaluation', objectPlural: 'evaluations' },
{ key: 'experiment', objectName: 'Experiment', objectPlural: 'experiments' },
@@ -112,6 +112,7 @@ export const API_SCOPES: APIScope[] = [
{ key: 'insight_variable', objectName: 'Insight variable', objectPlural: 'insight variables' },
{ key: 'integration', objectName: 'Integration', objectPlural: 'integrations', disabledActions: ['write'] },
{ key: 'legal_document', objectName: 'Legal document', objectPlural: 'legal documents' },
+ { key: 'link', objectName: 'Link', objectPlural: 'links' },
{ key: 'live_debugger', objectName: 'Live debugger', objectPlural: 'live debugger' },
{ key: 'llm_analytics', objectName: 'AI observability', objectPlural: 'AI observability' },
{
@@ -169,8 +170,6 @@ export const API_SCOPES: APIScope[] = [
},
{ key: 'property_definition', objectName: 'Property definition', objectPlural: 'property definitions' },
{ key: 'query', objectName: 'Query', objectPlural: 'queries', disabledActions: ['write'] },
- // `query_performance` is omitted — OAuth-hidden, PAT-grantable only (see `OAUTH_HIDDEN_SCOPE_OBJECTS` in posthog/scopes.py).
- // `wizard_session` is also omitted for the same reason.
{ key: 'replay_scanner', objectName: 'Replay scanner', objectPlural: 'replay scanners' },
{ key: 'revenue_analytics', objectName: 'Revenue analytics', objectPlural: 'revenue analytics' },
{ key: 'session_recording', objectName: 'Session recording', objectPlural: 'session recordings' },
@@ -211,8 +210,10 @@ export const API_SCOPES: APIScope[] = [
},
},
{ key: 'signal_scout', objectName: 'Signals agent', objectPlural: 'signals agents' },
+ { key: 'streamlit_app', objectName: 'Streamlit app', objectPlural: 'Streamlit apps' },
{ key: 'task', objectName: 'Task', objectPlural: 'tasks' },
{ key: 'user_interview', objectName: 'User interview', objectPlural: 'user interviews' },
+ { key: 'vision_action', objectName: 'Vision action', objectPlural: 'vision actions' },
{ key: 'visual_review', objectName: 'Visual review', objectPlural: 'visual reviews' },
{
key: 'webhook',
@@ -226,6 +227,28 @@ export const API_SCOPES: APIScope[] = [
]
API_SCOPES.sort((a, b) => a.objectName.localeCompare(b.objectName))
+// Scope objects deliberately absent from the key-creation modal above, each with the reason.
+// Every scope object in `API_SCOPE_OBJECTS` must be either offered in `API_SCOPES` or listed here —
+// scopes.test.ts enforces that partition so a newly added backend scope can't silently go missing.
+// Keep the internal/hidden entries in sync with `INTERNAL_API_SCOPE_OBJECTS` and
+// `OAUTH_HIDDEN_SCOPE_OBJECTS` in posthog/scopes.py.
+export const API_SCOPES_OMITTED_FROM_MODAL: Partial<Record<APIScopeObject, string>> = {
+ // INTERNAL_API_SCOPE_OBJECTS — server-minted only, never user-grantable.
+ clickhouse_test_cluster_perf: 'Internal: minted programmatically only.',
+ signal_scout_internal: 'Internal: sandbox-only writes for the headless Signals agent.',
+ signal_scout_report: 'Internal: sandbox-only writes for the scout report channel.',
+ // OAUTH_HIDDEN_SCOPE_OBJECTS — pasteable into a PAT, but never advertised via OAuth/CLI/MCP.
+ query_performance: 'OAuth-hidden: staff-only, pasteable into a PAT but not advertised.',
+ wizard_session: 'OAuth-hidden: pasteable into a PAT but not advertised.',
+ // Umbrella access-control resource that `warehouse_view`/`warehouse_table` inherit from —
+ // the granular scopes are offered instead, so keep the umbrella out of the modal.
+ warehouse_objects: 'Umbrella resource: grant warehouse_view/warehouse_table instead.',
+ // Pending removal — no endpoint enforces these, so they do nothing when granted.
+ // Remove from posthog/scopes.py once no PAK/OAuth grant references them.
+ batch_import: 'Pending removal: no endpoint enforces it (its viewset is INTERNAL).',
+ external_data_schema: 'Pending removal: covered by external_data_source; no viewset uses it.',
+}
+
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]
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 28f6dc7b77bf..b5dc7646a089 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -5653,100 +5653,116 @@ export interface RoleMemberType {
user_uuid: string
}
-export type APIScopeObject =
- | 'action'
- | 'access_control'
- | 'account'
- | 'activity_log'
- | 'agents'
- | 'agent_approvals'
- | 'alert'
- | 'annotation'
- | 'approvals'
- | 'batch_export'
- | 'business_knowledge'
- | 'clickhouse_test_cluster_perf'
- | 'cohort'
- | 'comment'
- | 'conversation'
- | 'customer_analytics'
- | 'customer_journey'
- | 'customer_profile_config'
- | 'data_catalog'
- | 'data_catalog_approval'
- | 'dashboard'
- | 'dashboard_template'
- | 'dataset'
- | 'early_access_feature'
- | 'element'
- | 'endpoint'
- | 'engineering_analytics'
- | 'error_tracking'
- | 'evaluation'
- | 'event_definition'
- | 'experiment'
- | 'experiment_holdout'
- | 'experiment_saved_metric'
- | 'external_data_source'
- | 'export'
- | 'feature_flag'
- | 'file_system'
- | 'file_system_shortcut'
- | 'group'
- | 'health_issue'
- | 'heatmap'
- | 'hog_flow'
- | 'hog_function'
- | 'ingestion_warning'
- | 'insight'
- | 'insight_variable'
- | 'integration'
- | 'legal_document'
- | 'live_debugger'
- | 'llm_analytics'
- | 'llm_gateway'
- | 'llm_prompt'
- | 'llm_provider_key'
- | 'llm_skill'
- | 'logs'
- | 'marketing_analytics'
- | 'mcp_analytics'
- | 'metrics'
- | 'notebook'
- | 'organization'
- | 'organization_integration'
- | 'organization_member'
- | 'person'
- | 'plugin'
- | 'product_enablement'
- | 'product_tour'
- | 'project'
- | 'property_definition'
- | 'query'
- | 'query_performance'
- | 'replay_scanner'
- | 'revenue_analytics'
- | 'session_recording'
- | 'session_recording_playlist'
- | 'sharing_configuration'
- | 'signal_scout'
- | 'subscription'
- | 'survey'
- | 'tagger'
- | 'task'
- | 'ticket'
- | 'uploaded_media'
- | 'usage_metric'
- | 'user'
- | 'user_interview'
- | 'visual_review'
- | 'warehouse_objects'
- | 'warehouse_table'
- | 'warehouse_view'
- | 'web_analytics'
- | 'webhook'
- | 'tracing'
- | 'field_note'
+// Single source of truth for scope objects on the frontend. Keep in sync with
+// `APIScopeObject` in posthog/scopes.py (same order). The runtime array lets
+// scopes.test.ts assert that every scope object is either offered in the PAK
+// creation modal or explicitly omitted — see `API_SCOPES_OMITTED_FROM_MODAL`.
+export const API_SCOPE_OBJECTS = [
+ 'action',
+ 'access_control',
+ 'account',
+ 'activity_log',
+ 'agents',
+ 'agent_approvals',
+ 'alert',
+ 'annotation',
+ 'approvals',
+ 'batch_export',
+ 'batch_import',
+ 'business_knowledge',
+ 'clickhouse_test_cluster_perf',
+ 'cohort',
+ 'comment',
+ 'conversation',
+ 'customer_analytics',
+ 'customer_journey',
+ 'customer_profile_config',
+ 'data_catalog',
+ 'data_catalog_approval',
+ 'dashboard',
+ 'event_filter',
+ 'dashboard_template',
+ 'dataset',
+ 'early_access_feature',
+ 'endpoint',
+ 'engineering_analytics',
+ 'error_tracking',
+ 'evaluation',
+ 'element',
+ 'event_definition',
+ 'experiment',
+ 'experiment_holdout',
+ 'experiment_saved_metric',
+ 'export',
+ 'external_data_schema',
+ 'external_data_source',
+ 'feature_flag',
+ 'file_system',
+ 'file_system_shortcut',
+ 'group',
+ 'health_issue',
+ 'heatmap',
+ 'hog_flow',
+ 'hog_function',
+ 'ingestion_warning',
+ 'insight',
+ 'insight_variable',
+ 'integration',
+ 'legal_document',
+ 'link',
+ 'live_debugger',
+ 'llm_analytics',
+ 'llm_gateway',
+ 'llm_prompt',
+ 'llm_provider_key',
+ 'llm_skill',
+ 'logs',
+ 'marketing_analytics',
+ 'mcp_analytics',
+ 'metrics',
+ 'notebook',
+ 'organization',
+ 'organization_integration',
+ 'organization_member',
+ 'person',
+ 'plugin',
+ 'product_enablement',
+ 'product_tour',
+ 'project',
+ 'property_definition',
+ 'query',
+ 'query_performance',
+ 'replay_scanner',
+ 'revenue_analytics',
+ 'session_recording',
+ 'session_recording_playlist',
+ 'sharing_configuration',
+ 'signal_scout',
+ 'signal_scout_internal',
+ 'signal_scout_report',
+ 'streamlit_app',
+ 'subscription',
+ 'survey',
+ 'tagger',
+ 'ticket',
+ 'task',
+ 'tracing',
+ 'field_note',
+ 'uploaded_media',
+ 'usage_metric',
+ 'user',
+ 'user_interview',
+ 'vision_action',
+ 'visual_review',
+ 'warehouse_objects',
+ 'warehouse_table',
+ 'warehouse_view',
+ 'web_analytics',
+ 'webhook',
+ 'wizard_session',
+] as const
+
+export type APIScopeObject = (typeof API_SCOPE_OBJECTS)[number]
export type APIScopeAction = 'read' | 'write'