mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 11:30:17 +08:00
## Context Previous PR was [here](https://github.com/supabase/supabase/pull/45143) but it got stale with lots of conflicts so figured it'll be easier redo it off the latest master Moves policies page from Auth to Database under an Access Control section along with Roles. This moves all existing files, applies redirects, and updates urls to point to the new route <img width="274" height="412" alt="image" src="https://github.com/user-attachments/assets/7952c185-64ae-4355-ba36-45397efe1787" /> <img width="453" height="471" alt="image" src="https://github.com/user-attachments/assets/04b3dcb3-48a5-4049-9893-d01109fb46a9" /> ## To test - [ ] Verify that policies now live under Database correctly <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a quick navigation shortcut to open **Database > Policies (RLS)**. * **Bug Fixes** * Updated Policies and RLS-related links across the product to open the **Database policies** area (menus, command palette, context actions, alerts, and link-outs). * Added a permanent redirect from the old **auth policies** URL to the new **database policies** URL. * **Documentation** * Updated RLS Dashboard and security checklist instructions to reference **Database > Policies**. * **Tests** * Adjusted automated tests to validate the new Policies route. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { type ProjectSecurityTable } from './ProjectNeedsSecuring.types'
|
|
import { parseDbSchemaString } from '@/data/config/project-postgrest-config-query'
|
|
|
|
const DEFAULT_EXPOSED_SCHEMA = 'public'
|
|
|
|
export const getTableKey = ({ schema, name }: { schema: string; name: string }) =>
|
|
`${schema}.${name}`
|
|
|
|
export const getTablePoliciesHref = (
|
|
projectRef: string | undefined,
|
|
schema: string | undefined,
|
|
name: string | undefined
|
|
): string => {
|
|
return `/project/${projectRef ?? ''}/database/policies?schema=${encodeURIComponent(
|
|
schema ?? ''
|
|
)}&search=${encodeURIComponent(name ?? '')}`
|
|
}
|
|
|
|
export const getExposedSchemas = (dbSchema: string | null | undefined) => {
|
|
const schemas = dbSchema ? parseDbSchemaString(dbSchema) : []
|
|
return schemas.length > 0 ? schemas : [DEFAULT_EXPOSED_SCHEMA]
|
|
}
|
|
|
|
export const formatRlsDescription = (count: number) => {
|
|
const isSingular = count === 1
|
|
const noun = isSingular ? 'table' : 'tables'
|
|
const verb = isSingular ? 'has' : 'have'
|
|
const pronoun = isSingular ? 'its' : 'their'
|
|
|
|
return `${count} ${noun} ${verb} RLS disabled which means anyone can access ${pronoun} data via the Data API.`
|
|
}
|
|
|
|
export const buildSecurityPromptMarkdown = (issueCount: number, tables: ProjectSecurityTable[]) => {
|
|
const header = [
|
|
'## Project security review',
|
|
'',
|
|
formatRlsDescription(issueCount),
|
|
'',
|
|
'### Tables',
|
|
'',
|
|
'| Table | Schema | Accessible via Data API | RLS |',
|
|
'| --- | --- | --- | --- |',
|
|
]
|
|
|
|
const rows = tables.map(
|
|
(table) =>
|
|
`| ${table.name} | ${table.schema} | ${table.dataApiAccessible ? 'Yes' : 'No'} | ${table.rlsEnabled ? 'Enabled' : 'Disabled'} |`
|
|
)
|
|
|
|
const footer = [
|
|
'',
|
|
'### Next step',
|
|
'',
|
|
'Help me enable RLS on these tables and suggest the minimum policies I should create.',
|
|
]
|
|
|
|
return [...header, ...rows, ...footer].join('\n')
|
|
}
|
|
|
|
export const sortTables = (tables: ProjectSecurityTable[]) => {
|
|
return [...tables].sort((a, b) => {
|
|
const aPriority = a.hasRlsIssue ? 0 : a.rlsEnabled ? 2 : 1
|
|
const bPriority = b.hasRlsIssue ? 0 : b.rlsEnabled ? 2 : 1
|
|
|
|
if (aPriority !== bPriority) return aPriority - bPriority
|
|
|
|
const schemaComparison = a.schema.localeCompare(b.schema)
|
|
if (schemaComparison !== 0) return schemaComparison
|
|
|
|
return a.name.localeCompare(b.name)
|
|
})
|
|
}
|