监控临时安全凭证
在华为云中执行操作时,有关调用日志可以记录到CTS中供账号管理员监控。管理员可以在配置信任委托时,要求调用AssumeAgency API时传递一个自定义字符串来标识在华为云中执行操作的人员或应用程序。这个字符串作为源身份(Source Identity)信息存储在CTS中。当管理员查看CTS中的活动时,可以通过源身份信息确定是谁切换了信任委托来执行了操作。
源身份信息设置后,会在该信任委托会话期间内执行的任何华为云操作请求中存在。通过AssumeAgency API使用一个信任委托切换到另一个信任委托(称为委托链)时,源身份信息在第一次设置后便不可更改,该值会持续传递。管理员可以根据源身份的存在或值配置身份策略,以进一步控制使用信任委托执行的华为云操作。您可以决定是否必须使用该属性以及可以使用什么值。
设置源身份信息所需要的权限
sts::setSourceIdentity
- 在IAM用户切换信任委托的场景中,要指定源身份信息,IAM用户的身份策略和信任委托的信任策略都必须包含sts::setSourceIdentity权限。
- 在信任委托切换信任委托的场景中,要指定源身份信息,发起切换的信任委托的身份策略和目标信任委托的信任策略都必须包含sts::setSourceIdentity权限。
{
"Version": "5.0",
"Statement": [{
"Effect": "Allow",
"Action": [
"sts:agencies:assume",
"sts::setSourceIdentity"
],
"Condition": {
"StringEquals": {
"sts:SourceIdentity": [
"${g:UserName}"
]
}
}
}]
} {
"Version": "5.0",
"Statement": [{
"Effect": "Allow",
"Action": [
"sts:agencies:assume",
"sts::setSourceIdentity"
],
"Condition": {
"StringEquals": {
"sts:SourceIdentity": [
"${g:UserName}"
]
}
}
}]
} 在AssumeAgency API中使用源身份
AssumeAgency API支持通过委托或者信任委托获取临时安全凭证,可用于访问华为云资源。如果要在AssumeAgency API中传递源身份,除了在身份策略和信任策略中设置相关权限,您还需要在调用API时设置source_identity参数。这样,通过调用AssumeAgency API获取的临时安全凭证便包含了源身份信息,可以在后续委托链中进行传递。
在AssumeAgencyWithSAML API中使用源身份
- 在您的公司或组织账号中配置SAML身份提供商。
- 在IAM中创建一个SAML身份提供商。
- 在IAM中为您的SAML身份提供商配置信任委托及其权限。
- 完成SAML身份提供商的配置,并为SAML身份验证响应创建SAML断言。
要为源身份设置SAML属性,请包含 Attribute 元素,并将 Name 属性设置为https://www.huaweicloud.com/SAML/Attributes/SourceIdentity。使用 AttributeValue元素指定源身份的值,为正在使用信任委托的个人或应用程序提供一个身份标识符。当您使用SAML会话代入另一个信任委托时(此行为称为委托链),源身份的值会持续存在。在委托会话期间执行的每个操作请求中,都会包含源身份的值,且该值在会话期间无法被更改。
<Attribute Name="https://www.huaweicloud.com/SAML/Attributes/SourceIdentity"> <AttributeValue>ZhangSan</AttributeValue> </Attribute>
在AssumeAgencyWithOIDC API中使用源身份
AssumeAgencyWithOIDC API是基于OIDC身份提供商进行身份验证,该操作同样会返回一组临时安全凭证,可用于访问华为云资源。如果要在AssumeAgencyWithOIDC API传递源身份,必须在OIDC令牌中包含源身份字段。当您提交 AssumeAgencyWithOIDC请求时,请在令牌中的https://www.huaweicloud.com/source_identity命名空间下设置源身份。
{
"sub": "repo:example-labs/oidc-with-hwc:ref:refs/heads/main",
"aud": "sts.myhuaweicloud.com",
"jti": "ZYUCeRMQVtqHypVPWAN3VB",
"iss": "https://xxx.com",
"iat": 1767196800,
"exp": 1767197100,
"auth_time": 1767196800,
"https://www.huaweicloud.com/source_identity": "Admin"
} 使用源身份信息控制访问
最初设置源身份时,切换委托请求会验证sts:SourceIdentity条件键。设置源身份后,在该委托会话期间内发出的所有后续请求中都可以验证g:SourceIdentity条件键。作为管理员,您可以根据源身份是否存在或源身份的值编写策略,授予调用华为云API的条件授权。
{
"Version": "5.0",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "iam::111122223333:saml-provider:name-of-identity-provider"
},
"Action": [
"sts:agencies:assumeWithSAML"
],
"Condition": {
"StringEquals": {
"saml:aud": "https://auth.huaweiclcoud.com/saml/acs/{idp_id}"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Federated": "iam::111122223333:saml-provider:name-of-identity-provider"
},
"Action": [
"sts::SetSourceIdentity"
],
"Condition": {
"StringEquals": {
"sts:SourceIdentity": [
"ZhangSan",
"LiSi"
]
}
}
}
]
} {
"Version": "5.0",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "iam::111122223333:oidc-provider:name-of-identity-provider"
},
"Action": [
"sts:agencies:assumeWithOIDC",
"sts::SetSourceIdentity"
],
"Condition": {
"StringEquals": {
"oidc:aud": "android-app-id",
"oidc:iss": "https://www.sample.com",
"oidc:sub": "sub-sample",
"oidc:amr": [
"pwd",
"mfa"
],
"sts:SourceIdentity": [
"ZhangSan",
"LiSi"
]
}
}
}
]
} 在CTS中查看源身份信息
{
"api_version": "v5",
"code": "204",
"account_id": "xxxxxx",
"event_type": "global",
"message": "xxxxxx",
"operation_id": "DeleteUserV5",
"project_id": "xxxxxx",
"read_only": false,
"request_id": "xxxxxx",
"resource_account_id": "xxxxxx",
"resource_id": "xxxxxx",
"resource_name": "xxxxxx",
"resource_type": "user",
"service_type": "IAM",
"source_ip": "xxx.xxx.xxx.xxx",
"trace_id": "xxxxxx",
"trace_name": "deleteUserV5",
"trace_rating": "normal",
"trace_type": "ApiCall",
"tracker_name": "system",
"user_agent": "xxxxxx",
"is_consistent": true,
"user": {
"access_key_id": "xxxxxx",
"account_id": "xxxxxx",
"domain": {
"id": "xxxxxx",
"name": "xxxxxx"
},
"name": "xxxxxx/test",
"principal_id": "xxxxxx:name",
"principal_urn": "sts::xxxxxx:assumed-agency:test/name",
"session_context": {
"assumed_by": {
"principal_id": "xxxxxx"
},
"attributes": {
"created_at": "xxxxxx",
"mfa_authenticated": "false"
},
"source_identity": "IAM User A"
},
"type": "AssumedAgency"
},
"response": "null",
"time": xxxxxx,
"record_time": xxxxxx
}