Utilizzare policy di controllo degli accessi IAM basate su tag - Amazon Athena

Utilizzare policy di controllo degli accessi IAM basate su tag

La presenza di tag consente di scrivere una policy IAM che include il blocco Condition per controllare l'accesso a una risorsa in base ai relativi tag. Questa sezione include esempi di policy sui tag per le risorse di gruppi di lavoro e cataloghi di dati.

Esempi di policy relative ai tag per gruppi di lavoro

La policy IAM seguente consente di eseguire query e interagire con i tag per il gruppo di lavoro denominato workgroupA:

JSON
{ "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" } ] }

I tag associati a una risorsa esistente sono definiti tag di risorsa. I tag delle risorse consentono di scrivere blocchi di policy come i seguenti che negano le operazioni elencate su qualsiasi gruppo di lavoro contrassegnato con una coppia chiave-valore come stack, production.

JSON
{ "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" } } } ] }

I tag passati come parametri alle operazioni che modificano i tag (ad esempio TagResource, UntagResource, o CreateWorkGroup con tag) vengono definiti tag di richiesta. Il seguente blocco di policy di esempio consente l'operazione CreateWorkGroup solo se uno dei tag passati ha la chiave costcenter e il valore 1, 2, o 3.

Nota

Se desideri autorizzare un ruolo IAM a passare i tag come parte di un'operazione CreateWorkGroup, assicurati di concedere al ruolo le autorizzazioni per le operazioni TagResource e CreateWorkGroup.

JSON
{ "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" ] } } } ] }

Esempi di policy relative ai tag per cataloghi dati

La seguente policy IAM consente di interagire con i tag per il catalogo dati denominato datacatalogA:

JSON
{ "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" } ] }

È possibile utilizzare i tag delle risorse per scrivere blocchi di policy che negano operazioni specifiche nei cataloghi dati contrassegnati con coppie chiave-valore di tag specifiche. La seguente policy di esempio nega le operazioni sui cataloghi dati con la coppia chiave-valore di tag stack, production.

JSON
{ "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" } } } ] }

I tag passati come parametri alle operazioni che modificano i tag (ad esempio TagResource, UntagResource, o CreateDataCatalog con tag) vengono definiti tag di richiesta. Il seguente blocco di policy di esempio consente l'operazione CreateDataCatalog solo se uno dei tag passati ha la chiave costcenter e il valore 1, 2, o 3.

Nota

Se desideri autorizzare un ruolo IAM a passare i tag come parte di un'operazione CreateDataCatalog, assicurati di concedere al ruolo le autorizzazioni per le operazioni TagResource e CreateDataCatalog.

JSON
{ "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" ] } } } ] }