logstash-filter-jwt-decode 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94b7495aae39a0ee8b0719922256ca9f697ad46c198a77737c2006d9c143a89b
4
+ data.tar.gz: 86be2b917a8af634572f4c844592cf24f42b5bf520e2d6290407d4e500dc0377
5
+ SHA512:
6
+ metadata.gz: 51a42eff24bf245dec14d6cff741f6b2a1c9de9d85480c30791f2d26b3a89c648409108a6d50a056fabc6435dc2fca48922035a8aed63ad2a53e345d5b76ad10
7
+ data.tar.gz: 6fad7d27efc836d57a2de63bc7745e2f652a93835d618980c9daf841204c03dd4061d2edd136f848bb93482e98c12c4f6d167a1b9ced41fcd833d7e75e0f2246
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Bharat Raj Arutla - v-bharat.a@turvo.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-jwt-decode
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/logstash-plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "jwt"
4
+
5
+ # This filter will decode the jwt token in your message event and retrievs the values
6
+ # as specified in `extract_fields` and adds the extracted values to the event.
7
+ #
8
+ # It is only intended to be used as an .
9
+ class LogStash::Filters::JWTDecode < LogStash::Filters::Base
10
+
11
+ # Setting the config_name here is required. This is how you
12
+ # configure this filter from your Logstash config.
13
+ #
14
+ # jwt-decode {
15
+ # "match" => "token",
16
+ # "extract_fields" => {"business_id" => "user.busId"}
17
+ # }
18
+ #
19
+ #
20
+ #
21
+ config_name "jwt-decode"
22
+
23
+ # Looks for a match in message which contains the token field
24
+ config :match, :validate => :string, :required => true
25
+ # Supported Algorithms NONE, HMAC, RSASSA and ECDSA
26
+ config :signature_alg, :validate => :string, :required => false, :default => "NONE"
27
+ config :key, :validate => :string, :required => false, :default => nil
28
+ config :extract_fields, :validate => :hash, :required => true
29
+
30
+
31
+ public
32
+ def register
33
+ # Add instance variables
34
+ if not ['NONE', 'HMAC', 'RSASSA', 'ECDSA'].include? @signature_alg
35
+ raise LogStash::ConfigurationError, "JWTDecode plugin: Invalid signature_alg '#{@signature_alg}' must be one of NONE, HMAC, RSASSA and ECDSA"
36
+ end
37
+ end # def register
38
+
39
+ public
40
+ def filter(event)
41
+ decoded_token = JWT.decode event.get(@match), @key, false, {algorithm: @signature_alg}
42
+ @extract_fields.each do |k, v|
43
+ event.set(k , getValueFromDecodedToken(v, decoded_token[0]))
44
+ end
45
+ # filter_matched should go in the last line of our successful code
46
+ filter_matched(event)
47
+ end # def filter
48
+
49
+ private
50
+ def getValueFromDecodedToken(key, decoded_token)
51
+ key.split(".").each do |val, index|
52
+ if decoded_token.nil?
53
+ return nil
54
+ end
55
+ decoded_token = decoded_token[val]
56
+ end
57
+ return decoded_token;
58
+ end
59
+ end # class LogStash::Filters::JWTDecode
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-jwt-decode'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Logstash filter plugin for decoding JSON Web Token (JWT)'
6
+ s.description = 'Logstash filter plugin for decoding JSON Web Token (JWT)'
7
+ s.homepage = 'https://github.com/bharatraj88/logstash-filter-jwt-decode'
8
+ s.authors = ['Bharat Raj Arutla']
9
+ s.email = 'bharatraj.arutla@gmail.com'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ s.add_development_dependency 'jwt',"=1.5.6"
24
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/jwt-decode"
4
+
5
+ describe LogStash::Filters::JWTDecode do
6
+ context "Check Decode token" do
7
+ describe " registering filter with all params" do
8
+ it "Get business from Token" do
9
+ filter = setup_filter({
10
+ "match" => "token",
11
+ "extract_fields" => {"business_id" => "user.busId"}
12
+ })
13
+ event = start_event({"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJuYW1lIjoidGVzdEB0dXJ2by5jb20iLCJjbGllbnRJZCI6Im1hZ2VsbGFuLXdzIiwiYnVzSWQiOjQsImJ1c05hbWUiOiJUZXN0IiwibG9naW5CeUlkIjo3LCJsb2dpbkJ5TmFtZSI6IlRlc3QgVXNlciAgICIsInVzZXJUaW1lem9uZSI6IkFtZXJpY2EvTG9zX0FuZ2VsZXMiLCJidXNUaW1lem9uZSI6IkFtZXJpY2EvTG9zX0FuZ2VsZXMiLCJ0eXBlIjoiQlVTVVNFUiIsImFkbWluIjpmYWxzZSwiZGV2aWNlSWQiOm51bGwsInNjb3BlIjoicmVhZCx3cml0ZSIsImF1dGhvcml6ZWRHcmFudFR5cGVzIjpudWxsLCJyZXNvdXJjZUlkcyI6InJlc291cmNlLWNvcmUifX0.3weaxgRD5qRTUaazA5DWO7t5WoAJB8jghDMjJF9mWew"})
14
+ filter.filter(event)
15
+ expect(event.get("business_id")).to eq(4)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/filters/jwt-decode"
4
+
5
+ def event(data = {})
6
+ LogStash::Event.new(data)
7
+ end
8
+
9
+ def start_event(data = {})
10
+ event(data)
11
+ end
12
+
13
+ def setup_filter(config = {})
14
+ filter = LogStash::Filters::JWTDecode.new(config)
15
+ filter.register()
16
+ return filter
17
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-jwt-decode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bharat Raj Arutla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-devutils
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.6
47
+ name: jwt
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.6
55
+ description: Logstash filter plugin for decoding JSON Web Token (JWT)
56
+ email: bharatraj.arutla@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - CONTRIBUTORS
63
+ - DEVELOPER.md
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - lib/logstash/filters/jwt-decode.rb
68
+ - logstash-filter-jwt-decode.gemspec
69
+ - spec/filters/jwt-filter_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/bharatraj88/logstash-filter-jwt-decode
72
+ licenses:
73
+ - Apache-2.0
74
+ metadata:
75
+ logstash_plugin: 'true'
76
+ logstash_group: filter
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Logstash filter plugin for decoding JSON Web Token (JWT)
97
+ test_files:
98
+ - spec/filters/jwt-filter_spec.rb
99
+ - spec/spec_helper.rb