View a markdown version of this page

使用 IAM 政策條件進行精細定義存取控制 - Amazon Route 53

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

使用 IAM 政策條件進行精細定義存取控制

您可在 Route 53 中指定使用 IAM 政策授予許可時的條件 (請參閱 存取控制)。例如,您可以:

  • 授予許可以允許他人存取單一資源記錄集。

  • 授予許可能讓使用者存取託管區域中特定 DNS 記錄類型的所有資源記錄集,例如 A 和 AAAA 記錄。

  • 授予許可能讓使用者存取其名稱包含特定字串的資源記錄集。

  • 授予許可能讓使用者在 Route 53 主控台上或在使用 ChangeResourceRecordSets API 時僅限執行某些 CREATE | UPSERT | DELETE 動作。

  • 授予許可,以允許使用者將私有託管區域與特定 VPC 建立關聯或取消關聯。

  • 授予許可,以允許使用者列出與特定 VPC 相關聯的託管區域。

  • 授予許可,以允許使用者存取以建立新的私有託管區域,並將其與特定 VPC 建立關聯。

  • 授予許可以允許使用者建立或刪除 VPC 關聯授權。

  • 授予許可,允許使用者僅管理 (associate/disassociate/update) 具有 Route 53 設定檔的特定資源類型。

  • 授予許可,允許使用者僅管理 (associate/disassociate/update) 具有 Route 53 設定檔的特定資源 ARNs。

  • 授予許可,允許使用者僅管理 (associate/disassociate/update) 具有 Route 53 設定檔的特定託管區域網域。

  • 授予許可,允許使用者僅管理 (associate/disassociate/update) 具有 Route 53 設定檔的特定解析程式規則網域。

  • 授予許可,以允許使用者管理 (associate/disassociate/update) Route 53 設定檔中具有特定優先順序範圍的防火牆規則群組。

  • 授予許可,允許使用者管理 (關聯/取消關聯) Route 53 設定檔與特定 VPCs。

您也可以建立將任何精細權限合併在一起的權限。

標準化 Route 53 條件索引鍵值

您在政策條件中輸入的值必須進行格式化或標準化,如下所示:

如果使用 route53:ChangeResourceRecordSetsNormalizedRecordNames

  • 所有字母必須小寫。

  • DNS 名稱不可有行尾點號。

  • a—z、0-9、- (連字號)、_ (底線) 和 . (用來分隔標籤的句點) 必須使用以下格式的逸出碼:\三位數八進位碼。例如,\052 是字元 * 的八進位碼。

如果使用 route53:ChangeResourceRecordSetsActions,則數值可能是下列任何一個值,且必須是大寫:

  • CREATE

  • UPSERT (更新插入)

  • DELETE

如果使用 route53:ChangeResourceRecordSetsRecordTypes

  • 該值必須是大寫字母,並且可能是任何 Route 53 支援的 DNS 記錄類型。如需詳細資訊,請參閱支援的 DNS 記錄類型

如果使用 route53:VPCs

  • 值的格式必須為 VPCId=<vpc-id>,VPCRegion=<region>

  • <vpc-id> 和 的值<region>必須小寫,例如 VPCId=vpc-123abcVPCRegion=us-east-1

  • 內容索引鍵和值區分大小寫。

重要

您必須遵循這些慣例,才能授予別人許可,進而允許或限制別人能做的動作。此條件索引鍵僅接受 VPCIdVPCRegion元素,不支援任何其他 AWS 資源 AWS 帳戶,例如 。

對於 route53profiles:ResourceTypes,該值可以是下列任何項目,且區分大小寫:

  • HostedZone

  • FirewallRuleGroup

  • ResolverQueryLoggingConfig

  • ResolverRule

  • VPCEndpoint

如果使用 route53profiles:ResourceArns

  • 值必須是有效的 AWS 資源 ARN,例如 arn:aws:route53:::hostedzone/Z12345

  • 比較 ARN 值時使用 ArnEqualsArnLike條件運算子。

如果使用 route53profiles:HostedZoneDomains

  • 值必須是有效的網域名稱,例如 example.com

  • 網域名稱必須沒有結尾的點。

  • 這些值區分大小寫。

如果使用 route53profiles:ResolverRuleDomains

  • 值必須是有效的網域名稱,例如 example.com

  • 網域名稱必須沒有結尾的點。

  • 這些值區分大小寫。

如果使用 route53profiles:FirewallRuleGroupPriority

  • 此值必須是代表 Firewall Rule Group 優先順序的數值。

  • 使用數值條件運算子,例如 NumericEqualsNumericGreaterThanEqualsNumericLessThanEquals來比較優先順序值或定義優先順序範圍。

如果使用 route53profiles:ResourceIds

  • 值必須是有效的 VPC ID,例如 vpc-1a2b3c4d5e6f

  • 這些值區分大小寫。

您可以使用 Access AnalyzerIAM 使用者指南中的政策模擬器來驗證您的政策是否如預期授予或限制他人權限。將 IAM 政策套用於要執行 Route 53 操作的測試使用者或測試角色也可以驗證許可。

指定條件:使用條件金鑰

AWS 為支援 IAM 進行存取控制的所有 AWS 服務提供一組預先定義的條件金鑰 (AWS全條件金鑰)。例如,您可以使用 aws:SourceIp 條件金鑰先檢查申請者的 IP 位址,再允許執行動作。如需詳細資訊以及 AWS通用金鑰的清單,請參閱《IAM 使用者指南》中的可用條件金鑰

注意

Route 53 不支援標籤型條件金鑰。

下表顯示適用於 Route 53 的 Route 53 服務特定條件金鑰。

Route 53 條件金鑰 API 操作 值類型 Description
route53:ChangeResourceRecordSetsNormalizedRecordNames

ChangeResourceRecordSets

多重值

在收到 ChangeResourceRecordSets 請求時,顯示 DNS 記錄名稱清單。為了獲得預期反應,IAM 政策中的 DNS 名稱必須依照下列方式進行標準化:

  • 所有字母必須小寫。

  • DNS 名稱不可有行尾點號。

  • a 到 z、0 到 9、- (連字號)、_ (底線) 和 . (用來分隔標籤的句點) 必須使用以下格式的逸出碼:\三位數八進位碼。

route53:ChangeResourceRecordSetsRecordTypes

ChangeResourceRecordSets

多重值

收到 ChangeResourceRecordSets 請求時,顯示 DNS 記錄類型清單。

ChangeResourceRecordSetsRecordTypes 可能是 Route 53 支援的任何 DNS 記錄類型。如需詳細資訊,請參閱支援的 DNS 記錄類型。政策的所有內容都必須以大寫輸入。

route53:ChangeResourceRecordSetsActions

ChangeResourceRecordSets

多重值

收到 ChangeResourceRecordSets 請求時,顯示動作清單。

ChangeResourceRecordSetsActions 可能是下列任何一個值 (必須是大寫):

  • CREATE

  • UPSERT (更新插入)

  • DELETE

route53:VPCs

AssociateVPCWithHostedZone

DisassociateVPCFromHostedZone

ListHostedZonesByVPC

CreateHostedZone

CreateVPCAssociationAuthorization

DeleteVPCAssociationAuthorization

多重值

代表 AssociateVPCWithHostedZoneDisassociateVPCFromHostedZoneListHostedZonesByVPCCreateVPCAssociationAuthorizationCreateHostedZone和 請求中的 VPCs 清單DeleteVPCAssociationAuthorization,格式為 "VPCId=<vpc-id>,VPCRegion=<region>
route53profiles:ResourceTypes

AssociateResourceToProfile

DisassociateResourceFromProfile

UpdateProfileResourceAssociation

String

依特定資源類型篩選存取權。

route53profiles:ResourceTypes 可以是下列任何值 (區分大小寫):

  • HostedZone

  • FirewallRuleGroup

  • ResolverQueryLoggingConfig

  • ResolverRule

  • VPCEndpoint

route53profiles:ResourceArns

AssociateResourceToProfile

DisassociateResourceFromProfile

ARN

依特定資源 ARNs篩選存取權。
route53profiles:HostedZoneDomains

AssociateResourceToProfile

DisassociateResourceFromProfile

UpdateProfileResourceAssociation

String

依託管區域網域篩選存取權。若要取得預期的行為,IAM 政策中的網域名稱必須標準化,如下所示:

  • 網域名稱必須沒有結尾的點。

  • 這些值區分大小寫。

route53profiles:ResolverRuleDomains

AssociateResourceToProfile

DisassociateResourceFromProfile

UpdateProfileResourceAssociation

String

依解析程式規則網域篩選存取權。若要取得預期的行為,IAM 政策中的網域名稱必須標準化,如下所示:

  • 網域名稱必須沒有結尾的點。

  • 這些值區分大小寫。

route53profiles:FirewallRuleGroupPriority

AssociateResourceToProfile

DisassociateResourceFromProfile

UpdateProfileResourceAssociation

數值

依防火牆規則群組的優先順序範圍篩選存取權。
route53profiles:ResourceIds

AssociateProfile

DisassociateProfile

String

依指定的 VPCs篩選存取權。

範例政策:使用條件進行精細定義存取

本節中的每個範例都會將 Effect 子句設定為 Allow,而且只指定允許的動作、資源及參數。只允許存取 IAM 政策中明確列出的項目。

在某些情況下,有可能會重新撰寫這些政策,讓它們成為拒絕類型 (即,將 Effect 子句設定為 Deny,並反轉政策中的所有邏輯)。不過,建議您避免使用拒絕類型政策,因為它們與允許類型政策相較之下會較難正確地撰寫。對於需要文字正規化的 Route 53 而言尤其如此。

透過授予許可來限制他人對含特定名稱之 DNS 記錄的存取行為

下列許可政策授予的權限可允許他人對 example.com 和 marketing.example.com 上的託管區域 Z12345 執行 ChangeResourceRecordSets 動作。它使用 route53:ChangeResourceRecordSetsNormalizedRecordNames 條件金鑰來限制使用者僅能對符合指定名稱的記錄進行處置動作。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "route53:ChangeResourceRecordSets", "Resource": "arn:aws:route53:::hostedzone/Z11111112222222333333", "Condition": { "ForAllValues:StringEquals":{ "route53:ChangeResourceRecordSetsNormalizedRecordNames": ["example.com", "marketing.example.com"] } } } ] }

ForAllValues:StringEquals 是適用於多值金鑰的 IAM 條件運算子。上述政策中的條件僅在 ChangeResourceRecordSets 的所有變更都含有 example.com 的 DNS 名稱時才允許執行。如需詳細資訊,請參閱《IAM 使用者指南》中的 IAM 條件運算子具有多個索引鍵或值的 IAM 條件

若要實作名稱中含有特定尾碼的權限,可在具有條件運算子 StringLikeStringNotLike 的政策中使用 IAM 萬用字元 (*)。以下策略會在當 ChangeResourceRecordSets 操作的所有變更都具有以「-beta.example.com」結尾的 DNS 名稱時允許執行。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "route53:ChangeResourceRecordSets", "Resource": "arn:aws:route53:::hostedzone/Z11111112222222333333", "Condition": { "ForAllValues:StringLike":{ "route53:ChangeResourceRecordSetsNormalizedRecordNames": ["*-beta.example.com"] } } } ] }
注意

IAM 萬用字元與網域名稱萬用字元不同。如需有關在網域名稱中使用萬用字元的方式,請參閱下列範例。

授予他人可限制其對含萬用字元之網域名稱的 DNS 記錄進行存取的許可權限

下列許可政策授予的權限可允許他人對 example.com 上的託管區域 Z12345 執行 ChangeResourceRecordSets 動作。它會使用 route53:ChangeResourceRecordSetsNormalizedRecordNames 條件金鑰來限制使用者,使其只能對符合 *.example.com 的記錄採取處置動作。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "route53:ChangeResourceRecordSets", "Resource": "arn:aws:route53:::hostedzone/Z11111112222222333333", "Condition": { "ForAllValues:StringEquals":{ "route53:ChangeResourceRecordSetsNormalizedRecordNames": ["\\052.example.com"] } } } ] }

\052 是 DNS 名稱中字元 * 的八進位碼,而 \052 中的 \ 則逸出為 \\,以便符合 JSON 語法。

透過授予許可權限來限制他人對特定 DNS 記錄的存取行為

下列許可政策授予的權限可允許他人對 example.com 上的託管區域 Z12345 執行 ChangeResourceRecordSets 動作。它使用三個條件金鑰的組合來限制使用者動作,只允許使用者建立或編輯具有特定 DNS 名稱和類型的 DNS 記錄。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "route53:ChangeResourceRecordSets", "Resource": "arn:aws:route53:::hostedzone/Z11111112222222333333", "Condition": { "ForAllValues:StringEquals":{ "route53:ChangeResourceRecordSetsNormalizedRecordNames": ["example.com"], "route53:ChangeResourceRecordSetsRecordTypes": ["MX"], "route53:ChangeResourceRecordSetsActions": ["CREATE", "UPSERT"] } } } ] }
授予許可權限以限制使用者的存取行為,使用者只能建立和編輯指定類型的 DNS 記錄

下列許可政策授予的權限可允許他人對 example.com 上的託管區域 Z12345 執行 ChangeResourceRecordSets 動作。它使用 route53:ChangeResourceRecordSetsRecordTypes 條件金鑰來限制使用者僅能對符合指定類型 (A 和 AAAA) 的記錄進行處置動作。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "route53:ChangeResourceRecordSets", "Resource": "arn:aws:route53:::hostedzone/Z11111112222222333333", "Condition": { "ForAllValues:StringEquals":{ "route53:ChangeResourceRecordSetsRecordTypes": ["A", "AAAA"] } } } ] }
授予許可,指定 IAM 主體可在其中操作的 VPC

下列許可政策會授予許可,允許 vpc-id AssociateVPCWithHostedZone 所指定之 VPC 上的 DisassociateVPCFromHostedZoneCreateVPCAssociationAuthorization、、CreateHostedZone、、 和 ListHostedZonesByVPCDeleteVPCAssociationAuthorization動作。

重要

條件值的格式必須為 VPCId=<vpc-id>,VPCRegion=<region>。如果您在條件值中指定 VPC ARN,則條件金鑰將不會生效。

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "Statement1", "Effect": "Allow", "Action": [ "route53:*" ], "Resource": [ "*" ], "Condition": { "StringLike": { "route53:VPCs": [ "VPCId=<vpc-id>,VPCRegion=<region>" ] } } }, { "Sid": "Statement2", "Effect": "Allow", "Action": "ec2:DescribeVpcs", "Resource": "*" } ] }
重要

route53profiles 條件索引鍵可在 AWS 區域 Route 53 Route53Profiles 可用的所有 中使用,但 me-central-1 和 me-south-1 除外。

授予許可,以限制與 Route 53 Profiles 中特定資源類型的資源關聯

下列許可政策會授予許可,只在資源類型為託管區域時允許 AssociateResourceToProfileDisassociateResourceFromProfile動作。它使用 route53profiles:ResourceTypes條件索引鍵來限制可與設定檔相關聯的資源類型。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateResourceToProfile", "route53profiles:DisassociateResourceFromProfile" ], "Resource": "*", "Condition": { "StringEquals": { "route53profiles:ResourceTypes": "HostedZone" } } }
授予許可,以限制與 Route 53 Profiles 中特定資源 ARNs 的資源關聯

下列許可政策會授予許可,只允許指定資源 ARN 的 AssociateResourceToProfileDisassociateResourceFromProfile動作。它使用 route53profiles:ResourceArns條件索引鍵來限制哪些資源可與設定檔相關聯。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateResourceToProfile", "route53profiles:DisassociateResourceFromProfile" ], "Resource": "*", "Condition": { "ArnEquals": { "route53profiles:ResourceArns": "arn:aws:route53:::hostedzone/Z12345" } } }
授予許可,以限制與 Route 53 Profiles 中特定託管區域網域的資源關聯

下列許可政策會授予許可,只在託管區域網域符合指定值時AssociateResourceToProfile,才允許 DisassociateResourceFromProfile、 和 UpdateProfileResourceAssociation動作。它使用 route53profiles:HostedZoneDomains條件索引鍵來限制哪些託管區域網域可與設定檔相關聯。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateResourceToProfile", "route53profiles:DisassociateResourceFromProfile", "route53profiles:UpdateProfileResourceAssociation" ], "Resource": "*", "Condition": { "StringEquals": { "route53profiles:HostedZoneDomains": "example.com" } } }
授予許可,以限制與 Route 53 設定檔中特定解析程式規則網域的資源關聯

下列許可政策會授予許可,只在解析程式規則網域符合指定的值時AssociateResourceToProfile,才允許 DisassociateResourceFromProfile、 和 UpdateProfileResourceAssociation動作。它使用 route53profiles:ResolverRuleDomains條件索引鍵來限制哪些解析程式規則網域可與設定檔相關聯。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateResourceToProfile", "route53profiles:DisassociateResourceFromProfile", "route53profiles:UpdateProfileResourceAssociation" ], "Resource": "*", "Condition": { "StringEquals": { "route53profiles:ResolverRuleDomains": "example.com" } } }
授予許可,將防火牆規則群組關聯限制為 Route 53 設定檔中的特定優先順序範圍

下列許可政策會授予許可,只在防火牆規則群組優先順序在指定範圍內時,才允許 DisassociateResourceFromProfile、 和 AssociateResourceToProfileUpdateProfileResourceAssociation動作。它使用 route53profiles:FirewallRuleGroupPriority條件索引鍵來限制可以使用的優先順序值。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateResourceToProfile", "route53profiles:DisassociateResourceFromProfile", "route53profiles:UpdateProfileResourceAssociation" ], "Resource": "*", "Condition": { "NumericGreaterThanEquals": { "route53profiles:FirewallRuleGroupPriority": "100" } } }
授予許可,限制與 Route 53 設定檔中特定 VPCs 的設定檔關聯

下列許可政策會授予許可,只允許指定 VPC 的 AssociateProfileDisassociateProfile動作。它使用 route53profiles:ResourceIds條件索引鍵來限制設定檔可以相關聯的 VPCs。

{ "Effect": "Allow", "Action": [ "route53profiles:AssociateProfile", "route53profiles:DisassociateProfile" ], "Resource": "*", "Condition": { "StringEquals": { "route53profiles:ResourceIds": "vpc-1a2b3c4d5e6f" } } }