fluent-plugin-email-obfuscate 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +29 -9
- data/fluent-plugin-email-obfuscate.gemspec +2 -1
- data/lib/fluent/plugin/filter_email_obfuscate.rb +56 -7
- data/tool/build_and_push_to_rubygems.sh +7 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8c95d15752cf1fbeeb6e933d0d42423b05ebaf1
|
4
|
+
data.tar.gz: 177b3fd14bf1c47b985aed8ac168e861006c0327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7799b236bddd340016ffe52d09f4f7bc489c08d643fc173c0d2a615d9d2a64ef9c71cab921af779467e3acfb9fb33615a301860f7c2a8bf1e92e23d81fc9f6
|
7
|
+
data.tar.gz: 951b4832e624681add3ac22b0e9ca1e57d02bd2392e3cf3c822d56feda391710b2a889f364992dafbb67030975c3b9ac4e3bd597fef9382259bfec8ad29854fe
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
**/*.gem
|
data/README.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
[Fluentd](https://fluentd.org/) filter plugin obfuscate email addresses.
|
4
4
|
|
5
|
-
|
5
|
+
[![CodeFactor](https://www.codefactor.io/repository/github/JamesJJ/fluent-plugin-email-obfuscate/badge)](https://www.codefactor.io/repository/github/JamesJJ/fluent-plugin-email-obfuscate)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-email-obfuscate.svg)](https://badge.fury.io/rb/fluent-plugin-email-obfuscate)
|
7
|
+
|
8
|
+
This filter attempts to parse each field in the record, and will obfuscate all or part of any email addresses it finds, by replacing with the same number of asterisks.
|
6
9
|
|
7
10
|
### For example:
|
8
11
|
|
@@ -66,22 +69,39 @@ $ bundle
|
|
66
69
|
|
67
70
|
## Configuration
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
<!---
|
72
|
-
You can generate configuration template:
|
72
|
+
Use `email_obfuscate` filter.
|
73
73
|
|
74
74
|
```
|
75
|
-
|
75
|
+
<filter **>
|
76
|
+
@type email_obfuscate
|
77
|
+
mode <mode>
|
78
|
+
suffix_whitelist <list>
|
79
|
+
</filter>
|
76
80
|
```
|
77
81
|
|
78
|
-
|
79
|
-
|
82
|
+
### mode (default: partial_name)
|
83
|
+
|
84
|
+
mode | Action | Example
|
85
|
+
:-- | :-- | :--
|
86
|
+
`domain_only` | Only replace all characters in the domain part | `testuser@*******.***`
|
87
|
+
`partial_name` | Replace all characters in domain and partially in the name | `testu***@*******.***`
|
88
|
+
`full` | Replace all characters in name and domain part of address | `********@*******.***`
|
89
|
+
|
90
|
+
_Note: `.` and `@` are never replaced_
|
91
|
+
|
92
|
+
### suffix_whitelist (optional)
|
93
|
+
|
94
|
+
A list of suffixes not to obfuscate. For example, with config `suffix_whitelist [".example.com", "@example.com"]` the result would be:
|
95
|
+
|
96
|
+
Input | Action
|
97
|
+
:-- | :--
|
98
|
+
`user@example.com` | no change
|
99
|
+
`user@subdomain.example.com` | no change
|
100
|
+
`user@example.museum` | obfuscated
|
80
101
|
|
81
102
|
## Todo
|
82
103
|
|
83
104
|
* Add tests!
|
84
|
-
* Support whitelists of domains not to be obfuscated
|
85
105
|
* Support configuration of which fields to act upon
|
86
106
|
* . . .
|
87
107
|
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-email-obfuscate"
|
6
|
-
spec.version = "0.0.
|
6
|
+
spec.version = "0.0.3"
|
7
7
|
spec.authors = ["JamesJJ"]
|
8
8
|
spec.email = ["jj@fcg.fyi"]
|
9
9
|
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.test_files = test_files
|
21
21
|
spec.require_paths = ["lib"]
|
22
|
+
spec.required_ruby_version = '>= 2.3.0'
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.14"
|
24
25
|
spec.add_development_dependency "rake", "~> 12.0"
|
@@ -20,33 +20,82 @@ module Fluent
|
|
20
20
|
class EmailObfuscateFilter < Fluent::Plugin::Filter
|
21
21
|
Fluent::Plugin.register_filter("email_obfuscate", self)
|
22
22
|
|
23
|
+
config_param :mode, :string, default: 'partial_name',
|
24
|
+
desc: <<-DESC
|
25
|
+
'full' will replace all characters.
|
26
|
+
'partial_name' will replace all characters in the 'domain' half of the address, and a subset of the 'name'.
|
27
|
+
'domain_only' will only replace characters in the 'domain' half of the address.
|
28
|
+
'.' and '@' are never replaced.
|
29
|
+
DESC
|
30
|
+
|
31
|
+
config_param :suffix_whitelist, :array, default: [],
|
32
|
+
desc: <<-DESC
|
33
|
+
List of email suffixes not to obfuscate e.g. ['@example.com', '.example.com'] would result in:
|
34
|
+
user@example.com => unchanged
|
35
|
+
user@subdomain.example.com => unchanged
|
36
|
+
user@example.net => obfuscated
|
37
|
+
DESC
|
38
|
+
|
39
|
+
def configure(conf)
|
40
|
+
super
|
41
|
+
|
42
|
+
if conf.has_key?('mode')
|
43
|
+
raise ConfigError, "'mode' must be one of: domain_only, full, partial_name" unless
|
44
|
+
['domain_only', 'full', 'partial_name'].include?(conf.dig('mode'))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def hide_partial(str)
|
49
|
+
case
|
50
|
+
when str.length < 5
|
51
|
+
len = str.length
|
52
|
+
when str.length < 11
|
53
|
+
len = (str.length / 2) + 2
|
54
|
+
else
|
55
|
+
len = (str.length / 3) + 4
|
56
|
+
end
|
57
|
+
str[0, len] + '*' * (str.length - len)
|
58
|
+
end
|
59
|
+
|
23
60
|
def obfuscate(str)
|
24
|
-
str.match(/^([^@]+)(@.+)$/){|m|
|
61
|
+
strmatch = str.match(/^([^@]+)(@.+)$/) { |m|
|
62
|
+
case @mode
|
63
|
+
when 'domain_only'
|
64
|
+
m[1] + m[2].tr("@.a-zA-Z0-9", "@.*")
|
65
|
+
when 'full'
|
66
|
+
m[1].gsub(/./, '*') + m[2].tr("@.a-zA-Z0-9", "@.*")
|
67
|
+
else
|
68
|
+
hide_partial(m[1]) + m[2].tr("@.a-zA-Z0-9", "@.*")
|
69
|
+
end
|
70
|
+
}
|
71
|
+
if strmatch.nil?
|
72
|
+
str
|
73
|
+
elsif @suffix_whitelist.select{ |a| str.downcase.end_with?(a.downcase)}.empty?
|
74
|
+
strmatch
|
75
|
+
else
|
76
|
+
str
|
77
|
+
end
|
25
78
|
end
|
26
79
|
|
27
80
|
def deep_process(o)
|
28
|
-
|
29
81
|
case o
|
30
82
|
when String
|
31
83
|
os = o.scan(/<([^<>]+@[^<>]+)>/)
|
32
|
-
o = os.length.zero? ? obfuscate(o) : deep_process(os).join(
|
33
|
-
|
84
|
+
o = os.length.zero? ? obfuscate(o) : deep_process(os).join(", ")
|
34
85
|
when Array
|
35
86
|
o.map! do |obj|
|
36
87
|
deep_process(obj)
|
37
88
|
end
|
38
|
-
|
39
89
|
when Hash
|
40
90
|
o.each_pair do |key, value|
|
41
91
|
o[key] = deep_process(value)
|
42
92
|
end
|
43
|
-
|
44
93
|
end
|
45
94
|
o
|
46
95
|
end
|
47
96
|
|
48
97
|
def filter(tag, time, record)
|
49
|
-
|
98
|
+
deep_process(record)
|
50
99
|
end
|
51
100
|
end
|
52
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-email-obfuscate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JamesJJ
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,6 +79,7 @@ executables: []
|
|
79
79
|
extensions: []
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
|
+
- ".gitignore"
|
82
83
|
- Gemfile
|
83
84
|
- LICENSE
|
84
85
|
- README.md
|
@@ -87,6 +88,7 @@ files:
|
|
87
88
|
- lib/fluent/plugin/filter_email_obfuscate.rb
|
88
89
|
- test/helper.rb
|
89
90
|
- test/plugin/test_filter_email_obfuscate.rb
|
91
|
+
- tool/build_and_push_to_rubygems.sh
|
90
92
|
homepage: https://github.com/JamesJJ/fluent-plugin-email-obfuscate
|
91
93
|
licenses:
|
92
94
|
- Apache-2.0
|
@@ -99,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
101
|
requirements:
|
100
102
|
- - ">="
|
101
103
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
104
|
+
version: 2.3.0
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
requirements:
|
105
107
|
- - ">="
|