

# AWS 全局条件上下文密钥
<a name="reference_policies_condition-keys"></a>

当[主体](https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html?icmpid=docs_homepage_addtlrcs#principal)向 AWS 发出[请求](intro-structure.md#intro-structure-request)时，AWS 会将请求信息收集到[请求上下文](intro-structure.md#intro-structure-request)中。您可以使用 JSON 策略的 `Condition` 元素将请求上下文中的键与您在策略中指定的键值进行比较。请求信息由不同的来源提供，包括发出请求的主体、请求所针对的资源以及有关请求本身的元数据。

**全局条件键**可在所有 AWS 服务中使用。虽然这些条件键可以在所有策略中使用，但该键并非在每个请求上下文中都可用。例如，只有当 [AWS 服务主体](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services)直接调用您的资源时，`aws:SourceAccount` 条件键才可用。要了解有关在请求上下文中包含全局键的情况的更多信息，请参阅每个键的**可用性**信息。

某些单独的服务创建自己的条件键，这些键在其他服务的请求上下文中可用。**跨服务条件键**是一种全局条件键，其包含与服务名称相匹配的前缀（例如 `ec2:` 或 `lambda:`），但可跨其他服务使用。

**服务特定条件键**是为与单独的 AWS 服务一起使用而定义的。例如，Amazon S3 允许您使用 `s3:VersionId` 条件键编写策略，以限制对特定版本 Amazon S3 对象的访问。此条件键是该服务所独有的，这意味着其仅适用于对 Amazon S3 服务的请求。对于服务特定的条件键，请参阅 [AWS 服务的操作、资源和条件键](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html)，然后选择要查看其键的服务。

**注意**  
如果您使用只在某些情况下可用的条件键，则可使用 [IfExists](reference_policies_elements_condition_operators.md#Conditions_IfExists) 版本的条件运算符。如果请求上下文中缺少条件键，则策略将无法通过评估。例如，将以下条件块与 `...IfExists` 运算符结合使用以在请求来自特定 IP 范围或特定 VPC 时进行匹配。如果请求上下文中未包含这两个键或其中之一，则条件仍将返回 `true`。仅当请求上下文中包含指定的键时，才检查值。有关在其他运算符不存在键时如何评估策略的更多信息，请参阅[条件运算符](reference_policies_elements_condition_operators.md)。  

```
"Condition": {
    "IpAddressIfExists": {"aws:SourceIp" : ["xxx"] },
    "StringEqualsIfExists" : {"aws:SourceVpc" : ["yyy"]} 
}
```

**重要**  
要将条件与具有多个键值的请求上下文进行比较，必须使用 `ForAllValues` 或者 `ForAnyValue` 集合运算符。仅将集合运算符用于多值条件键。不要将集合运算符用于单值条件键。有关更多信息，请参阅 [多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。


| 主体的属性 | 角色会话的属性 | 网络的属性 | 资源的属性 | 请求的属性 | 
| --- | --- | --- | --- | --- | 
|  `aws:PrincipalArn` `aws:PrincipalAccount` `aws:PrincipalOrgPaths` `aws:PrincipalOrgID` `aws:PrincipalTag/*tag-key*` `aws:PrincipalIsAWSService` `aws:PrincipalServiceName` `aws:PrincipalServiceNamesList` `aws:PrincipalType` `aws:userid` `aws:username`  |  `aws:AssumedRoot` `aws:FederatedProvider` `aws:TokenIssueTime` `aws:MultiFactorAuthAge` `aws:MultiFactorAuthPresent` `aws:ChatbotSourceArn` `aws:Ec2InstanceSourceVpc` `aws:Ec2InstanceSourcePrivateIPv4` `aws:SourceIdentity` `ec2:RoleDelivery` `ec2:SourceInstanceArn` `glue:RoleAssumedBy` `glue:CredentialIssuingService` `codebuild:BuildArn` `codebuild:ProjectArn` `lambda:SourceFunctionArn` `ssm:SourceInstanceArn` `identitystore:UserId`  |  `aws:SourceIp` `aws:SourceVpc` `aws:SourceVpcArn` `aws:SourceVpce` `aws:VpceAccount` `aws:VpceOrgID` `aws:VpceOrgPaths` `aws:VpcSourceIp`  |  `aws:ResourceAccount` `aws:ResourceOrgID` `aws:ResourceOrgPaths` `aws:ResourceTag/*tag-key*`  |  `aws:CalledVia` `aws:CalledViaFirst` `aws:CalledViaLast` `aws:CalledViaAWSMCP` `aws:ViaAWSService` `aws:ViaAWSMCPService` `aws:CurrentTime` `aws:EpochTime` `aws:referer` `aws:RequestedRegion` `aws:RequestTag/*tag-key*` `aws:TagKeys` `aws:SecureTransport` `aws:SourceAccount` `aws:SourceArn` `aws:SourceOrgID` `aws:SourceOrgPaths` `aws:UserAgent` `aws:IsMcpServiceAction`  | 

## 敏感条件键
<a name="condition-keys-sensitive"></a>

以下条件键被视为敏感信息。在这些条件键中使用通配符没有任何有效的使用场景，即使键值的子字符串带有通配符也是如此。这是因为通配符可以将条件键与任何值匹配，这可能会带来安全风险。
+ `aws:PrincipalAccount`
+ `aws:PrincipalOrgID`
+ `aws:ResourceAccount`
+ `aws:ResourceOrgID`
+ `aws:SourceAccount`
+ `aws:SourceOrgID`
+ `aws:SourceVpc`
+ `aws:SourceVpce`
+ `aws:VpceAccount`
+ `aws:VpceOrgID`

## 主体的属性
<a name="condition-keys-principal-properties"></a>

使用以下条件键可将有关发出请求的主体的详细信息与您在策略中指定的主体属性进行比较。有关可以发出请求的主体的列表，请参阅 [如何指定主体](reference_policies_elements_principal.md#Principal_specifying)。

### aws:PrincipalArn
<a name="condition-keys-principalarn"></a>

使用此键可将发出请求的主体的 [Amazon Resource Name (ARN)](reference_identifiers.md#identifiers-arns) 与您在策略中指定的 ARN 进行比较。对于 IAM 角色，请求上下文将返回角色的 ARN，而不是已代入角色的用户的 ARN。
+ **Availability**（可用性）- 此键包含在所有签名请求的请求上下文中。匿名请求不包括此键。您可以在此条件键中指定以下类型的主体：
  + IAM 角色
  + IAM 用户
  + AWS STS 联合用户主体
  + AWS 账户 根用户
+ **数据类型** – ARN

  AWS 建议在比较 ARN 时使用 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)而不是[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)。
+ **值类型** - 单值
+ **示例值**下表显示了您可以在 `aws:PrincipalArn` 条件键中指定的为不同类型的主体返回的请求上下文值：
  + **IAM 角色** – 请求上下文包含条件键 `aws:PrincipalArn` 的以下值。请勿将所担任角色会话 ARN 指定为此条件键的值。有关所担任角色会话主体的更多信息，请参阅 [角色会话主体](reference_policies_elements_principal.md#principal-role-session)。

    ```
    arn:aws:iam::123456789012:role/role-name
    ```
  + **IAM 用户** – 请求上下文包含条件键 `aws:PrincipalArn` 的以下值。

    ```
    arn:aws:iam::123456789012:user/user-name
    ```
  + **AWS STS 联合用户主体** – 请求上下文包含条件键 `aws:PrincipalArn` 的以下值。

    ```
    arn:aws:sts::123456789012:federated-user/user-name
    ```
  + **AWS 账户 根用户** – 请求上下文包含条件键 `aws:PrincipalArn` 的以下值。当您将根用户 ARN 指定为 `aws:PrincipalArn` 条件键，它仅限制 AWS 账户 根用户的权限。这不同于在基于资源策略的主体元素中指定根用户 ARN，后者会将权限委托给 AWS 账户。有关在基于资源策略的主体元素中指定根用户 ARN 的更多信息，请参阅 [AWS 账户 主体](reference_policies_elements_principal.md#principal-accounts)。

    ```
    arn:aws:iam::123456789012:root
    ```

您可以将根用户 ARN 指定为 AWS Organizations 服务控制策略（SCP）条件键 `aws:PrincipalArn` 的值。SCP 是一种组织策略，用于管理组织中的权限，仅影响组织中的成员账户。SCP 会限制成员账户中的 IAM 用户和角色的权限，包括成员账户的根用户。有关 SCP 对权限影响的更多信息，请参阅*《AWS Organizations 用户指南》*中的[SCP 对权限的影响](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html#scp-effects-on-permissions)。

### aws:PrincipalAccount
<a name="condition-keys-principalaccount"></a>

使用此键可将请求主体所属的账户与您在策略中指定的账户标识符进行比较。对于匿名请求，请求上下文将返回 `anonymous`。
+ **Availability**（可用性）– 此键包含在所有请求（包括匿名请求）的请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

在以下示例中，除了拥有账号 `123456789012` 的主体外，访问会被拒绝。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyAccessFromPrincipalNotInSpecificAccount",
      "Action": "service:*",
      "Effect": "Deny",
      "Resource": [
        "arn:aws:service:us-east-1:111122223333:resource"
      ],
      "Condition": {
        "StringNotEquals": {
          "aws:PrincipalAccount": [
            "123456789012"
          ]
        }
      }
    }
  ]
}
```

------

### aws:PrincipalOrgPaths
<a name="condition-keys-principalorgpaths"></a>

使用此键可将发出请求的主体的 AWS Organizations 路径与策略中的路径进行比较。该主体可以是 IAM 用户、IAM 角色、AWS STS 联合用户主体或 AWS 账户根用户。在策略中，此条件键可确保请求者是 AWS Organizations 中指定组织根或组织单位 (OU) 的账户成员。AWS Organizations 路径是 AWS Organizations 实体结构的文本表示形式。有关使用和了解路径的更多信息，请参阅[了解 AWS Organizations 实体路径](access_policies_last-accessed-view-data-orgs.md#access_policies_last-accessed-viewing-orgs-entity-path)。
+ **Availability**（可用性）- 仅在主体是企业成员时，才将此键包含在请求上下文中。匿名请求不包括此键。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

**注意**  
组织 ID 是全局唯一的，但 OU ID 和根目录 ID 仅在组织内是唯一的。这意味着没有两个组织具有相同的组织 ID。但是，另一个组织可能具有与您的组织相同的 OU 或根目录 ID。我们建议您在指定 OU 或根目录时始终包含组织 ID。

例如，以下条件返回账户中主体的 `true`，该主体直接附加到 `ou-ab12-22222222` OU 但不在其子 OU 中。

```
"Condition" : { "ForAnyValue:StringEquals" : {
     "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/"]
}}
```

以下条件为账户中的主体返回 `true`，该主体直接附加到 OU 或其任何子 OU。包含通配符时，您必须使用 `StringLike` 条件运算符。

```
"Condition" : { "ForAnyValue:StringLike" : {
     "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/*"]
}}
```

以下条件为账户中的主体返回 `true`，该主体直接附加到任意子 OU，但不会直接附加至父 OU。以前的条件适用于 OU 或任何子 OU。以下条件仅适用于子 OU（以及这些子 OU 的任何子 OU）。

```
"Condition" : { "ForAnyValue:StringLike" : {
     "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/ou-*"]
}}
```

以下条件允许访问 `o-a1b2c3d4e5` 组织中的各个主体，而无论其父 OU 如何。

```
"Condition" : { "ForAnyValue:StringLike" : {
     "aws:PrincipalOrgPaths":["o-a1b2c3d4e5/*"]
}}
```

`aws:PrincipalOrgPaths` 是一个多值条件键。多值键在请求上下文中可以有多个值。在您为 `ForAnyValue` 条件运算符使用多个值时，主体的路径必须与策略中列出的其中一个路径匹配。有关多值条件键的更多信息，请参阅[多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。

```
    "Condition": {
        "ForAnyValue:StringLike": {
            "aws:PrincipalOrgPaths": [
                "o-a1b2c3d4e5/r-ab12/ou-ab12-33333333/*",
                "o-a1b2c3d4e5/r-ab12/ou-ab12-22222222/*"
            ]
        }
    }
```

### aws:PrincipalOrgID
<a name="condition-keys-principalorgid"></a>

使用此键可将请求主体所属的 AWS Organizations 中组织的标识符与策略中指定的标识符进行比较。
+ **Availability**（可用性）- 仅在主体是企业成员时，才将此键包含在请求上下文中。匿名请求不包括此键。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

此全局键提供了列出组织中的所有 AWS 账户的所有账户 ID 的替代方法。您可以使用此条件键来简化在[基于资源的策略](access_policies_identity-vs-resource.md)中指定 `Principal` 元素的过程。您可以在条件元素中指定[组织 ID](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_details.html)。当您添加和删除账户时，包含 `aws:PrincipalOrgID` 键的策略将自动包括正确的账户，并且不需要手动更新。

例如，以下 Amazon S3 存储桶策略允许 `o-xxxxxxxxxxx` 企业中的任何账户成员将对象添加到 `amzn-s3-demo-bucket` 存储桶中。

------
#### [ JSON ]

****  

```
 {
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "AllowPutObject",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:PutObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {"StringEquals":
      {"aws:PrincipalOrgID":"o-xxxxxxxxxxx"}
    }
  }
}
```

------

**注意**  
此全局条件也适用于 AWS 企业的管理账户。此策略防止指定组织之外的所有主体访问 Amazon S3 存储桶。这包括与您的内部资源交互的任何 AWS 服务，如将日志数据发送到 Amazon S3 存储桶的 AWS CloudTrail。了解如何安全地授予 AWS 服务的访问权限，请参阅 [aws:PrincipalIsAWSService](#condition-keys-principalisawsservice)。

有关 AWS Organizations 的更多信息，请参阅《AWS Organizations 用户指南》中的 [什么是 AWS Organizations？](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)**。

### aws:PrincipalTag/*tag-key*
<a name="condition-keys-principaltag"></a>

使用此键可将附加到发出请求的主体的标签与您在策略中指定的标签进行比较。如果已为主体附加多个标签，则请求上下文会为每个附加的标签键包含一个 `aws:PrincipalTag` 键。
+ **可用性** - 仅在主体使用具有附加标签的 IAM 用户时，才将此键包含在请求上下文中。对于主体，如果使用附加了标签或[会话标签](id_session-tags.md)的 IAM 角色，则应包括它。匿名请求不包括此键。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

您可采用键/值对的形式向用户或角色添加自定义属性。有关 IAM 标签的更多信息，请参阅 [AWS Identity and Access Management 资源的标签](id_tags.md)。您可以将 `aws:PrincipalTag` 用于针对 AWS 主体的[访问控制](access_iam-tags.md#access_iam-tags_control-principals)。

此示例说明如何创建基于角色的策略，以允许具有 **department=hr** 标签的用户管理 IAM 用户、组或角色。要使用此策略，请将示例策略中的*斜体占位符文本*替换为您自己的信息。然后，按照[创建策略](access_policies_create.md)或[编辑策略](access_policies_manage-edit.md)中的说明操作。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iam:Get*",
        "iam:List*",
        "iam:Generate*"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:PrincipalTag/department": "hr"
        }
      }
    }
  ]
}
```

------

### aws:PrincipalIsAWSService
<a name="condition-keys-principalisawsservice"></a>

使用此密钥可检查对您资源的调用是否直接由 AWS [服务主体](reference_policies_elements_principal.md#principal-services)提出。例如，AWS CloudTrail 使用服务主体 `cloudtrail.amazonaws.com` 将日志写入 Amazon S3 存储桶。当服务使用服务主体对资源执行直接操作时，请求上下文密钥将设置为 true。如果服务使用 IAM 主体的凭证代表主体发出请求时，上下文密钥设置为 false。如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用，则请求也会被设为 false。
+ **可用性** — 此密钥存在于所有使用 AWS 凭证的签名 API 请求的请求上下文中。匿名请求不包括此键。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型**— 单值

您可以使用此条件键限制对可信身份和预期网络位置的访问，同时安全地授予对 AWS 服务的访问权限。

在以下 Amazon S3 存储桶策略示例中，对存储桶的访问受到限制，除非请求源自 `vpc-111bbb22` 或者来自服务主体，例如 CloudTrail。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ExpectedNetworkServicePrincipal",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket1/AWSLogs/AccountNumber/*",
      "Condition": {
        "StringNotEqualsIfExists": {
          "aws:SourceVpc": "vpc-111bbb22"
        },
        "BoolIfExists": {
          "aws:PrincipalIsAWSService": "false"
        }
      }
    }
  ]
}
```

------

在以下视频中，了解有关如何在策略中使用 `aws:PrincipalIsAWSService` 条件键的更多信息。

[![AWS Videos](http://img.youtube.com/vi/https://www.youtube.com/embed/gv-_H8a42G4/0.jpg)](http://www.youtube.com/watch?v=https://www.youtube.com/embed/gv-_H8a42G4)


### aws:PrincipalServiceName
<a name="condition-keys-principalservicename"></a>

使用此密钥可以将策略中的[服务主体](reference_policies_elements_principal.md#principal-services)名称与正在向您的资源发出请求的服务主体进行比较。您可以使用此密钥来检查此调用是否由特定的服务主体提出。当服务主体向您的资源发出直接请求时，`aws:PrincipalServiceName` 密钥将包含服务主体的名称。例如，AWS CloudTrail 服务主体的名称是 `cloudtrail.amazonaws.com`。
+ **可用性** — 当调用由 AWS 服务主体提出时，此密钥将存在于请求中。此密钥不会在任何其他情况中出现，包括以下情况：
  + 如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用。
  + 如果服务使用 IAM 主体的凭证代表主体发出请求。
  + 如果调用是由 IAM 主体直接发出的。
  + 如果调用是由匿名请求者发出的。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

您可以使用此条件键限制对可信身份和预期网络位置的访问，同时安全地授予对 AWS 服务的访问权限。

在以下 Amazon S3 存储桶策略示例中，对存储桶的访问受到限制，除非请求源自 `vpc-111bbb22` 或者来自服务主体，例如 CloudTrail。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ExpectedNetworkServicePrincipal",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket1/AWSLogs/AccountNumber/*",
      "Condition": {
        "StringNotEqualsIfExists": {
          "aws:SourceVpc": "vpc-111bbb22",
          "aws:PrincipalServiceName": "cloudtrail.amazonaws.com"
        }
      }
    }
  ]
}
```

------

### aws:PrincipalServiceNamesList
<a name="condition-keys-principalservicenameslist"></a>

此密钥提供了属于此服务的所有[服务主体](reference_policies_elements_principal.md#principal-services)名称列表。这是一个高级条件键。您可以用它来限制服务仅从特定地区访问您的资源。某些服务可能会创建区域服务主体，以指示特定区域内服务的特定实例。您可以将对资源的访问限制为服务的特定实例。当服务主体向您的资源发出直接请求时，`aws:PrincipalServiceNamesList` 会包含与服务的区域实例关联的所有服务主体名称的无序列表。
+ **可用性** — 当调用由 AWS 服务主体提出时，此密钥将存在于请求中。此密钥不会在任何其他情况中出现，包括以下情况：
  + 如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用。
  + 如果服务使用 IAM 主体的凭证代表主体发出请求。
  + 如果调用是由 IAM 主体直接发出的。
  + 如果调用是由匿名请求者发出的。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

`aws:PrincipalServiceNamesList` 是一个多值条件键。多值键在请求上下文中可以有多个值。对于此键，您必须将 `ForAnyValue` 或者 `ForAllValues` 集合运算符与[字符串条件运算符](reference_policies_elements_condition_operators.md#Conditions_String)搭配使用。有关多值条件键的更多信息，请参阅[多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。

### aws:PrincipalType
<a name="condition-keys-principaltype"></a>

使用此键可将发出请求的主体的类型与您在策略中指定的主体类型进行比较。有关更多信息，请参阅 [如何指定主体](reference_policies_elements_principal.md#Principal_specifying)。有关 `principal` 密钥值的具体示例，请参阅 [主体键值](reference_policies_variables.md#principaltable)。
+ **Availability**（可用性）– 此键包含在所有请求（包括匿名请求）的请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

### aws:userid
<a name="condition-keys-userid"></a>

使用此键可将请求者的主体标识符与您在策略中指定的 ID 进行比较。对于 IAM 用户，请求上下文值是用户 ID。对于 IAM 角色，此值的格式可能有所不同。有关如何为不同的主体显示信息的详细信息，请参阅[如何指定主体](reference_policies_elements_principal.md#Principal_specifying)。有关 `principal` 密钥值的具体示例，请参阅 [主体键值](reference_policies_variables.md#principaltable)。
+ **Availability**（可用性）– 此键包含在所有请求（包括匿名请求）的请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

### aws:username
<a name="condition-keys-username"></a>

使用此键可将请求者的用户名与您在策略中指定的用户名进行比较。有关如何为不同的主体显示信息的详细信息，请参阅[如何指定主体](reference_policies_elements_principal.md#Principal_specifying)。有关 `principal` 密钥值的具体示例，请参阅 [主体键值](reference_policies_variables.md#principaltable)。
+ **可用性** - 此键始终包含在 IAM 用户的请求上下文中。匿名请求和使用 AWS 账户根用户 或 IAM 角色发出的请求不包含此键。使用 IAM Identity Center 凭证发出的请求不会在上下文中包含此键。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

## 角色会话的属性
<a name="condition-keys-role-session-properties"></a>

使用以下条件键来比较生成会话时角色会话的属性。只有拥有角色会话或联合用户主体凭证的主体发出请求时，这些条件键才可用。这些条件键的值嵌入角色的会话令牌中。

[角色](reference_policies_elements_principal.md#principal-roles)是一种主体。您还可以使用 [主体的属性](#condition-keys-principal-properties) 部分中的条件键在角色发出请求时评估角色的属性。

### aws:AssumedRoot
<a name="condition-keys-assumedroot"></a>

使用此键可检查是否已使用 [AssumeRoot](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoot.html) 发出请求。`AssumeRoot` 返回特权根用户会话的短期凭证，您可以使用该凭证对组织中的成员账户执行特权操作。有关更多信息，请参阅 [集中管理成员账户的根访问权限](id_root-user.md#id_root-user-access-management)。
+ **可用性** – 仅当主体使用来自 [AssumeRoot](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoot.html) 的凭证发出请求时，此键才包含在请求上下文中。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

在以下示例中，当用作服务控制策略时，拒绝在 AWS Organizations 成员账户中使用根用户的长期凭证。该策略不会拒绝 `AssumeRoot` 会话采取 `AssumeRoot` 会话允许的操作。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement":[
       {
          "Effect":"Deny",
          "Action":"*",
          "Resource": "*",
          "Condition":{
             "ArnLike":{
                "aws:PrincipalArn":[
                   "arn:aws:iam::*:root"
                ]
             },
             "Null":{
                "aws:AssumedRoot":"true"
             }
          }
       }
    ]
 }
```

------

### aws:FederatedProvider
<a name="condition-keys-federatedprovider"></a>

使用此密钥将主体的发布身份提供程序 (IdP) 与您在策略中指定的 IdP 进行比较。这意味着 IAM 角色使用 [https://docs.aws.amazon.com//STS/latest/APIReference/API_AssumeRoleWithWebIdentity](https://docs.aws.amazon.com//STS/latest/APIReference/API_AssumeRoleWithWebIdentity) AWS STS 操作代入。使用生成的角色会话的临时证书发出请求时，请求上下文将标识对原始联合身份进行身份验证的 IdP。
+ **可用性** – 此键存在于使用 OpenID Connect (OIDC) 提供程序代入的角色的角色会话中，以及当使用 OIDC 提供程序调用 `AssumeRoleWithWebIdentity` 时的角色信任策略中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)\$1
+ **值类型** - 单值

\$1 数据类型取决于您的 IdP：
+ 如果您使用的是内置 AWS IdP，比如 [Amazon Cognito](https://docs.aws.amazon.com/cognito/latest/developerguide/iam-roles.html)，则密钥值将是一个**字符串**。密钥值可能如下所示：`cognito-identity.amazonaws.com`。
+ 如果您使用的是没有内置于 AWS 的 IdP 、比如 [https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) 或 [Amazon EKS](https://docs.aws.amazon.com//eks/latest/userguide/associate-service-account-role.html)，则密钥值将为 **ARN**。密钥值可能如下所示：`arn:aws:iam::111122223333:oidc-provider/oidc.eks.region.amazonaws.com/id/OIDC_Provider_ID`。

有关外部 IdP 和 `AssumeRoleWithWebIDentity` 的更多信息，请参阅 [常见场景](id_federation_common_scenarios.md)。有关更多信息，请参阅 [角色会话主体](reference_policies_elements_principal.md#principal-role-session)。

### aws:TokenIssueTime
<a name="condition-keys-tokenissuetime"></a>

使用此键可将临时安全凭证的颁发日期和时间与您在策略中指定的日期和时间进行比较。
+ **Availability**（可用性）- 仅在主体使用临时凭证发出请求时，才将此键包含在请求上下文中。使用访问密钥发出的 AWS CLI、AWS API 或 AWS 开发工具包请求中未提供此键。
+ **数据类型** – [日期](reference_policies_elements_condition_operators.md#Conditions_Date)
+ **值类型**— 单值

要了解哪些服务支持使用临时凭证，请参阅[使用 IAM 的 AWS 服务](reference_aws-services-that-work-with-iam.md)。

### aws:MultiFactorAuthAge
<a name="condition-keys-multifactorauthage"></a>

使用此键可将自使用 MFA 向请求主体授权以来的秒数与您在策略中指定的数量进行比较。有关 MFA 的更多信息，请参阅 [IAM 中的 AWS 多重身份验证](id_credentials_mfa.md)。

**重要**  
对于联合身份或使用访问密钥签署 AWS CLI、AWS API 或 AWS SDK 请求而发出的请求，此条件键不存在。要了解有关使用临时安全凭证为 API 操作添加 MFA 保护的更多信息，请参阅 [使用 MFA 保护 API 访问](id_credentials_mfa_configure-api-require.md)。  
要检查是否使用 MFA 来验证 IAM 联合身份，您可以将身份提供者的身份验证方法作为会话标签传递给 AWS。有关更多信息，请参阅 [在 AWS STS 中传递会话标签](id_session-tags.md)。要对 IAM Identity Center 身份强制执行 MFA，您可以[启用访问控制属性](https://docs.aws.amazon.com/singlesignon/latest/userguide/configure-abac.html)，以使用身份提供者的身份验证方法将 SAML 断言声明传递给 IAM Identity Center。
+ **可用性** – 仅在主体使用[临时安全凭证](id_credentials_temp.md)发出请求时，才将此键包含在请求上下文中。带 MFA 条件的策略可附加到：
  + 对于 IAM 用户或组：
  + Amazon S3 存储桶、Amazon SQS 队列或 Amazon SNS 主题等资源
  + 可由用户担任的 IAM 角色的信任策略
+ **数据类型** – [数字](reference_policies_elements_condition_operators.md#Conditions_Numeric)
+ **值类型** - 单值

### aws:MultiFactorAuthPresent
<a name="condition-keys-multifactorauthpresent"></a>

使用此键可检查是否已使用多重身份验证（MFA）来验证发出请求的[临时安全凭证](id_credentials_temp.md)。

**重要**  
对于联合身份或使用访问密钥签署 AWS CLI、AWS API 或 AWS SDK 请求而发出的请求，此条件键不存在。要了解有关使用临时安全凭证为 API 操作添加 MFA 保护的更多信息，请参阅 [使用 MFA 保护 API 访问](id_credentials_mfa_configure-api-require.md)。  
要检查是否使用 MFA 来验证 IAM 联合身份，您可以将身份提供者的身份验证方法作为会话标签传递给 AWS。有关更多信息，请参阅 [在 AWS STS 中传递会话标签](id_session-tags.md)。要对 IAM Identity Center 身份强制执行 MFA，您可以[启用访问控制属性](https://docs.aws.amazon.com/singlesignon/latest/userguide/configure-abac.html)，以使用身份提供者的身份验证方法将 SAML 断言声明传递给 IAM Identity Center。
+ **Availability**（可用性）- 仅在主体使用临时凭证发出请求时，才将此键包含在请求上下文中。带 MFA 条件的策略可附加到：
  + 对于 IAM 用户或组：
  + Amazon S3 存储桶、Amazon SQS 队列或 Amazon SNS 主题等资源
  + 可由用户担任的 IAM 角色的信任策略
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

临时凭证用于验证具有来自 [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) 或 [GetSessionToken](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetSessionToken.html) 的临时令牌的 IAM 角色和 IAM 用户，以及 AWS 管理控制台 用户。

IAM 用户访问密钥是长期凭证，但在某些情况下，AWS 会代表 IAM 用户创建临时凭证以执行操作。在这些情况下，`aws:MultiFactorAuthPresent` 密钥存在于请求中，并设置为值 `false`。有两种常见情况可能会发生这种情形：
+ AWS 管理控制台中的 IAM 用户在不知情的情况下使用了临时凭证。用户使用其作为长期凭证的用户名和密码登录控制台。但在后台，控制台代表用户生成临时凭证。
+ 如果 IAM 用户对某个 AWS 服务进行调用，则该服务将重新使用该用户的凭证向其他服务发出另一个请求。例如，当调用 Athena 以访问 Amazon S3 存储桶或使用 CloudFormation 创建 Amazon EC2 实例时。对于后续请求，AWS 使用临时凭证。

要了解哪些服务支持使用临时凭证，请参阅[使用 IAM 的 AWS 服务](reference_aws-services-that-work-with-iam.md)。

在使用长期凭证（例如，用户访问密钥对）调用 API 或 CLI 命令时，不提供 `aws:MultiFactorAuthPresent` 键。因此我们建议，当您检查此键时使用 `...IfExists` 版本的条件运算符。

必须理解，以下 `Condition` 元素***不是*** 检查请求是否使用 MFA 进行身份验证的可靠方式。

```
#####   WARNING: NOT RECOMMENDED   #####
"Effect" : "Deny",
"Condition" : { "Bool" : { "aws:MultiFactorAuthPresent" : "false" } }
```

`Deny` 效果、`Bool` 元素和 `false` 值的这一组合可拒绝可以使用但未使用 MFA 进行身份验证的请求。这仅适用于支持使用 MFA 的临时凭证。此语句不会拒绝对使用长期凭证发出的请求或使用 MFA 进行身份验证的请求的访问权限。使用此示例时务必要谨慎，因为其逻辑复杂，并且未对是否实际使用 MFA 身份验证进行测试。

此外，请勿使用 `Deny` 效果、`Null` 元素和 `true` 的组合，因为该组合行为方式相同，但逻辑更加复杂。

**建议的组合**  
我们建议您使用 [`BoolIfExists`](reference_policies_elements_condition_operators.md#Conditions_IfExists) 运算符检查是否使用 MFA 对请求进行身份验证。

```
"Effect" : "Deny",
"Condition" : { "BoolIfExists" : { "aws:MultiFactorAuthPresent" : "false" } }
```

`Deny`、`BoolIfExists` 和 `false` 的组合将拒绝未使用 MFA 进行身份验证的请求。具体来说，它拒绝来自不包含 MFA 的临时凭证的请求。它还拒绝使用长期凭证发出的请求，例如使用访问密钥执行的 AWS CLI 或 AWS API 操作。`*IfExists` 运算符用于检查 `aws:MultiFactorAuthPresent` 键是否存在以及它是否可以存在（由其存在性指示）。当您要拒绝未使用 MFA 进行身份验证的任何请求时，可使用此运算符。这是更安全的，但可能会中断使用访问密钥访问 AWS CLI 或 AWS API 的任何代码或脚本。

**替代组合**  
您还可以使用 [`BoolIfExists`](reference_policies_elements_condition_operators.md#Conditions_IfExists) 运算符以允许通过 MFA 进行身份验证的请求以及使用长期凭证发出的 AWS CLI 或 AWS API 请求。

```
"Effect" : "Allow",
"Condition" : { "BoolIfExists" : { "aws:MultiFactorAuthPresent" : "true" } }
```

此条件将匹配键存在**或**键不存在的情况。`Allow`、`BoolIfExists` 和 `true` 的组合允许已使用 MFA 进行身份验证的请求或无法使用 MFA 进行身份验证的请求。这意味着，在请求者使用其长期访问密钥时，允许执行 AWS CLI、AWS API 和 AWS 开发工具包操作。该组合不允许来自临时凭证的请求，这些凭证可能包含 MFA，但未包含 MFA。

在使用 IAM 控制台可视化编辑器创建策略并选择**需要 MFA** 时，将应用该组合。该设置要求使用 MFA 进行控制台访问，但允许在没有 MFA 的情况下进行编程访问。

或者，您也可以使用 `Bool` 运算符，以便仅在使用 MFA 进行身份验证时允许编程和控制台请求。

```
"Effect" : "Allow",
"Condition" : { "Bool" : { "aws:MultiFactorAuthPresent" : "true" } }
```

`Allow`、`Bool` 和 `true` 的组合仅允许已进行 MFA 身份验证的请求。这仅适用于支持使用 MFA 的临时凭证。该语句不允许访问使用长期访问密钥发出的请求，也不允许访问在没有 MFA 的情况下使用临时凭证发出的请求。

***请勿***使用策略进行类似以下的构建，以检查 MFA 密钥是否存在：

```
#####   WARNING: USE WITH CAUTION   #####

"Effect" : "Allow",
"Condition" : { "Null" : { "aws:MultiFactorAuthPresent" : "false" } }
```

`Allow` 效果、`Null` 元素和 `false` 值的组合仅允许可以使用 MFA 进行身份验证的请求，而不考虑该请求是否已实际进行身份验证。这组合允许使用临时凭证发出的所有请求，而对长期凭证拒绝访问权限。使用此示例时务必要谨慎，因为它未对是否实际使用 MFA 身份验证进行测试。

### aws:ChatbotSourceArn
<a name="condition-keys-chatbotsourcearn"></a>

使用此键，可将主体设置的来源聊天配置 ARN 跟您在与频道配置关联的 IAM 角色策略中指定的聊天配置 ARN 进行比较。您可以根据聊天应用程序中的 Amazon Q 开发者版发起的代入角色会话对请求进行授权。
+ **可用性** – 每次代入角色会话时，此键都将包含在聊天应用程序中的 Amazon Q 开发者版服务发起的请求上下文中。键值是聊天配置 ARN，例如[从聊天频道运行 AWS CLI 命令](https://docs.aws.amazon.com/chatbot/latest/adminguide/chatbot-cli-commands.html)时。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – `arn:aws::chatbot::123456789021:chat-configuration/slack-channel/private_channel`

以下策略拒绝 Amazon S3 将所有来自 Slack 频道的请求放入指定存储桶。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "ExampleS3Deny",
            "Effect": "Deny",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
            "Condition": {
                "ArnLike": {
                      "aws:ChatbotSourceArn": "arn:aws:chatbot::*:chat-configuration/slack-channel/*"
                }
            }
        }
    ]
}
```

------

### aws:Ec2InstanceSourceVpc
<a name="condition-keys-ec2instancesourcevpc"></a>

此键标识将 Amazon EC2 IAM 角色凭证传递到的 VPC。您可以在具有 [`aws:SourceVPC`](#condition-keys-sourcevpc) 全局键的策略中使用此键，检查从中发出调用的 VPC (`aws:SourceVPC`) 是否与将凭证传送到的 VPC (`aws:Ec2InstanceSourceVpc`) 相匹配。
+ **可用性** – 仅在请求者使用 Amazon EC2 角色凭证签署请求时，才将此键包含在请求上下文中。它可以用于 IAM policy、服务控制策略、VPC 端点策略和资源策略。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

此键可以与 VPC 标识符值一起使用，但在用作与 `aws:SourceVpc` 上下文键组合的变量时最有用。只有当请求者使用 VPC 端点发出请求时，才将 `aws:SourceVpc` 上下文键包含在请求上下文中。搭配使用 `aws:Ec2InstanceSourceVpc` 和 `aws:SourceVpc` 时，您能够更广泛地使用 `aws:Ec2InstanceSourceVpc`，因为它可以比较通常一起变化的值。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "RequireSameVPC",
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "StringNotEquals": {
            "aws:SourceVpc": "${aws:Ec2InstanceSourceVpc}"
        },
        "Null": {
          "ec2:SourceInstanceARN": "false"
        },
        "BoolIfExists": {
          "aws:ViaAWSService": "false"
        }
      }
    }
  ]
}
```

------

在上面的示例中，如果 `aws:SourceVpc` 值不等于 `aws:Ec2InstanceSourceVpc` 值，则访问将被拒绝。通过测试 `ec2:SourceInstanceARN` 条件键是否存在，该策略声明仅限于用作 Amazon EC2 实例角色的角色。

该策略使用 `aws:ViaAWSService`，在代表您的 Amazon EC2 实例角色发出请求时允许 AWS 对请求进行授权。例如，当您从 Amazon EC2 实例向加密的 Amazon S3 存储桶发出请求时，Amazon S3 会代表您调用 AWS KMS。向 AWS KMS 发出请求时，某些键不存在。

### aws:Ec2InstanceSourcePrivateIPv4
<a name="condition-keys-ec2instancesourceprivateip4"></a>

此键标识 Amazon EC2 IAM 角色凭证传送到的主弹性网络接口的私有 IPv4 地址。您必须将此条件键与其配套键 `aws:Ec2InstanceSourceVpc` 一起使用，以确保您拥有 VPC ID 和源私有 IP 的全局唯一组合。将此键与 `aws:Ec2InstanceSourceVpc` 搭配使用可确保请求是从凭证传送到的同一私有 IP 地址发出的。
+ **可用性** – 仅在请求者使用 Amazon EC2 角色凭证签署请求时，才将此键包含在请求上下文中。它可以用于 IAM policy、服务控制策略、VPC 端点策略和资源策略。
+ **数据类型** – [IP 地址](reference_policies_elements_condition_operators.md#Conditions_IPAddress)
+ **值类型** - 单值

**重要**  
此键不应在 `Allow` 语句中单独使用。顾名思义，私有 IP 地址不是全局唯一的。每次使用 `aws:Ec2InstanceSourcePrivateIPv4` 键来指定可以从哪个 VPC 使用 Amazon EC2 实例凭证时，都应使用 `aws:Ec2InstanceSourceVpc` 键。

以下示例是一个服务控制策略 (SCP)，除非请求通过与角色凭证位于同一 VPC 中的 VPC 端点到达，否则该策略将拒绝访问所有资源。在此示例中，`aws:Ec2InstanceSourcePrivateIPv4` 根据源 IP 将凭证源限制为特定实例。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action":  "*",
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:Ec2InstanceSourceVpc": "${aws:SourceVpc}"
                },                
                "Null": {
                    "ec2:SourceInstanceARN": "false"
                },
                "BoolIfExists": {
                    "aws:ViaAWSService": "false"
                }
            }
        },
        {
            "Effect": "Deny",
            "Action":  "*",
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:Ec2InstanceSourcePrivateIPv4": "${aws:VpcSourceIp}"
                },                               
                "Null": {
                    "ec2:SourceInstanceARN": "false"
                },
                "BoolIfExists": {
                    "aws:ViaAWSService": "false"
                }
            }
        }
    ]
}
```

------

### aws:SourceIdentity
<a name="condition-keys-sourceidentity"></a>

使用此密钥可将主体设置的源身份与您在策略中指定的源身份进行比较。
+ **可用性** — 在使用任何 AWS STS 担任角色 CLI 命令或 AWS STS `AssumeRole`API 操作担任角色时设置好源身份后，此密钥将会被包含在请求中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

您可以在策略中使用此密钥来允许 AWS 中的主体操作，这些主体在担任角色时设置了源身份。角色指定源身份的活动显示在 [AWS CloudTrail](cloudtrail-integration.md#cloudtrail-integration_signin-tempcreds)。这使管理员能够更轻松地确定什么角色在 AWS 中执行了操作。

与 [`sts:RoleSessionName`](reference_policies_iam-condition-keys.md#ck_rolesessionname) 不同，在设置源身份后，无法更改该值。它存在于角色执行的所有操作的请求上下文中。当您使用会话凭证担任另一个角色时，该值将保留到后续角色会话中。从一个角色代入另一个角色的过程称为[角色链](id_roles.md#iam-term-role-chaining)。

当主体使用任何 AWS STS 担任角色 CLI 命令或 AWS STS `AssumeRole` API 操作担任角色并初次设置源身份时，[`sts:SourceIdentity`](reference_policies_iam-condition-keys.md#ck_sourceidentity) 密钥将会出现在请求中。`aws:SourceIdentity`键存在于对具有源身份设置的角色会话执行的任何操作请求中。

以下账户 `111122223333` 中适用于 `CriticalRole` 的角色信任策略包含一个条件适用于 `aws:SourceIdentity` 的条件，可防止未将源身份设置为 Saanvi 或 Diego 主体担任该角色。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AssumeRoleIfSourceIdentity",
            "Effect": "Allow",
            "Principal": {"AWS": "arn:aws:iam::123456789012:role/CriticalRole"},
            "Action": [
                "sts:AssumeRole",
                "sts:SetSourceIdentity"
            ],
            "Condition": {
                "StringLike": {
                    "aws:SourceIdentity": ["Saanvi","Diego"]
                }
            }
        }
    ]
}
```

------

要了解有关使用源身份信息的更多信息，请参阅 [监控和控制使用所担任角色执行的操作](id_credentials_temp_control-access_monitor.md)。

### ec2:RoleDelivery
<a name="condition-keys-ec2-role-delivery"></a>

使用此键可将签名请求中的实例元数据服务版本与 Amazon EC2 的 IAM 角色凭证进行比较。实例元数据服务根据以下条件区分 IMDSv1 和 IMDSv2 请求：对于任何给定请求，`PUT` 或 `GET` 标头（对于 IMDSv2 是唯一的）在该请求中是否存在。
+ **可用性** – 仅在 Amazon EC2 实例创建角色会话时，才将此键包含在请求上下文中。
+ **数据类型** – [数字](reference_policies_elements_condition_operators.md#Conditions_Numeric)
+ **值类型** - 单值
+ **示例值** – 1.0, 2.0

您可以在每个实例上配置实例元数据服务（IMDS），以确保本地代码或用户必须使用 IMDSv2。在指定必须使用 IMDSv2 时，IMDSv1 不再起作用。
+ 实例元数据服务版本 1（IMDSv1）– 一种请求/响应方法 
+ 实例元数据服务版本 2 (IMDSv2)：一种面向会话的方法

有关如何配置实例以使用 IMDSv2 的信息，请参阅[配置实例元数据选项](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html)。

在以下示例中，如果请求上下文中的 ec2:RoleDelivery 值为 1.0（IMDSv1），则访问将被拒绝。此策略语句可广泛应用，因为如果请求未由 Amazon EC2 角色证书签名，则其为无效。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
               {
            "Sid": "RequireAllEc2RolesToUseV2",
            "Effect": "Deny",
            "Action": "*",
            "Resource": "*",
            "Condition": {
                "NumericLessThan": {
                    "ec2:RoleDelivery": "2.0"
                }
            }
        }
    ]
}
```

------

有关更多信息，请参阅[使用实例元数据的示例策略](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#iam-example-instance-metadata)。

### ec2:SourceInstanceArn
<a name="condition-keys-ec2-source-instance-arn"></a>

使用此键可以比较生成角色会话的实例的 ARN。
+ **可用性** – 仅在 Amazon EC2 实例创建角色会话时，才将此键包含在请求上下文中。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – arn:aws::ec2:us-west-2:111111111111:instance/instance-id

对于策略示例，请参阅[允许特定实例查看其他 AWS 服务中的资源](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#iam-example-source-instance)。

### glue:RoleAssumedBy
<a name="condition-keys-glue-role-assumed-by"></a>

AWS Glue 服务为每个 AWS API 请求设置此条件键，其中 AWS Glue 使用服务角色代表客户发出请求（不是通过作业或开发人员端点，而是直接通过 AWS Glue 服务发出请求）。使用此键验证对 AWS 资源的调用是否来自 AWS Glue 服务。
+ **可用性** – 当 AWS Glue 代表客户使用服务角色发出请求时，此键包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值
+ **示例值** – 此键始终设置为 `glue.amazonaws.com`。

以下示例添加了一个允许 AWS Glue 服务从 Amazon S3 存储桶获取对象的条件。

```
{
    "Effect": "Allow",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {
        "StringEquals": {
            "glue:RoleAssumedBy": "glue.amazonaws.com"
        }
    }
}
```

### glue:CredentialIssuingService
<a name="condition-keys-glue-credential-issuing"></a>

AWS Glue 服务使用来自作业或开发人员端点的服务角色为每个 AWS API 请求设置此键。使用此键验证对 AWS 资源的调用是来自 AWS Glue 作业还是开发人员端点。
+ **可用性** – 当 AWS Glue 发出来自作业或开发人员端点的请求时，此键包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值
+ **示例值** – 此键始终设置为 `glue.amazonaws.com`。

以下示例添加一个附加到 AWS Glue 作业使用的 IAM 角色的条件。这确保了可以基于角色会话是否用于 AWS Glue 任务运行时环境而允许/拒绝某些操作。

```
{
    "Effect": "Allow",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {
        "StringEquals": {
            "glue:CredentialIssuingService": "glue.amazonaws.com"
        }
    }
}
```

### codebuild:BuildArn
<a name="condition-keys-codebuild-build-arn"></a>

此键标识将 IAM 角色凭证传递到的 CodeBuild 构建 ARN。使用此键可验证对 AWS 资源的调用是否来自特定 CodeBuild 构建。

**注意**  
事先不知道 `codebuild:BuildArn` 的完整值，因为其中包含动态生成的构建 ID。
+ **可用性** – 仅在由 CodeBuild 代入的角色发出请求时，将此键包含在请求上下文中。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – arn:aws:codebuild:us-east-1:123456789012:build/MyBuildProject:12345678-1234-1234-1234-123456789012

以下示例允许特定 CodeBuild 构建让 `s3:GetObject` 访问指定的存储桶。

```
{
    "Effect": "Allow",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {
        "ArnLike": {
            "codebuild:BuildArn": "arn:aws:codebuild:us-east-1:123456789012:build/MyBuildProject:*"
        }
    }
}
```

### codebuild:ProjectArn
<a name="condition-keys-codebuild-project-arn"></a>

此键标识将 IAM 角色凭证传递到 CodeBuild 构建的 CodeBuild 项目 ARN。使用此键可验证对 AWS 资源的调用是否来自特定 CodeBuild 项目。
+ **可用性** – 仅在由 CodeBuild 代入的角色发出请求时，将此键包含在请求上下文中。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – arn:aws:codebuild:us-east-1:123456789012:project/MyBuildProject

以下示例允许来自特定 CodeBuild 项目的任何构建让 `s3:GetObject` 访问指定的存储桶。

```
{
    "Effect": "Allow",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
    "Condition": {
        "ArnEquals": {
            "codebuild:ProjectArn": "arn:aws:codebuild:us-east-1:123456789012:project/MyBuildProject"
        }
    }
}
```

### lambda:SourceFunctionArn
<a name="condition-keys-lambda-source-function-arn"></a>

使用此键标识将 IAM 角色凭证传递到的 Lambda 函数 ARN。Lambda 服务会为来自函数执行环境的每个 AWS API 请求设置此键。使用此键可验证对 AWS 资源的调用是否来自特定 Lambda 函数的代码。Lambda 还为来自执行环境外部的一些请求设置此键，例如将日志写入 CloudWatch 并将跟踪发送到 X-Ray。
+ **可用性** – 每次调用 Lambda 函数代码时，此键都将包含在请求上下文中。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – arn:aws:lambda:us-east-1:123456789012:function:TestFunction

以下示例允许一个特定的 Lambda 函数让 `s3:PutObject` 访问指定的存储桶。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "ExampleSourceFunctionArn",
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
            "Condition": {
                "ArnEquals": {
                    "lambda:SourceFunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:source_lambda"
                }
            }
        }
    ]
}
```

------

有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的[使用 Lambda 执行环境凭证](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html#permissions-executionrole-source-function-arn)。

### ssm:SourceInstanceArn
<a name="condition-keys-ssm-source-instance-arn"></a>

使用此键标识将 IAM 角色凭证传递到的 AWS Systems Manager 托管实例 ARN。请求来自使用与 Amazon EC2 实例配置文件关联的 IAM 角色的托管实例时，此条件键不存在。
+ **可用性** – 每次将角色凭证传递到 AWS Systems Manager 托管实例时，此键都将包含在请求上下文中。
+ **数据类型** – [ARN](reference_policies_elements_condition_operators.md#Conditions_ARN)
+ **值类型** - 单值
+ **示例值** – arn:aws::ec2:us-west-2:111111111111:instance/instance-id

### identitystore:UserId
<a name="condition-keys-identity-store-user-id"></a>

使用此键可将签名请求中的 IAM Identy Center 员工身份与策略中指定的身份进行比较。
+ **可用性** – 当请求的调用方是 IAM Identity Center 中的用户时，将包含此键。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值
+ **示例值** – 94482488-3041-7026-18f3-be45837cd0e4

您可以使用 AWS CLI、AWS API 或 AWS 软件开发工具包向 [GetUserId](https://docs.aws.amazon.com//singlesignon/latest/IdentityStoreAPIReference/API_GetUserId.html) API 发出请求，以在 IAM Identity Center 查找用户的用户 ID。

## 网络的属性
<a name="condition-keys-network-properties"></a>

使用以下条件键可将有关请求源自或传递网络的详细信息与您在策略中指定的网络属性进行比较。

### aws:SourceIp
<a name="condition-keys-sourceip"></a>

使用此键可将请求者的 IP 地址与您在策略中指定的 IP 地址进行比较。`aws:SourceIp` 条件键只能用于公有 IP 地址范围。
+ **可用性** – 此键将包含在请求上下文中，但请求者使用 VPC 端点发出请求时除外。
+ **数据类型** – [IP 地址](reference_policies_elements_condition_operators.md#Conditions_IPAddress)
+ **值类型**— 单值

可在策略中使用 `aws:SourceIp` 条件键以仅允许主体从指定的 IP 范围发出请求。

**注意**  
`aws:SourceIp` 同时支持 IPv4 和 IPv6 地址或 IP 地址范围。有关支持 IPv6 的 AWS 服务 列表，请参阅《Amazon VPC 用户指南》**中[支持 IPv6 的 AWS 服务](https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html)。

例如，您可以将以下基于身份的策略附加到 IAM 角色。如果用户从指定的 IPv4 地址范围进行调用，此策略允许用户将对象放入 `amzn-s3-demo-bucket3` Amazon S3 存储桶。此策略还允许使用 [转发访问会话](access_forward_access_sessions.md) 的 AWS 服务代表您执行此操作。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "PrincipalPutObjectIfIpAddress",
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket3/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": "203.0.113.0/24"
                }
            }
        }
    ]
}
```

------

如果需要限制同时支持 IPv4 和 IPv6 寻址的网络访问，可以在 IAM 策略条件中包含 IPv4 和 IPv6 地址或 IP 地址范围。如果用户从指定的 IPv4 或 IPv6 地址范围进行调用，以下基于身份的策略将允许用户将对象放入 `amzn-s3-demo-bucket3` Amazon S3 存储桶。在 IAM 策略中包含 IPv6 地址范围之前，请验证您正在使用的 AWS 服务 是否支持 IPv6。有关支持 IPv6 的 AWS 服务 列表，请参阅《Amazon VPC 用户指南》**中[支持 IPv6 的 AWS 服务](https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "PrincipalPutObjectIfIpAddress",
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket3/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": [
                        "203.0.113.0/24",
                        "2001:DB8:1234:5678::/64"
                    ]
                }
            }
        }
    ]
}
```

------

如果请求来自使用 Amazon VPC 端点的主机，则 `aws:SourceIp` 密钥不可用。您应改用特定于 VPC 的键，例如 [aws:VpcSourceIp](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-vpcsourceip)。有关使用 VPC 端点的更多信息，请参阅《AWS PrivateLink 指南》中的 [VPC 端点和 VPC 端点服务的身份和访问管理](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-iam.html)**。

**注意**  
当 AWS 服务 代表您调用其它 AWS 服务（服务到服务调用）时，会编辑某些特定于网络的授权上下文。如果您的策略将此条件键与 `Deny` 语句结合使用，则 AWS 服务 主体可能会无意中受到屏蔽。要让 AWS 服务 在保持安全要求的同时正常运行，请通过添加值为 `false` 的 `aws:PrincipalIsAWSService` 条件键将服务主体排除在 `Deny` 语句之外。

### aws:SourceVpc
<a name="condition-keys-sourcevpc"></a>

使用此键检查请求是否经过 VPC 端点附加到的 VPC。在策略中，您可以使用此键以仅允许访问特定的 VPC。有关更多信息，请参阅《Amazon Simple Storage Service 用户指南》中的 [限制对特定 VPC 的访问](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies-vpc-endpoint.html#example-bucket-policies-restrict-access-vpc)**。
+ **可用性** – 仅在请求者使用 VPC 端点发出请求时，才将此键包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

在策略中，可以使用此键来允许或限制对特定 VPC 的访问。

例如，可以将以下基于身份的策略附加到 IAM 角色，以拒绝 `PutObject` 访问 `amzn-s3-demo-bucket3` Amazon S3 存储桶，除非请求是从指定的 VPC ID 发出的，或由使用[转发访问会话（FAS）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_forward_access_sessions.html)代表角色发出请求的 AWS 服务 发出的。与 [aws:SourceIp](#condition-keys-sourceip) 不同的是，必须使用 [aws:ViaAWSService](#condition-keys-viaawsservice) 或 [aws:CalledVia](#condition-keys-calledvia) 来允许 FAS 请求，因为初始请求的源 VPC 不会被保留。

**注意**  
该策略不允许进行任何操作。可将此策略与允许特定操作的其他策略结合使用。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "PutObjectIfNotVPCID",
      "Effect": "Deny",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket3/*",
      "Condition": {
        "StringNotEqualsIfExists": {
          "aws:SourceVpc": "vpc-1234567890abcdef0"
        },
        "Bool": {
          "aws:ViaAWSService": "false"
        }
      }
    }
  ]
}
```

------

**注意**  
如果您的目标服务支持 `aws:SourceVpcArn`，AWS 建议使用 `aws:SourceVpcArn` 而不是 `aws:SourceVpc`。有关支持的服务列表，请参阅 [aws:SourceVpcArn](#condition-keys-sourcevpcarn)。

### aws:SourceVpcArn
<a name="condition-keys-sourcevpcarn"></a>

使用此键可验证通过 VPC 端点发出请求的 VPC 的 ARN。此键返回 VPC 端点所连接 VPC 的 ARN。
+ **可用性**：通过 VPC 端点发出请求时将此键包含在所支持服务的请求上下文中。通过公共服务端点发出的请求不包括此键。以下服务支持此键：
  + AWS App Runner（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html)）
  + AWS Application Discovery Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html)）
  + Amazon Athena（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)）
  + AWS Cloud Map（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html)）
  + Amazon CloudWatch Application Insights（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html)）
  + AWS CloudFormation（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html)）
  + Amazon Comprehend Medical（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html)）
  + AWS Compute Optimizer（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html)）
  + Amazon；Elastic Container Registry（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html)）
  + Amazon Elastic Container Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html)）
  + Amazon Kinesis Analytics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html)）
  + Amazon Route 53（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html)）
  + AWS DataSync（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html)）
  + Amazon Elastic Block Store（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html)）
  + Amazon EventBridge 调度器（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html)）
  + Amazon Data Firehose（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html)）
  + AWS HealthImaging（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html)）
  + AWS HealthLake（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html)）
  + AWS HealthOmics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html)）
  + AWS Identity and Access Management（`iam:PassRole` 操作除外）（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html)）
  + AWS IoT FleetWise（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html)）
  + AWS IoT Wireless（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html)）
  + AWS Key Management Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html)）
  + AWS Lambda（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html)）
  + AWS Payment Cryptography（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html)）
  + Amazon Polly（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html)）
  + AWS 私有证书颁发机构（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html)）
  + AWS 回收站（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html)）
  + Amazon Rekognition（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html)）
  + 服务配额（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html)）
  + Amazon Simple Storage Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html)）
  + AWS Storage Gateway（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html)）
  + AWS Systems Manager Incident Manager Contacts（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html)）
  + Amazon Textract（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html)）
  + Amazon Transcribe（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html)）
  + AWS Transfer Family（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html)）
+ **数据类型** – ARN

  AWS 建议在比较 ARN 时使用 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)而不是[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)。
+ **值类型** - 单值
+ **示例值** – `arn:aws:ec2:us-east-1:123456789012:vpc/vpc-0e9801d129EXAMPLE`

以下是拒绝从 VPC `vpc-1a2b3c4d` 以外的任意位置访问 `amzn-s3-demo-bucket` 及其对象的存储桶策略示例。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [
     {
       "Sid": "Access-to-specific-VPC-only",
       "Principal": "*",
       "Action": "s3:*",
       "Effect": "Deny",
       "Resource": ["arn:aws:s3:::amzn-s3-demo-bucket",
                    "arn:aws:s3:::amzn-s3-demo-bucket/*"],
       "Condition": {
         "ArnNotEquals": {
           "aws:SourceVpcArn": "arn:aws:ec2:us-east-1:*:vpc/vpc-1a2b3c4d"
         }
       }
     }
   ]
}
```

### aws:SourceVpce
<a name="condition-keys-sourcevpce"></a>

使用此键可将请求的 VPC 端点标识符与您在策略中指定的端点 ID 进行比较。
+ **可用性** – 仅在请求者使用 VPC 端点发出请求时，才将此键包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

在策略中，您可以使用此键来限制对特定 VPC 端点的访问。有关更多信息，请参阅《*Amazon Simple Storage Service 用户指南*》中的[限制对特定 VPC 的访问](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies-vpc-endpoint.html#example-bucket-policies-restrict-access-vpc)。与使用 [aws:SourceVpc](#condition-keys-sourcevpc) 类似，必须使用 [aws:ViaAWSService](#condition-keys-viaawsservice) 或 [aws:CalledVia](#condition-keys-calledvia) 来允许 AWS 服务 使用[转发访问会话（FAS）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_forward_access_sessions.html)发出的请求。这是因为初始请求的源 VPC 端点未被保留。

### aws:VpceAccount
<a name="condition-keys-vpceaccount"></a>

此键用于将发出请求经由的 VPC 端点所属的 AWS 账户 ID 与您在策略中指定的账户 ID 进行比较。此条件键可确保请求经由特定账户拥有的 VPC 端点，从而帮助建立网络边界控制。
+ **可用性** – 通过 VPC 端点发出请求时将此键包含在请求上下文中。通过公共服务端点发出的请求不包括此键。

  以下服务支持此键：
  + AWS App Runner（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html)）
  + AWS Application Discovery Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html)）
  + Amazon Athena（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)）
  + AWS Cloud Map（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html)）
  + Amazon CloudWatch Application Insights（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html)）
  + AWS CloudFormation（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html)）
  + Amazon Comprehend Medical（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html)）
  + AWS Compute Optimizer（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html)）
  + Amazon；Elastic Container Registry（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html)）
  + Amazon Elastic Container Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html)）
  + Amazon Kinesis Analytics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html)）
  + Amazon Route 53（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html)）
  + AWS DataSync（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html)）
  + Amazon Elastic Block Store（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html)）
  + Amazon EventBridge 调度器（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html)）
  + Amazon Data Firehose（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html)）
  + AWS HealthImaging（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html)）
  + AWS HealthLake（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html)）
  + AWS HealthOmics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html)）
  + AWS Identity and Access Management（`iam:PassRole` 操作除外）（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html)）
  + AWS IoT FleetWise（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html)）
  + AWS IoT Wireless（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html)）
  + AWS Key Management Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html)）
  + AWS Lambda（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html)）
  + AWS Payment Cryptography（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html)）
  + Amazon Polly（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html)）
  + AWS 私有证书颁发机构（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html)）
  + AWS 回收站（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html)）
  + Amazon Rekognition（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html)）
  + 服务配额（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html)）
  + Amazon Simple Storage Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html)）
  + AWS Storage Gateway（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html)）
  + AWS Systems Manager Incident Manager Contacts（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html)）
  + Amazon Textract（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html)）
  + Amazon Transcribe（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html)）
  + AWS Transfer Family（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html)）
+ **数据类型 **– [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值
+ **示例值** – `123456789012`

可以使用此条件键来限制对资源的访问，以使请求必须经由您的账户拥有的 VPC 端点。以下 Amazon S3 存储桶策略示例允许在请求经由指定账户拥有的 VPC 端点时进行访问：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AccessToSpecificVpceAccountOnly",
            "Principal": {
                "AWS": "arn:aws:iam::111122223333:role/RoleName"
            },
            "Action": "s3:GetObject",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket1/*",
            "Condition": {
                "StringEquals": {
                    "aws:VpceAccount": "111122223333"
                }
            }
        }
    ]
}
```

------

**注意**  
此条件键目前适用于一组选定的 AWS 服务。将条件键用于不支持的服务可能会导致意想不到的授权结果。务必将条件键的范围限定为策略中支持的服务。

某些 AWS 服务在代表您行事时从其网络访问您的资源。如果使用此等服务，需要对上述策略示例进行编辑，以允许 AWS 服务从网络外部访问您的资源。有关在基于请求来源强制实施访问控制时需要考虑的访问模式的更多信息，请参阅[使用数据边界建立权限防护机制](access_policies_data-perimeters.md)。

### aws:VpceOrgID
<a name="condition-keys-vpceorgid"></a>

此键用于将发出请求经由的 VPC 端点所属的 AWS Organizations 中组织的标识符与您在策略中指定的标识符进行比较。此条件键提供了最具扩展性的网络边界控制方法，自动包括组织内账户拥有的所有 VPC 端点。
+ **可用性** - 在通过 VPC 端点发出请求且 VPC 端点的所有者账户是 AWS 组织成员时，请求上下文中将包含此键。对于通过其他网络路径发出的请求，或者当 VPC 端点的所有者账户不属于某个组织时，则不包括此键。

  以下服务支持此键：
  + AWS App Runner（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html)）
  + AWS Application Discovery Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html)）
  + Amazon Athena（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)）
  + AWS B2B Data Interchange（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsb2bdatainterchange.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsb2bdatainterchange.html)）
  + AWS Cloud Map（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html)）
  + Amazon CloudWatch Application Insights（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html)）
  + AWS CloudFormation（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html)）
  + Amazon Cognito（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncognitoidentity.html)）
  + Amazon Comprehend Medical（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html)）
  + AWS Compute Optimizer（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html)）
  + AWS Database Migration Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatabasemigrationservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatabasemigrationservice.html)）
  + AWS 目录服务数据（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdirectoryservicedata.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdirectoryservicedata.html)）
  + Amazon；Elastic Container Registry（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html)）
  + Amazon Elastic Container Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html)）
  + Amazon Kinesis Analytics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html)）
  + Amazon Route 53（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html)）
  + AWS DataSync（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html)）
  + Amazon Elastic Block Store（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html)）
  + Amazon EventBridge 调度器（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html)）
  + Amazon Data Firehose（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html)）
  + AWS HealthImaging（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html)）
  + AWS HealthLake（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html)）
  + AWS HealthOmics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html)）
  + AWS Identity and Access Management（`iam:PassRole` 操作除外）（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html)）
  + AWS 身份存储（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentitystore.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentitystore.html)）
  + AWS IoT FleetWise（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html)）
  + AWS IoT TwinMaker（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiottwinmaker.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiottwinmaker.html)）
  + AWS IoT Wireless（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html)）
  + Amazon Keyspaces（Apache Cassandra 兼容）（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html)）
  + AWS Key Management Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html)）
  + AWS Lambda（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html)）
  + AWS Network Firewall（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsnetworkfirewall.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsnetworkfirewall.html)）
  + AWS Payment Cryptography（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html)）
  + Amazon Pinpoint SMS and Voice Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpinpointsmsandvoiceservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpinpointsmsandvoiceservice.html)）
  + Amazon Polly（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html)）
  + AWS 价目表（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspricelist.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspricelist.html)）
  + AWS 私有证书颁发机构（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html)）
  + AWS 回收站（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html)）
  + Amazon Rekognition（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html)）
  + 服务配额（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html)）
  + Amazon Simple Email Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonses.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonses.html)）
  + Amazon Simple Storage Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html)）
  + Amazon Simple Queue Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsqs.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsqs.html)）
  + AWS Storage Gateway（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html)）
  + AWS Systems Manager Incident Manager Contacts（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html)）
  + Amazon Textract（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html)）
  + Amazon Transcribe（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html)）
  + AWS Transfer Family（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html)）
  + Amazon WorkMail（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonworkmail.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonworkmail.html)）
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值
+ **示例值** – `o-a1b2c3d4e5`

以下资源控制策略示例拒绝访问 Amazon S3 和 AWS Key Management Service 资源，除非请求经由指定组织拥有的 VPC 端点或代表您行事的 AWS 服务网络。某些组织可能需要进一步编辑此政策以满足其组织的需求，例如，允许第三方合作伙伴进行访问。有关在基于请求来源强制实施访问控制时需要考虑的访问模式的更多信息，请参阅[使用数据边界建立权限防护机制](access_policies_data-perimeters.md)。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "EnforceNetworkPerimeterVpceOrgID",
      "Effect": "Deny",
      "Principal": "*",
      "Action": [
        "s3:*",
        "kms:*"
      ],
      "Resource": "*",
      "Condition": {
        "BoolIfExists": {
          "aws:PrincipalIsAWSService": "false",
          "aws:ViaAWSService": "false"
        },
        "StringNotEqualsIfExists": {
            "aws:VpceOrgID": "o-abcdef0123",
            "aws:PrincipalTag/network-perimeter-exception": "true"
        }
      }
    }
  ]
}
```

------

**注意**  
此条件键目前适用于一组选定的 AWS 服务。将条件键用于不支持的服务可能会导致意想不到的授权结果。务必将条件键的范围限定为策略中支持的服务。

### aws:VpceOrgPaths
<a name="condition-keys-vpceorgpaths"></a>

此键用于将发出请求经由的 VPC 端点的 AWS Organizations 路径与您在策略中指定的路径进行比较。此条件键支持在组织单元 (OU) 级别实施网络边界控制，当您在指定的 OU 中添加新的端点时，可根据 VPC 端点的使用情况自动扩展。
+ **可用性** - 在通过 VPC 端点发出请求且 VPC 端点的所有者账户是组织成员时，请求上下文中将包含此键。对于通过其他网络路径发出的请求，或者当 VPC 端点的所有者账户不属于某个组织时，则不包括此键。

  以下服务支持此键：
  + AWS App Runner（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapprunner.html)）
  + AWS Application Discovery Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsapplicationdiscoveryservice.html)）
  + Amazon Athena（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonathena.html)）
  + AWS Cloud Map（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudmap.html)）
  + Amazon CloudWatch Application Insights（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchapplicationinsights.html)）
  + AWS CloudFormation（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html)）
  + Amazon Comprehend Medical（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncomprehendmedical.html)）
  + AWS Compute Optimizer（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscomputeoptimizer.html)）
  + Amazon；Elastic Container Registry（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html)）
  + Amazon Elastic Container Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerservice.html)）
  + Amazon Kinesis Analytics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisanalytics.html)）
  + Amazon Route 53（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonroute53.html)）
  + AWS DataSync（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsdatasync.html)）
  + Amazon Elastic Block Store（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticblockstore.html)）
  + Amazon EventBridge 调度器（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoneventbridgescheduler.html)）
  + Amazon Data Firehose（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkinesisfirehose.html)）
  + AWS HealthImaging（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthimaging.html)）
  + AWS HealthLake（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthlake.html)）
  + AWS HealthOmics（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awshealthomics.html)）
  + AWS Identity and Access Management（`iam:PassRole` 操作除外）（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsidentityandaccessmanagementiam.html)）
  + AWS IoT FleetWise（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotfleetwise.html)）
  + AWS IoT Wireless（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiotwireless.html)）
  + AWS Key Management Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awskeymanagementservice.html)）
  + AWS Lambda（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awslambda.html)）
  + AWS Payment Cryptography（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awspaymentcryptography.html)）
  + Amazon Polly（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonpolly.html)）
  + AWS 私有证书颁发机构（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsprivatecertificateauthority.html)）
  + AWS 回收站（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsrecyclebin.html)）
  + Amazon Rekognition（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrekognition.html)）
  + 服务配额（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_servicequotas.html)）
  + Amazon Simple Storage Service（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html)）
  + AWS Storage Gateway（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstoragegateway.html)）
  + AWS Systems Manager Incident Manager Contacts（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssystemsmanagerincidentmanagercontacts.html)）
  + Amazon Textract（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontextract.html)）
  + Amazon Transcribe（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazontranscribe.html)）
  + AWS Transfer Family（前缀：[https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awstransferfamily.html)）
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值
+ **示例值** – `o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/`

由于 `aws:VpceOrgPaths` 是一个多值条件键，您必须将 `ForAnyValue` 或者 `ForAllValues` 集合运算符与此键的[字符串条件运算符](reference_policies_elements_condition_operators.md#Conditions_String)搭配使用。以下 Amazon S3 存储桶策略示例仅允许在请求经由特定组织单元中的账户拥有的 VPC 端点时进行访问：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowAccessFromSpecificOrgPaths",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:role/RoleName"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket1/*",
      "Condition": {
        "ForAnyValue:StringLike": {
          "aws:VpceOrgPaths": [
            "o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/*",
            "o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-33333333/*"
          ]
        }
      }
    }
  ]
}
```

------

**注意**  
此条件键目前适用于一组选定的 AWS 服务。将条件键用于不支持的服务可能会导致意想不到的授权结果。务必将条件键的范围限定为策略中支持的服务。

某些 AWS 服务在代表您行事时从其网络访问您的资源。如果使用此等服务，需要对上述策略示例进行编辑，以允许 AWS 服务从网络外部访问您的资源。有关在基于请求来源强制实施访问控制时需要考虑的访问模式的更多信息，请参阅[使用数据边界建立权限防护机制](access_policies_data-perimeters.md)。

### aws:VpcSourceIp
<a name="condition-keys-vpcsourceip"></a>

使用此键可将从中发出请求的 IP 地址与您在策略中指定的 IP 地址进行比较。在策略中，键仅在请求来自指定的 IP 地址并经过 VPC 端点时进行匹配。
+ **可用性** – 仅在使用 VPC 端点发出请求时，才将此键包含在请求上下文中。
+ **数据类型** – [IP 地址](reference_policies_elements_condition_operators.md#Conditions_IPAddress)
+ **值类型** - 单值

有关更多信息，请参阅《*Amazon VPC 用户指南*》中的[使用端点策略控制对 VPC 端点的访问](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints-access.html)。与使用 [aws:SourceVpc](#condition-keys-sourcevpc) 类似，必须使用 [aws:ViaAWSService](#condition-keys-viaawsservice) 或 [aws:CalledVia](#condition-keys-calledvia) 来允许 AWS 服务 使用[转发访问会话（FAS）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_forward_access_sessions.html)发出的请求。这是因为使用 VPC 端点发出的初始请求的源 IP 不会保留在 FAS 请求中。

**注意**  
`aws:VpcSourceIp` 同时支持 IPv4 和 IPv6 地址或 IP 地址范围。有关支持 IPv6 的 AWS 服务 列表，请参阅《Amazon VPC 用户指南》**中[支持 IPv6 的 AWS 服务](https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html)。  
`aws:VpcSourceIp` 条件键应始终与 `aws:SourceVpc` 或 `aws:SourceVpce` 条件键结合使用。否则，策略可能会允许来自使用相同或重叠的 IP CIDR 的意外 VPC 的 API 调用。之所以发生这种情况，是因为来自两个不相关的 VPC 的 IP CIDR 可能相同或重叠。相反，应在策略中使用 VPC ID 或 VPC 端点 ID，因为它们具有全局唯一的标识符。这些唯一标识符可确保不会出现意外结果。

**注意**  
当 AWS 服务 代表您调用其它 AWS 服务（服务到服务调用）时，会编辑某些特定于网络的授权上下文。如果您的策略将此条件键与 `Deny` 语句结合使用，则 AWS 服务 主体可能会无意中受到屏蔽。要让 AWS 服务 在保持安全要求的同时正常运行，请通过添加值为 `false` 的 `aws:PrincipalIsAWSService` 条件键将服务主体排除在 `Deny` 语句之外。

## 资源的属性
<a name="condition-keys-resource-properties"></a>

使用以下条件键可将有关请求目标资源的详细信息与您在策略中指定的资源属性进行比较。

### aws:ResourceAccount
<a name="condition-keys-resourceaccount"></a>

使用此键，将策略中所请求的资源所有者的 [AWS 账户 ID](https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html) 与资源账户进行比较。然后，您可以根据拥有该资源的账户来允许或拒绝对该资源的访问。
+ **Availability**（可用性）– 对于大多数服务操作，此键始终包含在请求上下文中。以下操作不支持此键：
  + AWS Audit Manager
    + `auditmanager:UpdateAssessmentFrameworkShare`
  + Amazon Detective
    + `detective:AcceptInvitation`
  + AWS Directory Service
    + `ds:AcceptSharedDirectory`
  + Amazon Elastic Block Store – 所有操作
  + Amazon EC2
    + `ec2:AcceptTransitGatewayPeeringAttachment`
    + `ec2:AcceptVpcEndpointConnections`
    + `ec2:AcceptVpcPeeringConnection`
    + `ec2:CreateTransitGatewayPeeringAttachment`
    + `ec2:CreateVpcEndpoint`
    + `ec2:CreateVpcPeeringConnection`
  + Amazon EventBridge
    + `events:PutEvents` – EventBridge `PutEvents` 将调用其他账户中的事件总线，前提是该事件总线已在 2023 年 3 月 2 日之前被配置为跨账户 EventBridge 目标。有关更多信息，请参阅《Amazon EventBridge 用户指南》中的 [授予权限以允许来自其他 AWS 账户的事件](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cross-account.html#eb-receiving-events-from-another-account)**。
  + Amazon GuardDuty
    + `guardduty:AcceptAdministratorInvitation`
  + Amazon Macie
    + `macie2:AcceptInvitation`
  + Amazon OpenSearch Service
    + `es:AcceptInboundConnection`
  + Amazon Route 53
    + `route53:AssociateVpcWithHostedZone`
    + `route53:CreateVPCAssociationAuthorization`
  + AWS Security Hub CSPM
    + `securityhub:AcceptAdministratorInvitation`
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

**注意**  
有关上述不支持的操作的其他注意事项，请参阅 [Data Perimeter Policy Examples](https://github.com/aws-samples/data-perimeter-policy-examples) 存储库。

此键等于包含请求中受评估资源的账户的 AWS 账户 ID。

对于您的账户中的大多数资源，[ARN](reference_policies_elements_condition_operators.md#Conditions_ARN) 包含该资源的所有者账户 ID。对于某些资源（如 Amazon S3 存储桶），资源 ARN 不包含该账户 ID。以下两个示例显示了在 ARN 中具有账户 ID 的资源与没有账户 ID 的 Amazon S3 ARN 之间的区别：
+ `arn:aws:iam::123456789012:role/AWSExampleRole` – 在账户 123456789012 中创建和拥有的 IAM 角色。
+ `arn:aws:s3:::amzn-s3-demo-bucket2` – 在账户 `111122223333` 中创建且拥有的 Amazon S3 存储桶，在 ARN 中不显示。

使用 AWS 控制台、API 或 CLI 查找您的所有资源和相应的 ARN。

您编写的策略根据资源所有者的账户 ID 拒绝对资源的权限。例如，如果*指定资源*不属于*指定账户*，以下基于身份的策略会拒绝访问该资源。

要使用此策略，请将示例策略中的*斜体占位符文本*替换为您的账户信息。

**重要**  
该策略不允许进行任何操作。相反，该策略会使用 `Deny` 效果，这会显式拒绝访问语句中列出而不属于已列出账户的所有资源。将此策略与允许访问特定资源的其他策略结合使用。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyInteractionWithResourcesNotInSpecificAccount",
      "Action": "service:*",
      "Effect": "Deny",
      "Resource": [
        "arn:aws:service:us-east-1:111122223333:*"
      ],
      "Condition": {
        "StringNotEquals": {
          "aws:ResourceAccount": [
            "111122223333"
          ]
        }
      }
    }
  ]
}
```

------

此策略会拒绝对特定 AWS 服务所有资源的访问，除非指定 AWS 账户 拥有该资源。

**注意**  
某些 AWS 服务 需要访问托管在其他 AWS 中的 AWS 账户 所拥有的资源。在基于身份的策略中使用 `aws:ResourceAccount` 可能会影响您的身份访问这些资源的能力。

某些 AWS 服务，例如 AWS Data Exchange，依赖于对您的 AWS 账户 以外的资源的访问来进行正常操作。如果您在策略中使用元素 `aws:ResourceAccount`，请在策略中包含额外声明来为这些服务创建豁免。示例策略 [AWS：拒绝访问您账户之外的 Amazon S3 资源，AWS Data Exchange 除外。](reference_policies_examples_resource_account_data_exch.md) 演示了如何根据资源账户拒绝访问，同时定义对于服务拥有的资源的例外情况。

将此策略示例用作创建自己的自定义策略的模板。参阅服务[文档](https://docs.aws.amazon.com/index.html)以了解更多信息。

### aws:ResourceOrgPaths
<a name="condition-keys-resourceorgpaths"></a>

使用此键来比较所访问资源的 AWS Organizations 路径与策略中的路径。在策略中，此条件键可确保该资源属于 AWS Organizations 中指定组织根或组织单位（OU）的账户成员。AWS Organizations 路径是 Organizations 实体结构的文本表示形式。有关使用和了解路径的更多信息，请参阅 [了解 AWS Organizations 实体路径](access_policies_last-accessed-view-data-orgs.md#access_policies_last-accessed-viewing-orgs-entity-path) 
+ **Availability**（可用性）- 仅在拥有资源的账户是企业成员时，才将此键包含在请求上下文中。此全局条件键不支持以下操作：
  + AWS Audit Manager
    + `auditmanager:UpdateAssessmentFrameworkShare`
  + Amazon Detective
    + `detective:AcceptInvitation`
  + AWS Directory Service
    + `ds:AcceptSharedDirectory`
  + Amazon Elastic Block Store – 所有操作
  + Amazon EC2
    + `ec2:AcceptTransitGatewayPeeringAttachment`
    + `ec2:AcceptVpcEndpointConnections`
    + `ec2:AcceptVpcPeeringConnection`
    + `ec2:CreateTransitGatewayPeeringAttachment`
    + `ec2:CreateVpcEndpoint`
    + `ec2:CreateVpcPeeringConnection`
  + Amazon EventBridge
    + `events:PutEvents` – EventBridge `PutEvents` 将调用其他账户中的事件总线，前提是该事件总线已在 2023 年 3 月 2 日之前被配置为跨账户 EventBridge 目标。有关更多信息，请参阅《Amazon EventBridge 用户指南》中的 [授予权限以允许来自其他 AWS 账户的事件](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cross-account.html#eb-receiving-events-from-another-account)**。
  + Amazon GuardDuty
    + `guardduty:AcceptAdministratorInvitation`
  + Amazon Macie
    + `macie2:AcceptInvitation`
  + Amazon OpenSearch Service
    + `es:AcceptInboundConnection`
  + Amazon Route 53
    + `route53:AssociateVpcWithHostedZone`
    + `route53:CreateVPCAssociationAuthorization`
  + AWS Security Hub CSPM
    + `securityhub:AcceptAdministratorInvitation`
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

**注意**  
有关上述不支持的操作的其他注意事项，请参阅 [Data Perimeter Policy Examples](https://github.com/aws-samples/data-perimeter-policy-examples) 存储库。

`aws:ResourceOrgPaths` 是一个多值条件键。多值键在请求上下文中可以有多个值。对于此键，您必须将 `ForAnyValue` 或者 `ForAllValues` 集合运算符与[字符串条件运算符](reference_policies_elements_condition_operators.md#Conditions_String)搭配使用。有关多值条件键的更多信息，请参阅[多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。

例如，对于属于组织 `o-a1b2c3d4e5` 的资源，以下条件会返回为 `True`。包含通配符时，您必须使用 [StringLike](reference_policies_elements_condition_operators.md) 条件运算符。

```
"Condition": { 
      "ForAnyValue:StringLike": {
             "aws:ResourceOrgPaths":["o-a1b2c3d4e5/*"]
   }
}
```

对于具有 OU ID `ou-ab12-11111111` 的资源，以下条件返回 `True`。它将匹配附加到 OU ou-ab12-11111111 或任何子 OU 的账户所拥有的资源。

```
"Condition": { "ForAnyValue:StringLike" : {
     "aws:ResourceOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/*"]
}}
```

对于直接附加到 OU ID `ou-ab12-22222222`（而非子 OU）的账户所拥有的资源，以下条件返回 `True`。下列示例使用 [StringEquals](reference_policies_elements_condition_operators.md) 条件运算符来指定 OU ID 的完全匹配（而非通配符匹配）要求。

```
"Condition": { "ForAnyValue:StringEquals" : {
     "aws:ResourceOrgPaths":["o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/"]
}}
```

**注意**  
某些 AWS 服务 需要访问托管在其他 AWS 中的 AWS 账户 所拥有的资源。在基于身份的策略中使用 `aws:ResourceOrgPaths` 可能会影响您的身份访问这些资源的能力。

某些 AWS 服务，例如 AWS Data Exchange，依赖于对您的 AWS 账户 以外的资源的访问来进行正常操作。如果您在策略中使用 `aws:ResourceOrgPaths` 键，请在策略中包含额外声明来为这些服务创建豁免。示例策略 [AWS：拒绝访问您账户之外的 Amazon S3 资源，AWS Data Exchange 除外。](reference_policies_examples_resource_account_data_exch.md) 演示了如何根据资源账户拒绝访问，同时定义对于服务拥有的资源的例外情况。您可以使用 `aws:ResourceOrgPaths` 键来创建类似的策略，限制对组织单元（OU）内部资源的访问，同时包括服务拥有的资源。

将此策略示例用作创建自己的自定义策略的模板。参阅服务[文档](https://docs.aws.amazon.com/index.html)以了解更多信息。

### aws:ResourceOrgID
<a name="condition-keys-resourceorgid"></a>

使用此键可将被请求资源所属的 AWS Organizations 中组织的标识符与策略中指定的标识符进行比较。
+ **Availability**（可用性）- 仅在拥有资源的账户是企业成员时，才将此键包含在请求上下文中。此全局条件键不支持以下操作：
  + AWS Audit Manager
    + `auditmanager:UpdateAssessmentFrameworkShare`
  + Amazon Detective
    + `detective:AcceptInvitation`
  + AWS Directory Service
    + `ds:AcceptSharedDirectory`
  + Amazon Elastic Block Store – 所有操作
  + Amazon EC2
    + `ec2:AcceptTransitGatewayPeeringAttachment`
    + `ec2:AcceptVpcEndpointConnections`
    + `ec2:AcceptVpcPeeringConnection`
    + `ec2:CreateTransitGatewayPeeringAttachment`
    + `ec2:CreateVpcEndpoint`
    + `ec2:CreateVpcPeeringConnection`
  + Amazon EventBridge
    + `events:PutEvents` – EventBridge `PutEvents` 将调用其他账户中的事件总线，前提是该事件总线已在 2023 年 3 月 2 日之前被配置为跨账户 EventBridge 目标。有关更多信息，请参阅《Amazon EventBridge 用户指南》中的 [授予权限以允许来自其他 AWS 账户的事件](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cross-account.html#eb-receiving-events-from-another-account)**。
  + Amazon GuardDuty
    + `guardduty:AcceptAdministratorInvitation`
  + Amazon Macie
    + `macie2:AcceptInvitation`
  + Amazon OpenSearch Service
    + `es:AcceptInboundConnection`
  + Amazon Route 53
    + `route53:AssociateVpcWithHostedZone`
    + `route53:CreateVPCAssociationAuthorization`
  + AWS Security Hub CSPM
    + `securityhub:AcceptAdministratorInvitation`
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

**注意**  
有关上述不支持的操作的其他注意事项，请参阅 [Data Perimeter Policy Examples](https://github.com/aws-samples/data-perimeter-policy-examples) 存储库。

此全局键会返回给定请求的资源组织 ID。它允许您创建适用于组织中所有资源的规则，这些资源在[基于身份的策略](access_policies_identity-vs-resource.md)的 `Resource` 元素中指定。您可以在条件元素中指定[组织 ID](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_details.html)。当您添加和删除账户时，包含 `aws:ResourceOrgID` 键的策略将自动包括正确的账户，并且不必手动更新。

例如，以下策略会阻止主体将对象添加到 `policy-genius-dev` 资源，除非 Amazon S3 资源与发出请求的主体属于同一组织。

**重要**  
该策略不允许进行任何操作。相反，该策略会使用 `Deny` 效果，这会显式拒绝访问语句中列出而不属于已列出账户的所有资源。将此策略与允许访问特定资源的其他策略结合使用。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Sid": "DenyPutObjectToS3ResourcesOutsideMyOrganization",
        "Effect": "Deny",
        "Action": "s3:PutObject",
        "Resource": "arn:aws:s3:::policy-genius-dev/*",
        "Condition": {
            "StringNotEquals": {
                "aws:ResourceOrgID": "${aws:PrincipalOrgID}"
            }
        }
    }
}
```

------

**注意**  
某些 AWS 服务 需要访问托管在其他 AWS 中的 AWS 账户 所拥有的资源。在基于身份的策略中使用 `aws:ResourceOrgID` 可能会影响您的身份访问这些资源的能力。

某些 AWS 服务，例如 AWS Data Exchange，依赖于对您的 AWS 账户 以外的资源的访问来进行正常操作。如果您在策略中使用 `aws:ResourceOrgID` 键，请在策略中包含额外声明来为这些服务创建豁免。示例策略 [AWS：拒绝访问您账户之外的 Amazon S3 资源，AWS Data Exchange 除外。](reference_policies_examples_resource_account_data_exch.md) 演示了如何根据资源账户拒绝访问，同时定义对于服务拥有的资源的例外情况。您可以使用 `aws:ResourceOrgID` 键来创建类似的策略，限制对企业内部资源的访问，同时包括服务拥有的资源。

将此策略示例用作创建自己的自定义策略的模板。参阅服务[文档](https://docs.aws.amazon.com/index.html)以了解更多信息。

在以下视频中，了解有关如何在策略中使用 `aws:ResourceOrgID` 条件键的更多信息。

[![AWS Videos](http://img.youtube.com/vi/https://www.youtube.com/embed/cWVW0xAiWwc/0.jpg)](http://www.youtube.com/watch?v=https://www.youtube.com/embed/cWVW0xAiWwc)


### aws:ResourceTag/*tag-key*
<a name="condition-keys-resourcetag"></a>

使用此键可将您在策略中指定的标签键/值对与附加到资源的键/值对进行比较。例如，您可能会要求只有在资源具有附加的标签键 `"Dept"` 和值 `"Marketing"` 时才允许访问该资源。有关更多信息，请参阅 [控制对 AWS 资源的访问](access_tags.md#access_tags_control-resources)。
+ **Availability**（可用性）– 当请求的资源已附加标签，或者是在利用附加包创建资源的请求中，键会包含在请求上下文中。只有[支持基于标签的授权](reference_aws-services-that-work-with-iam.md)的资源返回此键。每个标签键/值对均有一个上下文密钥。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

该上下文密钥的格式为 `"aws:ResourceTag/tag-key":"tag-value"`，其中 *tag-key* 和 *tag-value* 是标签键值对。标签键不区分大小写。这意味着，如果您在策略的条件元素中指定 `"aws:ResourceTag/TagKey1": "Value1"`，则条件将匹配名为 `TagKey1` 或 `tagkey1` 的资源标签键，但不会同时匹配两者。这些标签键/值对中的值应区分大小写。这意味着，如果您在策略的条件元素中指定 `"aws:ResourceTag/TagKey1": "Production"`，则条件将匹配名为 `Production` 的资源标签值，但不会同时匹配 `production` 或 `PRODUCTION`。

有关使用 `aws:ResourceTag` 键控制对 IAM 资源的访问的示例，请参阅 [控制对 AWS 资源的访问](access_tags.md#access_tags_control-resources)。

有关使用 `aws:ResourceTag` 键控制对其他 AWS 资源的访问的示例，请参阅 [使用标签控制对 AWS 资源的访问](access_tags.md)。

有关使用 `aws:ResourceTag` 条件键进行基于属性的访问控制 (ABAC) 的教程，请参阅 [IAM 教程：根据标签定义访问 AWS 资源的权限](tutorial_attribute-based-access-control.md)。

## 请求的属性
<a name="condition-keys-request-properties"></a>

使用以下条件键可将有关请求本身以及请求内容的详细信息与您在策略中指定的请求属性进行比较。

### aws:CalledVia
<a name="condition-keys-calledvia"></a>

使用此键可以将策略中的服务与代表 IAM 主体（用户或角色）发出请求的服务进行比较。当主体向 AWS 服务发出请求时，该服务可能会使用主体的凭证向其他服务发出后续请求。当使用前向访问会话 (FAS) 发出请求时，此键将设置为服务主体的值。`aws:CalledVia` 键包含链中代表主体发出请求的每个服务的有序列表。

有关更多信息，请参阅 [转发访问会话](access_forward_access_sessions.md)。
+ **可用性** - 当支持 `aws:CalledVia` 的服务使用 IAM 主体的凭证向其他服务发出请求时，此键会出现在请求中。如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用，则此键不存在。当主体直接进行调用时，此键也不存在。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

要在策略中使用 `aws:CalledVia` 条件键，您必须提供服务主体以允许或拒绝 AWS 服务请求。例如，您可以使用 AWS CloudFormation 从 Amazon DynamoDB 表中读取和写入。然后，DynamoDB 使用 AWS Key Management Service (AWS KMS) 提供的加密操作。

要在*任何* 服务使用主体的凭证发出请求时允许或拒绝访问，请使用 `aws:ViaAWSService` 条件键。该条件键支持 AWS 服务。

`aws:CalledVia` 键是[多值键](reference_policies_condition-single-vs-multi-valued-context-keys.md)。但是，您不能在条件下强制使用此键进行排序。使用上面的示例，**User 1**（用户 1）向 CloudFormation 发出请求，然后依次调用 DynamoDB 和调用 AWS KMS。这是三个单独的请求。对 AWS KMS 的最终调用是由用户 1 *通过* CloudFormation，然后通过 DynamoDB 进行的。

![\[使用 aws:CalledVia 的示例\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/condition-key-calledvia-example-diagram.png)


在这种情况下，请求上下文中的 `aws:CalledVia` 键包括 `cloudformation.amazonaws.com` 和 `dynamodb.amazonaws.com`（按照该顺序）。如果您只关心调用是在请求链中的某个地方通过 DynamoDB 进行的，则可以在策略中使用此条件键。

例如，以下策略允许管理名为 `my-example-key` 的 AWS KMS 键，但前提为 DynamoDB 是发出请求的服务之一。`ForAnyValue:StringEquals` 条件运算符确保 DynamoDB 是发出调用的服务之一。如果主体直接调用 AWS KMS，则条件将返回 `false`，且此策略不允许请求。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "KmsActionsIfCalledViaDynamodb",
            "Effect": "Allow",
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey",
                "kms:DescribeKey"
            ],
            "Resource": "arn:aws:kms:us-east-1:111122223333:key/my-example-key",
            "Condition": {
                "ForAnyValue:StringEquals": {
                    "aws:CalledVia": [
                        "dynamodb.amazonaws.com"
                    ]
                }
            }
        }
    ]
}
```

------

如果要强制由哪个服务在链中进行第一个或最后一个调用，可以使用 `aws:CalledViaFirst` 和 `aws:CalledViaLast` 键。例如，以下策略允许管理 AWS KMS 中名为 `my-example-key` 的键。仅当链中包含多个请求时，才允许执行这些 AWS KMS 操作。第一个请求必须通过 CloudFormation 发出，而最后一个请求必须通过 DynamoDB 发出。如果其他服务在链的中间发出请求，则仍然允许该操作。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "KmsActionsIfCalledViaChain",
            "Effect": "Allow",
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey",
                "kms:DescribeKey"
            ],
            "Resource": "arn:aws:kms:us-east-1:111122223333:key/my-example-key",
            "Condition": {
                "StringEquals": {
                    "aws:CalledViaFirst": "cloudformation.amazonaws.com",
                    "aws:CalledViaLast": "dynamodb.amazonaws.com"
                }
            }
        }
    ]
}
```

------

当服务使用 IAM 主体的凭证调用另一个服务时，请求中会存在 `aws:CalledViaFirst` 和 `aws:CalledViaLast` 键。它们表示在请求链中进行调用的第一个和最后一个服务。例如，假定 CloudFormation 调用另一个名为 `X Service` 的服务，然后依次调用 DynamoDB，然后调用 AWS KMS。对 AWS KMS 的最终调用是由 `User 1` 依次*通过* CloudFormation、`X Service` 和 DynamoDB 进行的。首先通过 DynamoDB 进行调用，最后通过 CloudFormation 进行调用。

![\[使用 aws:CalledViaFirst 和 aws:CalledViaLast 的示例\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/condition-key-calledviafirstlast-example-diagram.png)


### aws:CalledViaFirst
<a name="condition-keys-calledviafirst"></a>

使用此键可以将策略中的服务与代表 IAM 主体（用户或角色）发出请求的***第一个服务*** 进行比较。有关更多信息，请参阅 `aws:CalledVia`。
+ **Availability**（可用性）- 当服务使用 IAM 主体的凭证向其他服务发出至少一个其他请求时，此键会出现在请求中。如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用，则此键不存在。当主体直接进行调用时，此键也不存在。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

### aws:CalledViaLast
<a name="condition-keys-calledvialast"></a>

使用此键可以将策略中的服务与代表 IAM 主体（用户或角色）发出请求的*最后一个服务*进行比较。有关更多信息，请参阅 `aws:CalledVia`。
+ **Availability**（可用性）- 当服务使用 IAM 主体的凭证向其他服务发出至少一个其他请求时，此键会出现在请求中。如果服务使用[服务角色或服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)代表主体进行调用，则此键不存在。当主体直接进行调用时，此键也不存在。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

### aws:ViaAWSService
<a name="condition-keys-viaawsservice"></a>

使用此键检查 AWS 服务 是否使用[转发访问会话（FAS）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_forward_access_sessions.html)代表你向另一项服务发出请求。

当服务使用转发访问会话代表原始 IAM 主体发出请求时，请求上下文键会返回 `true`。当主体直接进行调用时，请求上下文密钥也会返回 `false`。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

### aws:CalledViaAWSMCP
<a name="condition-keys-calledviaawasmcp"></a>

使用此键可以将策略中的服务与代表 IAM 主体（用户或角色）发出请求的 AWS MCP 服务进行比较。当主体向 AWS MCP 服务发出请求时，该服务可能会使用主体的凭证向其他服务发出后续请求。当使用 AWS MCP 服务发出请求时，此键将设置为服务主体的值。`aws:CalledViaAWSMCP` 键包含代表主体发出请求的 MCP 服务的服务主体名称。
+ **可用性** - 当 AWS MCP 服务使用 IAM 主体的凭证向 AWS 服务发出请求时，此键会出现在请求中。当主体直接进行调用时，此键也不存在。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

您可以根据由哪个特定 MCP 服务器发出请求，使用此条件键允许或拒绝访问。例如，当敏感的删除操作通过特定 MCP 服务器发出时，以下策略会拒绝这些操作：

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "DenySensitiveActionsViaSpecificMCP",
            "Effect": "Deny",
            "Action": [
                "s3:DeleteBucket",
                "s3:DeleteObject",
                "dynamodb:DeleteTable"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:CalledViaAWSMCP": "aws-mcp.amazonaws.com"
                }
            }
        }
    ]
}
```

### aws:ViaAWSMCPService
<a name="condition-keys-viaawsmcpservice"></a>

使用此键检查 AWS MCP 服务是否使用转发访问会话（FAS）代表你向另一项 AWS 服务发出请求。当 AWS MCP 服务代表原始 IAM 主体将请求转发到 AWS 请求时，请求上下文键会返回 `true`。当主体直接进行调用时，请求上下文密钥也会返回 `false`。
+ **可用性** – 当 AWS MCP 服务器代表 IAM 主体向下游 AWS 服务发出请求时，此键包含在请求上下文中。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

当特定操作通过 MCP 服务器时，您可以使用此键来限制这些操作。例如，以下策略拒绝通过任何 AWS MCP 服务器发出的敏感删除操作：

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "DenySensitiveActionsViaMCP",
            "Effect": "Deny",
            "Action": [
                "s3:DeleteBucket",
                "s3:DeleteObject",
                "dynamodb:DeleteTable"
            ],
            "Resource": "*",
            "Condition": {
                "Bool": {
                    "aws:ViaAWSMCPService": "true"
                }
            }
        }
    ]
}
```

### aws:CurrentTime
<a name="condition-keys-currenttime"></a>

使用此键可将请求的日期和时间与您在策略中指定的日期和时间进行比较。要查看使用此条件键的示例策略，请参阅[AWS：允许基于日期和时间进行访问](reference_policies_examples_aws-dates.md)。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [日期](reference_policies_elements_condition_operators.md#Conditions_Date)
+ **值类型** - 单值

### aws:EpochTime
<a name="condition-keys-epochtime"></a>

使用此键可将请求的日期和时间（以 epoch 或 Unix 时间表示）与您在策略中指定的值进行比较。此键还接受自 1970 年 1 月 1 日以来的秒数。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [日期](reference_policies_elements_condition_operators.md#Conditions_Date)、[数字](reference_policies_elements_condition_operators.md#Conditions_Numeric)
+ **值类型** - 单值

### aws:referer
<a name="condition-keys-referer"></a>

使用此键可将在客户端浏览器中引用请求的站点与您在策略中指定的引用站点进行比较。`aws:referer` 请求上下文值是由调用方在 HTTP 标头中提供的。当您在网页上选择链接时，`Referer` 标题将包含在 Web 浏览器请求中。`Referer` 标题包含选定链接的网页的 URL。
+ **Availability**（可用性）- 仅当通过从浏览器中的网页 URL 链接来调用对 AWS 资源的请求时，才将此键包含在请求上下文中。编程请求不包括此键，因为它不使用浏览器链接即可访问 AWS 资源。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

例如，您可以直接使用 URL 或使用直接 API 调用访问 Amazon S3 对象。有关更多信息，请参阅[使用 Web 浏览器直接调用 Amazon S3 API 操作](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html#example-bucket-policies-use-case-4)。当您从网页中存在的 URL 访问 Amazon S3 对象时，源网页的 URL 将在 `aws:referer` 中使用。当您通过在浏览器中键入 URL 来访问 Amazon S3 对象时，`aws:referer` 不存在。直接调用 API 时，`aws:referer` 也不存在。您可以使用策略中的 `aws:referer` 条件键以允许来自特定引用站点发出的请求，例如公司域中网页上的链接。

**警告**  
应谨慎使用此键。包含公共已知的引用站点标头值是非常危险的。未经授权方可能会使用修改的浏览器或自定义浏览器提供他们选择的任何 `aws:referer` 值。因此，`aws:referer` 不应用于阻止未经授权方直接发出 AWS 请求。提供它只是为了允许客户保护其数字内容（如存储在 Amazon S3 中的内容），以免在未经授权的第三方站点上引用。

### aws:RequestedRegion
<a name="condition-keys-requestedregion"></a>

使用此键可将已在请求中调用的 AWS 区域与您在策略中指定的区域进行比较。您可以使用此全局条件键来控制可请求的区域。要查看每个服务的 AWS 区域，请参阅《Amazon Web Services 一般参考》中的 [服务端点和限额](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)**。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

一些全球服务（如 IAM）具有单个端点。因为此端点的物理位置在美国东部（弗吉尼亚北部）区域，所以 IAM 调用始终会向 us-east-1 区域发出。例如，如果您创建一个策略以在请求的区域不是 us-west-2 时拒绝访问所有服务，则 IAM 调用将始终失败。要查看如何解决此问题的示例，请参阅 [NotAction 与 Deny](reference_policies_elements_notaction.md)。

**注意**  
使用 `aws:RequestedRegion` 条件键可以控制服务的哪个端点被调用，但不控制该操作产生的影响。一些服务具有跨区域影响。  
例如，Amazon S3 具有跨区域扩展的 API 操作。  
您可以在一个区域中调用 `s3:PutBucketReplication`（受 `aws:RequestedRegion` 条件键的影响），但其他区域将会受到影响，具体取决于复制配置设置。
您可以调用 `s3:CreateBucket` 在另一个区域创建存储桶，然后使用 `s3:LocationConstraint` 条件键来控制适用区域。

您可以使用该上下文密钥将访问限制为一组给定区域中的 AWS 服务。例如，以下策略允许用户查看 AWS 管理控制台 中的所有 Amazon EC2 实例。但是，它仅允许用户更改爱尔兰 (eu-west-1)、伦敦 (eu-west-2) 或巴黎 (eu-west-3) 中的实例。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InstanceConsoleReadOnly",
            "Effect": "Allow",
            "Action": [
                "ec2:Describe*",
                "ec2:Export*",
                "ec2:Get*",
                "ec2:Search*"
            ],
            "Resource": "*"
        },
        {
            "Sid": "InstanceWriteRegionRestricted",
            "Effect": "Allow",
            "Action": [
                "ec2:Associate*",
                "ec2:Import*",
                "ec2:Modify*",
                "ec2:Monitor*",
                "ec2:Reset*",
                "ec2:Run*",
                "ec2:Start*",
                "ec2:Stop*",
                "ec2:Terminate*"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:RequestedRegion": [
                        "eu-west-1",
                        "eu-west-2",
                        "eu-west-3"
                    ]
                }
            }
        }
    ]
}
```

------

### aws:RequestTag/*tag-key*
<a name="condition-keys-requesttag"></a>

使用此键可将请求中传递的标签键/值对与您在策略中指定的标签对进行比较。例如，您可以检查请求是否包含标签键 `"Dept"` 并具有 `"Accounting"` 值。有关更多信息，请参阅 [在 AWS 请求期间控制访问](access_tags.md#access_tags_control-requests)。
+ **Availability**（可用性）– 当在请求中传递标签键值对时，将此键包含在请求上下文中。在请求中传递多个标签时，每个标签键/值对均有一个上下文密钥。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

该上下文密钥的格式为 `"aws:RequestTag/tag-key":"tag-value"`，其中 *tag-key* 和 *tag-value* 是标签键值对。标签键不区分大小写。这意味着，如果您在策略的条件元素中指定 `"aws:RequestTag/TagKey1": "Value1"`，则条件将匹配名为 `TagKey1` 或 `tagkey1` 的请求标签键，但不会同时匹配两者。这些标签键/值对中的值应区分大小写。这意味着，如果您在策略的条件元素中指定 `"aws:RequestTag/TagKey1": "Production"`，则条件将匹配名为 `Production` 的请求标签值，但不会同时匹配 `production` 或 `PRODUCTION`。

这个例子表明，虽然该键是单值的，但如果键不同，您仍然可以在请求中使用多个键值对。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "ec2:CreateTags",
    "Resource": "arn:aws:ec2::111122223333:instance/*",
    "Condition": {
      "StringEquals": {
        "aws:RequestTag/environment": [
          "preprod",
          "production"
        ],
        "aws:RequestTag/team": [
          "engineering"
        ]
      }
    }
  }
}
```

------

### aws:TagKeys
<a name="condition-keys-tagkeys"></a>

使用此键可将请求中的标签键与您在策略中指定的键进行比较。我们建议当使用策略来通过标签控制访问时，请使用 `aws:TagKeys` 条件键来定义允许的标签键。有关示例策略和更多信息，请参阅[根据标签键控制访问](access_tags.md#access_tags_control-tag-keys)。
+ **Availability**（可用性）– 仅在操作支持将标签传递到请求中时，才将此键包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

该上下文密钥的格式为 `"aws:TagKeys":"tag-key"`，其中 *tag-key* 是没有值的标签键列表 (例如，`["Dept","Cost-Center"]`)。

由于可在一个请求中包含多个标签键/值对，因此，请求内容可以是[多值](reference_policies_condition-single-vs-multi-valued-context-keys.md)请求。在此情况下，您必须使用 `ForAllValues` 或 `ForAnyValue` 集合运算符。有关更多信息，请参阅 [多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。

某些服务支持同时使用标记和资源操作，例如创建、修改或删除资源。要允许在单次调用中同时使用标记和操作，您必须创建同时包含标记操作和资源修改操作的策略。然后，您可以使用 `aws:TagKeys` 条件键强制在请求中使用特定标签键。例如，要在某人创建 Amazon EC2 快照时限制标签，您必须在策略中包含 `ec2:CreateSnapshot`创建操作***和*** `ec2:CreateTags` 标记操作。要查看此使用 `aws:TagKeys` 场景的策略，请参阅《*Amazon EC2 用户指南*》中的[创建具有标签的快照](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#iam-creating-snapshot-with-tags)。

### aws:SecureTransport
<a name="condition-keys-securetransport"></a>

使用此键可检查是否已使用 TLS 发送请求。请求上下文将返回 `true` 或 `false`。在策略中，只能在使用 TLS 发送请求时允许特定操作。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

**注意**  
当 AWS 服务 代表您调用其它 AWS 服务（服务到服务调用）时，会编辑某些特定于网络的授权上下文。如果您的策略将此条件键与 `Deny` 语句结合使用，则 AWS 服务 主体可能会无意中受到屏蔽。要让 AWS 服务 在保持安全要求的同时正常运行，请通过添加值为 `false` 的 `aws:PrincipalIsAWSService` 条件键将服务主体排除在 `Deny` 语句之外。例如：  

```
{
  "Effect": "Deny",
  "Action": "s3:*",
  "Resource": "*",
  "Condition": {
    "Bool": {
      "aws:SecureTransport": "false",
      "aws:PrincipalIsAWSService": "false"
    }
  }
}
```
当未使用 HTTPS（`aws:SecureTransport` 为 false）时，此策略拒绝访问 Amazon S3 操作，但仅适用于非 AWS 服务主体。这可以确保条件限制适用于除 AWS 服务 主体之外的所有主体。

### aws:SourceAccount
<a name="condition-keys-sourceaccount"></a>

使用该键可将发出服务到服务请求的资源的账户 ID 与您在策略中指定的账户 ID 进行比较，但仅当请求由 AWS 服务主体发出时才有效。
+ **可用性** – 仅当 [AWS 服务主体](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services)代表配置触发服务到服务请求的资源直接调用您的资源时，才会将该键包含在请求上下文中。发出调用的服务将原始资源的账户 ID 传递给被调用的服务。
**注意**  
此键提供了一种统一机制，用于跨 AWS 服务 执行跨服务的混淆代理控制。但是，并非所有服务集成都需要使用此全局条件键。有关缓解跨服务的混淆代理风险的服务特定机制的更多信息，请参阅您使用的 AWS 服务 的文档。  
![\[aws:SourceAccount\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/sourceAccount.png)
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

您可以使用此条件键，帮助确保调用服务仅能够在请求来自特定账户时访问您的资源。例如，您可以附加以下资源控制策略（RCP）来拒绝服务主体针对 Amazon S3 存储桶提出的请求，除非这些请求是由指定账户中的资源触发的。此策略仅对存在 `aws:SourceAccount` 密钥的服务主体（`"Bool": {"aws:PrincipalIsAWSService": "true"}`）（`"Null": {"aws:SourceAccount": "false"}`）进行的请求应用控制，因此不需要使用此键的服务集成和主体的调用不会受到影响。如果 `aws:SourceAccount` 键存在于请求上下文中，则 `Null` 条件将评估为 `true`，从而强制执行 `aws:SourceAccount` 键。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "RCPEnforceConfusedDeputyProtection",
      "Effect": "Deny",
      "Principal": "*",
      "Action": [
        "s3:*"
      ],
      "Resource": "*",
      "Condition": {
        "StringNotEqualsIfExists": {
          "aws:SourceAccount": "111122223333"
        },
        "Null": {
          "aws:SourceAccount": "false"
        },
        "Bool": {
          "aws:PrincipalIsAWSService": "true"
        }
      }
    }
  ]
}
```

------

在主体为 AWS 服务 主体的基于资源的策略中，使用键限制授予服务的权限。例如，当 Amazon S3 存储桶被配置为向 Amazon SNS 主题发送通知时，Amazon S3 服务将为所有已配置的事件调用 `sns:Publish` API 操作。在允许 `sns:Publish` 操作的主题策略中，将条件键的值设置为 Amazon S3 桶的账户 ID。

### aws:SourceArn
<a name="condition-keys-sourcearn"></a>

使用该键可将发出服务到服务请求的资源的 [Amazon 资源名称（ARN）](reference_identifiers.md#identifiers-arns)与您在策略中指定的 ARN 进行比较，但仅当请求由 AWS 服务主体发出时才有效。源的 ARN 包含账户 ID 时，不必将 `aws:SourceAccount` 与 `aws:SourceArn` 结合使用。

此键不适用于发出请求的主体的 ARN。请改用`aws:PrincipalArn`。
+ **可用性** – 仅当 [AWS 服务主体](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services)代表配置触发服务到服务请求的资源直接调用您的资源时，才会将该键包含在请求上下文中。发出调用的服务将原始资源的 ARN 传递给被调用的服务。
**注意**  
此键提供了一种统一机制，用于跨 AWS 服务 执行跨服务的混淆代理控制。但是，并非所有服务集成都需要使用此全局条件键。有关缓解跨服务的混淆代理风险的服务特定机制的更多信息，请参阅您使用的 AWS 服务 的文档。  
![\[aws:SourceArn\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/sourceArn.png)
+ **数据类型** – ARN

  AWS 建议在比较 ARN 时使用 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)而不是[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)。
+ **值类型** - 单值

您可以使用此条件键，帮助确保调用服务仅能够在请求来自特定资源时访问您的资源。使用 AWS 服务 主体为 `Principal` 的基于资源的策略时，请将此条件键的值设置为您要限制访问的资源的 ARN。例如，当 Amazon S3 存储桶被配置为向 Amazon SNS 主题发送通知时，Amazon S3 服务将为所有已配置的事件调用 `sns:Publish` API 操作。在允许 `sns:Publish` 操作的主题策略中，将条件键的值设置为 Amazon S3 桶的 ARN。有关何时在基于资源的策略中使用此条件键的建议，请参阅您正在使用的 AWS 服务 的文档。

### aws:SourceOrgID
<a name="condition-keys-sourceorgid"></a>

使用该键可将发出服务到服务请求的资源的[组织 ID](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_details.html) 与您在策略中指定的组织 ID 进行比较，但仅当请求由 AWS 服务主体发出时才有效。当您在 AWS Organizations 中向组织添加和删除账户时，包含 `aws:SourceOrgID` 键的策略将自动包含正确的账户，并且不必手动更新。
+ **可用性** – 仅当 [AWS 服务主体](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services)代表属于组织成员的账户拥有的资源直接调用您的资源时，才会将该键包含在请求上下文中。发出调用的服务将原始资源的组织 ID 传递给被调用的服务。
**注意**  
此键提供了一种统一机制，用于跨 AWS 服务 执行跨服务的混淆代理控制。但是，并非所有服务集成都需要使用此全局条件键。有关缓解跨服务的混淆代理风险的服务特定机制的更多信息，请参阅您使用的 AWS 服务 的文档。  
![\[aws:SourceOrgID\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/sourceOrgID.png)
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型** - 单值

您可以使用此条件键，帮助确保调用服务仅能够在请求来自特定组织时访问您的资源。例如，您可以附加以下资源控制策略（RCP）来拒绝服务主体针对 Amazon S3 存储桶提出的请求，除非这些请求是由指定的 AWS 组织中的资源触发的。此策略仅对存在 `aws:SourceAccount` 密钥（`"Null": {"aws:SourceAccount": "false"}`）的服务主体（`"Bool": {"aws:PrincipalIsAWSService": "true"}`）进行的请求应用控制，因此不需要使用此键的服务集成和主体的调用不会受到影响。如果 `aws:SourceAccount` 键存在于请求上下文中，则 `Null` 条件将评估为 `true`，从而强制执行 `aws:SourceOrgID` 键。我们在 `Null` 条件运算符中使用 `aws:SourceAccount` 代替 `aws:SourceOrgID`，因此，如果请求来自不属于组织的账户，则控制仍然适用。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "RCPEnforceConfusedDeputyProtection",
      "Effect": "Deny",
      "Principal": "*",
      "Action": [
        "s3:*"
      ],
      "Resource": "*",
      "Condition": {
        "StringNotEqualsIfExists": {
          "aws:SourceOrgID": "o-xxxxxxxxxx"
        },
        "Null": {
          "aws:SourceAccount": "false"
        },
        "Bool": {
          "aws:PrincipalIsAWSService": "true"
        }
      }
    }
  ]
}
```

------

### aws:SourceOrgPaths
<a name="condition-keys-sourceorgpaths"></a>

使用该键可将发出服务到服务请求的资源的 AWS Organizations 路径与您在策略中指定的组织路径进行比较，但仅当请求由 AWS 服务主体发出时才有效。AWS Organizations 路径是 AWS Organizations 实体结构的文本表示形式。有关使用和了解路径的更多信息，请参阅[了解 AWS Organizations 实体路径](access_policies_last-accessed-view-data-orgs.md#access_policies_last-accessed-viewing-orgs-entity-path)。
+ **可用性** – 仅当 [AWS 服务主体](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services)代表属于组织成员的账户拥有的资源直接调用您的资源时，才会将该键包含在请求上下文中。发出调用的服务将原始资源的组织路径传递给被调用的服务。
**注意**  
此键提供了一种统一机制，用于跨 AWS 服务 执行跨服务的混淆代理控制。但是，并非所有服务集成都需要使用此全局条件键。有关缓解跨服务的混淆代理风险的服务特定机制的更多信息，请参阅您使用的 AWS 服务 的文档。  
![\[aws:SourceOrgPaths\]](http://docs.aws.amazon.com/zh_cn/IAM/latest/UserGuide/images/sourceOrgPaths.png)
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)（列表）
+ **值类型**— 多值

使用此条件键，帮助确保调用服务仅能够在请求来自 AWS Organizations 中特定组织单元（OU）时访问您的资源。

与 `aws:SourceOrgID` 类似的是，为了帮助防止对不需要使用此键的服务集成造成影响，请结合使用 `Null` 条件运算符和 `aws:SourceAccount` 条件键，这样，如果请求来自不属于组织的账户，则该控制仍然适用。

```
{
      "Condition": {
        "ForAllValues:StringNotLikeIfExists": {
            "aws:SourceOrgPaths": "o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/ou-ab12-22222222/"
        },
        "Null": {
          "aws:SourceAccount": "false"
        },
        "Bool": {
          "aws:PrincipalIsAWSService": "true"
        }
      }
}
```

`aws:SourceOrgPaths` 是一个多值条件键。多值键在请求上下文中可以有多个值。对于此键，您必须将 `ForAnyValue` 或者 `ForAllValues` 集合运算符与[字符串条件运算符](reference_policies_elements_condition_operators.md#Conditions_String)搭配使用。有关多值条件键的更多信息，请参阅[多值上下文键的集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)。

### aws:UserAgent
<a name="condition-keys-useragent"></a>

使用此键可将请求者的客户端应用程序与您在策略中指定的应用程序进行比较。
+ **Availability**（可用性）- 此键始终包含在请求上下文中。
+ **数据类型** – [字符串](reference_policies_elements_condition_operators.md#Conditions_String)
+ **值类型**— 单值

**警告**  
应谨慎使用此键。由于 `aws:UserAgent` 值由发起人在 HTTP 标头中提供，因此未经授权方可以修改或自定义浏览器以提供他们选择的任何 `aws:UserAgent` 值。因此，`aws:UserAgent` 不应用于阻止未经授权方直接发出 AWS 请求。您可以使用它来仅允许特定客户端应用程序，并且仅在对策略进行测试之后。

### aws:IsMcpServiceAction
<a name="condition-keys-ismcpserviceaction"></a>

使用此键可验证正在授权的操作是否是 MCP 服务操作。此键不涉及 MCP 服务对其他 AWS 服务执行的操作。
+ **可用性**：此键包含在请求上下文中，仅当 MCP 服务授权 MCP 服务操作时设置为 True。
+ **数据类型** – [布尔值](reference_policies_elements_condition_operators.md#Conditions_Boolean)
+ **值类型** - 单值

## 其他跨服务条件键
<a name="condition-keys-other"></a>

AWS STS 支持将[基于 SAML 的联合身份验证条件键](reference_policies_iam-condition-keys.md#condition-keys-saml)和跨服务条件键用于 [OIDC 联合身份验证](reference_policies_iam-condition-keys.md#condition-keys-wif)。当使用 OIDC 或 SAML 联合的用户在其他服务中执行 AWS 操作时，这些键可用。