LoginSignup
2
1

More than 1 year has passed since last update.

Supabase: ロールに割り当てられたカラムの権限を確認するSQL

Posted at

Supabaseは、Firebaseに代わるオープンソースのアプリケーション開発プラットフォームです。データベースの管理や認証機能など、アプリケーション開発に必要な機能を提供しています。今回は、Supabaseで使用する、ロールに割り当てられたカラムの権限を確認するSQLについてご紹介します。

SQLクエリ

以下のSQLクエリを使って、特定のロールがどのカラムにどのような権限を持っているかを簡単に確認することができます。

select grantee, table_name, column_name, privilege_type
from postgres.information_schema.role_column_grants
where table_schema = 'public'
  and grantee in ('anon', 'authenticated');

出力結果の例:

grantee table_name column_name privilege_type
anon posts id SELECT
anon posts title SELECT
anon posts content SELECT
anon posts author_id SELECT
authenticated posts id SELECT
authenticated posts title SELECT
authenticated posts content SELECT
authenticated posts author_id SELECT
authenticated posts id INSERT
authenticated posts title INSERT
authenticated posts content INSERT
authenticated posts author_id INSERT
authenticated posts id DELETE

クエリの解説

  • grantee: 権限を持っているロール名です。
  • table_name: 権限が割り当てられたテーブル名です。
  • column_name: 権限が割り当てられたカラム名です。
  • privilege_type: カラムに対する権限の種類です(例:SELECT, INSERT, UPDATE, DELETEなど)。

information_schema.role_column_grantsというテーブルを使って、特定のスキーマ(この例ではpublic)に属するテーブルのカラム権限をリストすることができます。例では、anon(匿名ユーザー)とauthenticated(認証済みユーザー)という2つのロールの権限を確認しています。

結果

このクエリを実行すると、各カラムの権限とロールを一覧で確認でき、どのロールがどの権限を持っているかひと目でわかります。これにより、セキュリティポリシーやアクセス制御を適切に管理することが容易になります。

関連

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1