logstash-filter-auth0jwt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c6ea12e209674b3f207246b8b0e613151705c6e
4
+ data.tar.gz: 638d72570f8d0a9d451b65296504ee421553d193
5
+ SHA512:
6
+ metadata.gz: 0ed10f3470ed3b2c430f49ed5cb0dff3af1ac1acf8f91804ba67899fa4979e9854952b5d54a18f88268d2ca175c73d5c5ce24b08e9ed516f1ecbb77c54eac096
7
+ data.tar.gz: b2b8e5f7933c1c7600d44323c061c9fa2976ba0fe3604d3f154051a123244418db33f557295f1038b7c07971102370b8979d4138f03647b33f79da5171783a85
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
data/CONTRIBUTORS ADDED
@@ -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
+ * Peter Price - peter@binder.works
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.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-auth0jwt
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.
data/README.md ADDED
@@ -0,0 +1,92 @@
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
+ # Config
8
+
9
+ This filter one required configuration parameter - 'domain'. This maps to the value shown in the Auth0 dashboard under Clients > Settings > Domain.
10
+
11
+ Also available is an optional parameter - 'purge_seconds' - for configuraing the length of time for which the cache is kept.
12
+
13
+ ## Documentation
14
+
15
+ 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/).
16
+
17
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
18
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
19
+
20
+ ## Need Help?
21
+
22
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
23
+
24
+ ## Developing
25
+
26
+ ### 1. Plugin Developement and Testing
27
+
28
+ #### Code
29
+ - To get started, you'll need JRuby with the Bundler gem installed.
30
+
31
+ - 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).
32
+
33
+ - Install dependencies
34
+ ```sh
35
+ bundle install
36
+ ```
37
+
38
+ #### Test
39
+
40
+ - Update your dependencies
41
+
42
+ ```sh
43
+ bundle install
44
+ ```
45
+
46
+ - Run tests
47
+
48
+ ```sh
49
+ bundle exec rspec
50
+ ```
51
+
52
+ ### 2. Running your unpublished Plugin in Logstash
53
+
54
+ #### 2.1 Run in a local Logstash clone
55
+
56
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
57
+ ```ruby
58
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
59
+ ```
60
+ - Install plugin
61
+ ```sh
62
+ bin/logstash-plugin install --no-verify
63
+ ```
64
+ - Run Logstash with your plugin
65
+ ```sh
66
+ bin/logstash -e 'filter {awesome {}}'
67
+ ```
68
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
69
+
70
+ #### 2.2 Run in an installed Logstash
71
+
72
+ 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:
73
+
74
+ - Build your plugin gem
75
+ ```sh
76
+ gem build logstash-filter-awesome.gemspec
77
+ ```
78
+ - Install the plugin from the Logstash home
79
+ ```sh
80
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
81
+ ```
82
+ - Start Logstash and proceed to test the plugin
83
+
84
+ ## Contributing
85
+
86
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
87
+
88
+ 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.
89
+
90
+ It is more important to the community that you are able to contribute.
91
+
92
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'uri'
7
+ require 'net/https'
8
+
9
+ # This filter will replace the contents of the default
10
+ # message field with whatever you specify in the configuration.
11
+ #
12
+ # It is only intended to be used as an .
13
+ class LogStash::Filters::Auth0Jwt < LogStash::Filters::Base
14
+
15
+ # Setting the config_name here is required. This is how you
16
+ # configure this filter from your Logstash config.
17
+ #
18
+ # filter {
19
+ # {
20
+ # message => "My message..."
21
+ # }
22
+ # }
23
+ #
24
+ config_name "auth0jwt"
25
+
26
+ # Replace the message with this value.
27
+ config :domain, :validate => :string, :required => true
28
+ config :purge_seconds, :validate => :number, :default => 3600
29
+
30
+ public
31
+ def register
32
+ @cache = Hash.new
33
+ @last_purge = Time.now
34
+ end # def register
35
+
36
+ public
37
+ def filter(event)
38
+
39
+ if @last_purge - Time.now > @purge_seconds
40
+ @cache.clear
41
+ end
42
+
43
+ if !@cache[event['jwt']]
44
+ data = {
45
+ id_token: event['jwt']
46
+ }
47
+ uri = URI.parse("https://#{@domain}/tokeninfo")
48
+ headers = {'Content-Type' => "application/json"}
49
+ https = Net::HTTP.new(uri.host, uri.port)
50
+ https.use_ssl = true
51
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
52
+ request.body = data.to_json
53
+ response = https.request(request)
54
+
55
+ @cache[event['jwt']] = response.code == "200"
56
+ end
57
+
58
+ if @cache[event['jwt']] != true
59
+ event.cancel
60
+ end
61
+
62
+ # filter_matched should go in the last line of our successful code
63
+ filter_matched(event)
64
+ end # def filter
65
+ end # class LogStash::Filters::Auth0Jwt
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-auth0jwt'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = 'Logstash filter plugin for Auth0 JWT validation.'
6
+ s.description = 'Logstash filter plugin for Auth0 JWT validation.'
7
+ s.homepage = 'https://github.com/binderhq/logstash-filter-auth0jwt'
8
+ s.authors = ['Peter Price']
9
+ s.email = 'peter@binder.works'
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.60", "<= 2.99"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/auth0jwt"
4
+
5
+ describe LogStash::Filters::Auth0 do
6
+ describe "Set to Hello World" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ auth0jwt {
10
+ domain => "Hello World"
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample("message" => "some text") do
17
+ expect(subject).to include("message")
18
+ expect(subject['message']).to eq('Hello World')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-auth0jwt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Price
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.60'
20
+ - - <=
21
+ - !ruby/object:Gem::Version
22
+ version: '2.99'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - <=
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Logstash filter plugin for Auth0 JWT validation.
48
+ email: peter@binder.works
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/logstash/filters/auth0jwt.rb
54
+ - spec/filters/auth0jwt_spec.rb
55
+ - spec/spec_helper.rb
56
+ - logstash-filter-auth0jwt.gemspec
57
+ - CHANGELOG.md
58
+ - DEVELOPER.md
59
+ - README.md
60
+ - CONTRIBUTORS
61
+ - Gemfile
62
+ - LICENSE
63
+ homepage: https://github.com/binderhq/logstash-filter-auth0jwt
64
+ licenses:
65
+ - Apache License (2.0)
66
+ metadata:
67
+ logstash_plugin: 'true'
68
+ logstash_group: filter
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.0.14.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Logstash filter plugin for Auth0 JWT validation.
89
+ test_files:
90
+ - spec/filters/auth0jwt_spec.rb
91
+ - spec/spec_helper.rb