Usar políticas de controle de acesso do IAM baseadas em tags - Amazon Athena

Usar políticas de controle de acesso do IAM baseadas em tags

As etiquetas permitem que você escreva uma política do IAM que inclua o bloco Condition para controlar o acesso a um recurso com base em suas etiquetas. Esta seção inclui exemplos de políticas de tags para recursos de grupos de trabalho e catálogos de dados.

Exemplos de política de etiquetas para grupos de trabalho

A seguinte política do IAM permite que você execute consultas e interaja com as etiquetas do grupo de trabalho chamado workgroupA:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListWorkGroups", "athena:ListEngineVersions", "athena:ListDataCatalogs", "athena:ListDatabases", "athena:GetDatabase", "athena:ListTableMetadata", "athena:GetTableMetadata" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:GetWorkGroup", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource", "athena:StartQueryExecution", "athena:GetQueryExecution", "athena:BatchGetQueryExecution", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream", "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:BatchGetNamedQuery", "athena:ListNamedQueries", "athena:DeleteNamedQuery", "athena:CreatePreparedStatement", "athena:GetPreparedStatement", "athena:ListPreparedStatements", "athena:UpdatePreparedStatement", "athena:DeletePreparedStatement" ], "Resource": "arn:aws:athena:us-east-1:123456789012:workgroup/workgroupA" } ] }

As tags associadas a um recurso, como um grupo de trabalho, são chamadas de tags de recurso. As tags de recursos permitem escrever blocos de política, como os seguintes, que negam as ações listadas em qualquer grupo de trabalho marcado com um par de chave-valor como stack, production.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": [ "athena:GetWorkGroup", "athena:UpdateWorkGroup", "athena:DeleteWorkGroup", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource", "athena:StartQueryExecution", "athena:GetQueryExecution", "athena:BatchGetQueryExecution", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream", "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:BatchGetNamedQuery", "athena:ListNamedQueries", "athena:DeleteNamedQuery", "athena:CreatePreparedStatement", "athena:GetPreparedStatement", "athena:ListPreparedStatements", "athena:UpdatePreparedStatement", "athena:DeletePreparedStatement" ], "Resource": "arn:aws:athena:us-east-1:123456789012:workgroup/*", "Condition": { "StringEquals": { "aws:ResourceTag/stack": "production" } } } ] }

As tags que são passadas como parâmetros para operações que alteram tags (por exemplo, TagResource, UntagResource ou CreateWorkGroup com tags) são chamadas de tags de solicitação. O seguinte exemplo de bloco de política permite a operação CreateWorkGroup apenas se uma das tags passadas tiver a chave costcenter e o valor 1, 2 ou 3.

nota

Se você deseja permitir que um perfil do IAM especifique as etiquetas como parte de uma operação CreateWorkGroup, certifique-se de conceder ao perfil as permissões para as ações TagResource e CreateWorkGroup.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:CreateWorkGroup", "athena:TagResource" ], "Resource": "arn:aws:athena:us-east-1:123456789012:workgroup/*", "Condition": { "StringEquals": { "aws:RequestTag/costcenter": [ "1", "2", "3" ] } } } ] }

Exemplos de políticas de etiquetas para catálogos de dados

A seguinte política do IAM permite interagir com as etiquetas do catálogo de dados chamado datacatalogA:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:ListWorkGroups", "athena:ListEngineVersions", "athena:ListDataCatalogs", "athena:ListDatabases", "athena:GetDatabase", "athena:ListTableMetadata", "athena:GetTableMetadata" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "athena:GetWorkGroup", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource", "athena:StartQueryExecution", "athena:GetQueryExecution", "athena:BatchGetQueryExecution", "athena:ListQueryExecutions", "athena:StopQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream", "athena:CreateNamedQuery", "athena:GetNamedQuery", "athena:BatchGetNamedQuery", "athena:ListNamedQueries", "athena:DeleteNamedQuery" ], "Resource": [ "arn:aws:athena:us-east-1:123456789012:workgroup/*" ] }, { "Effect": "Allow", "Action": [ "athena:CreateDataCatalog", "athena:GetDataCatalog", "athena:UpdateDataCatalog", "athena:DeleteDataCatalog", "athena:ListDatabases", "athena:GetDatabase", "athena:ListTableMetadata", "athena:GetTableMetadata", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource": "arn:aws:athena:us-east-1:123456789012:datacatalog/datacatalogA" } ] }

Você pode usar tags de recursos para gravar blocos de política que negam ações específicas em catálogos de dados marcados com pares de chave-valor de tag específicos. O exemplo a seguir nega ações em catálogos de dados que têm o par de chave-valor da tag stack, production.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": [ "athena:CreateDataCatalog", "athena:GetDataCatalog", "athena:UpdateDataCatalog", "athena:DeleteDataCatalog", "athena:GetDatabase", "athena:ListDatabases", "athena:GetTableMetadata", "athena:ListTableMetadata", "athena:StartQueryExecution", "athena:TagResource", "athena:UntagResource", "athena:ListTagsForResource" ], "Resource": "arn:aws:athena:us-east-1:123456789012:datacatalog/*", "Condition": { "StringEquals": { "aws:ResourceTag/stack": "production" } } } ] }

As tags que são passadas como parâmetros para operações que alteram tags (por exemplo, TagResource, UntagResource ou CreateDataCatalog com tags) são chamadas de tags de solicitação. O seguinte exemplo de bloco de política permite a operação CreateDataCatalog apenas se uma das tags passadas tiver a chave costcenter e o valor 1, 2 ou 3.

nota

Se você deseja permitir que um perfil do IAM especifique as etiquetas como parte de uma operação CreateDataCatalog, certifique-se de conceder ao perfil as permissões para as ações TagResource e CreateDataCatalog.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "athena:CreateDataCatalog", "athena:TagResource" ], "Resource": "arn:aws:athena:us-east-1:123456789012:datacatalog/*", "Condition": { "StringEquals": { "aws:RequestTag/costcenter": [ "1", "2", "3" ] } } } ] }