

# IAM 和 Amazon STS 条件上下文密钥
<a name="reference_policies_iam-condition-keys"></a>

您可以在 JSON 策略中使用 `Condition` 元素来测试所有 Amazon 请求的请求上下文中所包含键的值。这些键提供有关请求本身或请求所引用资源的信息。在允许用户请求的操作之前，您可以检查这些键是否具有指定值。这样，您就可以精细控制 JSON 策略语句何时与传入的请求匹配或不匹配。有关如何在 JSON 策略中使用 `Condition` 元素的信息，请参阅[IAM JSON 策略元素：Condition](reference_policies_elements_condition.md)。

本主题介绍了由 IAM 服务定义和提供的键（带 `iam:` 前缀）以及由 Amazon Security Token Service (Amazon STS) 服务定义和提供的键（带 `sts:` 前缀）。其他几个 Amazon 服务也提供与该服务定义的操作和资源相关的服务特定键。有关更多信息，请参阅 [Amazon 服务的操作、资源和条件键](reference_policies_actions-resources-contextkeys.html)。支持条件键的服务的文档通常包含附加信息。例如，有关可在 Amazon S3 资源的策略中使用的密钥信息，请参阅 *Amazon Simple Storage Service 用户指南*中的 [Amazon S3 策略密钥](https://docs.amazonaws.cn/AmazonS3/latest/userguide/amazon-s3-policy-keys.html#AvailableKeys-iamV2)。

**Topics**
+ [IAM 的可用键](#available-keys-for-iam)
+ [Amazon OIDC 联合身份验证的可用键](#condition-keys-wif)
+ [基于 SAML 的 Amazon STS 联合身份验证的可用键](#condition-keys-saml)
+ [基于 SAML 的跨服务 Amazon STS 联合身份验证上下文键](#cross-condition-keys-saml)
+ [Amazon STS 的可用键](#condition-keys-sts)

## IAM 的可用键
<a name="available-keys-for-iam"></a>

可以在控制对 IAM 资源的访问的策略中使用以下条件键：

**iam:AssociatedResourceArn**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
指定此角色在目标服务上关联的资源的 ARN。资源通常属于主体将角色传递到的服务。有时，资源可能属于第三个服务。例如，您可以将角色传递给他们在 Amazon EC2 实例上使用的 Amazon EC2 Auto Scaling。在这种情况下，条件将匹配 Amazon EC2 实例的 ARN。  
此条件键仅适用于策略中的 [PassRole](id_roles_use_passrole.md) 操作。无法使用它来限制任何其他操作。  
当在策略中使用 `iam:AssociatedResourceArn` 条件来限制 [PassRole](id_roles_use_passrole.md) 操作时，如果该策略旨在定义 [AddRoleToInstanceProfile](https://docs.amazonaws.cn/IAM/latest/APIReference/API_AddRoleToInstanceProfile.html) 操作的访问权限，则需要特别考虑。在这种情况下，您无法在 EC2 实例 ARN 中指定区域或实例 ID。ARN 值必须为 `arn:aws:ec2:*:CallerAccountId:instance/*`。使用任何其他 ARN 值都可能会导致意外的评估结果。
在基于身份的策略中使用此条件键可允许实体传递角色，但前提是角色与指定资源相关联。例如，您可以允许 IAM 用户或角色将任何角色传递给 Amazon EC2 服务，以便与 Amazon Web Services 账户 中的实例一起使用。不允许将 IAM 用户或角色传递给其他服务。  

```
{
    "Effect": "Allow",
    "Action": "iam:PassRole",
    "Resource": "*",
    "Condition": {
        "StringEquals": {
            "iam:PassedToService": "ec2.amazonaws.com"
        },
        "ArnLike": {
            "iam:AssociatedResourceARN": [
                "arn:aws:ec2:*:111122223333:instance/*"
            ]
        }
    }
}
```
支持 [iam:PassedToService](#ck_PassedToService) 的 Amazon 服务也支持此条件键。

**iam:AWSServiceName**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
指定此角色将附加到的 Amazon 服务。  
[https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceLinkedRole.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceLinkedRole.html) API 操作支持此条件键。  
有关哪些服务支持使用服务相关角色的信息，请参阅 [使用 IAM 的 Amazon 服务](reference_aws-services-that-work-with-iam.md) 并查找其在**服务相关角色**列中为**是**的服务。请选择**是**与查看该服务的服务关联角色文档的链接。
在此示例中，如果服务名称为 *access-analyzer.amazonaws.com*，您将允许实体使用 [https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceLinkedRole.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceLinkedRole.html) API 操作创建与服务关联的角色。    
****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [{
       "Effect": "Allow",
       "Action": "iam:CreateServiceLinkedRole",
       "Resource": "*",
       "Condition": {
         "StringLike": {
           "iam:AWSServiceName": "access-analyzer.amazonaws.com"
         }
       }
     }]
 }
```

**iam:FIDO-certification**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
在注册 FIDO 安全密钥时，检查 MFA 设备 FIDO 认证级别。从 [FIDO Alliance Metadata Service（MDS）](https://fidoalliance.org/metadata/)获取设备认证。如果您的 FIDO 安全密钥的认证状态或级别发生变化，则除非设备取消注册，然后重新注册，以获取更新的认证信息，否则不会对其进行更新。  
L1、L1plus、L2、L2plus、L3、L3plus 的可能值  
在本例中，您注册了安全密钥，并为设备检索 FIDO 1 级 \$1 认证。    
****  

```
{
      "Version":"2012-10-17",		 	 	 
      "Statement": [{
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Create"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Activate",
                    "iam:FIDO-certification": "L1plus"
                }
            }
        }
    ]
                  
 }
```

**iam:FIDO-FIPS-140-2-certification**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
在注册 FIDO 安全密钥时，检查 MFA 设备 FIPS-140-2 验证认证级别。从 [FIDO Alliance Metadata Service（MDS）](https://fidoalliance.org/metadata/)获取设备认证。如果您的 FIDO 安全密钥的认证状态或级别发生变化，则除非设备取消注册，然后重新注册，以获取更新的认证信息，否则不会对其进行更新。  
L1、L2、L3、L4 的可能值  
在本例中，您注册了安全密钥，并为设备检索 FIPS-140-2 2 级认证。    
****  

```
{
      "Version":"2012-10-17",		 	 	 
      "Statement": [{
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Create"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Activate",
                    "iam:FIDO-FIPS-140-2-certification": "L2"
                }
            }
        }
    ]
                  
 }
```

**iam:FIDO-FIPS-140-3-certification**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
在注册 FIDO 安全密钥时，检查 MFA 设备 FIPS-140-3 验证认证级别。从 [FIDO Alliance Metadata Service（MDS）](https://fidoalliance.org/metadata/)获取设备认证。如果您的 FIDO 安全密钥的认证状态或级别发生变化，则除非设备取消注册，然后重新注册，以获取更新的认证信息，否则不会对其进行更新。  
L1、L2、L3、L4 的可能值  
在本例中，您注册了安全密钥，并为设备检索 FIPS-140-3 3 级认证。    
****  

```
{
      "Version":"2012-10-17",		 	 	 
      "Statement": [{
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Create"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Activate",
                    "iam:FIDO-FIPS-140-3-certification": "L3"
                }
            }
        }
    ]
                  
 }
```

**iam:OrganizationsPolicyId**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
检查具有指定 Amazon Organizations ID 的策略是否与请求中使用的策略匹配。要查看使用此条件键的示例 IAM policy，请参阅。[IAM：查看 Amazon Organizations 策略的服务上次访问信息](reference_policies_examples_iam_service-accessed-data-orgs.md)

**iam:PassedToService**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
指定可将角色传递到的服务的服务主体。此条件键仅适用于策略中的 [PassRole](id_roles_use_passrole.md) 操作。无法使用它来限制任何其他操作。  
在策略中使用此条件键时，请使用服务主体指定服务。服务主体是可在策略的 `Principal` 元素中指定的服务的名称。常见格式为：`SERVICE_NAME_URL.amazonaws.com`。  
您可以使用 `iam:PassedToService` 限制您的用户，使其只能将角色传递到特定服务。例如，用户可能会创建一个[服务角色](id_roles.md#iam-term-service-role)，该角色信任 CloudWatch 代表用户将日志数据写入到 Amazon S3 存储桶。之后，用户必须将一个权限策略和一个信任策略附加到新的服务角色。在此情况下，信任策略必须指定 `cloudwatch.amazonaws.com` 元素中的 `Principal`。要查看允许用户将角色传递给 CloudWatch 的策略，请参阅 [IAM：将 IAM 角色传递给特定 Amazon 服务](reference_policies_examples_iam-passrole-service.md)。  
通过使用此条件键，您可以确保用户仅为您指定的服务创建服务角色。例如，如果具有之前的策略的用户尝试为 Amazon EC2 创建服务角色，操作将失败。失败的原因是因为用户无权将角色传递到 Amazon EC2。  
有时，您会将角色传递给一个服务，随后将角色传递给另一个服务。`iam:PassedToService` 仅包含担任角色的最终服务，而不包括传递角色的中间服务。  
某些服务不支持此条件键。

**iam:PermissionsBoundary**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
检查指定的策略附加为 IAM 主体资源上的权限边界。有关更多信息，请参阅 [IAM 实体的权限边界](access_policies_boundaries.md)

**iam:PolicyARN**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
检查涉及托管策略的请求中的托管策略的 Amazon Resource Name (ARN)。有关更多信息，请参阅 [控制对策略的访问](access_controlling.md#access_controlling-policies)。

**iam:RegisterSecurityKey**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
检查 MFA 设备支持的当前状态。  
`Create` 或 `Activate` 的可能值。  
在本例中，您注册了安全密钥，并为设备检索 FIPS-140-3 1 级认证。    
****  

```
{
      "Version":"2012-10-17",		 	 	 
      "Statement": [{
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Create"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "iam:EnableMFADevice",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:RegisterSecurityKey" : "Activate",
                    "iam:FIDO-FIPS-140-3-certification": "L1"
                }
            }
        }
    ]
                  
 }
```

**iam:ResourceTag/*key-name***  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
检查附加到身份资源（用户或角色）的标签是否与指定的键名称和键值匹配。  
IAM 和 Amazon STS 同时支持 `iam:ResourceTag` IAM 条件键和 `aws:ResourceTag` 全局条件键。
您可采用键值对的形式向 IAM 资源添加自定义属性。有关 IAM 资源的标签的更多信息，请参阅 [Amazon Identity and Access Management 资源的标签](id_tags.md)。您可以使用 `ResourceTag` [控制](access_tags.md#access_tags_control-resources)对 Amazon 资源（包括 IAM 资源）的访问。但是，由于 IAM 不支持组的标签，因此您不能使用标签来控制对组的访问。  
此示例说明如何创建基于身份的策略以允许删除具有 **status=terminated** 标签的用户。要使用此策略，请将示例策略中的*斜体占位符文本*替换为您自己的信息。然后，按照[创建策略](access_policies_create.md)或[编辑策略](access_policies_manage-edit.md)中的说明操作。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Action": "iam:DeleteUser",
        "Resource": "*",
        "Condition": {"StringEquals": {"iam:ResourceTag/status": "terminated"}}
    }]
}
```

**iam:ServiceSpecificCredentialAgeDays**  
与[数字运算符](reference_policies_elements_condition_operators.md#Conditions_Numeric)结合使用。  
此条件键根据过期设置限制特定服务凭证的创建。通过此键，您可以控制可创建的特定服务凭证的最大期限（以天为单位）。  
有效天数范围为 1 到 36600 天（最短 1 天，最长 36600 天）。  
[https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html) API 操作支持此条件键。  
在此示例中，只有在 90 天内过期时，才允许用户为 Amazon Bedrock 服务创建特定服务凭证。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceSpecificCredential",
            "Resource": "arn:aws:iam::111122223333:user/username",
            "Condition": {
                "StringEquals": {
                    "iam:ServiceSpecificCredentialServiceName": "bedrock.amazonaws.com"
                },
                "NumericLessThanEquals": {
                    "iam:ServiceSpecificCredentialAgeDays": "90"
                }
            }
        }
    ]
}
```

**iam:ServiceSpecificCredentialServiceName**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
指定在管理特定服务凭证时可以使用哪些 Amazon 服务。通过此条件键，您可以限制在管理特定服务凭证时允许使用哪些 Amazon 服务。  
以下 API 操作支持此条件键：  
+ [https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html)
+ [https://docs.amazonaws.cn/IAM/latest/APIReference/API_DeleteServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_DeleteServiceSpecificCredential.html)
+ [https://docs.amazonaws.cn/IAM/latest/APIReference/API_ResetServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_ResetServiceSpecificCredential.html)
+ [https://docs.amazonaws.cn/IAM/latest/APIReference/API_UpdateServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_UpdateServiceSpecificCredential.html)
以下服务支持特定服务凭证及其精确值格式：  
+ `bedrock.amazonaws.com`
+ `cassandra.amazonaws.com`
+ `codecommit.amazonaws.com`
在此示例中，允许用户仅使用 [https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html](https://docs.amazonaws.cn/IAM/latest/APIReference/API_CreateServiceSpecificCredential.html) API 操作为 Amazon Bedrock 服务创建特定服务凭证。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceSpecificCredential",
            "Resource": "arn:aws:iam::111122223333:user/username",
            "Condition": {
                "StringEquals": {
                    "iam:ServiceSpecificCredentialServiceName": "bedrock.amazonaws.com"
                }
            }
        }
    ]
}
```

**iam:DelegationDuration**  
与[数字运算符](reference_policies_elements_condition_operators.md#Conditions_Numeric)结合使用。  
根据在委派请求中请求临时访问的持续时间筛选访问权限。  
产品提供商可以使用此条件键来控制其允许向客户发送的委派请求的最大持续时间。持续时间以秒为单位指定，其决定了客户发放交换令牌后临时凭证保持有效的时长。这有助于产品提供商根据其使用案例强制执行有关访问持续时间限制的内部策略。  
`CreateDelegationRequest` API 操作支持此条件键。  
在此示例中，仅当请求的持续时间为 7200 秒（2 小时）或更短时，才允许创建委派请求。  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:CreateDelegationRequest",
            "Resource": "*",
            "Condition": {
                "NumericLessThanEquals": {
                    "iam:DelegationDuration": "7200"
                }
            }
        }
    ]
}
```

**iam:NotificationChannel**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
根据为接收委派请求通知指定的 Amazon SNS 主题 ARN 筛选访问权限。  
产品提供商可以使用此条件键来限制哪些 SNS 主题可用于 CreateDelegationRequest API 调用中的委派请求通知。产品提供商必须指定 SNS 主题才能接收状态变更通知和交换令牌。这可确保通知仅发送到产品提供商组织内经批准的渠道。  
`CreateDelegationRequest` API 操作支持此条件键。  
在此示例中，仅当委派请求使用特定 SNS 主题进行通知时，才允许创建委派请求。  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:CreateDelegationRequest",
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "iam:NotificationChannel": "arn:aws:sns:us-east-1:123456789012:delegation-notifications"
                }
            }
        }
    ]
}
```

**iam:TemplateArn**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
根据用于在委派请求中定义权限的策略模板 ARN 筛选访问权限。  
产品提供商可以使用此条件键来控制哪些策略模板能够在 CreateDelegationRequest API 调用中使用。策略模板定义产品提供商在客户账户中请求的临时权限。这允许产品提供商限制在创建委派请求时可以使用哪些注册的策略模板。  
`CreateDelegationRequest` API 操作支持此条件键。  
在此示例中，仅当委派请求使用来自特定合作伙伴域的策略模板时，才允许创建委派请求。  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:CreateDelegationRequest",
            "Resource": "*",
            "Condition": {
                "ArnLike": {
                    "iam:TemplateArn": "arn:aws:iam:::delegation-template/partner_*"
                }
            }
        }
    ]
}
```

**iam:DelegationRequestOwner**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
根据拥有委派请求的 Amazon 身份或主体筛选访问权限。  
客户可以使用此条件键来控制哪些人员可以根据所有权对委派请求执行操作。委派请求的所有者是发起或接收委派请求的客户账户中的 Amazon 身份或主体。  
以下 API 操作支持此条件键：  
+ `GetDelegationRequest`
+ `AcceptDelegationRequest`
+ `RejectDelegationRequest`
+ `SendDelegatedToken`
+ `ListDelegationRequests`
+ `UpdateDelegationRequest`
在此示例中，仅允许用户管理其拥有的委派请求。  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iam:GetDelegationRequest",
                "iam:AcceptDelegationRequest",
                "iam:RejectDelegationRequest",
                "iam:SendDelegatedToken",
                "iam:UpdateDelegationRequest",
                "iam:ListDelegationRequests"
            ],
            "Resource": "*",
            "Condition": {
                "ArnEquals": {
                    "iam:DelegationRequestOwner": "${aws:PrincipalArn}"
                }
            }
        }
    ]
}
```

## Amazon OIDC 联合身份验证的可用键
<a name="condition-keys-wif"></a>

您可以使用 OIDC 联合身份验证，为已通过 OpenID Connect 兼容的身份提供者（IdP）向您的 Amazon 账户中的 IAM OpenID Connect（OIDC）身份提供者进行身份验证的用户提供临时安全凭证。此类提供者的示例包括 GitHub、Amazon Cognito、Login with Amazon 和 Google。可以使用您自己的 IdP 中的身份令牌和访问令牌，也可以使用授给 Amazon Elastic Kubernetes 服务工作负载的[服务账户令牌](https://docs.amazonaws.cn/eks/latest/userguide/service-accounts.html#service-account-tokens)。

您可以使用 Amazon OIDC 条件上下文键编写策略，将联合主体的访问权限限制为与特定提供者、应用或用户关联的资源。这些键通常在角色的信任策略中使用。使用 OIDC 提供者的名称 (`token.actions.githubusercontent.com`) 和声明 (`:aud`) 定义条件键：`token.actions.githubusercontent.com:aud`。

某些 OIDC 联合身份验证条件键可以在角色会话中用于授权资源访问权限。如果“**在会话中可用**”列中的值为“**是**”，则可以在策略中使用这些条件键来定义其他 Amazon 服务中允许用户访问的内容。当声明在会话中不可用时，OIDC 条件上下文键只能在角色信任策略中用于初始 [AssumeRoleWithWebIdentity](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html) 身份验证。

选择您的 IdP，查看 IdP 中的声明如何映射到 Amazon 中的 IAM 条件上下文键。有关 GitHub 和 Google 密钥的更多信息，可在**默认**选项卡下找到。

------
#### [ Default ]

默认列出了标准 OIDC 声明以及它们如何映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。如果选项卡选项中未列出您的 IdP，则使用此映射。

GitHub Actions 工作流和 Google 是在 OIDC JWT ID 令牌中使用默认实现的 IDP 的一些示例。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| amr | amr | 是 | 
| aud | azp 如果未为 `azp` 设置任何值，则 `aud` 条件键将映射到 `aud` 声明。 | 是 | 
| 电子邮件 | 电子邮件 | 否 | 
| oaud | aud | 否 | 
| sub | sub | 是 | 

有关将 OIDC 条件上下文键与 GitHub 结合使用的更多信息，请参阅 [为 GitHub OIDC 身份提供程序配置角色](id_roles_create_for-idp_oidc.md#idp_oidc_Create_GitHub)。有关 Google `aud` 和 `azp` 字段的更多信息，请参阅 [Google Identity Platform OpenID Connect](https://developers.google.com/identity/protocols/OpenIDConnect) 指南。

**amr**  
与[字符串运算符](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)的策略中对它进行测试。  
**示例**：`token.actions.githubusercontent.com:amr`  
“身份验证方法引用”包括有关用户的登录信息。该键可包含以下值：  
+ 如果用户未经过身份验证，则该键仅包含 `unauthenticated`。
+ 如果用户已通过身份验证，则该键包含值 `authenticated` 以及调用 (`accounts.google.com`) 中使用的登录提供者的名称。

**aud**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例：**  
+ `accounts.google.com:aud`
+ `token.actions.githubusercontent.com:aud`
使用 `aud` 条件键验证受众是否与您在策略中指定的内容匹配。对于同一身份提供者，可以将 aud 键与 sub 键结合使用。  
此条件键是从以下令牌字段设置的：  
+ 应用程序的 OAuth 2.0 Google 客户端 ID 的 `aud`（如果未设置 `azp` 字段）。如果设置了 `azp` 字段，则 `aud` 字段将与 `accounts.google.com:oaud` 条件键匹配。
+ `azp`（如果设置了 `azp` 字段）。对于 Web 应用程序和 Android 应用程序具有不同的 OAuth 2.0 Google 客户端 ID 但共享相同的 Google API 项目的混合应用程序，可能会出现这种情况。
在使用 `accounts.google.com:aud` 条件键编写策略时，您必须了解该应用程序是否为设置 `azp` 字段的混合应用程序。  
`azp` 字段未设置  
以下示例策略适用于未设置 `azp` 字段的非混合应用程序。在此情况下，Google ID 令牌 `aud` 字段值将与 `accounts.google.com:aud` 和 `accounts.google.com:oaud` 条件键值匹配。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {"Federated": "accounts.google.com"},
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "accounts.google.com:aud": "aud-value",
                    "accounts.google.com:oaud": "aud-value",
                    "accounts.google.com:sub": "sub-value"
                }
            }
        }
    ]
}
```
`azp` 字段已设置  
以下示例策略适用于设置 `azp` 字段的混合应用程序。在此情况下，Google ID 令牌 `aud` 字段值仅与 `accounts.google.com:oaud` 条件键值匹配。`azp` 字段值与 `accounts.google.com:aud` 条件键值匹配。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {"Federated": "accounts.google.com"},
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "accounts.google.com:aud": "azp-value",
                    "accounts.google.com:oaud": "aud-value",
                    "accounts.google.com:sub": "sub-value"
                }
            }
        }
    ]
}
```

**email**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例**：`accounts.google.com:email`  
此条件键验证用户的电子邮件地址。此声明的值可能不是此账户所独有的，并且可能会随着时间的推移而发生变化，因此您不应使用此值作为主要标识符来验证用户记录。

**oaud**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例**：`accounts.google.com:oaud`  
此键指定此 ID 令牌用于的其他受众 (`aud`)。它必须是应用程序的 OAuth 2.0 客户端 ID 之一。

**sub**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例：**  
+ `accounts.google.com:sub`
+ token.actions.githubusercontent.com:sub
使用这些键验证使用者是否与您在策略中指定的内容匹配。对于同一身份提供程序，可以将 `sub` 键与 `aud` 键结合使用。  
在以下角色信任策略中，`sub` 条件键将角色限制为名为 `demo` 的 GitHib 分支。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
          "token.actions.githubusercontent.com:sub": "repo:org-name/repo-name:ref:refs/heads/demo"
        }
      }
    }
  ]
}
```

------
#### [ Amazon Cognito ]

此选项卡说明了 Amazon Cognito 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。

对于 Amazon Cognito 使用的角色，键是使用 `cognito-identity.amazonaws.com` 和声明定义的。

有关身份池声明映射的更多信息，请参阅《*Amazon Cognito 开发人员指南*》中的[默认提供商映射](https://docs.amazonaws.cn/cognito/latest/developerguide/provider-mappings.html)。有关用户池声明映射的更多信息，请参阅《*Amazon Cognito 开发人员指南*》中的[使用 ID 令牌](https://docs.amazonaws.cn/cognito/latest/developerguide/amazon-cognito-user-pools-using-the-id-token.html)。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| amr | amr | 是 | 
| aud | aud | 是 | 
| oaud | aud | 否 | 
| sub | sub | 是 | 

**amr**  
与[字符串运算符](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)的策略中对它进行测试。  
**示例** – `cognito-identity.amazonaws.com:amr`  
“身份验证方法引用”包括有关用户的登录信息。该键可包含以下值：  
+ 如果用户未经过身份验证，则该键仅包含 `unauthenticated`。
+ 如果用户已通过身份验证，则该键包含值 `authenticated` 以及调用 (`cognito-identity.amazonaws.com`) 中使用的登录提供者的名称。
例如，某 Amazon Cognito 角色信任策略中的以下条件测试用户是否未经身份验证：  

```
"Condition": {
  "StringEquals": 
    { "cognito-identity.amazonaws.com:aud": "us-east-2:identity-pool-id" },
  "ForAnyValue:StringLike": 
    { "cognito-identity.amazonaws.com:amr": "unauthenticated" }
}
```

**aud**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `cognito-identity.amazonaws.com:aud`  
对用户进行身份验证的用户群体应用程序客户端。Amazon Cognito 在访问令牌 `client_id` 声明中呈现相同的值。

**oaud**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `cognito-identity.amazonaws.com:oaud`  
对用户进行身份验证的用户群体应用程序客户端。Amazon Cognito 在访问令牌 `client_id` 声明中呈现相同的值。

**sub**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `cognito-identity.amazonaws.com:sub`  
经过身份验证的用户的唯一标识符（UUID）或主题。用户名在您的用户群体中可能不是唯一的。此子声明是识别给定用户的最佳方法。对于同一身份提供程序，可以将 `sub` 键与 `aud` 键结合使用。  

```
"Condition": {
         "StringEquals": {
            "cognito-identity.amazonaws.com:aud": "us-east-1:12345678-abcd-abcd-abcd-123456790ab",
            "cognito-identity.amazonaws.com:sub": [
               "us-east-1:12345678-1234-1234-1234-123456790ab",
               "us-east-1:98765432-1234-1234-1243-123456790ab"
            ]
         }
      }
```

------
#### [ Login with Amazon ]

此选项卡说明了 Login with Amazon 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
|  app\$1id  |  应用程序 ID  |  是  | 
|  sub  |  用户 ID  |  是  | 
|  user\$1id  |  用户 ID  |  是  | 

**app\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `www.amazon.com:app_id`  
此键指定与其他身份提供者使用的 `aud` 字段匹配的受众上下文。

**sub**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `www.amazon.com:sub`  
此键验证用户 ID 是否与您在策略中指定的内容匹配。对于同一身份提供程序，可以将 `sub ` 键与 `aud` 键结合使用。

**user\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `www.amazon.com:user_id`  
此键指定与其他身份提供者使用的 `aud` 字段匹配的受众上下文。对于同一身份提供者，可以将 `user_id` 键与 `id` 键结合使用。

------
#### [ Facebook ]

此选项卡说明了 Facebook 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| app\$1id | 应用程序 ID | 是 | 
| id | id | 是 | 

**app\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `graph.facebook.com:app_id`  
此键验证受众上下文是否与其他身份提供者使用的 `aud` 字段匹配。

**id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `graph.facebook.com:id`  
此键验证应用程序（或站点）ID 是否与您在策略中指定的内容匹配。

------
#### [ GitHub ]

此选项卡说明了 GitHub Actions 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| 演员 | 演员 | 否 | 
| actor\$1id | actor\$1id | 否 | 
| job\$1workflow\$1ref | job\$1workflow\$1ref | 否 | 
| repository | repository | 否 | 
| repository\$1id | repository\$1id | 否 | 
| workflow | workflow | 否 | 
| ref | ref | 否 | 
| 环境 | 环境 | 否 | 
| enterprise\$1id | enterprise\$1id | 否 | 

**演员**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:actor`  
此密钥标识启动工作流程运行的个人账户。使用此密钥限制对特定角色的访问权限

**actor\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:actor_id`  
此密钥验证启动工作流程运行的个人账户的 ID。角色 ID 由 GitHub 生成，并且是不可变的。

**job\$1workflow\$1ref**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:job_workflow_ref`  
对于使用可重用工作流程的作业，此密钥包含可重用工作流程的参考路径。使用此密钥限制对特定工作流程的访问权限，并确保只有经过批准的工作流程才能担任角色。

**repository**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:repository`  
此密钥标识运行工作流程的存储库。使用此密钥限制对特定 GitHub 存储库的访问权限。

**repository\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:repository_id`  
此密钥验证运行工作流程的存储库的 ID。存储库 ID 是不可变的，即使存储库被重命名也不会更改。

**workflow**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:workflow`  
此密钥包含工作流程的名称。使用此密钥限制对存储库中特定工作流程的访问权限。

**ref**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:ref`  
此密钥标识触发工作流程运行的 git ref（分支或标签）。使用此密钥根据特定分支限制访问权限，例如仅允许 `main` 或 `production` 分支。

**环境**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:environment`  
此密钥包含作业使用的环境的名称。使用此密钥实现基于环境的访问控制，例如开发环境、暂存环境和生产环境的单独权限。  
如果您的信任策略中包含环境声明，则必须在 GitHub 工作流程中配置和提供环境。

**enterprise\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `token.actions.githubusercontent.com:enterprise_id`  
此密钥验证企业的 ID，该企业包含运行工作流程的存储库。使用此密钥确保访问权限仅限于您的 GitHub Enterprise 组织内的存储库。

以下示例信任策略使用 GitHub OIDC 令牌中的自定义声明来限制对角色的访问权限。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "Federated": "arn:aws:iam::AWS_ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com"
         },
         "Action": "sts:AssumeRoleWithWebIdentity",
         "Condition": {
            "StringLike": {
                "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
                "token.actions.githubusercontent.com:job_workflow_ref": "octo-org/octo-automation/.github/workflows/oidc.yml@refs/heads/main",
                "token.actions.githubusercontent.com:repository": "octo-org/octo-repo",
                "token.actions.githubusercontent.com:actor": "octocat",
                "token.actions.githubusercontent.com:ref": "refs/heads/main",
                "token.actions.githubusercontent.com:enterprise_id": "345"
               }
           }
        }
    ]
}
```

------
#### [ Google ]

此选项卡说明了 Google 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| google/organization\$1number | google:organization\$1number | 否 | 

**google/organization\$1number**  
与[数字运算符](reference_policies_elements_condition_operators.md#Conditions_Numeric)结合使用。  
**示例** – `accounts.google.com:google/organization_number`  
此密钥验证令牌是否代表属于特定 Google Cloud 或 Google Workspace 组织的 Google 身份。使用此密钥限制对来自特定组织的用户的访问权限，确保只有您所在组织的身份才能担任该角色。

以下示例信任策略使用 `google/organization_number` 声明来限制对角色的访问权限。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "Federated": "accounts.google.com"
         },
         "Action": "sts:AssumeRoleWithWebIdentity",
         "Condition": {
            "NumericEquals": {
                "accounts.google.com:google/organization_number": "123456"
               }
           }
        }
    ]
}
```

------
#### [ CircleCI ]

此选项卡说明了 CircleCI 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| oidc.circleci.com/project-id | oidc.circleci.com/project-id | 否 | 

**oidc.circleci.com/project-id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `circleci-issuer-url:oidc.circleci.com/project-id`  
此密钥标识运行作业的 CircleCI 项目。其值是一个包含 UUID 的字符串，该 UUID 唯一标识 CircleCI 项目。使用此密钥限制对特定 CircleCI 项目的访问权限。

以下示例信任策略使用 `oidc.circleci.com/project-id` 声明来限制对角色的访问权限。

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::123456789012:oidc-provider/oidc.circleci.com/org/12345"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "oidc.circleci.com/org/12345:aud": "sts.amazonaws.com",
          "oidc.circleci.com/org/12345:oidc.circleci.com/project-id": "76543210-ba98-fedc-3210-edcba0987654"
        }
      }
    }
  ]
}
```

------
#### [ Oracle Cloud Infrastructure (OCI) ]

此选项卡说明了 Oracle Cloud Infrastructure 如何将 OIDC 声明映射到 Amazon 中的 Amazon STS 条件上下文键。您可以使用这些键来控制对角色的访问。为此，请将 **Amazon STS 条件键**与 **IdP JWT 声明**列中的值进行比较。


| Amazon STS 条件键 | IdP JWT 声明 | 在会话中可用 | 
| --- | --- | --- | 
| rpst\$1id | rpst\$1id | 否 | 

**rpst\$1id**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
**示例** – `oci-issuer-url:rpst_id`  
此密钥唯一标识 OCI 中的资源主体。使用此密钥限制对特定 OCI 资源主体的访问权限。rpst\$1id（资源主体会话令牌 ID）为基于 OCI 资源的身份验证提供稳定的标识符。

以下示例信任策略使用 `rpst_id` 声明来限制对角色的访问权限。

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::123456789012:oidc-provider/idcs-abc123ef5678901234abcd.identity.oraclecloud.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "idcs-abc123ef5678901234abcd.identity.oraclecloud.com:aud": "sts.amazonaws.com",
          "idcs-abc123ef5678901234abcd.identity.oraclecloud.com:rpst_id": "your-rpst-id"
        }
      }
    }
  ]
}
```

------

### 有关 OIDC 联合身份验证的更多信息
<a name="condition-keys-wif-more-info"></a>


+ [Amazon Cognito 用户指南](https://docs.amazonaws.cn/cognito/latest/developerguide/cognito-identity.html)
+ [OIDC 联合身份验证](id_roles_providers_oidc.md)

## 基于 SAML 的 Amazon STS 联合身份验证的可用键
<a name="condition-keys-saml"></a>

如果您通过 Amazon Security Token Service (Amazon STS) 使用[基于 SAML 的联合](https://docs.amazonaws.cn/STS/latest/UsingSTS/CreatingSAML.html)，则可以在策略中包含更多条件键。

### SAML 角色信任策略
<a name="condition-keys-saml_trust-policy"></a>

在角色的信任策略中，您可以包括以下键，以帮助您确定发起人是否有权担任角色。除了 `saml:doc`，所有值均源自 SAML 断言。在创建或编辑带条件的策略时，可在 IAM 控制台可视化编辑器中使用列表中的所有项目。标有 `[]` 的项目*可以* 具有指定类型列表中的值。

**saml:aud**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
SAML 断言提交到的终端节点 URL。此键的值来自断言中的 `SAML Recipient` 字段，而*不是* `Audience` 字段。

**saml:commonName[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `commonName` 属性。

**saml:cn[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:doc**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这代表担任角色所用的主体。格式为 *account-ID*/*provider-friendly-name*，例如 `123456789012/SAMLProviderName`。*账户 ID* 值指拥有 [SAML 提供商](id_roles_providers_create_saml.md)的账户。

**saml:edupersonaffiliation[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonassurance[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonentitlement[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonnickname[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonorgdn**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonorgunitdn[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonprimaryaffiliation**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonprimaryorgunitdn**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonprincipalname**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersonscopedaffiliation[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:edupersontargetedid[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduPerson` 属性。

**saml:eduorghomepageuri[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:eduorgidentityauthnpolicyuri[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:eduorglegalname[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:eduorgsuperioruri[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:eduorgwhitepagesuri[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `eduOrg` 属性。

**saml:givenName[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `givenName` 属性。

**saml:iss**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
发布者，以 URN 表示。

**saml:mail[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `mail` 属性。

**saml:name[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `name` 属性。

**saml:namequalifier**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
基于 SAML 提供商的友好名称的哈希值。该值是以下值按顺序的连接，以“/”字符分隔：  

1. `Issuer` 响应值 (`saml:iss`)

1. `AWS` 账户 ID

1.  IAM 中 SAML 提供商的友好名称（ARN 的最后一部分） 
账户 ID 与 SAML 提供商的易记名称的串联可作为键 `saml:doc` 供 IAM policy 使用。有关更多信息，请参阅 [唯一标识基于 SAML 的联合中的用户](id_roles_providers_saml.md#CreatingSAML-userid)。

**saml:organizationStatus[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `organizationStatus` 属性。

**saml:primaryGroupSID[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `primaryGroupSID` 属性。

**saml:sub**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是该陈述的主题，其中包含唯一标识组织中某个用户的值 (例如 `_cbb88bf52c2510eabe00c1642d4643f41430fe25e3`)。

**saml:sub\$1type**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
此键的值可以是 `persistent`、`transient` 或由 SAML 断言中使用的 `Format` 和 `Subject` 元素的完整 `NameID` URI 构成。`persistent` 值表示在不同会话之间用户的 `saml:sub` 值是相同的。如果值为 `transient`，则用户在每个会话中拥有不同的 `saml:sub` 值。有关 `NameID` 元素的 `Format` 属性的信息，请参阅[为身份验证响应配置 SAML 断言。](id_roles_providers_create_saml_assertions.md)。

**saml:surname[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `surnameuid` 属性。

**saml:uid[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `uid` 属性。

**saml:x500UniqueIdentifier[]**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是 `x500UniqueIdentifier` 属性。

有关 `eduPerson` 和 `eduOrg` 属性的一般信息，请参阅 [REFEDS Wiki 网站](https://wiki.refeds.org/display/STAN/eduPerson)。有关 `eduPerson` 属性的列表，请参阅 [eduPerson 对象类规范 (201602)](https://software.internet2.edu/eduperson/internet2-mace-dir-eduperson-201602.html)。

列表类型的条件键可以包含多个值。要在策略中创建条件以获取列表值，可以使用[集合运算符](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)（`ForAllValues`、`ForAnyValue`）。例如，要支持从属关系为“教员”或“职员”（而非“学生”）的用户，可以使用下面这样的条件：

```
"Condition": {
   "ForAllValues:StringLike": {
     "saml:edupersonaffiliation":[ "faculty", "staff"] 
   }
}
```

## 基于 SAML 的跨服务 Amazon STS 联合身份验证上下文键
<a name="cross-condition-keys-saml"></a>

一些基于 SAML 的联合身份验证条件键可用于后续请求中，以授权其他服务和 `AssumeRole` 调用中的 Amazon 操作。以下是条件键，当联合主体担任其他角色时，可以在角色信任策略中使用它们，也可以在其他 Amazon 服务的资源策略中使用它们来授权联合主体访问资源。有关使用这些键的更多信息，请参阅[关于基于 SAML 2.0 的联合身份验证](https://docs.amazonaws.cn/IAM/latest/UserGuide/id_roles_providers_saml.html#CreatingSAML-userid)。

选择条件键以查看描述。
+ [saml:namequalifier](#ck_saml-namequalifier)
+ [saml:sub](#ck_saml-sub)
+ [saml:sub_type](#ck_saml-subtype)

**注意**  
在初始外部身份提供者（IdP）身份验证响应后，没有其他基于 SAML 的联合身份验证条件键可供使用。

## Amazon STS 的可用键
<a name="condition-keys-sts"></a>

您可以对使用 Amazon Security Token Service (Amazon STS) 操作担任的角色使用 IAM 角色信任策略中的以下条件键。

**saml:sub**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
这是该陈述的主题，其中包含唯一标识组织中某个用户的值 (例如 `_cbb88bf52c2510eabe00c1642d4643f41430fe25e3`)。

**sts:AWSServiceName**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键指定可以在其中使用持有者令牌的服务。在策略中使用此条件键时，请使用服务主体指定服务。服务主体是可在策略的 `Principal` 元素中指定的服务的名称。例如，`codeartifact.amazonaws.com` 是 Amazon CodeArtifact 服务主体。  
**Availability**（可用性）- 此键存在于获取持有者令牌的请求中。您不能直接调用 Amazon STS 以获取持有者令牌。当您在其他服务中执行某些操作时，服务代表您请求持有者令牌。  
某些 Amazon 服务需要您有权获取 Amazon STS 服务持有者令牌，然后您才能以编程方式访问它们的资源。例如，Amazon CodeArtifact 要求主体使用持有者令牌来执行某些操作。`aws codeartifact get-authorization-token` 命令返回一个持有者令牌。然后，您可以使用持有者令牌来执行 Amazon CodeArtifact 操作。有关持有者令牌的更多信息，请参阅 [服务持有者令牌](id_credentials_bearer.md)。  
您可以使用此条件键以允许主体获取用于特定服务的持有人令牌。

**sts:DurationSeconds**  
与[数字运算符](reference_policies_elements_condition_operators.md#Conditions_Numeric)结合使用。  
使用此键指定主体在从 [GetWebIdentityToken](https://docs.amazonaws.cn/STS/latest/APIReference/API_GetWebIdentityToken.html) API 获取 Amazon Amazon STS 持有者令牌或 JSON Web 令牌时可以使用的持续时间（以秒为单位）。  
**可用性**：此键存在于从 GetWebIdentityToken API 获取持有者令牌或 JSON Web 令牌的请求中。您不能直接调用 Amazon STS 以获取持有者令牌。当您在其他服务中执行某些操作时，服务代表您请求持有者令牌。此键不适用于 Amazon STS assume-role 操作。  
某些 Amazon 服务需要您有权获取 Amazon STS 服务持有者令牌，然后您才能以编程方式访问它们的资源。例如，Amazon CodeArtifact 要求主体使用持有者令牌来执行某些操作。`aws codeartifact get-authorization-token` 命令返回一个持有者令牌。然后，您可以使用持有者令牌来执行 Amazon CodeArtifact 操作。有关持有者令牌的更多信息，请参阅 [服务持有者令牌](id_credentials_bearer.md)。

**sts:IdentityTokenAudience**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键指定 IAM 主体可以使用 [GetWebIdentityToken](https://docs.amazonaws.cn/STS/latest/APIReference/API_GetWebIdentityToken.html) API 向其请求 JSON Web 令牌（JWT）的受众。IAM 策略中存在此条件键时，IAM 主体只能为策略中指定的受众请求令牌。外部服务会验证 JSON Web 令牌中的受众（“aud”）声明，以确保该令牌是为其准备的。  
**可用性**：此键存在于 GetWebIdentityToken API 的请求中，该 API 用于获取通过外部服务进行身份验证的 JSON Web 令牌（JWT）。  
在策略中使用此条件键时，请指定与目标收件人的标识符匹配的受众值（例如 https://api.example.com）。  
以下示例策略将允许主体请求指定外部服务的令牌：  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "sts:GetWebIdentityToken",
            "Resource": "*",
            "Condition": {
                "ForAnyValue:StringEquals": {
                    "sts:IdentityTokenAudience": [
                        "https://api2.example.com",
                        "https://api1.example.com"
                    ]
                }
            }
        }
    ]
}
```

**sts:SigningAlgorithm**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键指定 Amazon Amazon STS 用于签署 [GetWebIdentityToken](https://docs.amazonaws.cn/STS/latest/APIReference/API_GetWebIdentityToken.html) API 生成的 JSON Web 令牌（JWT）的加密算法。在策略中使用此条件键时，请指定 ES384（带有 P-384 曲线和 SHA-384 的 ECDSA）或 RS256（带有 SHA-256 的 RSA）。  
**可用性**：此键存在于 GetWebIdentityToken API 的请求中，该 API 用于获取通过外部服务进行身份验证的 JSON Web 令牌（JWT）。  
您可以使用此条件键强制要求 IAM 主体使用与您的安全要求或与您集成的外部服务兼容的签名算法来请求令牌。ES384 提供最佳安全性和性能，而 RS256 则提供与不支持 ECDSA 的系统更广泛的兼容性。  
以下示例策略要求主体使用 ES384 签名算法：  

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "sts:GetWebIdentityToken",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "sts:SigningAlgorithm": "ES384"
                }
            }
        }
    ]
}
```

**sts:ExternalId**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键可要求主体在代入 IAM 角色时提供特定标识符。  
**可用性** - 如果主体在使用 Amazon CLI 或 Amazon API 代入角色时提供外部 ID，则请求中存在此键。  
在其他账户中担任角色时可能需要的唯一标识符。如果角色所属的账户的管理员为您提供了外部 ID，请在 `ExternalId` 参数中提供该值。该值可以是任意字符串，如密码或账号。外部 ID 的主要功能是解决并防止混淆代理人问题。有关外部 ID 和混淆代理人问题的更多信息，请参阅[访问第三方拥有的 Amazon Web Services 账户](id_roles_common-scenarios_third-party.md)。  
`ExternalId` 值的长度必须最少为 2 个字符，最多为 1224 个字符。该值必须是字母数字，没有空格。它还可以包含以下符号：加号 (\$1)、等号 (=)、逗号 (,)、句点 (.)、@ 符号、冒号 (:)、正斜杠 (/) 和连字符 (-)。

**sts:RequestContext/*context-key***  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用该键可将在请求中传递的可信令牌颁发者签名上下文断言中嵌入的会话上下文键值对与角色信任策略中指定的上下文键值进行比较。  
**可用性** – 如果在使用 Amazon STS [AssumeRole](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRole.html) API 操作代入了角色，则在 `ProvidedContexts` 请求参数中提供上下文断言时，该请求中存在该键。  
此上下文键的格式为 `"sts:RequestContext/context-key":"context-value"`，其中 `context-key` 和 `context-value` 是上下文键值对。在请求中传递的已签名上下文断言中嵌入多个上下文键时，每个键值对都有一个上下文键。您必须在角色信任策略中授予 `sts:SetContext` 操作的权限，才能允许主体在生成的会话令牌中设置上下文键。要详细了解可与此键一起使用的支持的 IAM Identity Center 上下文键，请参阅*Amazon IAM Identity Center用户指南*中的 [IAM Identity Center 的 Amazon STS 条件键](https://docs.amazonaws.cn/singlesignon/latest/userguide/condition-context-keys-sts-idc.html)。  
您可以在角色信任策略中使用该键，以在用户代入角色时根据用户或其属性实施精细的访问控制。代入该角色后，活动将在 Amazon CloudTrail 日志的 `AdditionalEventData` 属性中显示，其中包含由上下文提供程序在代入角色请求中设置的会话上下文键值对。这样，当不同的主体使用角色时，管理员可以更轻松地区分角色会话。键值对由指定的上下文提供程序设置，而不是由 Amazon CloudTrail 或 Amazon STS 设置。这使上下文提供程序可以控制 CloudTrail 日志和会话信息中包含哪些上下文。

**sts:RequestContextProviders**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
使用该键可将请求中的上下文提供程序 ARN 与角色信任策略中指定的上下文提供程序 ARN 进行比较。  
**可用性** – 如果在使用 Amazon STS [AssumeRole](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRole.html) API 操作代入了角色，则在 `ProvidedContexts` 请求参数中提供上下文断言时，该请求中存在该键。  
以下示例条件检查请求中传递的上下文提供程序 ARN 是否与角色信任策略条件中指定的 ARN 匹配。我们建议您使用 `ForAllValues` 添加一个空检查，以防止缺少上下文键或具有空值的上下文键的计算结果为 true。有关更多信息，请参阅 [用于检查条件键是否存在的条件运算符](reference_policies_elements_condition_operators.md#Conditions_Null)。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Action": "sts:SetContext",
    "Effect": "Allow",
    "Resource": "*",
    "Condition": {
      "ForAllValues:ArnEquals": {
        "sts:RequestContextProviders": [
          "arn:aws:iam::aws:contextProvider/IdentityCenter"
        ]
      },
      "Null": {
        "sts:RequestContextProviders": "false"
      }
    }
  }
}
```

**sts:RoleSessionName**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键可将主体在代入角色时指定的会话名称与策略中指定的值进行比较。  
**可用性** - 当主体使用 Amazon Web Services 管理控制台 管理控制台、assume-role CLI 命令或 Amazon STS `AssumeRole` API 操作代入角色时，则请求中存在此键。  
您可以在角色信任策略中使用此键，以要求您的用户在代入角色时提供特定的会话名称。例如，您可以要求 IAM 用户指定自己的用户名作为其会话名称。在 IAM 用户代入角色后，活动将与匹配用户名的会话名称一起显示在 [Amazon CloudTrail 日志](cloudtrail-integration.md#cloudtrail-integration_signin-tempcreds)中。这样，当不同的主体使用角色时，管理员可以更轻松地区分角色会话。  
以下角色信任策略要求账户 `111122223333` 中的 IAM 用户在代入角色时提供其 IAM 用户名作为会话名称。使用条件键中的 `aws:username` [条件变量](reference_policies_variables.md)来强制执行此要求。此策略允许 IAM 用户代入策略附加到的角色。此策略禁止任何使用临时凭证的人员代入角色，因为 `username` 变量仅适用于 IAM 用户。  
您可以使用任何可用的单值条件密钥作为[变量](reference_policies_variables.md)。您不能使用多值条件键作为变量。  
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "RoleTrustPolicyRequireUsernameForSessionName",
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Principal": {"AWS": "arn:aws:iam::111122223333:root"},
            "Condition": {
                "StringLike": {"sts:RoleSessionName": "prefix-${aws:username}"}
            }
        }
    ]
}
```
当管理员查看操作的 Amazon CloudTrail 日志时，他们可以将会话名称与其账户中的用户名进行比较。在以下示例中，名为 `matjac` 的用户使用名为 `MateoRole` 的角色执行操作。之后，管理员会联系具有名为 `matjac` 用户的 Mateo Jackson。  

```
    "assumedRoleUser": {
        "assumedRoleId": "AROACQRSTUVWRAOEXAMPLE:matjac",
        "arn": "arn:aws:sts::111122223333:assumed-role/MateoRole/matjac"
    }
```
如果您允许[使用角色进行跨账户访问](id_roles_common-scenarios_aws-accounts.md)，则一个账户中的用户可以代入另一个账户中的角色。CloudTrail 中列出的代入角色的 ARN 包括*角色所在*的账户。它不包括已代入角色的用户的账户。用户仅在账户中是唯一的。因此，我们建议您使用此方法以仅在 CloudTrail 日志中查看您管理的账户中的用户所代入的角色。您的用户可以在多个账户中使用相同的用户名。

**sts:SourceIdentity**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键可将主体在代入角色时指定的源身份与策略中指定的值进行比较。  
**可用性** — 如果主体提供源身份，同时担任使用任何 Amazon STS 担任角色 CLI 命令或 Amazon STS `AssumeRole` API 操作时，此密钥将会出现在请求中。  
您可以在角色信任策略中使用此键，以要求您的用户在代入角色时设置特定的源身份。例如，您可以要求您的工作人员或联合身份为源身份指定值。您可以将身份提供程序 (IdP) 配置为使用与用户关联的属性之一（例如用户名或电子邮件）作为源身份。然后，IdP 会将源身份作为其发送的断言或声明中的一个属性传递给 Amazon。源身份属性的值标识担任角色的用户或应用程序。  
在用户担任角色后，活动将在使用已设置源身份值的 [Amazon CloudTrail 日志](cloudtrail-integration.md#cloudtrail-integration_signin-tempcreds)中出现。这使管理员能够更轻松地确定什么角色在 Amazon 中执行了操作。您必须授予 `sts:SetSourceIdentity` 操作相应权限以允许身份设置源身份。  
与 [`sts:RoleSessionName`](#ck_rolesessionname) 不同，在设置源身份后，无法更改该值。它将存在于源身份对角色执行的所有操作的请求上下文中。当您使用会话凭证担任另一个角色时，该值将保留到后续角色会话中。从一个角色代入另一个角色的过程称为[角色链](id_roles.md#iam-term-role-chaining)。  
您可以使用 [`aws:SourceIdentity`](reference_policies_condition-keys.md#condition-keys-sourceidentity) 全局条件键根据后续请求中源身份的值进一步控制对 Amazon 资源的访问权限。  
以下角色信任策略允许 IAM 用户 `AdminUser` 在账户中担任角色 `111122223333`。它还会向 `AdminUser` 授予权限来设置源身份，只要源身份设置为 `DiegoRamirez` 即可。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowAdminUserAssumeRole",
            "Effect": "Allow",
            "Principal": {"AWS": " arn:aws:iam::111122223333:user/AdminUser"},
            "Action": [
                "sts:AssumeRole",
                "sts:SetSourceIdentity"
            ],
            "Condition": {
                "StringEquals": {"sts:SourceIdentity": "DiegoRamirez"}
            }
        }
    ]
}
```
要了解有关使用源身份信息的更多信息，请参阅 [监控和控制使用所担任角色执行的操作](id_credentials_temp_control-access_monitor.md)。

**sts:TaskPolicyArn**  
与 [ARN 运算符](reference_policies_elements_condition_operators.md#Conditions_ARN)结合使用。  
使用该键可将 [sts:AssumeRoot](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRoot.html) 请求中的策略 ARN 与在策略中指定的策略 ARN 进行比较。  
**可用性**：当您使用 [sts:AssumeRoot](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRoot.html) 发出请求时，此键会出现在请求中。  
管理员可以在 IAM 策略中使用此条件键，限制管理账户或委托管理员账户中的特定角色或用户使用根凭证执行某些操作。有关更多信息，请参阅 [在 Amazon Organizations 成员账户上执行特权任务](id_root-user-privileged-task.md)。

**sts:TransitiveTagKeys**  
与[字符串运算符](reference_policies_elements_condition_operators.md#Conditions_String)结合使用。  
使用此键将请求中的可传递会话标签键，与在策略中指定的键进行比较。  
**Availability**（可用性）- 使用临时安全凭证发出请求时，请求中存在此密钥。这些凭证包括使用任何 assume-role 操作或 `GetFederationToken` 操作创建的凭证。  
当您使用临时安全凭证发出请求时，[请求上下文](reference_policies_elements_condition.md#AccessPolicyLanguage_RequestContext)包含 `aws:PrincipalTag` 上下文密钥。此键包括[会话标签](id_session-tags.md)、[可传递会话标签](id_session-tags.md#id_session-tags_role-chaining)和角色标签的列表。可传递会话标签是当您使用会话凭证代入另一个角色时，持续传递到所有后续会话中的标记。从一个角色代入另一个角色的过程称为[角色链](id_roles.md#iam-term-role-chaining)。  
您可以在策略中使用此条件键，以便要求在代入角色或联合身份用户身份时，要求将特定会话标签设置为可传递标签。