auth-centric-firewall 0.0.2 → 0.0.4
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 +4 -4
- data/lib/auth/centric/firewall/capture_request.rb +77 -0
- data/lib/auth/centric/firewall/constants.rb +32 -0
- data/lib/auth/centric/firewall/version.rb +9 -0
- data/lib/auth/centric/firewall.rb +76 -0
- data/sig/auth/centric/firewall/capture_request.rbs +33 -0
- data/sig/auth/centric/firewall/check_ip.rbs +11 -0
- data/sig/auth/centric/firewall/constants.rbs +9 -0
- data/sig/auth/centric/firewall.rbs +23 -0
- metadata +9 -9
- data/lib/auth_centric/firewall/capture_request.rb +0 -70
- data/lib/auth_centric/firewall/constants.rb +0 -30
- data/lib/auth_centric/firewall/version.rb +0 -7
- data/lib/auth_centric/firewall.rb +0 -74
- data/sig/auth_centric/firewall/capture_request.rbs +0 -30
- data/sig/auth_centric/firewall/check_ip.rbs +0 -9
- data/sig/auth_centric/firewall/constants.rbs +0 -7
- data/sig/auth_centric/firewall.rbs +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73f5529567eb03703ed4e70afb7b872da1c994c0e7cc9d9a4ffd369054f4c02
|
4
|
+
data.tar.gz: b97774a9cdb6ea4bb4f7d2d12dbf3e8651f7f07862c3a8dc407f5eb98842e3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50255e6af2bed88acb9c6c91c09f38d771ed53aaf439d195cf57907e713fda6f0be9fdc06cf9545424b6b4e67d72c4874d1cc93422db7b736c16989b50fd9f1e
|
7
|
+
data.tar.gz: 72fbbe2d4f0f0af3feed9c13bfec2ea36ee3f8f8811bb3bcee07991a28bb8bfd7e9c2bdcc6c4ef27eb1356cfb3c58e6da527afded99f9303ed19b21c6b431266
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Auth
|
4
|
+
module Centric
|
5
|
+
module Firewall
|
6
|
+
# Takes the incoming request and extracts
|
7
|
+
class CaptureRequest
|
8
|
+
def initialize(request)
|
9
|
+
@request = request
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_json
|
13
|
+
{
|
14
|
+
ip:,
|
15
|
+
domain:,
|
16
|
+
url:,
|
17
|
+
query_string:,
|
18
|
+
request_method:,
|
19
|
+
request_post_body:,
|
20
|
+
user_agent:,
|
21
|
+
language:,
|
22
|
+
request_formats:,
|
23
|
+
remote_ip:,
|
24
|
+
headers:
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def ip
|
29
|
+
@request.env['HTTP_X_FORWARDED_FOR'] || @request.remote_ip
|
30
|
+
end
|
31
|
+
|
32
|
+
def domain
|
33
|
+
@request.domain || @request.headers.env['HTTP_HOST']
|
34
|
+
end
|
35
|
+
|
36
|
+
def url
|
37
|
+
return @request.original_fullpath if @request.original_fullpath.length == 1
|
38
|
+
|
39
|
+
@request.original_fullpath[1...]
|
40
|
+
end
|
41
|
+
|
42
|
+
def query_string
|
43
|
+
@request.query_string
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_method
|
47
|
+
@request.method
|
48
|
+
end
|
49
|
+
|
50
|
+
def request_post_body
|
51
|
+
@request.body.read
|
52
|
+
end
|
53
|
+
|
54
|
+
def user_agent
|
55
|
+
@request.user_agent
|
56
|
+
end
|
57
|
+
|
58
|
+
def language
|
59
|
+
@request.accept_language
|
60
|
+
end
|
61
|
+
|
62
|
+
def request_formats
|
63
|
+
@request.formats.map(&:to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def remote_ip
|
67
|
+
@request.remote_ip
|
68
|
+
end
|
69
|
+
|
70
|
+
def headers
|
71
|
+
data = @request.headers.env.reject { |key| key.to_s.include?('.') || IGNORE_HEADER_KEYS.include?(key) }
|
72
|
+
data.as_json
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Auth
|
4
|
+
module Centric
|
5
|
+
module Firewall
|
6
|
+
IGNORE_HEADER_KEYS = %w[
|
7
|
+
HTTP_HOST
|
8
|
+
HTTP_REFERER
|
9
|
+
HTTP_IF_NONE_MATCH
|
10
|
+
HTTP_CACHE_CONTROL
|
11
|
+
ORIGINAL_FULLPATH
|
12
|
+
PATH_INFO
|
13
|
+
QUERY_STRING
|
14
|
+
REMOTE_ADDR
|
15
|
+
REQUEST_URI
|
16
|
+
REQUEST_PATH
|
17
|
+
REQUEST_METHOD
|
18
|
+
SERVER_NAME
|
19
|
+
SERVER_SOFTWARE
|
20
|
+
warden
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
IGNORE_IP = %w[
|
24
|
+
0.0.0.0
|
25
|
+
127.0.0.1
|
26
|
+
127.0.0.2
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
IGNORE_REQUEST = %w[/ delayed_job favicon.ico robots.txt ads.txt humans.txt].freeze
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'pry'
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
require_relative 'firewall/version'
|
7
|
+
require_relative 'firewall/constants'
|
8
|
+
require_relative 'firewall/capture_request'
|
9
|
+
|
10
|
+
module Auth
|
11
|
+
module Centric
|
12
|
+
# Client firewall module
|
13
|
+
module Firewall
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
def log_firewall(request)
|
17
|
+
return true if IGNORE_IP.include?(request.remote_ip)
|
18
|
+
return true if IGNORE_REQUEST.include?(request.original_fullpath)
|
19
|
+
|
20
|
+
cr = CaptureRequest.new(request)
|
21
|
+
payload = { request: cr.as_json }
|
22
|
+
|
23
|
+
http = HTTP
|
24
|
+
.timeout(timeout_seconds)
|
25
|
+
.headers(apikey:)
|
26
|
+
.post(capture_path, json: payload)
|
27
|
+
|
28
|
+
http.status == 200
|
29
|
+
rescue HTTP::TimeoutError
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid_ip?(ip_address)
|
34
|
+
return true if IGNORE_IP.include?(ip_address)
|
35
|
+
|
36
|
+
http = HTTP
|
37
|
+
.timeout(timeout_seconds)
|
38
|
+
.headers(apikey:)
|
39
|
+
.get(ip_status_path(ip_address))
|
40
|
+
|
41
|
+
case http.status
|
42
|
+
when 200, 202
|
43
|
+
true
|
44
|
+
when 403
|
45
|
+
false
|
46
|
+
else
|
47
|
+
raise Error, "#{http.status}: #{http.body}"
|
48
|
+
end
|
49
|
+
rescue HTTP::TimeoutError
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def host
|
56
|
+
@host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
|
57
|
+
end
|
58
|
+
|
59
|
+
def apikey
|
60
|
+
@apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
|
61
|
+
end
|
62
|
+
|
63
|
+
def ip_status_path(ip_address)
|
64
|
+
[host, "api/v1/internet_protocols/status?ip=#{ip_address}"].join('/')
|
65
|
+
end
|
66
|
+
|
67
|
+
def capture_path
|
68
|
+
@capture_path ||= [host, 'api/v1/incoming_requests/capture'].join('/')
|
69
|
+
end
|
70
|
+
|
71
|
+
def timeout_seconds
|
72
|
+
@timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Auth
|
2
|
+
module Centric
|
3
|
+
module Firewall
|
4
|
+
class CaptureRequest
|
5
|
+
@request: Net::HTTPRequest
|
6
|
+
|
7
|
+
def as_json: -> { }
|
8
|
+
|
9
|
+
def domain: -> string
|
10
|
+
|
11
|
+
def headers: -> { }
|
12
|
+
|
13
|
+
def ip: -> string
|
14
|
+
|
15
|
+
def language: -> string
|
16
|
+
|
17
|
+
def query_string: -> string
|
18
|
+
|
19
|
+
def remote_ip: -> string
|
20
|
+
|
21
|
+
def request_formats: -> [ ]
|
22
|
+
|
23
|
+
def request_method: -> string
|
24
|
+
|
25
|
+
def request_post_body: -> string
|
26
|
+
|
27
|
+
def url: -> string
|
28
|
+
|
29
|
+
def user_agent: -> string
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Auth
|
2
|
+
module Centric
|
3
|
+
module Firewall
|
4
|
+
VERSION: string
|
5
|
+
|
6
|
+
@host: string
|
7
|
+
@apikey: string
|
8
|
+
@capture_path: string
|
9
|
+
@timeout_seconds: int
|
10
|
+
|
11
|
+
def log_firewall: -> bool
|
12
|
+
def valid_ip?: -> bool
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def host: -> string
|
17
|
+
def apikey: -> string
|
18
|
+
def capture_path: -> string
|
19
|
+
def ip_status_path: -> string
|
20
|
+
def timeout_seconds: -> int
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth-centric-firewall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saimon Lovell
|
@@ -37,15 +37,15 @@ files:
|
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.md
|
39
39
|
- Rakefile
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
40
|
+
- lib/auth/centric/firewall.rb
|
41
|
+
- lib/auth/centric/firewall/capture_request.rb
|
42
|
+
- lib/auth/centric/firewall/constants.rb
|
43
|
+
- lib/auth/centric/firewall/version.rb
|
44
44
|
- public/403.html
|
45
|
-
- sig/
|
46
|
-
- sig/
|
47
|
-
- sig/
|
48
|
-
- sig/
|
45
|
+
- sig/auth/centric/firewall.rbs
|
46
|
+
- sig/auth/centric/firewall/capture_request.rbs
|
47
|
+
- sig/auth/centric/firewall/check_ip.rbs
|
48
|
+
- sig/auth/centric/firewall/constants.rbs
|
49
49
|
- sig/ignore_header_keys.rbs
|
50
50
|
- sig/ignore_ip.rbs
|
51
51
|
- sig/ignore_request.rbs
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AuthCentric
|
4
|
-
module Firewall
|
5
|
-
# Takes the incoming request and extracts
|
6
|
-
class CaptureRequest
|
7
|
-
def initialize(request)
|
8
|
-
@request = request
|
9
|
-
end
|
10
|
-
|
11
|
-
def as_json
|
12
|
-
{
|
13
|
-
domain:,
|
14
|
-
url:,
|
15
|
-
query_string:,
|
16
|
-
request_method:,
|
17
|
-
request_post_body:,
|
18
|
-
user_agent:,
|
19
|
-
language:,
|
20
|
-
request_formats:,
|
21
|
-
remote_ip:,
|
22
|
-
headers:
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def domain
|
27
|
-
@request.domain || @request.headers.env['HTTP_HOST']
|
28
|
-
end
|
29
|
-
|
30
|
-
def url
|
31
|
-
return @request.original_fullpath if @request.original_fullpath.length == 1
|
32
|
-
|
33
|
-
@request.original_fullpath[1...]
|
34
|
-
end
|
35
|
-
|
36
|
-
def query_string
|
37
|
-
@request.query_string
|
38
|
-
end
|
39
|
-
|
40
|
-
def request_method
|
41
|
-
@request.method
|
42
|
-
end
|
43
|
-
|
44
|
-
def request_post_body
|
45
|
-
@request.body.read
|
46
|
-
end
|
47
|
-
|
48
|
-
def user_agent
|
49
|
-
@request.user_agent
|
50
|
-
end
|
51
|
-
|
52
|
-
def language
|
53
|
-
@request.accept_language
|
54
|
-
end
|
55
|
-
|
56
|
-
def request_formats
|
57
|
-
@request.formats.map(&:to_s)
|
58
|
-
end
|
59
|
-
|
60
|
-
def remote_ip
|
61
|
-
@request.remote_ip
|
62
|
-
end
|
63
|
-
|
64
|
-
def headers
|
65
|
-
data = @request.headers.env.reject { |key| key.to_s.include?('.') || IGNORE_HEADER_KEYS.include?(key) }
|
66
|
-
data.as_json
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AuthCentric
|
4
|
-
module Firewall
|
5
|
-
IGNORE_HEADER_KEYS = %w[
|
6
|
-
HTTP_HOST
|
7
|
-
HTTP_REFERER
|
8
|
-
HTTP_IF_NONE_MATCH
|
9
|
-
HTTP_CACHE_CONTROL
|
10
|
-
ORIGINAL_FULLPATH
|
11
|
-
PATH_INFO
|
12
|
-
QUERY_STRING
|
13
|
-
REMOTE_ADDR
|
14
|
-
REQUEST_URI
|
15
|
-
REQUEST_PATH
|
16
|
-
REQUEST_METHOD
|
17
|
-
SERVER_NAME
|
18
|
-
SERVER_SOFTWARE
|
19
|
-
warden
|
20
|
-
].freeze
|
21
|
-
|
22
|
-
IGNORE_IP = %w[
|
23
|
-
0.0.0.0
|
24
|
-
127.0.0.1
|
25
|
-
127.0.0.2
|
26
|
-
].freeze
|
27
|
-
|
28
|
-
IGNORE_REQUEST = %w[/ delayed_job favicon.ico robots.txt ads.txt humans.txt].freeze
|
29
|
-
end
|
30
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# require 'pry'
|
4
|
-
require 'http'
|
5
|
-
|
6
|
-
require_relative 'firewall/version'
|
7
|
-
require_relative 'firewall/constants'
|
8
|
-
require_relative 'firewall/capture_request'
|
9
|
-
|
10
|
-
module AuthCentric
|
11
|
-
# Client code for the firewall
|
12
|
-
module Firewall
|
13
|
-
class Error < StandardError; end
|
14
|
-
|
15
|
-
def log_firewall(request)
|
16
|
-
return true if IGNORE_IP.include?(request.remote_ip)
|
17
|
-
return true if IGNORE_REQUEST.include?(request.original_fullpath)
|
18
|
-
|
19
|
-
cr = CaptureRequest.new(request)
|
20
|
-
payload = { request: cr.as_json }
|
21
|
-
|
22
|
-
http = HTTP
|
23
|
-
.timeout(timeout_seconds)
|
24
|
-
.headers(apikey:)
|
25
|
-
.post(capture_path, json: payload)
|
26
|
-
|
27
|
-
http.status == 200
|
28
|
-
rescue HTTP::TimeoutError
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
def valid_ip?(ip_address)
|
33
|
-
return true if IGNORE_IP.include?(ip_address)
|
34
|
-
|
35
|
-
http = HTTP
|
36
|
-
.timeout(timeout_seconds)
|
37
|
-
.headers(apikey:)
|
38
|
-
.get(ip_status_path(ip_address))
|
39
|
-
|
40
|
-
case http.status
|
41
|
-
when 200, 202
|
42
|
-
true
|
43
|
-
when 403
|
44
|
-
false
|
45
|
-
else
|
46
|
-
raise Error, "#{http.status}: #{http.body}"
|
47
|
-
end
|
48
|
-
rescue HTTP::TimeoutError
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def host
|
55
|
-
@host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
|
56
|
-
end
|
57
|
-
|
58
|
-
def apikey
|
59
|
-
@apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
|
60
|
-
end
|
61
|
-
|
62
|
-
def ip_status_path(ip_address)
|
63
|
-
[host, "api/v1/internet_protocols/status?ip=#{ip_address}"].join('/')
|
64
|
-
end
|
65
|
-
|
66
|
-
def capture_path
|
67
|
-
@capture_path ||= [host, 'api/v1/incoming_requests/capture'].join('/')
|
68
|
-
end
|
69
|
-
|
70
|
-
def timeout_seconds
|
71
|
-
@timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module AuthCentric
|
2
|
-
module Firewall
|
3
|
-
class CaptureRequest
|
4
|
-
@request: Net::HTTPRequest
|
5
|
-
|
6
|
-
def as_json: -> { }
|
7
|
-
|
8
|
-
def domain: -> string
|
9
|
-
|
10
|
-
def headers: -> { }
|
11
|
-
|
12
|
-
def language: -> string
|
13
|
-
|
14
|
-
def query_string: -> string
|
15
|
-
|
16
|
-
def remote_ip: -> string
|
17
|
-
|
18
|
-
def request_formats: -> [ ]
|
19
|
-
|
20
|
-
def request_method: -> string
|
21
|
-
|
22
|
-
def request_post_body: -> string
|
23
|
-
|
24
|
-
def url: -> string
|
25
|
-
|
26
|
-
def user_agent: -> string
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module AuthCentric
|
2
|
-
module Firewall
|
3
|
-
VERSION: string
|
4
|
-
|
5
|
-
@host: string
|
6
|
-
@apikey: string
|
7
|
-
@capture_path: string
|
8
|
-
@timeout_seconds: int
|
9
|
-
|
10
|
-
def log_firewall: -> bool
|
11
|
-
def valid_ip?: -> bool
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def host: -> string
|
16
|
-
def apikey: -> string
|
17
|
-
def capture_path: -> string
|
18
|
-
def ip_status_path: -> string
|
19
|
-
def timeout_seconds: -> int
|
20
|
-
end
|
21
|
-
end
|