本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
基于标签的 IAM 访问控制策略
拥有标签后,您可以编写包含 Condition
块的 IAM 策略,以便基于其标签来控制对资源的访问。
工作组的标签策略示例
例 1. 基本标记策略
以下 IAM 策略允许您运行查询并与名为 workgroupA
的工作组的标签进行交互:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListWorkGroups", "athena:GetExecutionEngine", "athena:GetExecutionEngines", "athena:GetNamespace", "athena:GetCatalogs", "athena:GetNamespaces", "athena:GetTables", "athena:GetTable" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery", "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResultsStream", "athena:GetQueryExecutions", "athena:ListNamedQueries", "athena:CreateNamedQuery", "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution", "athena:GetWorkGroup", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource":
"arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA"
} ] }
例 2: 根据标签键和标签值对拒绝对工作组的操作的策略块
与资源(如工作组)关联的标签称作资源标签。利用资源标签,您可以编写如下所示的策略块,以拒绝对使用键-值对(如 stack
、production
)标记的任何工作组执行列出的操作。
{ "Effect": "Deny", "Action": [ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery", "athena:UpdateWorkGroup", "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:GetWorkGroup", "athena:StopQueryExecution", "athena:GetQueryResultsStream", "athena:GetQueryExecutions", "athena:ListNamedQueries", "athena:CreateNamedQuery", "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource":
"arn:aws:athena:us-east-1:123456789012:workgroup/*"
, "Condition": { "StringEquals": { "aws:ResourceTag/stack": "production" } } }
例 3. 限制对指定标签执行标签更改操作请求的策略块
作为参数传入将更改标签的操作(例如,带标签的 TagResource
、UntagResource
或 CreateWorkGroup
)的标签称作请求标签。仅在传递的某个标签的键为 costcenter
且值为 1
、2
或 3
时,以下示例策略块才允许 CreateWorkGroup
操作。
如果要允许 IAM 用户将标签作为 CreateWorkGroup
操作的一部分传入,请确保向用户授予执行 TagResource
和 CreateWorkGroup
操作的权限。
{ "Effect": "Allow", "Action": [ "athena:CreateWorkGroup", "athena:TagResource" ], "Resource":
"arn:aws:athena:us-east-1:123456789012:workgroup/*"
, "Condition": { "StringEquals": { "aws:RequestTag/costcenter": [ "1", "2", "3" ] } } }
数据目录的标签策略示例
例 1. 基本标记策略
以下 IAM 策略允许您与名为 datacatalogA
的数据目录的标签进行交互:
{ "Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Action":[ "athena:ListWorkGroups", "athena:ListDataCatalogs", "athena:GetExecutionEngine", "athena:GetExecutionEngines", "athena:GetNamespace", "athena:GetNamespaces", "athena:GetTables", "athena:GetTable" ], "Resource":"*" }, { "Effect":"Allow", "Action":[ "athena:StartQueryExecution", "athena:GetQueryResults", "athena:DeleteNamedQuery", "athena:GetNamedQuery", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResultsStream", "athena:GetQueryExecutions", "athena:ListNamedQueries", "athena:CreateNamedQuery", "athena:GetQueryExecution", "athena:BatchGetNamedQuery", "athena:BatchGetQueryExecution", "athena:GetWorkGroup", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*" ] }, { "Effect":"Allow", "Action":[ "athena:CreateDataCatalog", "athena:DeleteDataCatalog", "athena:GetDataCatalog", "athena:GetDatabase", "athena:GetTableMetadata", "athena:ListDatabases", "athena:ListTableMetadata", "athena:UpdateDataCatalog", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource":"
arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA
" } ] }
例 2: 基于标签键和标签值对拒绝对数据目录的操作的策略块
您可以使用资源标签编写策略块,以拒绝对使用特定标签键/值对标记的数据目录执行特定操作。以下示例策略拒绝对具有标签键/值对 stack
production
的数据目录执行操作。
{ "Effect":"Deny", "Action":[ "athena:CreateDataCatalog", "athena:DeleteDataCatalog", "athena:GetDataCatalog", "athena:GetDatabase", "athena:GetTableMetadata", "athena:ListDatabases", "athena:ListTableMetadata", "athena:UpdateDataCatalog", "athena:StartQueryExecution", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource":"
arn:aws:athena:us-east-1:123456789012:datacatalog/*
", "Condition":{ "StringEquals":{ "aws:ResourceTag/stack
":"production
" } } }
例 3. 限制对指定标签执行标签更改操作请求的策略块
作为参数传入将更改标签的操作(例如,带标签的 TagResource
、UntagResource
或 CreateDataCatalog
)的标签称作请求标签。仅在传递的某个标签的键为 costcenter
且值为 1
、2
或 3
时,以下示例策略块才允许 CreateDataCatalog
操作。
如果要允许 IAM 用户将标签作为 CreateDataCatalog
操作的一部分传入,请确保向用户授予执行 TagResource
和 CreateDataCatalog
操作的权限。
{ "Effect":"Allow", "Action":[ "athena:CreateDataCatalog", "athena:TagResource" ], "Resource":"
arn:aws:athena:us-east-1:123456789012:datacatalog/*
", "Condition":{ "StringEquals":{ "aws:RequestTag/costcenter
":[ "1
", "2
", "3
" ] } } }