logstash-filter-jwt-decode 0.1.0 → 0.1.1
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/CONTRIBUTORS +1 -1
- data/lib/logstash/filters/jwt-decode.rb +11 -6
- data/logstash-filter-jwt-decode.gemspec +1 -1
- data/spec/filters/jwt-filter_spec.rb +76 -5
- 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: f204b3f7b98a56ffcf869f9b9f9ec0ec8329d5dfc70aae81372c835ddc6c1eb9
|
4
|
+
data.tar.gz: 877e39c40ea6565d6dedb8e5ee3ba51de09ea7c0bb4074be03183e2d359e5978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b88f101fc8280b2ff14e67bdf2ff4f1d23ca599533b311b7df77d45f4b2a18b04f1f1edd75db825545a4991e958b92e3421462aefb2d4bbc12d145b12bdc55fc
|
7
|
+
data.tar.gz: 0a2be8e2d27244a20a31c994d35a3c6861159f383b0bfb98d53e9dcc653e83b83f13feb21373d4955172a8b3a351bfdc0bc3fe401798b09440b0c1700f45edeb
|
data/CONTRIBUTORS
CHANGED
@@ -2,7 +2,7 @@ The following is a list of people who have contributed ideas, code, bug
|
|
2
2
|
reports, or in general have helped logstash along its way.
|
3
3
|
|
4
4
|
Contributors:
|
5
|
-
* Bharat Raj Arutla -
|
5
|
+
* Bharat Raj Arutla - bharatraj.arutla@gmail.com
|
6
6
|
|
7
7
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
8
|
Logstash, and you aren't on the list above and want to be, please let us know
|
@@ -13,7 +13,7 @@ class LogStash::Filters::JWTDecode < LogStash::Filters::Base
|
|
13
13
|
#
|
14
14
|
# jwt-decode {
|
15
15
|
# "match" => "token",
|
16
|
-
# "extract_fields" => {"
|
16
|
+
# "extract_fields" => {"user_id" => "user.id"}
|
17
17
|
# }
|
18
18
|
#
|
19
19
|
#
|
@@ -22,8 +22,8 @@ class LogStash::Filters::JWTDecode < LogStash::Filters::Base
|
|
22
22
|
|
23
23
|
# Looks for a match in message which contains the token field
|
24
24
|
config :match, :validate => :string, :required => true
|
25
|
-
#
|
26
|
-
config :signature_alg, :validate => :string, :required => false, :default => "
|
25
|
+
# Valid algorithms are defined here https://tools.ietf.org/html/rfc7518#section-3.1
|
26
|
+
config :signature_alg, :validate => :string, :required => false, :default => "HS256"
|
27
27
|
config :key, :validate => :string, :required => false, :default => nil
|
28
28
|
config :extract_fields, :validate => :hash, :required => true
|
29
29
|
|
@@ -31,14 +31,19 @@ class LogStash::Filters::JWTDecode < LogStash::Filters::Base
|
|
31
31
|
public
|
32
32
|
def register
|
33
33
|
# Add instance variables
|
34
|
-
if
|
35
|
-
raise LogStash::ConfigurationError, "
|
34
|
+
if @key && !@signature_alg
|
35
|
+
raise LogStash::ConfigurationError, "signature_alg has to be specified if key is present "
|
36
36
|
end
|
37
37
|
end # def register
|
38
38
|
|
39
39
|
public
|
40
40
|
def filter(event)
|
41
|
-
|
41
|
+
if not @key
|
42
|
+
decoded_token = JWT.decode event.get(@match), nil, false
|
43
|
+
else
|
44
|
+
decoded_token = JWT.decode event.get(@match), @key, true, {algorithm: @signature_alg}
|
45
|
+
end
|
46
|
+
|
42
47
|
@extract_fields.each do |k, v|
|
43
48
|
event.set(k , getValueFromDecodedToken(v, decoded_token[0]))
|
44
49
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-jwt-decode'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.licenses = ['Apache-2.0']
|
5
5
|
s.summary = 'Logstash filter plugin for decoding JSON Web Token (JWT)'
|
6
6
|
s.description = 'Logstash filter plugin for decoding JSON Web Token (JWT)'
|
@@ -1,19 +1,90 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require_relative '../spec_helper'
|
3
3
|
require "logstash/filters/jwt-decode"
|
4
|
+
require "jwt"
|
4
5
|
|
5
6
|
describe LogStash::Filters::JWTDecode do
|
7
|
+
|
8
|
+
context "Configuration Validations " do
|
9
|
+
describe " No match field" do
|
10
|
+
it "Expect LogStash::ConfigurationError" do
|
11
|
+
expect{
|
12
|
+
filter = setup_filter({
|
13
|
+
"extract_fields" => {"business_id" => "user.busId"}
|
14
|
+
})
|
15
|
+
}.to raise_error(LogStash::ConfigurationError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe " No extract_fields" do
|
20
|
+
it "Expect LogStash::ConfigurationError" do
|
21
|
+
expect{
|
22
|
+
filter = setup_filter({
|
23
|
+
"match" => "token"
|
24
|
+
})
|
25
|
+
}.to raise_error(LogStash::ConfigurationError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe " No signature_alg defined for key" do
|
30
|
+
it "Expect LogStash::ConfigurationError" do
|
31
|
+
expect{
|
32
|
+
filter = setup_filter({
|
33
|
+
"match" => "token",
|
34
|
+
"extract_fields" => {"name" => "user.name", "id" => "user.id"},
|
35
|
+
"key" => "SECRET",
|
36
|
+
"signature_alg"=> nil
|
37
|
+
})
|
38
|
+
}.to raise_error(LogStash::ConfigurationError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe " Invalid Key" do
|
43
|
+
it "Expect JWT::VerificationError" do
|
44
|
+
expect{
|
45
|
+
filter = setup_filter({
|
46
|
+
"match" => "token",
|
47
|
+
"extract_fields" => {"name" => "user.name", "id" => "user.id"},
|
48
|
+
"key" => "SECRET123",
|
49
|
+
"signature_alg"=>"HS256"
|
50
|
+
})
|
51
|
+
event = start_event({"token" => "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7Im5hbWUiOiJ0ZXN0TmFtZSIsImlkIjo0fX0.5fs1Ghwm9rtN2GaB66bhTLbYrEAuBxh4s46uOyX6Zos"})
|
52
|
+
filter.filter(event)
|
53
|
+
}.to raise_error(JWT::VerificationError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
6
59
|
context "Check Decode token" do
|
7
|
-
describe "
|
8
|
-
it "
|
60
|
+
describe " Decode token with no key " do
|
61
|
+
it "Decode token with no key" do
|
9
62
|
filter = setup_filter({
|
10
63
|
"match" => "token",
|
11
|
-
"extract_fields" => {"
|
64
|
+
"extract_fields" => {"name" => "user.name", "id" => "user.id"}
|
12
65
|
})
|
13
|
-
event = start_event({"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
66
|
+
event = start_event({"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5hbWUiOiJ0ZXN0TmFtZSIsImlkIjo0fX0.P_GRg4n5J7ka3SQKG308clou9OuyxLxAj6V7kb7NcQQ"})
|
14
67
|
filter.filter(event)
|
15
|
-
expect(event.get("
|
68
|
+
expect(event.get("id")).to eq(4)
|
69
|
+
expect(event.get("name")).to eq("testName")
|
16
70
|
end
|
17
71
|
end
|
72
|
+
|
73
|
+
describe " Decode token with key " do
|
74
|
+
it "Decode token with no key" do
|
75
|
+
filter = setup_filter({
|
76
|
+
"match" => "token",
|
77
|
+
"extract_fields" => {"name" => "user.name", "id" => "user.id"},
|
78
|
+
"key" => "SECRET",
|
79
|
+
"signature_alg"=>"HS256"
|
80
|
+
})
|
81
|
+
event = start_event({"token" => "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7Im5hbWUiOiJ0ZXN0TmFtZSIsImlkIjo0fX0.5fs1Ghwm9rtN2GaB66bhTLbYrEAuBxh4s46uOyX6Zos"})
|
82
|
+
filter.filter(event)
|
83
|
+
expect(event.get("id")).to eq(4)
|
84
|
+
expect(event.get("name")).to eq("testName")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
18
88
|
end
|
89
|
+
|
19
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-jwt-decode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bharat Raj Arutla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|