This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
template.yml
109 lines (107 loc) · 2.94 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
ecs_cosign_verify
Template for ecs_cosign_verify
Globals:
Function:
Timeout: 5
Parameters:
KeyArn:
Type: String
Default: ""
KeyPem:
Type: String
Default: ""
Conditions:
IsKeyArn: !Not [!Equals [!Ref KeyArn, ""]]
Resources:
TeamNotificationTopic:
Type: AWS::SNS::Topic
Properties:
KmsMasterKeyId: !GetAtt TeamNotificationTopicKey.Arn
TeamNotificationTopicKey:
Type: AWS::KMS::Key
Properties:
KeyPolicy:
Statement:
- Action: kms:*
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Resource: '*'
EnableKeyRotation: true
KmsAccess:
Type: AWS::IAM::Policy
Condition: IsKeyArn
Properties:
PolicyDocument:
Effect: Allow
Action:
- kms:GetPublicKey
- kms:DescribeKey
Resource: !Ref KeyArn
PolicyName: KmsAccess
Roles:
- !GetAtt ECSApprovedContainerRegistryFunction.Role
ECSApprovedContainerRegistryFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: cosign-ecs-function/
Handler: cosign-ecs-function
Runtime: go1.x
Timeout: 20
Environment:
Variables:
SNS_TOPIC_ARN: !Ref TeamNotificationTopic
COSIGN_KEY_ARN: !Ref KeyArn
COSIGN_KEY_PEM: !Ref KeyPem
Tracing: Active
MemorySize: 512
Policies:
- AWSXrayWriteOnlyAccess
- AWSLambdaBasicExecutionRole
- SNSPublishMessagePolicy:
TopicName:
!Ref TeamNotificationTopic
- Statement: # Stop unauthorized tasks
- Sid: ECSTaskPolicy
Effect: Allow
Action:
- ecs:StopTask
Resource: !Sub 'arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task/*'
- Statement: # KMS key for communication with SNS
- Sid: KMSPolicy
Effect: Allow
Action:
- kms:GenerateDataKey
- kms:Decrypt
Resource: !GetAtt TeamNotificationTopicKey.Arn
- Statement: # Cosign needs access images/signatures to verify.
- Sid: ECRPolicy
Effect: Allow
Action:
- ecr:*
Resource: '*'
- Statement: # Notify about invalid signatures via SNS
- Sid: SNSPublishPolicy
Effect: Allow
Action:
- sns:Publish
Resource: !Ref TeamNotificationTopic
Events:
Trigger:
Type: CloudWatchEvent
Properties:
Pattern:
source:
- aws.ecs
detail-type:
- ECS Task State Change
- ECS Container Instance State Change
detail:
desiredStatus:
- RUNNING
- PENDING
- ACTIVATING
- PROVISIONING