logstash-filter-jwt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0d68f1b4fd555a22117ce16b67212928de920be
4
+ data.tar.gz: 96b5915f12e31e972a010ad91f0787e8de598e4b
5
+ SHA512:
6
+ metadata.gz: 006f497ddde8c9729f6d5e2f8a8dada892c19b3bb89290cc67b4bd5aa8f43aeb255a61ce49e2c973a1d6b6611d3d21304b759b01a7820885b34397443bba6dfc
7
+ data.tar.gz: f0b1a9ad0b9fa22182ceb9cfb7572a45e6cc00ba1b0b3993a08beca7925ae21da720f58ecd9d36bd3328d3975356d95c261b9b5ff6b83934b1335f875920a1e7
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
@@ -0,0 +1,11 @@
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
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/diegofernandes/logstash-filter-jwt.svg)](https://travis-ci.org/diegofernandes/logstash-filter-jwt)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ 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/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - 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).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ 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:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "jwt"
5
+
6
+ # This example filter will replace the contents of the default
7
+ # message field with whatever you specify in the configuration.
8
+ #
9
+ # It is only intended to be used as an example.
10
+ class LogStash::Filters::JWTFilter < LogStash::Filters::Base
11
+
12
+ # Setting the config_name here is required. This is how you
13
+ # configure this filter from your Logstash config.
14
+ #
15
+ # filter {
16
+ # jwt {
17
+ # secret => "passsupersecret"
18
+ # }
19
+ # }
20
+ #
21
+ config_name "jwt"
22
+
23
+ # JWT secret
24
+ config :secret, :validate => :string
25
+ # JWT algorithm
26
+ config :algorithm , :validate => :string, :default => "HS256"
27
+ # token field
28
+ config :field, :validate => :string, :default => "token"
29
+
30
+ # Remove token field
31
+ config :remove_token, :validate => :boolean, :default => true
32
+
33
+ public
34
+ def register
35
+ # Add instance variables
36
+ end # def register
37
+
38
+ public
39
+ def filter(event)
40
+ if event.include?(@field)
41
+ token = event[@field]
42
+ begin
43
+ decoded_token = JWT.decode token, @secret, true, { :algorithm => algorithm }
44
+ @logger.debug? && @logger.debug("Decoded token is: #{decoded_token}")
45
+ event['[@metadata][jwt_data]'] = decoded_token.first
46
+ event.remove(@field) if @remove_token
47
+ filter_matched(event)
48
+ rescue => e
49
+ @logger.error("Invalid JWT token. exception => #{e.inspect}") if @logger
50
+ end
51
+ end
52
+ end # def filter
53
+ end # class LogStash::Filters::JWTFilter
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-jwt'
3
+ s.version = '1.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter validates and extracts data from Json Web Tokens"
6
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Diego Osse Fernandes"]
8
+ s.email = 'diego.osse@gmail.com'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
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", "~> 1.0"
22
+ s.add_runtime_dependency "jwt", "~> 1.5"
23
+ s.add_development_dependency 'logstash-devutils'
24
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/filters/jwt"
4
+ require "jwt"
5
+
6
+ describe LogStash::Filters::JWTFilter do
7
+ describe "JWT valid" do
8
+ secret = "test";
9
+ algorithm = 'HS256'
10
+ payload = {:data => 'test'}
11
+ token = JWT.encode payload, secret, algorithm
12
+ let(:config) do <<-CONFIG
13
+ filter {
14
+ jwt {
15
+ secret => "#{secret}"
16
+ algorithm => "#{algorithm}"
17
+ field => "token"
18
+ }
19
+ }
20
+ CONFIG
21
+ end
22
+
23
+ sample("token" => "#{token}") do
24
+ expect(subject["[@metadata][jwt_data]"]).to_not be_nil
25
+ expect(subject["[token]"]).to be_nil
26
+ expect(subject["[@metadata][jwt_data][data]"]).to eq('test')
27
+ end
28
+ end
29
+ describe "JWT invalid" do
30
+ secret = "test";
31
+ algorithm = 'HS256'
32
+ payload = {:data => 'test'}
33
+ token = JWT.encode payload, secret, algorithm
34
+ let(:config) do <<-CONFIG
35
+ filter {
36
+ jwt {
37
+ secret => "foo"
38
+ algorithm => "#{algorithm}"
39
+ field => "token"
40
+ }
41
+ }
42
+ CONFIG
43
+ end
44
+ sample("token" => "#{token}") do
45
+ expect(subject["[@metadata][jwt_data]"]).to be_nil
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-jwt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Diego Osse Fernandes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-04 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: '1.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: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.5'
33
+ name: jwt
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: logstash-devutils
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
56
+ email: diego.osse@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
+ - NOTICE.TXT
67
+ - README.md
68
+ - lib/logstash/filters/jwt.rb
69
+ - logstash-filter-jwt.gemspec
70
+ - spec/filters/jwt_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
73
+ licenses:
74
+ - Apache License (2.0)
75
+ metadata:
76
+ logstash_plugin: 'true'
77
+ logstash_group: filter
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This filter validates and extracts data from Json Web Tokens
98
+ test_files:
99
+ - spec/filters/jwt_spec.rb
100
+ - spec/spec_helper.rb