amazon-web-services - 限制登录到 AWS 联合身份池的企业 Google 域
问题描述
我正在使用带有 aws-amplify ( https://aws.github.io/aws-amplify/media/authentication_guide#enabling-federated-identities ) 的联合身份池,并且我想将域的范围限制为我的 google 域组织(例如 johndoe@foobar.com)。
似乎没有办法将其锁定在 Google API 控制台或 AWS Cognito 身份池设置中,只是提示可以将 hd 参数附加到 google 请求以按域限制它(仍然需要修改 aws-amplify 核心包),它仍然不安全,因为任何人都可以在没有 hd 的情况下发出相同的请求并获得对 cognito 的访问权限。
我的问题是:有没有办法将 google oauth 密钥限制为仅允许 @foobar.com 电子邮件地址,或者使用 aws cognito 实施相同的限制?
解决方案
我相信我找到了解决方案(通过几次快速测试,它似乎工作正常)
不要试图通过角色中的信任关系来控制托管域部分。
转到:Cognito / 编辑身份池 / 身份验证提供程序
选择谷歌+
在“经过身份验证的角色选择”中选择“使用规则选择角色”
现在要求声明“hd”“等于”
<your-domain>
将“角色解析”设置为“拒绝”
来源:https ://forums.aws.amazon.com/thread.jspa?messageID=527303
这是一个 cloudformation 堆栈,可以一次性设置所有内容(身份池、角色等)。您需要在所有标有注释的地方进行必要的调整。EDIT HERE:
AWSTemplateFormatVersion : 2010-09-09
Description : "An Identity Pool stack which uses Google for sign-in"
Resources:
IdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: identity_pool_a
AllowUnauthenticatedIdentities: false
SupportedLoginProviders:
# EDIT HERE:
"accounts.google.com": "11111111111-22222222222222222222222222222222.apps.googleusercontent.com"
IdentityForbiddenRole:
Type: AWS::IAM::Role
Properties:
MaxSessionDuration: 3600
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud": !Ref IdentityPool
ForAnyValue:StringLike:
"cognito-identity.amazonaws.com:amr": unauthenticated
Policies:
- PolicyName: None
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Deny
Action: "*"
Resource: "*"
IdentityAllowedRole:
Type: AWS::IAM::Role
Properties:
MaxSessionDuration: 3600
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud": !Ref IdentityPool
ForAnyValue:StringLike:
"cognito-identity.amazonaws.com:amr": authenticated
Policies:
- PolicyName: UserPermissions
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
# EDIT HERE:
Action: "s3:GetObject"
# EDIT HERE:
Resource: "arn:aws:s3:::my-bucket/*"
RoleAttachment:
Type: AWS::Cognito::IdentityPoolRoleAttachment
Properties:
IdentityPoolId: !Ref IdentityPool
Roles:
unauthenticated: !GetAtt IdentityForbiddenRole.Arn
authenticated: !GetAtt IdentityForbiddenRole.Arn
RoleMappings:
accounts.google.com:
AmbiguousRoleResolution: Deny
Type: Rules
RulesConfiguration:
Rules:
- Claim: hd
MatchType: Equals
# EDIT HERE:
Value: mydomain.com
RoleARN: !GetAtt IdentityAllowedRole.Arn
推荐阅读
- cx-oracle - cx_Oracle 连接 - 具有负载平衡的连接字符串
- php - 修改wordpress主题php链接
- c++ - 具有空定义的模板特化
- php - 带有闭包 CURL 标头的 PHP 类方法
- npm - 发布 npm 包的部署工作流程
- java - 如何检查文件是否存在于 java 中的 Azure Blob 容器中
- c# - 在 Linux 中找不到 PL2303 设备的序列号属性
- excel - 在 Countifs 中使用 ABS 函数
- apache-kafka - Kafka中'metric.reporters'和'kafka.metrics.reporters'属性之间的区别
- sql - R在读取数据帧时复制大整数