0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Snowflakeのロール階層をデータベースロールも含めて可視化する方法

Last updated at Posted at 2025-01-31

①ロール階層を取得

以下のクエリを使いロール階層構造を取得する

SELECT 
    grantee_name role_name
    , name child_role_name
FROM
    SNOWFLAKE.ACCOUNT_USAGE.GRANTS_TO_ROLES
WHERE
    granted_on in ('ROLE', 'DATABASE_ROLE')
    and granted_to in ('ROLE', 'DATABASE_ROLE')
    and privilege = 'USAGE'
    and deleted_on is null
order by
    1,2
;

②. dotファイル形式にする

クエリ結果を整形し以下のdotファイルを作成する

digraph a_tree {
    // グラフ全体の配置を縦方向にする(TB: top to bottom)
    rankdir = TB;

    // 上記のクエリ結果を整形し「"[role_name]" -> "[child_role_name]";」の形式で羅列する
    "ACCOUNTADMIN" -> "SYSADMIN";
    "ACCOUNTADMIN" -> "MY_CUSTOM_ROLE";
    // ...以下省略...
}

③. 適当なツールを使い可視化する

例えば、VS CodeのGraphviz (dot) language support for Visual Studio Codeを使い可視化する

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?