forked from org-formation/org-formation-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudtrail.yml
102 lines (91 loc) · 3.25 KB
/
cloudtrail.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
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
# Section that contains a named list 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: S3Bucket, S3BucketPolicy
CloudTrailBucketBinding:
Account: !Ref SharedComplianceAccount
# Binding for: CloudTrail, CloudTrailLogGroup, CloudTrailLogGroupRole
CloudTrailBinding:
Account: '*'
IncludeMasterAccount: true
Resources:
CloudTrailS3Bucket:
OrganizationBinding: !Ref CloudTrailBucketBinding
DeletionPolicy: Retain
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub 'cloudtrail-${SharedComplianceAccount}'
CloudTrailS3BucketPolicy:
OrganizationBinding: !Ref CloudTrailBucketBinding
Type: AWS::S3::BucketPolicy
DependsOn: CloudTrailS3Bucket
Properties:
Bucket: !Ref CloudTrailS3Bucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: 'AWSCloudTrailAclCheck'
Effect: 'Allow'
Principal: { Service: 'cloudtrail.amazonaws.com' }
Action: 's3:GetBucketAcl'
Resource: !Sub 'arn:aws:s3:::${CloudTrailS3Bucket}'
- Sid: 'AWSCloudTrailWrite'
Effect: 'Allow'
Principal: { Service: 'cloudtrail.amazonaws.com' }
Action: 's3:PutObject'
Resource: !Sub 'arn:aws:s3:::${CloudTrailS3Bucket}/AWSLogs/*/*'
Condition:
StringEquals:
s3:x-amz-acl: 'bucket-owner-full-control'
CloudTrailLogGroup:
OrganizationBinding: !Ref CloudTrailBinding
Type: 'AWS::Logs::LogGroup'
Properties:
RetentionInDays: 14
LogGroupName: CloudTrail/audit-log
CloudTrailLogGroupRole:
OrganizationBinding: !Ref CloudTrailBinding
Type: 'AWS::IAM::Role'
Properties:
RoleName: AWSCloudTrailLogGroupRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AssumeRole1
Effect: Allow
Principal:
Service: 'cloudtrail.amazonaws.com'
Action: 'sts:AssumeRole'
Policies:
- PolicyName: 'cloudtrail-policy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AWSCloudTrailCreateLogStream
Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: !GetAtt 'CloudTrailLogGroup.Arn'
CloudTrail:
OrganizationBinding: !Ref CloudTrailBinding
Type: AWS::CloudTrail::Trail
DependsOn:
- CloudTrailS3BucketPolicy
- CloudTrailLogGroup
- CloudTrailLogGroupRole
Properties:
S3BucketName: !Ref CloudTrailS3Bucket
IsLogging: true
IncludeGlobalServiceEvents: true
IsMultiRegionTrail: true
CloudWatchLogsLogGroupArn: !GetAtt 'CloudTrailLogGroup.Arn'
CloudWatchLogsRoleArn: !GetAtt 'CloudTrailLogGroupRole.Arn'