Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/tigerfs/fs/synth/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ func GeneratePlainTextTableSQL(schema, name string) string {
// the table in tableSchema. For build apps, the view lives in the user's
// schema while the table lives in the tigerfs schema. For synthesized views
// on existing tables, both schemas may be the same.
//
// The view is created with security_invoker = true (PostgreSQL 15+) so that
// Row-Level Security policies on the backing table are evaluated as the
// querying user, not the view owner. Without this, RLS policies are bypassed
// when queries go through the view, since views execute as their owner by
// default. This is safe for all deployments: when RLS is not enabled on the
// backing table, security_invoker has no effect.
func GenerateViewSQL(viewSchema, viewName, tableSchema, tableName string) string {
return fmt.Sprintf(`CREATE VIEW %s.%s AS SELECT * FROM %s.%s`,
return fmt.Sprintf(`CREATE VIEW %s.%s WITH (security_invoker = true) AS SELECT * FROM %s.%s`,
db.QuoteIdent(viewSchema), db.QuoteIdent(viewName),
db.QuoteIdent(tableSchema), db.QuoteIdent(tableName))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tigerfs/fs/synth/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ func TestGenerateBuildSQL_Markdown(t *testing.T) {
if !strings.Contains(allSQL, `"tigerfs"."posts"`) {
t.Errorf("table should be in tigerfs schema, got:\n%s", allSQL)
}
if !strings.Contains(allSQL, `"public"."posts" AS SELECT * FROM "tigerfs"."posts"`) {
t.Errorf("view should be in public schema referencing tigerfs, got:\n%s", allSQL)
if !strings.Contains(allSQL, `"public"."posts" WITH (security_invoker = true) AS SELECT * FROM "tigerfs"."posts"`) {
t.Errorf("view should be in public schema referencing tigerfs with security_invoker, got:\n%s", allSQL)
}
// Should have 10 statements: schema, resolve_path, table, parent_index, view, comment,
// modified_at function + trigger, parent_mtime function + trigger
Expand Down