logstash-filter-mask 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aff7e6693492acd7681b4a2b36a85c22acb4562c3d661709cb76805ae75689fd
4
+ data.tar.gz: 98eec5316d2f69ef69b9d70469f054117392fc82ca2613706890f38a893de973
5
+ SHA512:
6
+ metadata.gz: 69bee98e4c2c55abd9b4ce9ffb19e8239c748fee091c5c238ef5c7325c1bfdc39a5325c742bdc5e6613183b16d1b81cbc1b7bb5e33cfdd58d20b35edddc08a2c
7
+ data.tar.gz: b9c91ac313fd32b13811e63ef16958b961a8b086c6de9ca7e187a919e389f75a3dc302d358742662d207be1fca9999c37ebc47412185a07fa408ec965e8c84a0
@@ -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
+ * -
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-mask
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,86 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require 'securerandom'
4
+
5
+ # This filter will replace the contents of the default
6
+ # message field with whatever you specify in the configuration.
7
+ #
8
+ # It is only intended to be used as an .
9
+ class LogStash::Filters::Mask < 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
+ # filter {
15
+ # {
16
+ # message => "My message..."
17
+ # }
18
+ # }
19
+ #
20
+ config_name "mask"
21
+
22
+ # Replace the message with this value.
23
+ config :keys_to_mask, :validate => :string, :default => nil
24
+ config :mask_key, :validate => :string, :default => "*****"
25
+ config :message, :validate => :string, :default => "message"
26
+
27
+ public
28
+ def register
29
+ # Add instance variables
30
+ end # def register
31
+
32
+ public
33
+ def filter(event)
34
+ data = event.get(@message)
35
+
36
+ if @keys_to_mask.nil? || @keys_to_mask.empty?
37
+ raise "keys_to_mask missing"
38
+ end
39
+ keys = keys_to_mask.to_s.split(",")
40
+ logs = data['logs']
41
+
42
+ mLogs = logs.map do |log|
43
+ # This if condition is to avoid any boolean or strng type value in array of logs object
44
+ # as it is not a valid values
45
+ if !log.is_a?(FalseClass) && !log.is_a?(TrueClass) && !log.is_a?(String)
46
+ message = log['message']
47
+ if log["mask"] == "maskAll" && log["type"].match(/input|output/)
48
+ log = maskLog(log)
49
+ elsif log["type"].match(/input/)
50
+ log["message"] = maskTokens(keys, message)
51
+ end
52
+ log["uid"] = "log-#{SecureRandom.uuid}"
53
+ log
54
+ end
55
+ end
56
+ mLogs = mLogs.compact
57
+ mLogs.compact
58
+ event.set("message", mLogs)
59
+
60
+ # filter_matched should go in the last line of our successful code
61
+ filter_matched(event)
62
+ end # def filter
63
+
64
+ def maskLog(data)
65
+ if data["type"] == "input"
66
+ data["message"] = "Input data is masked"
67
+ elsif data["type"] == "output"
68
+ data["message"] = "Output data is masked"
69
+ end
70
+ return data
71
+ end
72
+
73
+ def maskTokens(keys, message)
74
+ begin
75
+ message = JSON.parse(message)
76
+ rescue
77
+ return message
78
+ end
79
+ for i in keys do
80
+ if !message[i].nil?
81
+ message[i] = mask_key
82
+ end
83
+ end
84
+ return message.to_json
85
+ end
86
+ end # class LogStash::Filters::Mask
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-mask'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['MIT']
5
+ s.summary = 'mask the sensitive keys'
6
+ s.description = 'mask the sensitive keys'
7
+ s.homepage = 'https://rubygems.org/gems/logstash-filter-mask'
8
+ s.authors = ['Ravi Shah']
9
+ s.email = 'ravi.shah@softwareag.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
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/mask"
4
+
5
+ describe LogStash::Filters::Mask do
6
+ describe "Set to Hello World" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ mask {
10
+ message => "Hello World"
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample("message" => "some text") do
17
+ expect(subject).to include("message")
18
+ expect(subject.get('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,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-mask
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ravi Shah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: mask the sensitive keys
14
+ email: ravi.shah@softwareag.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - CONTRIBUTORS
21
+ - DEVELOPER.md
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - lib/logstash/filters/mask.rb
26
+ - logstash-filter-mask.gemspec
27
+ - spec/filters/mask_spec.rb
28
+ - spec/spec_helper.rb
29
+ homepage: https://rubygems.org/gems/logstash-filter-mask
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ logstash_plugin: 'true'
34
+ logstash_group: filter
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.7.6
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: mask the sensitive keys
55
+ test_files:
56
+ - spec/filters/mask_spec.rb
57
+ - spec/spec_helper.rb