rack-dedos 0.2.2 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5358dccb09197e0042d35f689f02a913a8c566e975b2bac47c7dbdfbd4c01c56
4
- data.tar.gz: 63c029725b96d240ac4700c02585772b8a8a843c2e8fcca574ada29ae344a740
3
+ metadata.gz: 499458581f04fa158a8cd0bfb41068b72c41e0d33c0a4321aeaa123a66af7c53
4
+ data.tar.gz: 22777d21fa4db1beb2571792683835780a561dd466c366803212b88a5e828711
5
5
  SHA512:
6
- metadata.gz: bc44d5579d132a3960f280f26f8c4f0b1eca01d7001d15d5dbfbe907fbc08f2a0d0ad775e610c018ff1f8f7cef6e47611bcf0ad0c4618cf5eed100d59cc97188
7
- data.tar.gz: 329b51f582b0c664b1754f8f8169b8623c0675695171560aadacd3ce6963863644ced781a144c8d55d35d8de5cd75801f85a1d7640ff4bba43e6f14ab0196679
6
+ metadata.gz: 889de2da536b7376f39e901caa59e78fb3a59faffd3dddb833051dafe8fae40199d31125ea1c5595480df4cb85cfb61edeb0e3a224335e0a512a503c5275121f
7
+ data.tar.gz: 22c1060501f2c686b8ad0f499e9ffd366d99640aedcc40f84ac94208ed6e5a917c03e3ad82ae0583705306bb6d9ca09a350e82c838466dbc34316bc24560ff34
data/CHANGELOG.md CHANGED
@@ -2,28 +2,59 @@
2
2
 
3
3
  Nothing so far
4
4
 
5
+ ## 0.4.0
6
+
7
+ ### Changes
8
+ * Drop certs
9
+ * Add action for trusted release
10
+
11
+ ## 0.3.2
12
+
13
+ ### Changes
14
+ * Resolve all paths to prevent problems with relative paths
15
+
16
+ ## 0.3.1
17
+
18
+ ### Changes
19
+ * Root `File` operations to prevent clashes with Rack
20
+
21
+ ## 0.3.0
22
+
23
+ ### Changes
24
+ * Convert `geoipget` from Bash to Ruby
25
+
26
+ ## 0.2.4
27
+
28
+ ### Changes
29
+ * Use Bash for `geoipget` to prevent problems with `/bin/sh` diversity
30
+
31
+ ## 0.2.3
32
+
33
+ ### Additions
34
+ * `geoipget` shell script
35
+
5
36
  ## 0.2.2
6
37
 
7
- #### Changes
38
+ ### Changes
8
39
  * Update to Ruby 3.4
9
40
 
10
41
  ## 0.2.1
11
42
 
12
- #### Fixes
43
+ ### Fixes
13
44
 
14
45
  * Fix paths on conditional requires
15
46
  * Renew certificate
16
47
 
17
48
  ## 0.2.0
18
49
 
19
- #### Changes
50
+ ### Changes
20
51
 
21
52
  * Determine real client IP
22
53
  * Drop autoload and put filters in proper namespace
23
54
 
24
55
  ## 0.1.0
25
56
 
26
- #### Initial implementation
57
+ ### Initial implementation
27
58
 
28
59
  * UserAgent filter
29
60
  * Country filter
data/README.md CHANGED
@@ -19,16 +19,6 @@ Thank you for supporting free and open-source software by sponsoring on [GitHub]
19
19
 
20
20
  ## Install
21
21
 
22
- ### Security
23
-
24
- This gem is [cryptographically signed](https://guides.rubygems.org/security/#using-gems) in order to assure it hasn't been tampered with. Unless already done, please add the author's public key as a trusted certificate now:
25
-
26
- ```
27
- gem cert --add <(curl -Ls https://raw.github.com/svoop/rack-dedos/main/certs/svoop.pem)
28
- ```
29
-
30
- ### Bundler
31
-
32
22
  Add the following to the <tt>Gemfile</tt> or <tt>gems.rb</tt> of your [Bundler](https://bundler.io) powered Ruby project:
33
23
 
34
24
  ```ruby
@@ -38,7 +28,7 @@ gem 'rack-dedos'
38
28
  And then install the bundle:
39
29
 
40
30
  ```
41
- bundle install --trust-policy MediumSecurity
31
+ bundle install
42
32
  ```
43
33
 
44
34
  ## Configuration
@@ -125,18 +115,13 @@ Either allow or deny requests by probable country of origin. If both are set, th
125
115
 
126
116
  The MaxMind GeoLite2 database is free, however, you have to create an account on [maxmind.com](https://www.maxmind.com) and then download the country database.
127
117
 
128
- For automatic updates, create a `geoipupdate.conf` file and then use the [geoipupdate tool](https://github.com/maxmind/geoipupdate/releases) to fetch the latest country database:
118
+ For automatic updates, create a `geoipupdate.conf` file and then use the [geoipupdate tool for your arch](https://github.com/maxmind/geoipupdate/releases) to fetch the latest country database.
119
+
120
+ The bundled `geoipget` executable does all this in one swipe:
129
121
 
130
122
  ```
131
- version=4.10.0
132
- arch=linux_amd64
133
- conf=/etc/geoipupdate.conf
134
- dir=/var/db/maxmind/
135
-
136
- mkdir -p "${dir}"
137
- wget --quiet -O /tmp/geoipupdate.tgz https://github.com/maxmind/geoipupdate/releases/download/v${version}/geoipupdate_${version}_${arch}.tar.gz
138
- tar -xz -C /tmp -f /tmp/geoipupdate.tgz
139
- /tmp/geoipupdate_${version}_${arch}/geoipupdate -f "${conf}" -d "${dir}"
123
+ geoipget --help
124
+ geoipget --dir . --arch linux_amd64 /etc/geoipupdate.conf
140
125
  ```
141
126
 
142
127
  ## Real Client IP
data/exe/geoipget ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack/dedos'
4
+
5
+ Rack::Dedos::Executables::Geoipget.new.run
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'tmpdir'
5
+ require 'open-uri'
6
+ require 'json'
7
+ require 'rubygems/package'
8
+
9
+ module Rack
10
+ module Dedos
11
+ module Executables
12
+ class Geoipget
13
+ attr_reader :config, :dir, :arch
14
+
15
+ def initialize(**options)
16
+ @arch, @dir = 'linux_amd64', '.'
17
+ OptionParser.new do |o|
18
+ o.banner = <<~END
19
+ Download the geoip database from Maxmind.
20
+ Usage: #{::File.basename($0)} CONFIG_FILE
21
+ END
22
+ o.on('-a', '--arch ARCH', String, "architecture (default: #{arch})") { @arch = _1 }
23
+ o.on('-d', '--dir DIR', String, "destination directory (default: #{dir})") { @dir = _1 }
24
+ o.on('-A', '--about', 'show author/license information and exit') { self.class.about }
25
+ o.on('-V', '--version', 'show version and exit') { self.class.version }
26
+ end.parse!
27
+ @config = ARGV.first
28
+ end
29
+
30
+ def run
31
+ fail "cannot read config file #{config}" unless config && ::File.readable?(config)
32
+ Maxmind.new(::File.realpath(config), ::File.realpath(dir), arch).get
33
+ end
34
+
35
+ def self.about
36
+ puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'
37
+ exit
38
+ end
39
+
40
+ def self.version
41
+ puts Rack::Dedos::VERSION
42
+ exit
43
+ end
44
+
45
+ class Maxmind
46
+ REPO = "maxmind/geoipupdate"
47
+
48
+ attr_reader :config, :dir, :arch
49
+
50
+ def initialize(config, dir, arch)
51
+ @config, @dir, @arch = config, dir, arch
52
+ end
53
+
54
+ def get
55
+ prepare(latest_version) { download }
56
+ end
57
+
58
+ private
59
+
60
+ def latest_version
61
+ URI("https://api.github.com/repos/#{REPO}/releases/latest")
62
+ .read
63
+ .then { JSON.parse(_1) }
64
+ .fetch('tag_name')
65
+ .slice(1..)
66
+ end
67
+
68
+ def prepare(version)
69
+ uri = URI("https://github.com/#{REPO}/releases/download/v#{version}/geoipupdate_#{version}_#{arch}.tar.gz")
70
+ Dir.mktmpdir do |tmp|
71
+ Dir.chdir tmp
72
+ uri.open do |file|
73
+ Zlib::GzipReader.wrap(file) do |gz|
74
+ Gem::Package::TarReader.new(gz) do |tar|
75
+ tar.each do |entry|
76
+ if entry.full_name.match? %r(/geoipupdate$)
77
+ ::File.write('geoipupdate', entry.read)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ ::File.chmod(0755, 'geoipupdate')
84
+ yield
85
+ end
86
+ ensure
87
+ lockfile = "#{dir}/.geoipupdate.lock"
88
+ ::File.unlink(lockfile) if ::File.exist? lockfile
89
+ end
90
+
91
+ def download
92
+ `./geoipupdate -f "#{config}" -d "#{dir}"`
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -22,7 +22,7 @@ module Rack
22
22
  end
23
23
 
24
24
  def allowed?(request, ip)
25
- if country = maxmind_db.get(ip)
25
+ if country = maxmind_db&.get(ip)
26
26
  country_code = country.dig('country', 'iso_code').to_sym
27
27
  @countries.include?(country_code) ? @allowed : !@allowed
28
28
  else # not found in database
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  module Dedos
5
- VERSION = "0.2.2"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/rack/dedos.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rack'
4
4
 
5
5
  require_relative 'dedos/version'
6
+ require_relative 'dedos/executables/geoipget'
6
7
 
7
8
  module Rack
8
9
  module Dedos
metadata CHANGED
@@ -1,34 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dedos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
8
- bindir: bin
9
- cert_chain:
10
- - |
11
- -----BEGIN CERTIFICATE-----
12
- MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhydWJ5
13
- L0RDPWJpdGNldGVyYS9EQz1jb20wHhcNMjQxMTIwMjExMDIwWhcNMjUxMTIwMjEx
14
- MDIwWjAjMSEwHwYDVQQDDBhydWJ5L0RDPWJpdGNldGVyYS9EQz1jb20wggEiMA0G
15
- CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDcLg+IHjXYaUlTSU7R235lQKD8ZhEe
16
- KMhoGlSUonZ/zo1OT3KXcqTCP1iMX743xYs6upEGALCWWwq+nxvlDdnWRjF3AAv7
17
- ikC+Z2BEowjyeCCT/0gvn4ohKcR0JOzzRaIlFUVInlGSAHx2QHZ2N8ntf54lu7nd
18
- L8CiDK8rClsY4JBNGOgH9UC81f+m61UUQuTLxyM2CXfAYkj/sGNTvFRJcNX+nfdC
19
- hM9r2kH1+7wsa8yG7wJ2IkrzNACD8v84oE6qVusN8OLEMUI/NaEPVPbw2LUM149H
20
- PVa0i729A4IhroNnFNmw4wOC93ARNbM1+LW36PLMmKjKudf5Exg8VmDVAgMBAAGj
21
- dzB1MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBSfK8MtR62mQ6oN
22
- yoX/VKJzFjLSVDAdBgNVHREEFjAUgRJydWJ5QGJpdGNldGVyYS5jb20wHQYDVR0S
23
- BBYwFIEScnVieUBiaXRjZXRlcmEuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQDSeB1x
24
- 8QK8F/ML37isgvwGiQxovDUqu6Sq14cQ1qE9y5prUBmL2AsDuCBpXXctcvamFqNC
25
- PgfJtj7ZZcXmY0SfKCog7T1btkr6zYxPXpxwUqB45n0I6v5qc0UCNvMEfBzxlak5
26
- VW7UMNlKD9qukeN55hxuLF2F/sLldMcHUo/ATgdV4zk1t3sK6A9+02wz5K5qfWdM
27
- Mi+XWXmGd57uojk3RcIXNwBRRP4DTKcKgVXhuyHb7q1vjTXrS6bw1Ortu0KmWOIk
28
- jTyRsT1gymASS2KHe+BaCTwD74GqO8q4woYLZgXnJ/PvgcFgY2FEi2Kn/sXLp4JE
29
- boIgxQCMT+nxBHCD
30
- -----END CERTIFICATE-----
31
- date: 2024-12-25 00:00:00.000000000 Z
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
32
11
  dependencies:
33
12
  - !ruby/object:Gem::Dependency
34
13
  name: rack
@@ -195,18 +174,21 @@ description: |
195
174
  resort only to be enabled during an attack.
196
175
  email:
197
176
  - ruby@bitcetera.com
198
- executables: []
177
+ executables:
178
+ - geoipget
199
179
  extensions: []
200
180
  extra_rdoc_files:
201
- - README.md
202
181
  - CHANGELOG.md
203
182
  - LICENSE.txt
183
+ - README.md
204
184
  files:
205
185
  - CHANGELOG.md
206
186
  - LICENSE.txt
207
187
  - README.md
188
+ - exe/geoipget
208
189
  - lib/rack/dedos.rb
209
190
  - lib/rack/dedos/cache.rb
191
+ - lib/rack/dedos/executables/geoipget.rb
210
192
  - lib/rack/dedos/filters/base.rb
211
193
  - lib/rack/dedos/filters/country.rb
212
194
  - lib/rack/dedos/filters/user_agent.rb
@@ -241,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
223
  - !ruby/object:Gem::Version
242
224
  version: '0'
243
225
  requirements: []
244
- rubygems_version: 3.6.2
226
+ rubygems_version: 3.6.9
245
227
  specification_version: 4
246
228
  summary: Radical filters to block denial-of-service (DoS) requests.
247
229
  test_files: []
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file