在 中設定資料庫和資料表的存取權 AWS Glue Data Catalog - Amazon Athena

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

在 中設定資料庫和資料表的存取權 AWS Glue Data Catalog

如果您將 AWS Glue Data Catalog 與 Amazon Athena 搭配使用,您可以為 Athena 中使用的資料庫和資料表 Data Catalog 物件定義資源層級政策。

注意

本主題討論資料庫層級和資料表層級的安全性。如需有關設定資料欄層級、資料列層級和儲存格層級安全性的資訊,請參閱 Lake Formation 中的資料篩選和儲存格層級安全性

您可以定義 IAM 身分型政策中的資源層級許可。

重要

本節討論 IAM 身分型政策中的資源層級許可。這些不同於資源型政策。如需有關相關差異的詳細資訊,請參閱《IAM 使用者指南》中的身分型政策和資源型政策

請參閱以下主題以了解這些任務:

執行此任務 參閱以下主題
建立定義 資源存取權的 IAM 政策 《IAM 使用者指南》中的建立 IAM 政策
了解 中使用的 IAM 身分型政策 AWS Glue 《AWS Glue 開發人員指南》中的身分型政策 (IAM 政策)

本節內容

限制

當您使用 和 Athena 的資料庫 AWS Glue Data Catalog 和資料表層級存取控制時,請考慮下列限制:

  • 啟用 IAM Identity Center 的 Athena 工作群組需要將 Lake Formation 設定為使用 IAM Identity Center 身分。如需詳細資訊,請參閱《AWS Lake Formation 開發人員指南》中的整合 IAM Identity Center

  • 您可以限制只能存取資料庫和資料表。這些控制項適用於資料表層級。您不能限制存取資料表中個別分割區。如需詳細資訊,請參閱關於 中資料表分割區和版本的存取控制 AWS Glue

  • AWS Glue Data Catalog 包含下列資源:CATALOGTABLEDATABASEFUNCTION

    注意

    從此清單中,Athena 和 之間的常見資源 AWS Glue Data Catalog 是CATALOG每個帳戶的 DATABASETABLE和 。 Function 是特定的 AWS Glue。對於 Athena 中的刪除動作,您必須包含 AWS Glue 動作的許可。請參閱 資料庫和資料表層級許可的範例

    其階層如下:CATALOG 是每個帳戶中所有 DATABASES 的上階,而每個 DATABASE 是它的所有 TABLESFUNCTIONS 的上階。例如,在帳戶中目錄裡的 db 資料庫中名為 table_test 的資料表,它的上階是帳戶中的 db 和目錄。對 db 資料庫來說,它的上階是帳戶中的目錄,而它的子代是資料表和函數。如需有關資源階層架構的詳細資訊,請參閱《AWS Glue 開發人員指南》中的資料目錄中的 ARN 清單

  • 對於資源的任何非刪除 Athena 動作,例如 CREATE DATABASECREATE TABLESHOW DATABASESHOW TABLEALTER TABLE,您需要許可,才能對資源 (資料表或資料庫) 以及資料目錄中資源的所有上階呼叫此動作。例如,對於表格,其上階為其所屬的資料庫,以及帳戶的目錄。對於資料庫,其上階為帳戶的目錄。請參閱 資料庫和資料表層級許可的範例

  • 對於 Athena 中的刪除動作,例如 DROP DATABASEDROP TABLE,您也需要許可,才能對資料型錄中資源的所有上階和下階呼叫刪除動作。例如,若要刪除資料庫,您需要資料庫,目錄 (即其上階),以及所有表格和使用者定義函數 (即其下階) 的許可。表格沒有下階。若要執行 DROP TABLE,您需要許可,才能對表格、其所屬資料庫,以及目錄執行此動作。請參閱 資料庫和資料表層級許可的範例

根據 設定目錄和資料庫的 AWS Glue 存取權 AWS 區域

若要讓 Athena 使用 AWS Glue, AWS 區域 需要一個政策,以授予 AWS Glue Data Catalog 您 帳戶中每個 的資料庫和 存取權。若要建立資料庫,還需要 CreateDatabase 許可。在下列範例政策中,將 AWS 區域、 AWS 帳戶 ID 和 資料庫名稱取代為您自己的名稱。

{ "Sid": "DatabasePermissions", "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetDatabases", "glue:CreateDatabase" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/default" ] }

關於 中資料表分割區和版本的存取控制 AWS Glue

在 中 AWS Glue,資料表可以有分割區和版本。資料表版本和分割區不會被視為 中的獨立資源 AWS Glue。授予資料表和資料表上階資源的存取權,便可得到資料表版本和分割區的存取權。

基於存取控制的目的,適用下列存取許可:

  • 控制項適用於資料表層級。您可以限制只能存取資料庫和資料表。例如,如果允許存取有分割區的資料表,則此存取權會套用到資料表中的所有分割區。您不能限制存取資料表中個別分割區。

    重要

    若要 AWS Glue 在分割區上執行動作,目錄、資料庫和資料表層級需要分割區動作的許可。存取資料表內的分割區並不足夠。例如,若要GetPartitions在資料庫 myTable中的資料表上執行 myDB,您必須授予目錄、myDB資料庫myTable和資源的glue:GetPartitions許可。

  • 存取控制不適用於資料表版本。與分割區一樣,透過存取資料表 AWS Glue 上 中的資料表版本 APIs 和資料表前代來授予對資料表舊版的存取權。

如需有關 AWS Glue 動作許可的資訊,請參閱《 AWS Glue 開發人員指南》中的 AWS Glue API 許可:動作和資源參考

資料庫和資料表層級許可的範例

下表列出允許存取 Athena 中資料庫和資料表的 IAM 身分型政策範例。我們建議您從這些範例開始,並根據您的需要調整它們,來允許或拒絕對特定資料庫和資料表的特定動作。

這些範例包括存取資料庫和目錄,以便 Athena 和 AWS Glue 可以一起運作。對於多個 AWS 區域,請為每個資料庫和目錄包含類似的政策,每個區域一行。

在此範例中,將 example_db 資料庫和 test 資料表名稱取代為您自己的資料庫和資料表名稱。

DDL 陳述式 IAM 存取政策授予資源存取權的範例
ALTER DATABASE 可讓您修改 example_db 資料庫的屬性。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:UpdateDatabase" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db" ] }
CREATE DATABASE 可讓您建立名為 example_db 的資料庫。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:CreateDatabase" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db" ] }
CREATE TABLE 可讓您在 example_db 資料庫中建立名為 test 的資料表。
{ "Sid": "DatabasePermissions", "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetDatabases" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db" ] }, { "Sid": "TablePermissions", "Effect": "Allow", "Action": [ "glue:GetTables", "glue:GetTable", "glue:GetPartitions", "glue:CreateTable" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db", "arn:aws:glue:us-east-1:123456789012:table/example_db/test" ] }
DROP DATABASE 可讓您捨棄 example_db 資料庫,包括其中的所有資料表。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:DeleteDatabase", "glue:GetTables", "glue:GetTable", "glue:DeleteTable" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db", "arn:aws:glue:us-east-1:123456789012:table/example_db/*", "arn:aws:glue:us-east-1:123456789012:userDefinedFunction/example_db/*" ] }
DROP TABLE 可讓您捨棄 example_db 資料庫中名為 test 的分割資料表。如果您的資料表沒有分割區,請勿包含分割動作。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetTable", "glue:DeleteTable", "glue:GetPartitions", "glue:GetPartition", "glue:DeletePartition" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db", "arn:aws:glue:us-east-1:123456789012:table/example_db/test" ] }
MSCK REPAIR TABLE 允許您在將 Hive 相容分割區新增至 example_db 資料庫中名為 test 的資料表後更新目錄中繼資料。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:CreateDatabase", "glue:GetTable", "glue:GetPartitions", "glue:GetPartition", "glue:BatchCreatePartition" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db", "arn:aws:glue:us-east-1:123456789012:table/example_db/test" ] }
SHOW DATABASES 可讓您列出 AWS Glue Data Catalog中的所有資料庫。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetDatabases" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/*" ] }
SHOW TABLES 可讓您列出 example_db 資料庫中的所有資料表。
{ "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetTables" ], "Resource": [ "arn:aws:glue:us-east-1:123456789012:catalog", "arn:aws:glue:us-east-1:123456789012:database/example_db", "arn:aws:glue:us-east-1:123456789012:table/example_db/*" ] }