-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.yaml
96 lines (90 loc) · 3.09 KB
/
iam.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
AWSTemplateFormatVersion: "2010-09-09"
Description: "IAM resources for the Bad Bots component."
Metadata:
Tags:
CostCenter: "hosting-deployment"
Parameters:
AppGroup:
Type: "String"
Default: "bad-bots"
Description: "The name of the AppGroup"
AllowedPattern: "^[a-z0-9\\-]{1,32}$"
Environment:
Type: "AWS::SSM::Parameter::Value<String>"
Default: "/global/environment"
Region:
Description: "Specify the region"
Type: "String"
Default: "eu-west-1"
AllowedValues:
- "eu-west-1"
Conditions:
isTestingEnvironment: !Equals [ !Ref Environment, testing ]
Resources:
BadBotsManagedPolicyAWSWAFv2GetUpdateIPSet:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: !Sub "Policy for managing WAFv2 IP blocklist ${AppGroup}"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "wafv2:GetIPSet"
- "wafv2:UpdateIPSet"
Resource:
- !Sub "arn:aws:wafv2:${Region}:${AWS::AccountId}:regional/ipset/ip_set_bad_bots_ipv4/*"
- !Sub "arn:aws:wafv2:${Region}:${AWS::AccountId}:regional/ipset/ip_set_bad_bots_ipv6/*"
- !If
- isTestingEnvironment
- !Sub "arn:aws:wafv2:${Region}:${AWS::AccountId}:regional/ipset/ip_set_bad_bots_ipv4_test/*"
- !Ref AWS::NoValue
- !If
- isTestingEnvironment
- !Sub "arn:aws:wafv2:${Region}:${AWS::AccountId}:regional/ipset/ip_set_bad_bots_ipv6_test/*"
- !Ref AWS::NoValue
BadBotsManagedPolicyAWSWAFv2ListIPSet:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: !Sub "Policy for managing WAFv2 IP blocklist ${AppGroup}"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "wafv2:ListIPSets"
Resource: "*"
BadBotsParserLambdaRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: !Sub "${AppGroup}-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- !ImportValue "default-lambda-managed-policy-arn"
- !Ref "BadBotsManagedPolicyAWSWAFv2GetUpdateIPSet"
- !Ref "BadBotsManagedPolicyAWSWAFv2ListIPSet"
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
PermissionsBoundary: !ImportValue "iam-boundary-application-deployment-permission-boundary"
Tags:
- Key: "AppGroup"
Value: !Ref "AppGroup"
- Key: "AppRole"
Value: "role"
- Key: "Environment"
Value: !Ref "Environment"
- Key: "Name"
Value: !Sub "${AppGroup}-role"
Outputs:
BadBotsLambdaRole:
Description: "The role ARN that should be used by the bad-bots lambda"
Value: !GetAtt "BadBotsParserLambdaRole.Arn"
Export:
Name: !Sub "${AppGroup}-iam-role-arn"