-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsm-identity-pool.yaml
115 lines (109 loc) · 3.5 KB
/
bsm-identity-pool.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
AWSTemplateFormatVersion: "2010-09-09"
Description: An Amazon Cognito Identity Pool for BSM
Parameters:
IdentityPoolName:
Type: String
Default: 'BSM Users'
DeveloperProviderName:
Type: String
Default: 'login.bsm.pub'
BucketName:
Type: String
Default: 'bsm-user-media'
Resources:
CognitoIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
AllowUnauthenticatedIdentities: false
IdentityPoolName:
Ref: IdentityPoolName
DeveloperProviderName:
Ref: DeveloperProviderName
CognitoAuthenticatedRole:
Type: AWS::IAM::Role
Properties:
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: CognitoIdentityPool
ForAnyValue:StringLike:
cognito-identity.amazonaws.com:amr: authenticated
Path: "/"
Policies:
- PolicyName: 'userBucketAccess'
PolicyDocument:
Version: '2012-10-17'
Statement:
# Allow authenticated users to read files from main media bucket
- Effect: Allow
Action:
- s3:ListBucket
- s3:GetObject
Resource:
- Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: BucketName
- '/*'
- Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: BucketName
# Allow authenticated users to write to dedicated subdirectories
- Effect: Allow
Action:
- s3:PutObject
- s3:DeleteObject
Resource:
- Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: BucketName
- '/${cognito-identity.amazonaws.com:sub}'
- Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: BucketName
- '/${cognito-identity.amazonaws.com:sub}/*'
IdentityPoolManagerUser:
Type: AWS::IAM::User
Properties:
Policies:
- PolicyName: 'supportDeveloperAuthenticatedIdentities'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- cognito-identity:GetOpenIdTokenForDeveloperIdentity
- cognito-identity:LookupDeveloperIdentity
- cognito-identity:MergeDeveloperIdentities
- cognito-identity:UnlinkDeveloperIdentity
Resource:
- Fn::Join:
- ''
- - 'arn:aws:cognito-identity:*:*:identitypool/'
- Ref: CognitoIdentityPool
IdentityPoolManagerUserKeys:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref IdentityPoolManagerUser
IdentityPoolRoleAttachment:
Type: AWS::Cognito::IdentityPoolRoleAttachment
Properties:
IdentityPoolId: !Ref CognitoIdentityPool
Roles: {"authenticated": !GetAtt CognitoAuthenticatedRole.Arn}
Outputs:
AccessKey:
Value: !Ref IdentityPoolManagerUserKeys
Description: AWSAccessKeyId of new user
SecretKey:
Value: !GetAtt [IdentityPoolManagerUserKeys, SecretAccessKey]
Description: AWSSecretAccessKey of new user