forked from hisashin0728/AmazonECRScanSecurityHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecr_scan.yaml
77 lines (77 loc) · 2.29 KB
/
ecr_scan.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
AWSTemplateFormatVersion: '2010-09-09'
Description: This Template will create Lambda Function for Amazon ECR Scan to Security Hub
Parameters:
PythonS3:
Type: "String"
Description: "Input S3 bucket that uploaded Lambda code"
Default: "s3bucket_of_yourlambda"
PythonCode:
Type: "String"
Description: "Check the python filename(default is lambda_function.py)"
Default: "lambda_function.zip"
Resources:
# Lambda作成
AmazonECRScan2SecurityHub:
Type: AWS::Lambda::Function
Properties:
FunctionName: AmazonECRScan2SecurityHub
Description: Get Amazon ECR Scan report and sent to Security Hub as converting ASFF format
Handler: lambda_function.lambda_handler
MemorySize: 128
Runtime: python3.7
Timeout: 180
Code:
S3Bucket: !Ref PythonS3
S3Key: !Ref PythonCode
Role:
Fn::GetAtt:
- LambdaRole
- Arn
# Lambdaのロール作成
LambdaRole:
Type: AWS::IAM::Role
Properties:
Policies:
- PolicyName: AmazonECRScan2SecurityHub-Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- cloudwatch:PutMetricData
- ecr:DescribeImageScanFindings
- securityhub:BatchImportFindings
Resource: '*'
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: { Service: lambda.amazonaws.com }
Action:
- sts:AssumeRole
ECREventRule:
Type: 'AWS::Events::Rule'
Properties:
Description: CloudWatch Events rule for SecurityHub to receive Amazon ECR Scan
EventPattern:
source:
- aws.ecr
detail-type:
- ECR Image Scan
State: ENABLED
Targets:
- Arn: !GetAtt AmazonECRScan2SecurityHub.Arn
Id: AmazonECRSHubTarget
LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref AmazonECRScan2SecurityHub
Principal: events.amazonaws.com
SourceArn: !GetAtt ECREventRule.Arn