fluent-plugin-aws_waf_ip_sets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +9 -0
- data/.rdoc_options +16 -0
- data/.travis.yml +15 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +58 -0
- data/Rakefile +11 -0
- data/exsample/exsample.conf +16 -0
- data/fluent-plugin-aws_waf_ip_sets.gemspec +25 -0
- data/lib/fluent/plugin/out_aws_waf_ip_sets.rb +81 -0
- data/test/helper.rb +18 -0
- data/test/plugin/test_out_aws_waf_ip_sets.rb +37 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90a886b4611ee28a83cb80adfb6f34f628a61dc2
|
4
|
+
data.tar.gz: d8410c97f37fd33d178da76266c0287cad0fe690
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60636815733336b62ff26078c67111f3ebcbd6371aef9c019110383a7747aded621ea4b5821bdfe47f7c3740c20afd832fd3d843bf1072fa7b5b78db827256ee
|
7
|
+
data.tar.gz: e367172e7de02baa09c4caface5569b79853aa7e1916d1a193df1380ad6a92e4ddef533650f3143b586178428632305b8fed53602130ce032e587f3c41fe2a08
|
data/.document
ADDED
data/.gitignore
ADDED
data/.rdoc_options
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- .
|
6
|
+
charset: UTF-8
|
7
|
+
exclude:
|
8
|
+
hyperlink_all: false
|
9
|
+
line_numbers: false
|
10
|
+
main_page: README.md
|
11
|
+
markup: markdown
|
12
|
+
show_hash: false
|
13
|
+
tab_width: 8
|
14
|
+
title: fluent-plugin-aws_waf_ip_sets Documentation
|
15
|
+
visibility: :protected
|
16
|
+
webcvs:
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2017 Hiroshi Toyama
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# fluent-plugin-aws_waf_ip_sets
|
2
|
+
<!-- [![Build Status](https://secure.travis-ci.org/toyama0919/fluent-plugin-aws_waf_ip_sets.png?branch=master)](http://travis-ci.org/toyama0919/fluent-plugin-aws_waf_ip_sets) -->
|
3
|
+
|
4
|
+
AWS waf ip_sets automation plugin for fluentd
|
5
|
+
|
6
|
+
## Examples
|
7
|
+
```
|
8
|
+
<match lambda.**>
|
9
|
+
@type aws_waf_ip_sets
|
10
|
+
ip_address_key ip_address
|
11
|
+
dos_threshold 1000
|
12
|
+
ip_set_id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
13
|
+
white_list 192.168.0.1
|
14
|
+
buffer_path /tmp/test
|
15
|
+
time_slice_format %Y%m%d_%H%M
|
16
|
+
time_slice_wait 10s
|
17
|
+
buffer_type file
|
18
|
+
</match>
|
19
|
+
```
|
20
|
+
|
21
|
+
## parameter
|
22
|
+
|
23
|
+
* ip_address_key
|
24
|
+
* ip address key of record
|
25
|
+
|
26
|
+
* dos_threshold
|
27
|
+
* threshold
|
28
|
+
|
29
|
+
* ip_set_id
|
30
|
+
* AWS waf ip_set_id
|
31
|
+
|
32
|
+
* white_list
|
33
|
+
* white list ip address (comma separated values)
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
```
|
37
|
+
fluent-gem install fluent-plugin-aws_waf_ip_sets
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new [Pull Request](../../pull/new/master)
|
47
|
+
|
48
|
+
## Information
|
49
|
+
|
50
|
+
* [Homepage](https://github.com/toyama0919/fluent-plugin-aws_waf_ip_sets)
|
51
|
+
* [Issues](https://github.com/toyama0919/fluent-plugin-aws_waf_ip_sets/issues)
|
52
|
+
* [Documentation](http://rubydoc.info/gems/fluent-plugin-aws_waf_ip_sets/frames)
|
53
|
+
* [Email](mailto:toyama0919@gmail.com)
|
54
|
+
|
55
|
+
## Copyright
|
56
|
+
|
57
|
+
Copyright (c) 2017 Hiroshi Toyama
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
<source>
|
2
|
+
type forward
|
3
|
+
port 24224
|
4
|
+
</source>
|
5
|
+
|
6
|
+
<match lambda.**>
|
7
|
+
@type aws_waf_ip_sets
|
8
|
+
ip_address_key ip_address
|
9
|
+
dos_threshold 1000
|
10
|
+
ip_set_id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
11
|
+
white_list 192.168.0.1
|
12
|
+
buffer_path /tmp/test
|
13
|
+
time_slice_format %Y%m%d_%H%M
|
14
|
+
time_slice_wait 10s
|
15
|
+
buffer_type file
|
16
|
+
</match>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-aws_waf_ip_sets"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.summary = %q{AWS waf ip_sets automation plugin for fluentd}
|
7
|
+
gem.description = %q{AWS waf ip_sets automation plugin for fluentd}
|
8
|
+
gem.license = "MIT"
|
9
|
+
gem.authors = ["Hiroshi Toyama"]
|
10
|
+
gem.email = "toyama0919@gmail.com"
|
11
|
+
gem.homepage = "https://github.com/toyama0919/fluent-plugin-aws_waf_ip_sets"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "aws-sdk"
|
19
|
+
gem.add_development_dependency 'bundler'
|
20
|
+
gem.add_development_dependency 'fluentd'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10.3.2'
|
22
|
+
gem.add_development_dependency 'rdoc', '~> 4.0'
|
23
|
+
gem.add_development_dependency 'rubocop', '~> 0.24.1'
|
24
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
25
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Fluent
|
2
|
+
class AwsWafIPSetsOutput < TimeSlicedOutput
|
3
|
+
Fluent::Plugin.register_output('aws_waf_ip_sets', self)
|
4
|
+
config_param :ip_address_key, :string
|
5
|
+
config_param :dos_threshold, :integer
|
6
|
+
config_param :ip_set_id, :string
|
7
|
+
config_param :ip_set_type, :enum, list: [:IPV4, :IPV6], :default => 'IPV4'
|
8
|
+
config_param :white_list, :string, :default => '127.0.0.1'
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
require 'aws-sdk'
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
|
+
@white_list = @white_list.split(',')
|
18
|
+
log.info("white list => #{@white_list}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
super
|
23
|
+
@client = Aws::WAFRegional::Client.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def shutdown
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def format(tag, time, record)
|
31
|
+
[tag, time, record].to_msgpack
|
32
|
+
end
|
33
|
+
|
34
|
+
def write(chunk)
|
35
|
+
counter = Hash.new{ |h,k| h[k] = 0 }
|
36
|
+
chunk.msgpack_each do |(tag, time, record)|
|
37
|
+
counter[record[ip_address_key]] += 1
|
38
|
+
end
|
39
|
+
|
40
|
+
counter.each do |ip_address, count|
|
41
|
+
if @dos_threshold < count
|
42
|
+
update_ip_set(ip_address)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def get_change_token
|
50
|
+
@client.get_change_token.change_token
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_ip_set(ip_address)
|
54
|
+
if @white_list.include?(ip_address)
|
55
|
+
log.info("white list ip_address => [#{ip_address}]")
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
updates = [
|
60
|
+
{
|
61
|
+
action: 'INSERT',
|
62
|
+
ip_set_descriptor: {
|
63
|
+
type: @ip_set_type,
|
64
|
+
value: "#{ip_address}/32"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
]
|
68
|
+
|
69
|
+
begin
|
70
|
+
resp = @client.update_ip_set({
|
71
|
+
change_token: get_change_token,
|
72
|
+
ip_set_id: @ip_set_id,
|
73
|
+
updates: updates
|
74
|
+
})
|
75
|
+
log.info("INSERT block ip_address => [#{ip_address}]")
|
76
|
+
rescue => e
|
77
|
+
log.error("\n#{e.message}\n#{e.backtrace.join("\n")}")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
require 'fluent/plugin/out_aws_waf_ip_sets'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class AwsWafIPSetsOutputTest < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
Fluent::Test.setup
|
5
|
+
end
|
6
|
+
|
7
|
+
DEFAULT_CONFIG = %[
|
8
|
+
|
9
|
+
]
|
10
|
+
|
11
|
+
def create_driver(conf = DEFAULT_CONFIG)
|
12
|
+
config = %[
|
13
|
+
apikey testkey
|
14
|
+
buffer_path tmp/buffer
|
15
|
+
] + conf
|
16
|
+
|
17
|
+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::AwsWafIPSetsOutput) do
|
18
|
+
def write(chunk)
|
19
|
+
chunk.instance_variable_set(:@key, @key)
|
20
|
+
super(chunk)
|
21
|
+
end
|
22
|
+
end.configure(config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_configure
|
26
|
+
d = create_driver
|
27
|
+
|
28
|
+
{
|
29
|
+
:@apikey => 'testkey',
|
30
|
+
:@use_ssl => true,
|
31
|
+
:@auto_create_table => true,
|
32
|
+
:@buffer_type => 'file'
|
33
|
+
}.each { |k, v|
|
34
|
+
assert_equal(d.instance.instance_variable_get(k), v)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-aws_waf_ip_sets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Toyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.3.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.3.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.24.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.24.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubygems-tasks
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
111
|
+
description: AWS waf ip_sets automation plugin for fluentd
|
112
|
+
email: toyama0919@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".document"
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rdoc_options"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- exsample/exsample.conf
|
126
|
+
- fluent-plugin-aws_waf_ip_sets.gemspec
|
127
|
+
- lib/fluent/plugin/out_aws_waf_ip_sets.rb
|
128
|
+
- test/helper.rb
|
129
|
+
- test/plugin/test_out_aws_waf_ip_sets.rb
|
130
|
+
homepage: https://github.com/toyama0919/fluent-plugin-aws_waf_ip_sets
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.6.11
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: AWS waf ip_sets automation plugin for fluentd
|
154
|
+
test_files:
|
155
|
+
- test/helper.rb
|
156
|
+
- test/plugin/test_out_aws_waf_ip_sets.rb
|