feat(tenant): enforce tenant isolation with row-level security
Every query runs inside a transaction carrying app.org_id, app.user_id or the explicit system scope. Without a scope no rows are visible. Closes #2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
95da376ac1
commit
ccc0fe58b8
4 files changed
+318
No files matched your search
@@ -60,5 +60,16 @@ func Connect(ctx context.Context, c config.Common, log *slog.Logger) (*Deps, err
|
||||
d.Close()
|
||||
return nil, err
|
||||
}
|
||||
warnIfRLSBypassed(ctx, d)
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// warnIfRLSBypassed flags deployments where tenant isolation silently degrades
|
||||
// to application-level filtering only.
|
||||
func warnIfRLSBypassed(ctx context.Context, d *Deps) {
|
||||
var bypass bool
|
||||
err := d.DB.QueryRow(ctx, `SELECT rolsuper OR rolbypassrls FROM pg_roles WHERE rolname = current_user`).Scan(&bypass)
|
||||
if err == nil && bypass {
|
||||
d.Log.Warn("database role bypasses row-level security; connect as a non-superuser role without BYPASSRLS")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user