forked from org-formation/org-formation-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross-account-bucket.yml
165 lines (145 loc) · 4.92 KB
/
cross-account-bucket.yml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
AWSTemplateFormatVersion: '2010-09-09-OC'
# Include file that contains Organization Section.
# The Organization Section describes Accounts, Organizational Units, etc.
Organization: !Include ../organization.yml
# Any Binding that does not explicitly specify a region will default to this.
# Value can be either string or list
DefaultOrganizationBindingRegion: eu-central-1
Parameters:
resourcePrefix:
Type: String
Default: my
bucketName:
Type: String
# Section contains a named set of Bindings.
# Bindings determine what resources are deployed where
# These bindings can be !Ref'd from the Resources in the resource section
OrganizationBindings:
# Binding for: Bucket, BucketPolicy
BucketAccountBinding:
Account: !Ref SharedServicesAccount
# Binding for: S3BucketReadAccessPolicy
ReadAccessAccountBinding: # null = empty binding
# Binding for: S3BucketWriteAccessPolicy
WriteAccessAccountBinding: # null = empty binding
# Binding for: S3BucketFullAccessPolicy
FullAccessAccountBinding: # null = empty binding
Conditions:
CreateReadBucketPolicy: !Not [ !Equals [ Fn::TargetCount ReadAccessAccountBinding, 0 ] ]
CreateWriteBucketPolicy: !Not [ !Equals [ Fn::TargetCount WriteAccessAccountBinding, 0 ] ]
CreateFullAccessBucketPolicy: !Not [ !Equals [ Fn::TargetCount FullAccessAccountBinding, 0 ] ]
Resources:
Bucket:
Type: AWS::S3::Bucket
OrganizationBinding: !Ref BucketAccountBinding
DeletionPolicy: Retain
Properties:
BucketName: !Sub '${bucketName}'
AccessControl: Private
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketReadPolicy:
Type: AWS::S3::BucketPolicy
OrganizationBinding: !Ref BucketAccountBinding
Condition: CreateReadBucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Statement:
- Sid: 'Read operations on bucket'
Action:
- s3:Get*
- s3:List*
Effect: "Allow"
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'
Principal:
AWS: Fn::EnumTargetAccounts ReadAccessAccountBinding arn:aws:iam::${account}:root
BucketWritePolicy:
Type: AWS::S3::BucketPolicy
OrganizationBinding: !Ref BucketAccountBinding
Condition: CreateWriteBucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Statement:
- Sid: 'Write operations on bucket'
Action:
- s3:Put*
Effect: "Allow"
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'
Principal:
AWS: Fn::EnumTargetAccounts WriteAccessAccountBinding arn:aws:iam::${account}:root
BucketFullAccessPolicy:
Type: AWS::S3::BucketPolicy
OrganizationBinding: !Ref BucketAccountBinding
Condition: CreateFullAccessBucketPolicy
Properties:
Bucket: !Ref Bucket
PolicyDocument:
Statement:
- Sid: 'Any operation on bucket'
Action:
- s3:*
Effect: "Allow"
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'
Principal:
AWS: Fn::EnumTargetAccounts FullAccessAccountBinding arn:aws:iam::${account}:root
S3BucketReadAccessPolicy:
Type: AWS::IAM::ManagedPolicy
OrganizationBinding: !Ref ReadAccessAccountBinding
Condition: CreateReadBucketPolicy
Properties:
ManagedPolicyName: !Sub '${resourcePrefix}-${bucketName}-read-policy'
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:Get*
- s3:List*
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'
S3BucketWriteAccessPolicy:
Type: AWS::IAM::ManagedPolicy
OrganizationBinding: !Ref WriteAccessAccountBinding
Condition: CreateWriteBucketPolicy
Properties:
ManagedPolicyName: !Sub '${resourcePrefix}-${bucketName}-write-policy'
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:Put*
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'
S3BucketFullAccessPolicy:
Type: AWS::IAM::ManagedPolicy
OrganizationBinding: !Ref FullAccessAccountBinding
Condition: CreateFullAccessBucketPolicy
Properties:
ManagedPolicyName: !Sub '${resourcePrefix}-${bucketName}-fullaccess-policy'
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub '${Bucket.Arn}'
- !Sub '${Bucket.Arn}/*'