yabeda-rack-attack 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +14 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +191 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +11 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +22 -0
- data/lib/yabeda/rack/attack.rb +36 -0
- data/lib/yabeda/rack/attack/notifier.rb +58 -0
- data/lib/yabeda/rack/attack/version.rb +9 -0
- data/yabeda-rack-attack.gemspec +39 -0
- metadata +173 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8c8d526fcec1e851d6cd07f9ba6efd5d1ea6ca37089904fe2d60ddb63b47f4ea
|
|
4
|
+
data.tar.gz: cfc89c946c32c6712d334ad9d4a1606d86d6e405ce711137a815ced4cbcfd0b4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c73321d781a10d759d08ad439900570f867a2f4bc779060595bbb6a0959b92712961c8539be76f02174900573a2102d0d234bed3aa751c520159996bac378213
|
|
7
|
+
data.tar.gz: cef3aa1c713faf7f8f3b7cb8a011a9f042d02ef2acf6525be6ff1106dc28f55b6d916afe6ea99a48e99aab5c0c24e27c4d7c7010b13045f2f9fefd0b81a9cf2f
|
data/.gitignore
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
# Ignore Byebug command history file.
|
|
17
|
+
.byebug_history
|
|
18
|
+
|
|
19
|
+
## Specific to RubyMotion:
|
|
20
|
+
.dat*
|
|
21
|
+
.repl_history
|
|
22
|
+
build/
|
|
23
|
+
*.bridgesupport
|
|
24
|
+
build-iPhoneOS/
|
|
25
|
+
build-iPhoneSimulator/
|
|
26
|
+
|
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
28
|
+
#
|
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
32
|
+
#
|
|
33
|
+
# vendor/Pods/
|
|
34
|
+
|
|
35
|
+
## Documentation cache and generated files:
|
|
36
|
+
/.yardoc/
|
|
37
|
+
/_yardoc/
|
|
38
|
+
/doc/
|
|
39
|
+
/rdoc/
|
|
40
|
+
|
|
41
|
+
## Environment normalization:
|
|
42
|
+
/.bundle/
|
|
43
|
+
/vendor/bundle
|
|
44
|
+
/lib/bundler/man/
|
|
45
|
+
|
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
48
|
+
# Gemfile.lock
|
|
49
|
+
# .ruby-version
|
|
50
|
+
# .ruby-gemset
|
|
51
|
+
|
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
53
|
+
.rvmrc
|
|
54
|
+
|
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
56
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
yabeda-rack-attack (0.1.0)
|
|
5
|
+
rack-attack
|
|
6
|
+
yabeda
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actioncable (6.1.3.2)
|
|
12
|
+
actionpack (= 6.1.3.2)
|
|
13
|
+
activesupport (= 6.1.3.2)
|
|
14
|
+
nio4r (~> 2.0)
|
|
15
|
+
websocket-driver (>= 0.6.1)
|
|
16
|
+
actionmailbox (6.1.3.2)
|
|
17
|
+
actionpack (= 6.1.3.2)
|
|
18
|
+
activejob (= 6.1.3.2)
|
|
19
|
+
activerecord (= 6.1.3.2)
|
|
20
|
+
activestorage (= 6.1.3.2)
|
|
21
|
+
activesupport (= 6.1.3.2)
|
|
22
|
+
mail (>= 2.7.1)
|
|
23
|
+
actionmailer (6.1.3.2)
|
|
24
|
+
actionpack (= 6.1.3.2)
|
|
25
|
+
actionview (= 6.1.3.2)
|
|
26
|
+
activejob (= 6.1.3.2)
|
|
27
|
+
activesupport (= 6.1.3.2)
|
|
28
|
+
mail (~> 2.5, >= 2.5.4)
|
|
29
|
+
rails-dom-testing (~> 2.0)
|
|
30
|
+
actionpack (6.1.3.2)
|
|
31
|
+
actionview (= 6.1.3.2)
|
|
32
|
+
activesupport (= 6.1.3.2)
|
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
|
34
|
+
rack-test (>= 0.6.3)
|
|
35
|
+
rails-dom-testing (~> 2.0)
|
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
37
|
+
actiontext (6.1.3.2)
|
|
38
|
+
actionpack (= 6.1.3.2)
|
|
39
|
+
activerecord (= 6.1.3.2)
|
|
40
|
+
activestorage (= 6.1.3.2)
|
|
41
|
+
activesupport (= 6.1.3.2)
|
|
42
|
+
nokogiri (>= 1.8.5)
|
|
43
|
+
actionview (6.1.3.2)
|
|
44
|
+
activesupport (= 6.1.3.2)
|
|
45
|
+
builder (~> 3.1)
|
|
46
|
+
erubi (~> 1.4)
|
|
47
|
+
rails-dom-testing (~> 2.0)
|
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
49
|
+
activejob (6.1.3.2)
|
|
50
|
+
activesupport (= 6.1.3.2)
|
|
51
|
+
globalid (>= 0.3.6)
|
|
52
|
+
activemodel (6.1.3.2)
|
|
53
|
+
activesupport (= 6.1.3.2)
|
|
54
|
+
activerecord (6.1.3.2)
|
|
55
|
+
activemodel (= 6.1.3.2)
|
|
56
|
+
activesupport (= 6.1.3.2)
|
|
57
|
+
activestorage (6.1.3.2)
|
|
58
|
+
actionpack (= 6.1.3.2)
|
|
59
|
+
activejob (= 6.1.3.2)
|
|
60
|
+
activerecord (= 6.1.3.2)
|
|
61
|
+
activesupport (= 6.1.3.2)
|
|
62
|
+
marcel (~> 1.0.0)
|
|
63
|
+
mini_mime (~> 1.0.2)
|
|
64
|
+
activesupport (6.1.3.2)
|
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
66
|
+
i18n (>= 1.6, < 2)
|
|
67
|
+
minitest (>= 5.1)
|
|
68
|
+
tzinfo (~> 2.0)
|
|
69
|
+
zeitwerk (~> 2.3)
|
|
70
|
+
ast (2.4.2)
|
|
71
|
+
builder (3.2.4)
|
|
72
|
+
byebug (11.1.3)
|
|
73
|
+
concurrent-ruby (1.1.8)
|
|
74
|
+
crass (1.0.6)
|
|
75
|
+
diff-lcs (1.4.4)
|
|
76
|
+
dry-initializer (3.0.4)
|
|
77
|
+
erubi (1.10.0)
|
|
78
|
+
globalid (0.4.2)
|
|
79
|
+
activesupport (>= 4.2.0)
|
|
80
|
+
i18n (1.8.10)
|
|
81
|
+
concurrent-ruby (~> 1.0)
|
|
82
|
+
loofah (2.9.1)
|
|
83
|
+
crass (~> 1.0.2)
|
|
84
|
+
nokogiri (>= 1.5.9)
|
|
85
|
+
mail (2.7.1)
|
|
86
|
+
mini_mime (>= 0.1.1)
|
|
87
|
+
marcel (1.0.1)
|
|
88
|
+
method_source (1.0.0)
|
|
89
|
+
mini_mime (1.0.3)
|
|
90
|
+
minitest (5.14.4)
|
|
91
|
+
nio4r (2.5.7)
|
|
92
|
+
nokogiri (1.11.4-x86_64-linux)
|
|
93
|
+
racc (~> 1.4)
|
|
94
|
+
parallel (1.20.1)
|
|
95
|
+
parser (3.0.1.1)
|
|
96
|
+
ast (~> 2.4.1)
|
|
97
|
+
racc (1.5.2)
|
|
98
|
+
rack (2.2.3)
|
|
99
|
+
rack-attack (6.5.0)
|
|
100
|
+
rack (>= 1.0, < 3)
|
|
101
|
+
rack-test (1.1.0)
|
|
102
|
+
rack (>= 1.0, < 3)
|
|
103
|
+
rails (6.1.3.2)
|
|
104
|
+
actioncable (= 6.1.3.2)
|
|
105
|
+
actionmailbox (= 6.1.3.2)
|
|
106
|
+
actionmailer (= 6.1.3.2)
|
|
107
|
+
actionpack (= 6.1.3.2)
|
|
108
|
+
actiontext (= 6.1.3.2)
|
|
109
|
+
actionview (= 6.1.3.2)
|
|
110
|
+
activejob (= 6.1.3.2)
|
|
111
|
+
activemodel (= 6.1.3.2)
|
|
112
|
+
activerecord (= 6.1.3.2)
|
|
113
|
+
activestorage (= 6.1.3.2)
|
|
114
|
+
activesupport (= 6.1.3.2)
|
|
115
|
+
bundler (>= 1.15.0)
|
|
116
|
+
railties (= 6.1.3.2)
|
|
117
|
+
sprockets-rails (>= 2.0.0)
|
|
118
|
+
rails-dom-testing (2.0.3)
|
|
119
|
+
activesupport (>= 4.2.0)
|
|
120
|
+
nokogiri (>= 1.6)
|
|
121
|
+
rails-html-sanitizer (1.3.0)
|
|
122
|
+
loofah (~> 2.3)
|
|
123
|
+
railties (6.1.3.2)
|
|
124
|
+
actionpack (= 6.1.3.2)
|
|
125
|
+
activesupport (= 6.1.3.2)
|
|
126
|
+
method_source
|
|
127
|
+
rake (>= 0.8.7)
|
|
128
|
+
thor (~> 1.0)
|
|
129
|
+
rainbow (3.0.0)
|
|
130
|
+
rake (10.5.0)
|
|
131
|
+
regexp_parser (2.1.1)
|
|
132
|
+
rexml (3.2.5)
|
|
133
|
+
rspec (3.10.0)
|
|
134
|
+
rspec-core (~> 3.10.0)
|
|
135
|
+
rspec-expectations (~> 3.10.0)
|
|
136
|
+
rspec-mocks (~> 3.10.0)
|
|
137
|
+
rspec-core (3.10.1)
|
|
138
|
+
rspec-support (~> 3.10.0)
|
|
139
|
+
rspec-expectations (3.10.1)
|
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
141
|
+
rspec-support (~> 3.10.0)
|
|
142
|
+
rspec-mocks (3.10.2)
|
|
143
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
144
|
+
rspec-support (~> 3.10.0)
|
|
145
|
+
rspec-support (3.10.2)
|
|
146
|
+
rubocop (1.15.0)
|
|
147
|
+
parallel (~> 1.10)
|
|
148
|
+
parser (>= 3.0.0.0)
|
|
149
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
150
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
151
|
+
rexml
|
|
152
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
|
153
|
+
ruby-progressbar (~> 1.7)
|
|
154
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
155
|
+
rubocop-ast (1.5.0)
|
|
156
|
+
parser (>= 3.0.1.1)
|
|
157
|
+
ruby-progressbar (1.11.0)
|
|
158
|
+
sprockets (4.0.2)
|
|
159
|
+
concurrent-ruby (~> 1.0)
|
|
160
|
+
rack (> 1, < 3)
|
|
161
|
+
sprockets-rails (3.2.2)
|
|
162
|
+
actionpack (>= 4.0)
|
|
163
|
+
activesupport (>= 4.0)
|
|
164
|
+
sprockets (>= 3.0.0)
|
|
165
|
+
thor (1.1.0)
|
|
166
|
+
tzinfo (2.0.4)
|
|
167
|
+
concurrent-ruby (~> 1.0)
|
|
168
|
+
unicode-display_width (2.0.0)
|
|
169
|
+
websocket-driver (0.7.3)
|
|
170
|
+
websocket-extensions (>= 0.1.0)
|
|
171
|
+
websocket-extensions (0.1.5)
|
|
172
|
+
yabeda (0.9.0)
|
|
173
|
+
concurrent-ruby
|
|
174
|
+
dry-initializer
|
|
175
|
+
zeitwerk (2.4.2)
|
|
176
|
+
|
|
177
|
+
PLATFORMS
|
|
178
|
+
x86_64-linux
|
|
179
|
+
|
|
180
|
+
DEPENDENCIES
|
|
181
|
+
bundler
|
|
182
|
+
byebug
|
|
183
|
+
rack-test
|
|
184
|
+
rails
|
|
185
|
+
rake (~> 10.0)
|
|
186
|
+
rspec (~> 3.0)
|
|
187
|
+
rubocop (~> 1.15)
|
|
188
|
+
yabeda-rack-attack!
|
|
189
|
+
|
|
190
|
+
BUNDLED WITH
|
|
191
|
+
2.2.15
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Dmitriy Salakhutdinov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Yabeda::Rack::Attack
|
|
2
|
+
|
|
3
|
+
Built-in metrics for rack-attack monitoring out of the box! Part of the [yabeda](https://github.com/yabeda-rb/yabeda) suite.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'yabeda-rack-attack'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install yabeda-rack-attack
|
|
20
|
+
|
|
21
|
+
## Metrics
|
|
22
|
+
|
|
23
|
+
Local per-process metrics
|
|
24
|
+
|
|
25
|
+
# `rack_attack_throttled_requests_total` - counter of throttled requests (segmented by rack-attack name and descriminator)
|
|
26
|
+
# `rack_attack_tracked_requests_total` - counter of tracked requests (segmented by rack-attack name)
|
|
27
|
+
# `rack_attack_safelisted_requests_total` - counter of safelisted requests (segmented by name)
|
|
28
|
+
# `rack_attack_blocklisted_requests_total` - counter of blocklisted requests (segmented by name)
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
33
|
+
|
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
35
|
+
|
|
36
|
+
## Contributing
|
|
37
|
+
|
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yabeda-rack-attack.
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'yabeda/rack/attack'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
version: '3.4'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
app:
|
|
5
|
+
image: ruby:latest
|
|
6
|
+
environment:
|
|
7
|
+
- BUNDLE_PATH=/bundle
|
|
8
|
+
- BUNDLE_CONFIG=/app/.bundle/config
|
|
9
|
+
- REDIS_URL=redis://redis
|
|
10
|
+
command: bash
|
|
11
|
+
working_dir: /app
|
|
12
|
+
volumes:
|
|
13
|
+
- .:/app:cached
|
|
14
|
+
- bundler_data:/bundle
|
|
15
|
+
tmpfs:
|
|
16
|
+
- /tmp
|
|
17
|
+
|
|
18
|
+
redis:
|
|
19
|
+
image: redis
|
|
20
|
+
|
|
21
|
+
volumes:
|
|
22
|
+
bundler_data:
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yabeda/rack/attack/version'
|
|
4
|
+
require 'yabeda'
|
|
5
|
+
require 'rack/attack'
|
|
6
|
+
require 'yabeda/rack/attack/notifier'
|
|
7
|
+
|
|
8
|
+
module Yabeda
|
|
9
|
+
module Rack
|
|
10
|
+
module Attack
|
|
11
|
+
::Yabeda.configure do
|
|
12
|
+
notifier = ::Yabeda::Rack::Attack::Notifier.new
|
|
13
|
+
if defined?(ActiveSupport::Notifications)
|
|
14
|
+
ActiveSupport::Notifications.subscribe(/rack_attack/) do |event_name, _start, _finish, _request_id, payload|
|
|
15
|
+
request = payload[:request]
|
|
16
|
+
notifier.instrument(event_name, request: request)
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
::Rack::Attack.notifier = notifier
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
group :rack_attack
|
|
23
|
+
|
|
24
|
+
counter :throttled_requests_total, tags: %i[name discriminator],
|
|
25
|
+
comment: 'Number of throttled requests my name/descriminator'
|
|
26
|
+
counter :tracked_requests_total, tags: %i[name],
|
|
27
|
+
comment: 'Number of tracked requests by name'
|
|
28
|
+
counter :safelisted_requests_total, tags: %i[name],
|
|
29
|
+
comment: 'Number of safelisted requests by name'
|
|
30
|
+
counter :blocklisted_requests_total, tags: %i[name],
|
|
31
|
+
comment: 'Number of blocklisted requests by name'
|
|
32
|
+
end
|
|
33
|
+
# Your code goes here...
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Yabeda
|
|
4
|
+
module Rack
|
|
5
|
+
module Attack
|
|
6
|
+
class Notifier
|
|
7
|
+
def instrument(event_type, request:)
|
|
8
|
+
# backwards compatibility issues
|
|
9
|
+
# https://github.com/rack/rack-attack/blob/2257f008763b405f6a1515b460f80ed5d0f06c2c/lib/rack/attack.rb#L42-L43
|
|
10
|
+
case event_type
|
|
11
|
+
when 'throttle.rack_attack'
|
|
12
|
+
track_throttled(request)
|
|
13
|
+
when 'track.rack_attack'
|
|
14
|
+
track_tracked(request)
|
|
15
|
+
when 'safelist.rack_attack'
|
|
16
|
+
track_safelisted(request)
|
|
17
|
+
when 'blocklist.rack_attack'
|
|
18
|
+
track_blacklisted(request)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def track_throttled(request)
|
|
25
|
+
::Yabeda.rack_attack.throttled_requests_total.increment(
|
|
26
|
+
{ name: name(request), discriminator: discriminator(request) }
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def track_tracked(request)
|
|
31
|
+
::Yabeda.rack_attack.tracked_requests_total.increment(
|
|
32
|
+
{ name: name(request) }
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def track_safelisted(request)
|
|
37
|
+
::Yabeda.rack_attack.safelisted_requests_total.increment(
|
|
38
|
+
{ name: name(request) }
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def track_blacklisted(request)
|
|
43
|
+
::Yabeda.rack_attack.blocklisted_requests_total.increment(
|
|
44
|
+
{ name: name(request) }
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def name(request)
|
|
49
|
+
request.env['rack.attack.matched']
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def discriminator(request)
|
|
53
|
+
request.env['rack.attack.match_discriminator']
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'yabeda/rack/attack/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'yabeda-rack-attack'
|
|
9
|
+
spec.version = Yabeda::Rack::Attack::VERSION
|
|
10
|
+
spec.authors = ['Dmitry Salahutdinov']
|
|
11
|
+
spec.email = ['dsalahutdinov@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Monitoring for rack-attack rules matching'
|
|
14
|
+
spec.description = 'Extends Yabeda metrics to collect rack-attack metrics'
|
|
15
|
+
spec.homepage = 'https://github.com/yabeda-rb/yabeda-rack-attack'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/yabeda-rb/yabeda-rack-attack'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
spec.add_dependency 'rack-attack'
|
|
31
|
+
spec.add_dependency 'yabeda'
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency 'bundler'
|
|
34
|
+
spec.add_development_dependency 'byebug'
|
|
35
|
+
spec.add_development_dependency 'rack-test'
|
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 1.15'
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: yabeda-rack-attack
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dmitry Salahutdinov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-05-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rack-attack
|
|
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: yabeda
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
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: bundler
|
|
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: byebug
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rack-test
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '10.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '10.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '3.0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '3.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rubocop
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '1.15'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '1.15'
|
|
125
|
+
description: Extends Yabeda metrics to collect rack-attack metrics
|
|
126
|
+
email:
|
|
127
|
+
- dsalahutdinov@gmail.com
|
|
128
|
+
executables: []
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".rubocop.yml"
|
|
135
|
+
- ".travis.yml"
|
|
136
|
+
- Gemfile
|
|
137
|
+
- Gemfile.lock
|
|
138
|
+
- LICENSE.txt
|
|
139
|
+
- README.md
|
|
140
|
+
- Rakefile
|
|
141
|
+
- bin/console
|
|
142
|
+
- bin/setup
|
|
143
|
+
- docker-compose.yml
|
|
144
|
+
- lib/yabeda/rack/attack.rb
|
|
145
|
+
- lib/yabeda/rack/attack/notifier.rb
|
|
146
|
+
- lib/yabeda/rack/attack/version.rb
|
|
147
|
+
- yabeda-rack-attack.gemspec
|
|
148
|
+
homepage: https://github.com/yabeda-rb/yabeda-rack-attack
|
|
149
|
+
licenses:
|
|
150
|
+
- MIT
|
|
151
|
+
metadata:
|
|
152
|
+
homepage_uri: https://github.com/yabeda-rb/yabeda-rack-attack
|
|
153
|
+
source_code_uri: https://github.com/yabeda-rb/yabeda-rack-attack
|
|
154
|
+
post_install_message:
|
|
155
|
+
rdoc_options: []
|
|
156
|
+
require_paths:
|
|
157
|
+
- lib
|
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
|
+
requirements:
|
|
160
|
+
- - ">="
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: '0'
|
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
|
+
requirements:
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: '0'
|
|
168
|
+
requirements: []
|
|
169
|
+
rubygems_version: 3.0.3
|
|
170
|
+
signing_key:
|
|
171
|
+
specification_version: 4
|
|
172
|
+
summary: Monitoring for rack-attack rules matching
|
|
173
|
+
test_files: []
|