【问题标题】:FederatedPrincipal with multiples Actions具有多个操作的联合主体
【发布时间】:2021-04-07 21:39:41
【问题描述】:

我正在尝试在 aws-cdk 中创建一个带有多个 ActionFederatedPrincipal,如下所示:

目前,我在c#中这样做(如下所示)

new FederatedPrincipal("cognito-identity.amazonaws.com", new Dictionary<string, object>
{
    { "ForAnyValue:StringLike", new Dictionary<string,string> { ["cognito-identity.amazonaws.com:amr"] = "authenticated" } },
    { "StringEquals", new Dictionary<string,string> { ["cognito-identity.amazonaws.com:aud"] = cfn_identitypool.Ref } }
}, "sts:AssumeRoleWithWebIdentity");

如何添加第二个操作 - sts:TagSession

【问题讨论】:

标签: amazon-web-services amazon-cloudformation aws-cdk


【解决方案1】:

目前使用高级构造是不可能的。看到这个仍未解决的问题:https://github.com/aws/aws-cdk/issues/6699

TL;DR

IPrincipal 要求 assumeRoleAction 是一个字符串。但是你需要的是一个数组。看起来它已被搁置,因为这意味着团队不想引入一个破坏 BC 的更改。

我最终得到的是使用低级构造CfnRole。我使用 TypeScript,但将其移植到 C# 应该很简单。

const authenticatedRole = new iam.CfnRole(this, 'AuthenticatedRole', {
    assumeRolePolicyDocument: {
        'Statement': [{
            'Effect': iam.Effect.ALLOW,
            'Action': ['sts:AssumeRoleWithWebIdentity', 'sts:TagSession'],
            'Condition': {
                'StringEquals': {
                    'cognito-identity.amazonaws.com:aud': identityPool.getAtt('Ref')
                },
                'ForAnyValue:StringLike': {
                    'cognito-identity.amazonaws.com:amr': 'authenticated'
                }
            },
            'Principal': {
                'Federated': 'cognito-identity.amazonaws.com'
            }
        }]
    }
});

const roleAttachment = new cognito.CfnIdentityPoolRoleAttachment(this, 'RoleAttachment', {
    identityPoolId: identityPool.getAtt('Ref').toString(),
    roles: {
        'authenticated': authenticatedRole.getAtt('Arn'),
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 1970-01-01
    • 2016-06-06
    • 2022-07-30
    • 2017-02-24
    相关资源
    最近更新 更多