cfn-guardian 0.6.12 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/docs/custom_checks/http.md +2 -0
- data/docs/custom_checks/log_group_metric_filters.md +12 -2
- data/docs/maintenance_mode.md +12 -4
- data/lib/cfnguardian/compile.rb +5 -3
- data/lib/cfnguardian/models/alarm.rb +1 -1
- data/lib/cfnguardian/models/check.rb +13 -2
- data/lib/cfnguardian/models/event.rb +2 -0
- data/lib/cfnguardian/resources/elastic_search.rb +1 -0
- data/lib/cfnguardian/resources/lambda.rb +2 -0
- data/lib/cfnguardian/resources/vpn_connection.rb +12 -1
- data/lib/cfnguardian/stacks/main.rb +47 -7
- data/lib/cfnguardian/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1417ef4853dc20a776837ec1fee0433449dd1f4fd5601081ca2602c8cc6b9f06
|
4
|
+
data.tar.gz: 5ff99a91ba3c512dca2cde401b0ce8c1ada0127c9e56928f7fde9ead8c4cc5b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3eed6e24561d7927408b771317a93d1fe421f784fd3b0e3260df790d710c90e1abe1749e856c0cbc3ec0ebe30a4842d40c3714f2943843e19c1f7eac215010d
|
7
|
+
data.tar.gz: 3851fe0ad73593f25bd0eff3a62031345b4214d5bff9384c072a11af93192308d548aca7f83525935602b4c794077f24462bccccf547cb8801d2b52cdc1d5de1
|
data/Dockerfile
CHANGED
data/docs/custom_checks/http.md
CHANGED
@@ -32,6 +32,8 @@ Resources:
|
|
32
32
|
Method: post
|
33
33
|
# specify headers using "key=value key=value"
|
34
34
|
Headers: content-type=application/json
|
35
|
+
# specify a useragent that contains spaces
|
36
|
+
UserAgent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Base2/Lambda
|
35
37
|
# pass in custom payload for the request
|
36
38
|
Payload: '{"name": "john"}'
|
37
39
|
```
|
@@ -15,10 +15,20 @@ Resources:
|
|
15
15
|
# Name of the cloud watch metric
|
16
16
|
- MetricName: MyFunctionErrors
|
17
17
|
# search pattern, see aws docs for syntax
|
18
|
-
Pattern: error
|
18
|
+
Pattern: 'error'
|
19
19
|
# metric to push to cloudwatch. Optional as it defaults to 1
|
20
20
|
MetricValue: 1
|
21
|
-
|
21
|
+
- Id: /prod/custom/app
|
22
|
+
# List of metric filters
|
23
|
+
MetricFilters:
|
24
|
+
# Name of the cloud watch metric
|
25
|
+
- MetricName: MyAppErrors
|
26
|
+
# search pattern, see aws docs for syntax
|
27
|
+
# note; any non-alphanumeric characters have to be wrapped in double quotes WITHIN single quotes
|
28
|
+
Pattern: '"Connection to ssl://mail.google.com:465 Timed Out"'
|
29
|
+
# metric to push to cloudwatch. Optional as it defaults to 1
|
30
|
+
MetricValue: 1
|
31
|
+
|
22
32
|
Templates:
|
23
33
|
LogGroup:
|
24
34
|
# use the MetricName name to override the alarm defaults
|
data/docs/maintenance_mode.md
CHANGED
@@ -8,8 +8,8 @@ Alarms can be provided to the function the following ways
|
|
8
8
|
Alarm names be provided by a space delimited list using the `--alarms` switch.
|
9
9
|
|
10
10
|
```bash
|
11
|
-
cfn-guardian disable-alarms --
|
12
|
-
cfn-guardian enable-alarms --
|
11
|
+
cfn-guardian disable-alarms --alarms alarm-1 alarm-2
|
12
|
+
cfn-guardian enable-alarms --alarms alarm-1 alarm-2
|
13
13
|
```
|
14
14
|
|
15
15
|
## Alarm Name Prefix
|
@@ -60,10 +60,16 @@ Resources:
|
|
60
60
|
StatusCode: 200
|
61
61
|
|
62
62
|
# Define the top level key
|
63
|
-
|
63
|
+
MaintenanceGroups:
|
64
64
|
|
65
65
|
# Define the group name
|
66
66
|
AppUpdate:
|
67
|
+
# Optionally set a schedule for enabling/disabling
|
68
|
+
Schedules:
|
69
|
+
Disable: '30 0 * * ? *'
|
70
|
+
Enable: '00 1 * * ? *'
|
71
|
+
#Optionally specify and set to true to enable logging on lambda
|
72
|
+
Debug: true
|
67
73
|
# Define the resource group
|
68
74
|
ECSService:
|
69
75
|
# define the alarms in the resource group
|
@@ -82,4 +88,6 @@ MaintenaceGroups:
|
|
82
88
|
```bash
|
83
89
|
cfn-guardian disable-alarms --group AppUpdate
|
84
90
|
cfn-guardian enable-alarms --group AppUpdate
|
85
|
-
```
|
91
|
+
```
|
92
|
+
|
93
|
+
Optionally add a Schedule for disabling and enabling alarm actions as shown in the example above to deploy a lambda function that will be invoked by event rules created with the given cron expressions.
|
data/lib/cfnguardian/compile.rb
CHANGED
@@ -61,7 +61,7 @@ module CfnGuardian
|
|
61
61
|
@composites = config.fetch('Composites',{})
|
62
62
|
@templates = config.fetch('Templates',{})
|
63
63
|
@topics = config.fetch('Topics',{})
|
64
|
-
@maintenance_groups = config.fetch('
|
64
|
+
@maintenance_groups = config.fetch('MaintenanceGroups', {})
|
65
65
|
@event_subscriptions = config.fetch('EventSubscriptions', {})
|
66
66
|
|
67
67
|
# Make sure the default topics exist if they aren't supplied in the alarms.yaml
|
@@ -69,7 +69,6 @@ module CfnGuardian
|
|
69
69
|
@topics[topic] = '' unless @topics.has_key?(topic)
|
70
70
|
end
|
71
71
|
|
72
|
-
@maintenance_group_list = @maintenance_groups.keys.map {|group| "#{group}MaintenanceGroup"}
|
73
72
|
@resources = []
|
74
73
|
@stacks = []
|
75
74
|
@checks = []
|
@@ -116,6 +115,9 @@ module CfnGuardian
|
|
116
115
|
|
117
116
|
@maintenance_groups.each do |maintenance_group,resource_groups|
|
118
117
|
resource_groups.each do |group, alarms|
|
118
|
+
if group == 'Schedules'
|
119
|
+
next
|
120
|
+
end
|
119
121
|
alarms.each do |alarm, resources|
|
120
122
|
resources.each do |resource|
|
121
123
|
|
@@ -190,7 +192,7 @@ module CfnGuardian
|
|
190
192
|
resources = split_resources(bucket,path)
|
191
193
|
|
192
194
|
main_stack = CfnGuardian::Stacks::Main.new()
|
193
|
-
main_stack.build_template(@stacks,@checks,@topics,@
|
195
|
+
main_stack.build_template(@stacks,@checks,@topics,@maintenance_groups,@ssm_parameters)
|
194
196
|
valid = main_stack.template.validate
|
195
197
|
FileUtils.mkdir_p 'out'
|
196
198
|
File.write("out/guardian.compiled.yaml", JSON.parse(valid.to_json).to_yaml)
|
@@ -40,7 +40,7 @@ module CfnGuardian
|
|
40
40
|
@name = 'HttpCheck'
|
41
41
|
@package = 'http-check'
|
42
42
|
@handler = 'handler.http_check'
|
43
|
-
@version = '
|
43
|
+
@version = '0e945240f9d93242f807e86d1a9b3383a1764b96'
|
44
44
|
@runtime = 'python3.7'
|
45
45
|
end
|
46
46
|
end
|
@@ -205,5 +205,16 @@ module CfnGuardian
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
+
class MaintenanceGroupCheck < BaseCheck
|
209
|
+
def initialize(resource)
|
210
|
+
super(resource)
|
211
|
+
@name = 'MaintenanceGroupCheck'
|
212
|
+
@package = 'maintenance-group-check'
|
213
|
+
@handler = 'handler.maintenance_group_check'
|
214
|
+
@version = '5b795e6509068d1767e4be80f2e6868cbeb3b425'
|
215
|
+
@runtime = 'python3.7'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
208
219
|
end
|
209
|
-
end
|
220
|
+
end
|
@@ -52,6 +52,7 @@ module CfnGuardian
|
|
52
52
|
@status_code = resource.fetch('StatusCode',200)
|
53
53
|
@body_regex = resource.fetch('BodyRegex',nil)
|
54
54
|
@headers = resource.fetch('Headers',nil)
|
55
|
+
@user_agent = resource.fetch('UserAgent',nil)
|
55
56
|
@payload = resource.fetch('Payload',nil)
|
56
57
|
@compressed = resource.fetch('Compressed',false)
|
57
58
|
end
|
@@ -65,6 +66,7 @@ module CfnGuardian
|
|
65
66
|
}
|
66
67
|
payload['BODY_REGEX_MATCH'] = @body_regex unless @body_regex.nil?
|
67
68
|
payload['HEADERS'] = @headers unless @headers.nil?
|
69
|
+
payload['USER_AGENT'] = @user_agent unless @user_agent.nil?
|
68
70
|
payload['PAYLOAD'] = @payload unless @payload.nil?
|
69
71
|
payload['COMPRESSED'] = '1' if @compressed
|
70
72
|
return payload.to_json
|
@@ -24,6 +24,7 @@ module CfnGuardian::Resource
|
|
24
24
|
alarm.name = 'IteratorAge'
|
25
25
|
alarm.metric_name = 'IteratorAge'
|
26
26
|
alarm.threshold = 600000
|
27
|
+
alarm.treat_missing_data = 'notBreaching'
|
27
28
|
@alarms.push(alarm)
|
28
29
|
|
29
30
|
alarm = CfnGuardian::Models::LambdaAlarm.new(@resource)
|
@@ -31,6 +32,7 @@ module CfnGuardian::Resource
|
|
31
32
|
alarm.metric_name = 'Duration'
|
32
33
|
alarm.statistic = 'Average'
|
33
34
|
alarm.threshold = 30
|
35
|
+
alarm.treat_missing_data = 'notBreaching'
|
34
36
|
@alarms.push(alarm)
|
35
37
|
end
|
36
38
|
|
@@ -3,7 +3,18 @@ module CfnGuardian::Resource
|
|
3
3
|
|
4
4
|
def default_alarms
|
5
5
|
alarm = CfnGuardian::Models::VPNConnectionAlarm.new(@resource)
|
6
|
-
alarm.name = '
|
6
|
+
alarm.name = 'VPNConnectionStateNonRedundant'
|
7
|
+
alarm.metric_name = 'TunnelState'
|
8
|
+
alarm.comparison_operator = 'LessThanThreshold'
|
9
|
+
alarm.statistic = 'Average'
|
10
|
+
alarm.threshold = 1.0
|
11
|
+
alarm.evaluation_periods = 3
|
12
|
+
alarm.treat_missing_data = 'breaching'
|
13
|
+
alarm.datapoints_to_alarm = 3
|
14
|
+
@alarms.push(alarm)
|
15
|
+
|
16
|
+
alarm = CfnGuardian::Models::VPNConnectionAlarm.new(@resource)
|
17
|
+
alarm.name = 'VPNConnectionStateAllDown'
|
7
18
|
alarm.metric_name = 'TunnelState'
|
8
19
|
alarm.comparison_operator = 'LessThanThreshold'
|
9
20
|
alarm.statistic = 'Average'
|
@@ -4,6 +4,7 @@ module CfnGuardian
|
|
4
4
|
module Stacks
|
5
5
|
class Main
|
6
6
|
include CfnDsl::CloudFormation
|
7
|
+
include Logging
|
7
8
|
|
8
9
|
attr_reader :parameters, :template
|
9
10
|
|
@@ -22,12 +23,10 @@ module CfnGuardian
|
|
22
23
|
parameter.Default sns
|
23
24
|
parameters[name] = Ref(name)
|
24
25
|
end
|
25
|
-
|
26
|
-
maintenance_groups.
|
27
|
-
|
28
|
-
|
29
|
-
topic.Tags([{ Key: 'Environment', Value: 'guardian' }])
|
30
|
-
parameters[group] = Ref(group)
|
26
|
+
|
27
|
+
if maintenance_groups.any?
|
28
|
+
add_lambda(CfnGuardian::Models::MaintenanceGroupCheck.new(maintenance_groups))
|
29
|
+
maintenance_groups.each {|group,config| add_maintenance_group(group,config,parameters)}
|
31
30
|
end
|
32
31
|
|
33
32
|
add_iam_role(ssm_parameters)
|
@@ -73,6 +72,17 @@ module CfnGuardian
|
|
73
72
|
}]
|
74
73
|
}
|
75
74
|
}
|
75
|
+
policies << {
|
76
|
+
PolicyName: 'maintenance-group-actions',
|
77
|
+
PolicyDocument: {
|
78
|
+
Version: '2012-10-17',
|
79
|
+
Statement: [{
|
80
|
+
Effect: 'Allow',
|
81
|
+
Action: [ 'cloudwatch:DescribeAlarms', 'cloudwatch:DisableAlarmActions', 'cloudwatch:EnableAlarmActions', 'cloudwatch:SetAlarmState' ],
|
82
|
+
Resource: FnSub("arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:*")
|
83
|
+
}]
|
84
|
+
}
|
85
|
+
}
|
76
86
|
if ssm_parameters.any?
|
77
87
|
policies << {
|
78
88
|
PolicyName: 'ssm-parameters',
|
@@ -165,7 +175,37 @@ module CfnGuardian
|
|
165
175
|
end
|
166
176
|
end
|
167
177
|
end
|
168
|
-
|
178
|
+
|
179
|
+
def add_maintenance_group(group,config,parameters)
|
180
|
+
group_name = "#{group}MaintenanceGroup"
|
181
|
+
schedules = config.fetch('Schedules', {})
|
182
|
+
logging = config.dig('Schedules', 'Debug').to_s
|
183
|
+
|
184
|
+
topic = @template.SNS_Topic(group_name)
|
185
|
+
topic.TopicName group_name
|
186
|
+
topic.Tags([{ Key: 'Environment', Value: 'guardian' }])
|
187
|
+
parameters[group_name] = Ref(group_name)
|
188
|
+
|
189
|
+
if schedules.any?
|
190
|
+
event = @template.Events_Rule("#{group_name}EnableEvent")
|
191
|
+
event.Name "#{group_name}EnableEvent"
|
192
|
+
event.ScheduleExpression "cron(#{schedules['Enable']})"
|
193
|
+
event.Targets([{
|
194
|
+
Arn: FnGetAtt('MaintenanceGroupCheckFunction', 'Arn'),
|
195
|
+
Id: "#{group_name}EnableTarget",
|
196
|
+
Input: {action:"enable_alarms", maintenance_group: group_name, logging: logging}.to_json
|
197
|
+
}])
|
198
|
+
|
199
|
+
event = @template.Events_Rule("#{group_name}DisableEvent")
|
200
|
+
event.Name "#{group_name}DisableEvent"
|
201
|
+
event.ScheduleExpression "cron(#{schedules['Disable']})"
|
202
|
+
event.Targets([{
|
203
|
+
Arn: FnGetAtt('MaintenanceGroupCheckFunction', 'Arn'),
|
204
|
+
Id: "#{group_name}DisableTarget",
|
205
|
+
Input: {action:"disable_alarms", maintenance_group: group_name, logging: logging}.to_json
|
206
|
+
}])
|
207
|
+
end
|
208
|
+
end
|
169
209
|
end
|
170
210
|
end
|
171
211
|
end
|
data/lib/cfnguardian/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfn-guardian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guslington
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|