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(api-keys): add read-only access preset (#58497)

Tom Piccirello6e62ee7c087b
diff --git a/frontend/src/lib/scopes.test.ts b/frontend/src/lib/scopes.test.ts
new file mode 100644
index 000000000000..f527899fbef4
--- /dev/null
+++ b/frontend/src/lib/scopes.test.ts
@@ -0,0 +1,31 @@
+import { API_KEY_SCOPE_PRESETS, API_SCOPES } from 'lib/scopes'
+
+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)
+ if (!preset) {
+ throw new Error(`Preset "${value}" not found`)
+ }
+ return preset
+ }
+
+ describe('read_only_access', () => {
+ it('exists with the expected label', () => {
+ const preset = findPreset('read_only_access')
+ expect(preset.label).toBe('Read-only access')
+ })
+
+ it('contains :read for every entry in API_SCOPES', () => {
+ const preset = findPreset('read_only_access')
+ const expected = API_SCOPES.map(({ key }) => `${key}:read`).sort()
+ expect([...preset.scopes].sort()).toEqual(expected)
+ })
+ })
+
+ describe('all_access', () => {
+ it('still uses the wildcard scope', () => {
+ const preset = findPreset('all_access')
+ expect(preset.scopes).toEqual(['*'])
+ })
+ })
+})
diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsx
index fed61b93f90d..928eaf7bd608 100644
--- a/frontend/src/lib/scopes.tsx
+++ b/frontend/src/lib/scopes.tsx
@@ -192,6 +192,11 @@ export const API_KEY_SCOPE_PRESETS: {
),
access_type: 'all',
},
+ {
+ value: 'read_only_access',
+ label: 'Read-only access',
+ scopes: API_SCOPES.map(({ key }) => `${key}:read`),
+ },
{ value: 'all_access', label: 'All access', scopes: ['*'] },
]