View a markdown version of this page

使用 IAM 條件索引鍵搭配 Amazon Aurora DSQL - Amazon Aurora DSQL

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

使用 IAM 條件索引鍵搭配 Amazon Aurora DSQL

Condition 元素 (或Condition區塊) 指定政策陳述式生效的條件。您可以使用 StringEquals或 等條件運算子來建置條件式表達式StringLike,將政策中的索引鍵與請求中的值進行比對。條件索引鍵不同於資源 ARN 範圍,這會使用 Resource元素將動作限制為特定資源。

Amazon Aurora DSQL 支援服務特定條件金鑰和 AWS 全域條件金鑰。您可以使用這些金鑰來精簡適用 IAM 政策陳述式的條件。如需 AWS 全域條件索引鍵的詳細資訊,請參閱《IAM 使用者指南》中的AWS 全域條件內容索引鍵

Amazon Aurora DSQL 的可用條件金鑰

Amazon Aurora DSQL 支援服務特定的條件金鑰 dsql:WitnessRegiondsql:FisActionIddsql:FisTargetArns。您也可以使用 AWS 全域條件金鑰,例如 aws:RequestTagaws:ResourceTagaws:TagKeys。如需您可以在政策中指定的 Amazon Aurora DSQL 動作、條件金鑰和資源的完整清單,請參閱《服務授權參考》中的 Amazon Aurora DSQL 的動作、資源和條件金鑰

範例:限制多區域叢集的見證區域

下列政策使用 dsql:WitnessRegion條件索引鍵,將多區域叢集建立限制為見證區域為美國西部 (奧勒岡) 的情況。如果沒有此條件,您可以將任何區域指定為見證區域。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "AllowCreateWithSpecificWitness", "Effect": "Allow", "Action": [ "dsql:CreateCluster", "dsql:PutWitnessRegion" ], "Resource": "arn:aws:dsql:*:123456789012:cluster/*", "Condition": { "StringEquals": { "dsql:WitnessRegion": "us-west-2" } } }, { "Sid": "AllowMultiRegionSetup", "Effect": "Allow", "Action": [ "dsql:PutMultiRegionProperties", "dsql:AddPeerCluster" ], "Resource": "arn:aws:dsql:*:123456789012:cluster/*" } ] }

第一個陳述式會將 dsql:WitnessRegion條件套用至支援該條件的動作 (dsql:CreateClusterdsql:PutWitnessRegion)。第二個陳述式會授予dsql:AddPeerCluster沒有 條件的 dsql:PutMultiRegionProperties和 ,因為 dsql:WitnessRegion條件金鑰僅適用於 dsql:CreateClusterdsql:PutWitnessRegion

範例:建立叢集時需要標籤

當您建立叢集時,下列政策會使用 aws:RequestTagaws:TagKeys條件索引鍵來要求 Environment標籤。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "AllowCreateWithRequiredTag", "Effect": "Allow", "Action": "dsql:CreateCluster", "Resource": "arn:aws:dsql:*:123456789012:cluster/*", "Condition": { "StringEquals": { "aws:RequestTag/Environment": [ "production", "staging", "development" ] }, "ForAllValues:StringEquals": { "aws:TagKeys": [ "Environment", "Owner" ] } } } ] }

此政策同時使用兩個條件索引鍵。aws:RequestTag/Environment 條件要求Environment標籤具有其中一個允許的值。具有ForAllValues集合運算子aws:TagKeys的條件可確保請求僅包含 EnvironmentOwner 標籤索引鍵。

範例:將錯誤注入限制在特定叢集

下列政策使用 dsql:FisActionIddsql:FisTargetArns條件金鑰,將 AWS FIS 錯誤注入限制為特定動作和目標叢集。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "AllowSpecificFaultInjection", "Effect": "Allow", "Action": "dsql:InjectError", "Resource": "*", "Condition": { "StringEquals": { "dsql:FisActionId": "aws:dsql:cluster-connection-failure" }, "ForAllValues:ArnLike": { "dsql:FisTargetArns": "arn:aws:dsql:us-east-1:123456789012:cluster/*" } } } ] }

dsql:FisActionId 條件會限制您可以執行的錯誤注入動作。dsql:FisTargetArns 條件使用ForAllValues集合運算子和ArnLike運算子。它們共同確保請求中的每個叢集 ARN 都符合允許的模式。這會封鎖任何包含預期範圍外叢集 ARNs 的請求。