logstash-filter-fingerprint 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +82 -9
- data/lib/logstash/filters/fingerprint.rb +41 -12
- data/logstash-filter-fingerprint.gemspec +2 -1
- data/spec/filters/fingerprint_spec.rb +260 -373
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a14dcbc1585cf2f6afea7bed7a0e056d2f098bc896dc6d7571caf3c5cc3c51d
|
4
|
+
data.tar.gz: 2c7714afaaee24b9a8995d541ffa1cab5d16dc907dd3d1e98213d7b218fb0ebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbaccf02918c11b39f2f1f7bc78d7a16fbbac76d7bef9edebcb907f89cba98126708c07c05497d1e1cd5862e1846bb37b5779aaa51937382d8f416264f111328
|
7
|
+
data.tar.gz: 2df22689f778872a0cd85e000ff8ef940e7a16dfec4c469c4a846e7457e599e887768d3d26bd630af0af45ae0b6740cd800d3b2d89cd08bdb08f76124cad1d2b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 3.3.0
|
2
|
+
- Add ECS compatibility [#62](https://github.com/logstash-plugins/logstash-filter-fingerprint/pull/62)
|
3
|
+
|
4
|
+
## 3.2.4
|
5
|
+
- Fixed the error in Murmur3 with Integer [#61](https://github.com/logstash-plugins/logstash-filter-fingerprint/pull/61)
|
6
|
+
|
7
|
+
## 3.2.3
|
8
|
+
- [DOC] Expanded description for concatenate_sources behavior and provided examples [#60](https://github.com/logstash-plugins/logstash-filter-fingerprint/pull/60)
|
9
|
+
|
10
|
+
## 3.2.2
|
11
|
+
- Fixed lack of consistent fingerprints on Hash/Map objects [#55](https://github.com/logstash-plugins/logstash-filter-fingerprint/pull/55)
|
12
|
+
|
13
|
+
## 3.2.1
|
14
|
+
- Fixed concurrent SHA fingerprinting by making the instances thread local
|
15
|
+
|
1
16
|
## 3.2.0
|
2
17
|
- Added support for non-keyed, regular hash functions [#18](https://github.com/logstash-plugins/logstash-filter-fingerprint/issues/18)
|
3
18
|
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2020 Elastic and contributors
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
[![Travis Build Status](https://travis-ci.
|
3
|
+
[![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-fingerprint.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-fingerprint)
|
4
4
|
|
5
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -23,15 +23,30 @@ include::{include_path}/plugin_header.asciidoc[]
|
|
23
23
|
Create consistent hashes (fingerprints) of one or more fields and store
|
24
24
|
the result in a new field.
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
You can use this plugin to create consistent document ids when events are
|
27
|
+
inserted into Elasticsearch. This approach means that existing documents can be
|
28
|
+
updated instead of creating new documents.
|
29
29
|
|
30
|
-
NOTE: When the `
|
30
|
+
NOTE: When the `method` option is set to `UUID` the result won't be
|
31
31
|
a consistent hash but a random
|
32
32
|
https://en.wikipedia.org/wiki/Universally_unique_identifier[UUID].
|
33
33
|
To generate UUIDs, prefer the {logstash-ref}/plugins-filters-uuid.html[uuid filter].
|
34
34
|
|
35
|
+
[id="plugins-{type}s-{plugin}-ecs_metadata"]
|
36
|
+
==== Event Metadata and the Elastic Common Schema (ECS)
|
37
|
+
This plugin adds a hash value to event as an identifier. You can configure the `target` option to change the output field.
|
38
|
+
|
39
|
+
When ECS compatibility is disabled, the hash value is stored in the `fingerprint` field.
|
40
|
+
When ECS is enabled, the value is stored in the `[event][hash]` field.
|
41
|
+
|
42
|
+
Here’s how ECS compatibility mode affects output.
|
43
|
+
[cols="<l,<l,e,<e"]
|
44
|
+
|=======================================================================
|
45
|
+
| ECS disabled | ECS v1 | Availability | Description
|
46
|
+
|
47
|
+
| fingerprint | [event][hash] | Always | a hash value of event
|
48
|
+
|=======================================================================
|
49
|
+
|
35
50
|
[id="plugins-{type}s-{plugin}-options"]
|
36
51
|
==== Fingerprint Filter Configuration Options
|
37
52
|
|
@@ -43,6 +58,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
43
58
|
| <<plugins-{type}s-{plugin}-base64encode>> |<<boolean,boolean>>|No
|
44
59
|
| <<plugins-{type}s-{plugin}-concatenate_sources>> |<<boolean,boolean>>|No
|
45
60
|
| <<plugins-{type}s-{plugin}-concatenate_all_fields>> |<<boolean,boolean>>|No
|
61
|
+
| <<plugins-{type}s-{plugin}-ecs_compatibility>> | <<string,string>>|No
|
46
62
|
| <<plugins-{type}s-{plugin}-key>> |<<string,string>>|No
|
47
63
|
| <<plugins-{type}s-{plugin}-method>> |<<string,string>>, one of `["SHA1", "SHA256", "SHA384", "SHA512", "MD5", "MURMUR3", "IPV4_NETWORK", "UUID", "PUNCTUATION"]`|Yes
|
48
64
|
| <<plugins-{type}s-{plugin}-source>> |<<array,array>>|No
|
@@ -72,9 +88,53 @@ base64 encoded rather than hex encoded strings.
|
|
72
88
|
When set to `true` and `method` isn't `UUID` or `PUNCTUATION`, the
|
73
89
|
plugin concatenates the names and values of all fields given in the
|
74
90
|
`source` option into one string (like the old checksum filter) before
|
75
|
-
doing the fingerprint computation.
|
76
|
-
|
77
|
-
|
91
|
+
doing the fingerprint computation.
|
92
|
+
|
93
|
+
If `false` and multiple source fields are given, the target field will be single
|
94
|
+
fingerprint of the last source field.
|
95
|
+
|
96
|
+
**Example: `concatenate_sources`=false**
|
97
|
+
|
98
|
+
This example produces a single fingerprint that is computed from "birthday," the
|
99
|
+
last source field.
|
100
|
+
|
101
|
+
[source,ruby]
|
102
|
+
-----
|
103
|
+
fingerprint {
|
104
|
+
source => ["user_id", "siblings", "birthday"]
|
105
|
+
}
|
106
|
+
-----
|
107
|
+
|
108
|
+
The output is:
|
109
|
+
|
110
|
+
[source,ruby]
|
111
|
+
-----
|
112
|
+
"fingerprint" => "6b6390a4416131f82b6ffb509f6e779e5dd9630f".
|
113
|
+
-----
|
114
|
+
|
115
|
+
**Example: `concatenate_sources`=false with array**
|
116
|
+
|
117
|
+
If the last source field is an array, you get an array of fingerprints.
|
118
|
+
|
119
|
+
In this example, "siblings" is an array ["big brother", "little sister", "little brother"].
|
120
|
+
|
121
|
+
[source,ruby]
|
122
|
+
-----
|
123
|
+
fingerprint {
|
124
|
+
source => ["user_id", "siblings"]
|
125
|
+
}
|
126
|
+
-----
|
127
|
+
|
128
|
+
The output is:
|
129
|
+
|
130
|
+
[source,ruby]
|
131
|
+
-----
|
132
|
+
"fingerprint" => [
|
133
|
+
[0] "8a8a9323677f4095fcf0c8c30b091a0133b00641",
|
134
|
+
[1] "2ce11b313402e0e9884e094409f8d9fcf01337c2",
|
135
|
+
[2] "adc0b90f9391a82098c7b99e66a816e9619ad0a7"
|
136
|
+
],
|
137
|
+
-----
|
78
138
|
|
79
139
|
[id="plugins-{type}s-{plugin}-concatenate_all_fields"]
|
80
140
|
===== `concatenate_all_fields`
|
@@ -89,6 +149,18 @@ fingerprint computation. If `false` and at least one source field is
|
|
89
149
|
given, the target field will be an array with fingerprints of the
|
90
150
|
source fields given.
|
91
151
|
|
152
|
+
[id="plugins-{type}s-{plugin}-ecs_compatibility"]
|
153
|
+
===== `ecs_compatibility`
|
154
|
+
|
155
|
+
* Value type is <<string,string>>
|
156
|
+
* Supported values are:
|
157
|
+
** `disabled`: unstructured data added at root level
|
158
|
+
** `v1`: uses `[event][hash]` fields that are compatible with Elastic Common Schema
|
159
|
+
|
160
|
+
Controls this plugin's compatibility with the
|
161
|
+
{ecs-ref}[Elastic Common Schema (ECS)].
|
162
|
+
See <<plugins-{type}s-{plugin}-ecs_metadata>> for detailed information.
|
163
|
+
|
92
164
|
[id="plugins-{type}s-{plugin}-key"]
|
93
165
|
===== `key`
|
94
166
|
|
@@ -112,7 +184,7 @@ the cryptographic hash function with the same name will be used to generate
|
|
112
184
|
the fingerprint. When a key set, the keyed-hash (HMAC) digest function will
|
113
185
|
be used.
|
114
186
|
|
115
|
-
If set to `MURMUR3` the non-cryptographic MurmurHash function will be used.
|
187
|
+
If set to `MURMUR3` the non-cryptographic 64 bit MurmurHash function will be used.
|
116
188
|
|
117
189
|
If set to `IPV4_NETWORK` the input data needs to be a IPv4 address and
|
118
190
|
the hash value will be the masked-out address using the number of bits
|
@@ -140,7 +212,8 @@ to create the fingerprint. If an array is given, see the
|
|
140
212
|
===== `target`
|
141
213
|
|
142
214
|
* Value type is <<string,string>>
|
143
|
-
* Default value is `"fingerprint"`
|
215
|
+
* Default value is `"fingerprint"` when ECS is disabled
|
216
|
+
* Default value is `"[event][hash]"` when ECS is enabled
|
144
217
|
|
145
218
|
The name of the field where the generated fingerprint will be stored.
|
146
219
|
Any current contents of that field will be overwritten.
|
@@ -6,6 +6,7 @@ require "openssl"
|
|
6
6
|
require "ipaddr"
|
7
7
|
require "murmurhash3"
|
8
8
|
require "securerandom"
|
9
|
+
require "logstash/plugin_mixins/ecs_compatibility_support"
|
9
10
|
|
10
11
|
# Create consistent hashes (fingerprints) of one or more fields and store
|
11
12
|
# the result in a new field.
|
@@ -22,6 +23,8 @@ require "securerandom"
|
|
22
23
|
# https://en.wikipedia.org/wiki/Universally_unique_identifier[UUID].
|
23
24
|
# To generate UUIDs, prefer the <<plugins-filters-uuid,uuid filter>>.
|
24
25
|
class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
26
|
+
include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
|
27
|
+
|
25
28
|
config_name "fingerprint"
|
26
29
|
|
27
30
|
# The name(s) of the source field(s) whose contents will be used
|
@@ -31,7 +34,7 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
31
34
|
|
32
35
|
# The name of the field where the generated fingerprint will be stored.
|
33
36
|
# Any current contents of that field will be overwritten.
|
34
|
-
config :target, :validate => :string
|
37
|
+
config :target, :validate => :string
|
35
38
|
|
36
39
|
# When used with the `IPV4_NETWORK` method fill in the subnet prefix length.
|
37
40
|
# With other methods, optionally fill in the HMAC key.
|
@@ -76,6 +79,11 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
76
79
|
# without having to proide the field names in the `source` attribute
|
77
80
|
config :concatenate_all_fields, :validate => :boolean, :default => false
|
78
81
|
|
82
|
+
def initialize(*params)
|
83
|
+
super
|
84
|
+
@target ||= ecs_select[disabled: 'fingerprint', v1: '[event][hash]']
|
85
|
+
end
|
86
|
+
|
79
87
|
def register
|
80
88
|
# convert to symbol for faster comparisons
|
81
89
|
@method = @method.to_sym
|
@@ -100,7 +108,6 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
100
108
|
# nothing
|
101
109
|
else
|
102
110
|
class << self; alias_method :fingerprint, :fingerprint_openssl; end
|
103
|
-
@digest = select_digest(@method)
|
104
111
|
end
|
105
112
|
end
|
106
113
|
|
@@ -120,12 +127,12 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
120
127
|
if @concatenate_sources || @concatenate_all_fields
|
121
128
|
to_string = ""
|
122
129
|
if @concatenate_all_fields
|
123
|
-
event.to_hash.
|
130
|
+
deep_sort_hashes(event.to_hash).each do |k,v|
|
124
131
|
to_string << "|#{k}|#{v}"
|
125
132
|
end
|
126
133
|
else
|
127
134
|
@source.sort.each do |k|
|
128
|
-
to_string << "|#{k}|#{event.get(k)}"
|
135
|
+
to_string << "|#{k}|#{deep_sort_hashes(event.get(k))}"
|
129
136
|
end
|
130
137
|
end
|
131
138
|
to_string << "|"
|
@@ -135,9 +142,9 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
135
142
|
@source.each do |field|
|
136
143
|
next unless event.include?(field)
|
137
144
|
if event.get(field).is_a?(Array)
|
138
|
-
event.set(@target, event.get(field).collect { |v| fingerprint(v) })
|
145
|
+
event.set(@target, event.get(field).collect { |v| fingerprint(deep_sort_hashes(v)) })
|
139
146
|
else
|
140
|
-
event.set(@target, fingerprint(event.get(field)))
|
147
|
+
event.set(@target, fingerprint(deep_sort_hashes(event.get(field))))
|
141
148
|
end
|
142
149
|
end
|
143
150
|
end
|
@@ -146,6 +153,20 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
146
153
|
end
|
147
154
|
|
148
155
|
private
|
156
|
+
def deep_sort_hashes(object)
|
157
|
+
case object
|
158
|
+
when Hash
|
159
|
+
sorted_hash = Hash.new
|
160
|
+
object.sort.each do |sorted_key, value|
|
161
|
+
sorted_hash[sorted_key] = deep_sort_hashes(value)
|
162
|
+
end
|
163
|
+
sorted_hash
|
164
|
+
when Array
|
165
|
+
object.map {|element| deep_sort_hashes(element) }
|
166
|
+
else
|
167
|
+
object
|
168
|
+
end
|
169
|
+
end
|
149
170
|
|
150
171
|
def fingerprint_ipv4_network(ip_string)
|
151
172
|
# in JRuby 1.7.11 outputs as US-ASCII
|
@@ -153,27 +174,35 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
|
|
153
174
|
end
|
154
175
|
|
155
176
|
def fingerprint_openssl(data)
|
177
|
+
# since OpenSSL::Digest instances aren't thread safe, we must ensure that
|
178
|
+
# each pipeline worker thread gets its own instance.
|
179
|
+
# Also, since a logstash pipeline may contain multiple fingerprint filters
|
180
|
+
# we must include the id in the thread local variable name, so that we can
|
181
|
+
# store multiple digest instances
|
182
|
+
digest_string = "digest-#{id}"
|
183
|
+
Thread.current[digest_string] ||= select_digest(@method)
|
184
|
+
digest = Thread.current[digest_string]
|
156
185
|
# in JRuby 1.7.11 outputs as ASCII-8BIT
|
157
186
|
if @key.nil?
|
158
187
|
if @base64encode
|
159
|
-
|
188
|
+
digest.base64digest(data.to_s).force_encoding(Encoding::UTF_8)
|
160
189
|
else
|
161
|
-
|
190
|
+
digest.hexdigest(data.to_s).force_encoding(Encoding::UTF_8)
|
162
191
|
end
|
163
192
|
else
|
164
193
|
if @base64encode
|
165
|
-
hash = OpenSSL::HMAC.digest(
|
194
|
+
hash = OpenSSL::HMAC.digest(digest, @key, data.to_s)
|
166
195
|
Base64.strict_encode64(hash).force_encoding(Encoding::UTF_8)
|
167
196
|
else
|
168
|
-
OpenSSL::HMAC.hexdigest(
|
197
|
+
OpenSSL::HMAC.hexdigest(digest, @key, data.to_s).force_encoding(Encoding::UTF_8)
|
169
198
|
end
|
170
199
|
end
|
171
200
|
end
|
172
201
|
|
173
202
|
def fingerprint_murmur3(value)
|
174
203
|
case value
|
175
|
-
when
|
176
|
-
MurmurHash3::V32.
|
204
|
+
when Integer
|
205
|
+
MurmurHash3::V32.int64_hash(value)
|
177
206
|
else
|
178
207
|
MurmurHash3::V32.str_hash(value.to_s)
|
179
208
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-fingerprint'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.3.0'
|
5
5
|
s.licenses = ['Apache-2.0']
|
6
6
|
s.summary = "Fingerprints fields by replacing values with a consistent hash"
|
7
7
|
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"
|
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
24
|
s.add_runtime_dependency "murmurhash3" #(MIT license)
|
25
25
|
s.add_development_dependency 'logstash-devutils'
|
26
|
+
s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2'
|
26
27
|
end
|
27
28
|
|
@@ -1,415 +1,302 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/devutils/rspec/spec_helper"
|
3
3
|
require "logstash/filters/fingerprint"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "fingerprint string with MURMUR3 method" do
|
24
|
-
config <<-CONFIG
|
25
|
-
filter {
|
26
|
-
fingerprint {
|
27
|
-
source => ["clientip"]
|
28
|
-
method => "MURMUR3"
|
29
|
-
}
|
30
|
-
}
|
31
|
-
CONFIG
|
32
|
-
|
33
|
-
sample("clientip" => "123.52.122.33") do
|
34
|
-
insist { subject.get("fingerprint") } == 1541804874
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "fingerprint string with SHA1 algorithm" do
|
39
|
-
config <<-CONFIG
|
40
|
-
filter {
|
41
|
-
fingerprint {
|
42
|
-
source => ["clientip"]
|
43
|
-
method => 'SHA1'
|
44
|
-
}
|
45
|
-
}
|
46
|
-
CONFIG
|
47
|
-
|
48
|
-
sample("clientip" => "123.123.123.123") do
|
49
|
-
insist { subject.get("fingerprint") } == "3a5076c520b4b463f43806896ea0b3978d09dcae"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "fingerprint string with SHA1 HMAC algorithm" do
|
54
|
-
config <<-CONFIG
|
55
|
-
filter {
|
56
|
-
fingerprint {
|
57
|
-
source => ["clientip"]
|
58
|
-
key => "longencryptionkey"
|
59
|
-
method => 'SHA1'
|
60
|
-
}
|
61
|
-
}
|
62
|
-
CONFIG
|
63
|
-
|
64
|
-
sample("clientip" => "123.123.123.123") do
|
65
|
-
insist { subject.get("fingerprint") } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "fingerprint string with SHA1 HMAC algorithm on all event fields" do
|
70
|
-
config <<-CONFIG
|
71
|
-
filter {
|
72
|
-
fingerprint {
|
73
|
-
concatenate_all_fields => true
|
74
|
-
key => "longencryptionkey"
|
75
|
-
method => 'SHA1'
|
76
|
-
}
|
77
|
-
}
|
78
|
-
CONFIG
|
79
|
-
|
80
|
-
# The @timestamp field is specified in this sample event as we need the event contents to be constant for the tests
|
81
|
-
sample("@timestamp" => "2017-07-26T14:44:27.064Z", "clientip" => "123.123.123.123", "message" => "This is a test message", "log_level" => "INFO", "offset" => 123456789, "type" => "test") do
|
82
|
-
insist { subject.get("fingerprint") } == "d7c617f4d40b2cb677a7003af68a41c415f58031"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "fingerprint string with SHA1 algorithm and base64 encoding" do
|
87
|
-
config <<-CONFIG
|
88
|
-
filter {
|
89
|
-
fingerprint {
|
90
|
-
source => ["clientip"]
|
91
|
-
method => 'SHA1'
|
92
|
-
base64encode => true
|
93
|
-
}
|
94
|
-
}
|
95
|
-
CONFIG
|
96
|
-
|
97
|
-
sample("clientip" => "123.123.123.123") do
|
98
|
-
insist { subject.get("fingerprint") } == "OlB2xSC0tGP0OAaJbqCzl40J3K4="
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "fingerprint string with SHA1 HMAC algorithm and base64 encoding" do
|
103
|
-
config <<-CONFIG
|
104
|
-
filter {
|
105
|
-
fingerprint {
|
106
|
-
source => ["clientip"]
|
107
|
-
key => "longencryptionkey"
|
108
|
-
method => 'SHA1'
|
109
|
-
base64encode => true
|
110
|
-
}
|
111
|
-
}
|
112
|
-
CONFIG
|
113
|
-
|
114
|
-
sample("clientip" => "123.123.123.123") do
|
115
|
-
insist { subject.get("fingerprint") } == "/cYKzEdz3FrFaf+3j8uTyWMHl/Q="
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "fingerprint string with SHA256 algorithm" do
|
120
|
-
config <<-CONFIG
|
121
|
-
filter {
|
122
|
-
fingerprint {
|
123
|
-
source => ["clientip"]
|
124
|
-
method => 'SHA256'
|
125
|
-
}
|
126
|
-
}
|
127
|
-
CONFIG
|
128
|
-
|
129
|
-
sample("clientip" => "123.123.123.123") do
|
130
|
-
insist { subject.get("fingerprint") } == "4dabcab210766e35f03e77120e6986d6e6d4752b2a9ff22980b9253d026080d8"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "fingerprint string with SHA256 HMAC algorithm" do
|
135
|
-
config <<-CONFIG
|
136
|
-
filter {
|
137
|
-
fingerprint {
|
138
|
-
source => ["clientip"]
|
139
|
-
key => "longencryptionkey"
|
140
|
-
method => 'SHA256'
|
141
|
-
}
|
142
|
-
}
|
143
|
-
CONFIG
|
144
|
-
|
145
|
-
sample("clientip" => "123.123.123.123") do
|
146
|
-
insist { subject.get("fingerprint") } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "fingerprint string with SHA256 HMAC algorithm and base64 encoding" do
|
151
|
-
config <<-CONFIG
|
152
|
-
filter {
|
153
|
-
fingerprint {
|
154
|
-
source => ["clientip"]
|
155
|
-
key => "longencryptionkey"
|
156
|
-
method => 'SHA256'
|
157
|
-
base64encode => true
|
158
|
-
}
|
159
|
-
}
|
160
|
-
CONFIG
|
161
|
-
|
162
|
-
sample("clientip" => "123.123.123.123") do
|
163
|
-
insist { subject.get("fingerprint") } == "NFvsPv8kLVO1aJFsJhCz45PYhda5bWQ/OElP10v0qco="
|
4
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
|
5
|
+
|
6
|
+
describe LogStash::Filters::Fingerprint, :ecs_compatibility_support, :aggregate_failures do
|
7
|
+
ecs_compatibility_matrix(:disabled, :v1, :v8 => :v1) do |ecs_select|
|
8
|
+
|
9
|
+
let(:plugin) { described_class.new(config) }
|
10
|
+
let(:config) { { "method" => fingerprint_method } }
|
11
|
+
let(:fingerprint_method) { "SHA1" } # default
|
12
|
+
let(:data) { {} }
|
13
|
+
let(:event) { LogStash::Event.new(data) }
|
14
|
+
let(:fingerprint) { event.get(ecs_select[disabled: "fingerprint", v1: "[event][hash]"]) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
|
18
|
+
plugin.register
|
19
|
+
plugin.filter(event)
|
164
20
|
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "fingerprint string with SHA384 algorithm" do
|
168
|
-
config <<-CONFIG
|
169
|
-
filter {
|
170
|
-
fingerprint {
|
171
|
-
source => ["clientip"]
|
172
|
-
method => 'SHA384'
|
173
|
-
}
|
174
|
-
}
|
175
|
-
CONFIG
|
176
21
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "fingerprint string with SHA384 HMAC algorithm" do
|
183
|
-
config <<-CONFIG
|
184
|
-
filter {
|
185
|
-
fingerprint {
|
186
|
-
source => ["clientip"]
|
187
|
-
key => "longencryptionkey"
|
188
|
-
method => 'SHA384'
|
189
|
-
}
|
190
|
-
}
|
191
|
-
CONFIG
|
22
|
+
context "with a string field" do
|
23
|
+
let(:data) { {"clientip" => "123.123.123.123" } }
|
24
|
+
let(:config) { super().merge("source" => ["clientip" ]) }
|
192
25
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end
|
26
|
+
describe "the IPV4_NETWORK method" do
|
27
|
+
let(:fingerprint_method) { "IPV4_NETWORK" }
|
28
|
+
let(:config) { super().merge("key" => 24) }
|
197
29
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
source => ["clientip"]
|
203
|
-
key => "longencryptionkey"
|
204
|
-
method => 'SHA384'
|
205
|
-
base64encode => true
|
206
|
-
}
|
207
|
-
}
|
208
|
-
CONFIG
|
30
|
+
it "fingerprints the ip as the network" do
|
31
|
+
expect(fingerprint).to eq("123.123.123.0")
|
32
|
+
end
|
33
|
+
end
|
209
34
|
|
210
|
-
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|
35
|
+
describe "the MURMUR3 method" do
|
36
|
+
let(:fingerprint_method) { "MURMUR3" }
|
214
37
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
method => 'SHA512'
|
221
|
-
}
|
222
|
-
}
|
223
|
-
CONFIG
|
38
|
+
context "string" do
|
39
|
+
it "fingerprints the value" do
|
40
|
+
expect(fingerprint).to eq(4013733395)
|
41
|
+
end
|
42
|
+
end
|
224
43
|
|
225
|
-
|
226
|
-
|
227
|
-
end
|
228
|
-
end
|
44
|
+
context "number" do
|
45
|
+
let(:data) { {"clientip" => 123 } }
|
229
46
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
key => "longencryptionkey"
|
236
|
-
method => 'SHA512'
|
237
|
-
}
|
238
|
-
}
|
239
|
-
CONFIG
|
47
|
+
it "fingerprints the value" do
|
48
|
+
expect(fingerprint).to eq(823512154)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
240
52
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
53
|
+
describe "the SHA1 method" do
|
54
|
+
let(:fingerprint_method) { "SHA1" }
|
55
|
+
|
56
|
+
it "fingerprints the value" do
|
57
|
+
expect(fingerprint).to eq("3a5076c520b4b463f43806896ea0b3978d09dcae")
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with HMAC" do
|
61
|
+
let(:config) { super().merge("key" => "longencryptionkey") }
|
62
|
+
|
63
|
+
it "fingerprints the value" do
|
64
|
+
expect(fingerprint).to eq("fdc60acc4773dc5ac569ffb78fcb93c9630797f4")
|
65
|
+
end
|
66
|
+
context "with HMAC and base64 encoding" do
|
67
|
+
let(:config) { super().merge("base64encode" => true) }
|
68
|
+
it "fingerprints the value" do
|
69
|
+
expect(fingerprint).to eq("/cYKzEdz3FrFaf+3j8uTyWMHl/Q=")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "and base64 encoding" do
|
74
|
+
let(:config) { super().merge("base64encode" => true) }
|
75
|
+
it "fingerprints the value" do
|
76
|
+
expect(fingerprint).to eq("OlB2xSC0tGP0OAaJbqCzl40J3K4=")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
245
80
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
81
|
+
context "the SHA256 algorithm" do
|
82
|
+
let(:fingerprint_method) { "SHA256" }
|
83
|
+
it "fingerprints the value" do
|
84
|
+
expect(fingerprint).to eq("4dabcab210766e35f03e77120e6986d6e6d4752b2a9ff22980b9253d026080d8")
|
85
|
+
end
|
86
|
+
context "with HMAC" do
|
87
|
+
let(:config) { super().merge("key" => "longencryptionkey") }
|
88
|
+
it "fingerprints the value" do
|
89
|
+
expect(fingerprint).to eq("345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca")
|
90
|
+
end
|
91
|
+
context "and base64 encoding" do
|
92
|
+
let(:config) { super().merge("base64encode" => true) }
|
93
|
+
it "fingerprints the value" do
|
94
|
+
expect(fingerprint).to eq("NFvsPv8kLVO1aJFsJhCz45PYhda5bWQ/OElP10v0qco=")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
257
99
|
|
258
|
-
|
259
|
-
|
100
|
+
context "the SHA384 algorithm" do
|
101
|
+
let(:fingerprint_method) { "SHA384" }
|
102
|
+
it "fingerprints the value" do
|
103
|
+
expect(fingerprint).to eq("fd605b0a3af3e04ce0d7a0b0d9c48d67a12dab811f60072e6eae84e35d567793ffb68a1807536f11c90874065c2a4392")
|
104
|
+
end
|
105
|
+
context "with HMAC" do
|
106
|
+
let(:config) { super().merge("key" => "longencryptionkey") }
|
107
|
+
it "fingerprints the value" do
|
108
|
+
expect(fingerprint).to eq("22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a")
|
109
|
+
end
|
110
|
+
context "and base64 encoding" do
|
111
|
+
let(:config) { super().merge("base64encode" => true) }
|
112
|
+
it "fingerprints the value" do
|
113
|
+
expect(fingerprint).to eq("ItTA6MT7zcSIfSA4/KdlDw4uDiRX/0HAbrKpgN3tZ0lWHIFP4YKv+T4lONGFk5R6")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context "the SHA512 algorithm" do
|
119
|
+
let(:fingerprint_method) { "SHA512" }
|
120
|
+
it "fingerprints the value" do
|
121
|
+
expect(fingerprint).to eq("5468e2dc64ea92b617782aae884b35af60041ac9e168a283615b6a462c54c13d42fa9542cce9b7d76a8124ac6616818905e3e5dd35d6e519f77c3b517558639a")
|
122
|
+
end
|
123
|
+
context "with HMAC" do
|
124
|
+
let(:config) { super().merge("key" => "longencryptionkey") }
|
125
|
+
it "fingerprints the value" do
|
126
|
+
expect(fingerprint).to eq("11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8")
|
127
|
+
end
|
128
|
+
context "and base64 encoding" do
|
129
|
+
let(:config) { super().merge("base64encode" => true) }
|
130
|
+
it "fingerprints the value" do
|
131
|
+
expect(fingerprint).to eq("EcGbMmk2wI1sUKPIR9iD5aE2Lmpk3VUgGiXywawbZz99i/FbjxEqSXgnbVcydeOxQWbhckb2cMKlOUAcW/2s6A==")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
context "the MD5 algorithm" do
|
137
|
+
let(:fingerprint_method) { "MD5" }
|
138
|
+
it "fingerprints the value" do
|
139
|
+
expect(fingerprint).to eq("ccdd8d3d940a01b2fb3258c059924c0d")
|
140
|
+
end
|
141
|
+
context "with HMAC" do
|
142
|
+
let(:config) { super().merge("key" => "longencryptionkey") }
|
143
|
+
it "fingerprints the value" do
|
144
|
+
expect(fingerprint).to eq("9336c879e305c9604a3843fc3e75948f")
|
145
|
+
end
|
146
|
+
context "and base64 encoding" do
|
147
|
+
let(:config) { super().merge("base64encode" => true) }
|
148
|
+
it "fingerprints the value" do
|
149
|
+
expect(fingerprint).to eq("kzbIeeMFyWBKOEP8PnWUjw==")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
260
154
|
end
|
261
|
-
end
|
262
155
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
fingerprint {
|
267
|
-
source => ["clientip"]
|
268
|
-
method => 'MD5'
|
269
|
-
}
|
270
|
-
}
|
271
|
-
CONFIG
|
156
|
+
context "multiple values in the source field" do
|
157
|
+
let(:config) { super().merge("source" => ["clientip" ]) }
|
158
|
+
let(:data) { { "clientip" => [ "123.123.123.123", "223.223.223.223" ] } }
|
272
159
|
|
273
|
-
|
274
|
-
|
160
|
+
it "produces a fingerprint array" do
|
161
|
+
expect(fingerprint).to eq(["3a5076c520b4b463f43806896ea0b3978d09dcae", "47bbc4e06edebbace047fed35abeceec64968b81"])
|
162
|
+
end
|
275
163
|
end
|
276
|
-
end
|
277
164
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
method => 'MD5'
|
285
|
-
}
|
286
|
-
}
|
287
|
-
CONFIG
|
165
|
+
describe "concatenate_all_fields" do
|
166
|
+
let(:config) { { "concatenate_all_fields" => true } }
|
167
|
+
# The @timestamp field is specified in this sample event as we need the event contents to be constant for the tests
|
168
|
+
let(:data) do
|
169
|
+
{ "@timestamp" => "2017-07-26T14:44:27.064Z", "clientip" => "123.123.123.123", "message" => "This is a test message", "log_level" => "INFO", "offset" => 123456789, "type" => "test" }
|
170
|
+
end
|
288
171
|
|
289
|
-
|
290
|
-
|
172
|
+
it "fingerprints the concatenated values" do
|
173
|
+
expect(fingerprint).to eq("cbf022518e97860403160ed8a41847c0db104e63")
|
174
|
+
end
|
291
175
|
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe "fingerprint string with MD5 HMAC algorithm and base64 encoding" do
|
295
|
-
config <<-CONFIG
|
296
|
-
filter {
|
297
|
-
fingerprint {
|
298
|
-
source => ["clientip"]
|
299
|
-
key => "longencryptionkey"
|
300
|
-
method => 'MD5'
|
301
|
-
base64encode => true
|
302
|
-
}
|
303
|
-
}
|
304
|
-
CONFIG
|
305
176
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
end
|
177
|
+
context "when multiple fields are used" do
|
178
|
+
let(:config) { super().merge("source" => ['field1', 'field2']) }
|
179
|
+
let(:data) { { "field1" => "test1", "field2" => "test2" } }
|
310
180
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
source => ["clientip"]
|
316
|
-
key => "longencryptionkey"
|
317
|
-
method => 'MD5'
|
318
|
-
}
|
319
|
-
}
|
320
|
-
CONFIG
|
181
|
+
it "fingerprints the value of the last value" do
|
182
|
+
# SHA1 of "test2"
|
183
|
+
expect(fingerprint).to eq("109f4b3c50d7b0df729d299bc6f8e9ef9066971f")
|
184
|
+
end
|
321
185
|
|
322
|
-
|
323
|
-
|
186
|
+
describe "with concatenate_sources" do
|
187
|
+
let(:config) { super().merge("concatenate_sources" => true) }
|
188
|
+
it "fingerprints the value of concatenated key/pairs" do
|
189
|
+
# SHA1 of "|field1|test1|field2|test2|"
|
190
|
+
expect(fingerprint).to eq("e3b6b71eedc656f1d29408264e8a75535db985cb")
|
191
|
+
end
|
192
|
+
end
|
324
193
|
end
|
325
|
-
end
|
326
194
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
source => ['field1', 'field2']
|
332
|
-
key => "longencryptionkey"
|
333
|
-
method => 'MD5'
|
334
|
-
}
|
335
|
-
}
|
336
|
-
CONFIG
|
195
|
+
describe "PUNCTUATION method" do
|
196
|
+
let(:fingerprint_method) { 'PUNCTUATION' }
|
197
|
+
let(:config) { super().merge("source" => 'field1') }
|
198
|
+
let(:data) { { "field1" => "PHP Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in /var/www/htdocs/test.php on line 233" } }
|
337
199
|
|
338
|
-
|
339
|
-
|
200
|
+
it "extracts punctiation as the fingerprint" do
|
201
|
+
expect(fingerprint).to eq(":_()[<='.-'>.-</>]:-////.")
|
202
|
+
end
|
340
203
|
end
|
341
|
-
end
|
342
204
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
end
|
205
|
+
context 'Timestamps' do
|
206
|
+
epoch_time = Time.at(0).gmtime
|
207
|
+
let(:config) { super().merge("source" => ['@timestamp']) }
|
208
|
+
|
209
|
+
describe 'OpenSSL Fingerprinting' do
|
210
|
+
let(:config) { super().merge("key" => '0123') }
|
211
|
+
let(:fingerprint_method) { "SHA1" }
|
212
|
+
let(:data) { { "@timestamp" => epoch_time } }
|
213
|
+
it "fingerprints the timestamp correctly" do
|
214
|
+
expect(fingerprint).to eq('1d5379ec92d86a67cfc642d55aa050ca312d3b9a')
|
215
|
+
end
|
216
|
+
end
|
356
217
|
|
357
|
-
|
358
|
-
|
218
|
+
describe 'MURMUR3 Fingerprinting' do
|
219
|
+
let(:fingerprint_method) { "MURMUR3" }
|
220
|
+
let(:data) { { "@timestamp" => epoch_time } }
|
221
|
+
it "fingerprints the timestamp correctly" do
|
222
|
+
expect(fingerprint).to eq(743372282)
|
223
|
+
end
|
224
|
+
end
|
359
225
|
end
|
360
|
-
end
|
361
226
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
source => ['@timestamp']
|
370
|
-
key => '0123'
|
371
|
-
method => 'SHA1'
|
372
|
-
}
|
227
|
+
describe "post fingerprint execution triggers" do
|
228
|
+
let(:fingerprint_method) { "PUNCTUATION" }
|
229
|
+
let(:config) do
|
230
|
+
{
|
231
|
+
"source" => 'field1',
|
232
|
+
"add_field" => { 'myfield' => 'myvalue' },
|
233
|
+
"add_tag" => ['mytag']
|
373
234
|
}
|
374
|
-
|
235
|
+
end
|
236
|
+
let(:data) { { "field1" => "Hello, World!" } }
|
375
237
|
|
376
|
-
|
377
|
-
|
238
|
+
it "adds the new field" do
|
239
|
+
expect(event.get("myfield")).to eq("myvalue")
|
240
|
+
end
|
241
|
+
it "adds the new tag" do
|
242
|
+
expect(event.get("tags")).to include("mytag")
|
378
243
|
end
|
379
244
|
end
|
380
245
|
|
381
|
-
describe
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
246
|
+
describe "tolerance to hash order" do
|
247
|
+
# insertion order can influence the result of to_hash's keys
|
248
|
+
let(:data1) { {
|
249
|
+
"a" => {"a0" => 0, "a1" => 1},
|
250
|
+
"b" => {"b0" => 0, "b1" => 1},
|
251
|
+
} }
|
252
|
+
let(:event1) { LogStash::Event.new(data1) }
|
253
|
+
let(:data2) { {
|
254
|
+
"b" => {"b1" => 1, "b0" => 0},
|
255
|
+
"a" => {"a1" => 1, "a0" => 0},
|
256
|
+
} }
|
257
|
+
let(:event2) { LogStash::Event.new(data2) }
|
258
|
+
let(:config) { { "source" => [ "a" ] } }
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
# for testing purposes we want to ensure the hash order is different.
|
262
|
+
# since we can't easily control the order on the underlying Map,
|
263
|
+
# we're mocking the order here:
|
264
|
+
allow(event1).to receive(:to_hash).and_return(data1)
|
265
|
+
allow(event2).to receive(:to_hash).and_return(data2)
|
266
|
+
# by default event.get(key) fetches data from the event.
|
267
|
+
# mocking the default value has to be done first, and only
|
268
|
+
# then we can mock the getting "a" and "b"
|
269
|
+
allow(event1).to receive(:get).and_call_original
|
270
|
+
allow(event2).to receive(:get).and_call_original
|
271
|
+
# mock event.get("a") and event.get("b") for both events
|
272
|
+
# so we can inject an inconsistent order for the tests
|
273
|
+
allow(event1).to receive(:get).with("a") {|arg| data1["a"] }
|
274
|
+
allow(event1).to receive(:get).with("b") {|arg| data1["b"] }
|
275
|
+
allow(event2).to receive(:get).with("a") {|arg| data2["a"] }
|
276
|
+
allow(event2).to receive(:get).with("b") {|arg| data2["b"] }
|
277
|
+
plugin.filter(event1)
|
278
|
+
plugin.filter(event2)
|
279
|
+
end
|
280
|
+
it "computes the same hash" do
|
281
|
+
# confirm the order of the keys in the nested hash is different
|
282
|
+
# (of course it is, we just mocked the to_hash return)
|
283
|
+
expect(event1.to_hash["a"].keys).to_not eq(event2.to_hash["a"].keys)
|
284
|
+
# let's check that the fingerprint doesn't care about the insertion order
|
285
|
+
expect(event1.get("fingerprint")).to eq(event2.get("fingerprint"))
|
286
|
+
end
|
287
|
+
context "concatenate_sources" do
|
288
|
+
let("config") { { "source" => [ "a", "b"], "concatenate_sources" => true } }
|
289
|
+
it "computes the same hash" do
|
290
|
+
expect(event1.get("fingerprint")).to eq(event2.get("fingerprint"))
|
291
|
+
end
|
292
|
+
end
|
293
|
+
context "concatenate_all_fields => true" do
|
294
|
+
let(:config) { { "concatenate_all_fields" => true } }
|
295
|
+
it "computes the same hash" do
|
296
|
+
expect(event1.get("fingerprint")).to eq(event2.get("fingerprint"))
|
297
|
+
end
|
393
298
|
end
|
394
299
|
end
|
395
|
-
end
|
396
300
|
|
397
|
-
describe "execution triggers addition of fields and tags" do
|
398
|
-
config <<-CONFIG
|
399
|
-
filter {
|
400
|
-
fingerprint {
|
401
|
-
source => 'field1'
|
402
|
-
method => 'PUNCTUATION'
|
403
|
-
add_field => { 'myfield' => 'myvalue' }
|
404
|
-
add_tag => ['mytag']
|
405
|
-
}
|
406
|
-
}
|
407
|
-
CONFIG
|
408
|
-
|
409
|
-
sample("field1" => "Hello, World!") do
|
410
|
-
insist { subject.get("myfield") } == "myvalue"
|
411
|
-
insist { subject.get("tags") } == ["mytag"]
|
412
|
-
end
|
413
301
|
end
|
414
|
-
|
415
302
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-fingerprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.2'
|
67
|
+
name: logstash-mixin-ecs_compatibility_support
|
68
|
+
prerelease: false
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.2'
|
61
75
|
description: This gem is a Logstash plugin required to be installed on top of the
|
62
76
|
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
63
77
|
gem is not a stand-alone program
|