Skip to content

Commit 554ddcd

Browse files
authored
Switch to different UUID lib due to non-random generated UUIDs (#8458)
The previously used `github.com/satori/go-uuid` lib has a critical bug and it is no longer maintained. The community moved to an active fork of this existing lib named `github.com/gofrs/uuid`. I haven't seen other UUID libs worth mentioning apart from this. Changes compared to the previous dependency: * `uuid.NewV4` returns an error if the function call failed * `uuid.Equal` is deprecated and removed. The Way is to use `==` instead. Closes #8077
1 parent cff3e40 commit 554ddcd

35 files changed

+1097
-624
lines changed

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
4747
- Add backoff support to x-pack monitoring outputs. {issue}7966[7966]
4848
- Fix a race condition with the `add_host_metadata` and the event serialization. {pull}8223[8223]
4949
- Enforce that data used by k8s or docker doesn't use any reference. {pull}8240[8240]
50+
- Switch to different UUID lib due to to non-random generated UUIDs. {pull}8485[8485]
5051

5152
*Auditbeat*
5253

NOTICE.txt

+28-27
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,34 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11121112
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
11131113
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
11141114
SOFTWARE.
1115+
--------------------------------------------------------------------
1116+
Dependency: github.com/gofrs/uuid
1117+
Version: 3.1.1
1118+
Revision: 47cd1dca1a6e7f807d5a492bd7e7f41d0855b5a1
1119+
License type (autodetected): MIT
1120+
./vendor/github.com/gofrs/uuid/LICENSE:
1121+
--------------------------------------------------------------------
1122+
Copyright (C) 2013-2018 by Maxim Bublis <[email protected]>
1123+
1124+
Permission is hereby granted, free of charge, to any person obtaining
1125+
a copy of this software and associated documentation files (the
1126+
"Software"), to deal in the Software without restriction, including
1127+
without limitation the rights to use, copy, modify, merge, publish,
1128+
distribute, sublicense, and/or sell copies of the Software, and to
1129+
permit persons to whom the Software is furnished to do so, subject to
1130+
the following conditions:
1131+
1132+
The above copyright notice and this permission notice shall be
1133+
included in all copies or substantial portions of the Software.
1134+
1135+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1136+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1137+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1138+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1139+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1140+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1141+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1142+
11151143
--------------------------------------------------------------------
11161144
Dependency: github.com/gogo/protobuf
11171145
Revision: 636bf0302bc95575d69441b25a2603156ffdddf1
@@ -2078,33 +2106,6 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20782106
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20792107
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20802108

2081-
--------------------------------------------------------------------
2082-
Dependency: github.com/satori/go.uuid
2083-
Revision: 5bf94b69c6b68ee1b541973bb8e1144db23a194b
2084-
License type (autodetected): MIT
2085-
./vendor/github.com/satori/go.uuid/LICENSE:
2086-
--------------------------------------------------------------------
2087-
Copyright (C) 2013-2016 by Maxim Bublis <[email protected]>
2088-
2089-
Permission is hereby granted, free of charge, to any person obtaining
2090-
a copy of this software and associated documentation files (the
2091-
"Software"), to deal in the Software without restriction, including
2092-
without limitation the rights to use, copy, modify, merge, publish,
2093-
distribute, sublicense, and/or sell copies of the Software, and to
2094-
permit persons to whom the Software is furnished to do so, subject to
2095-
the following conditions:
2096-
2097-
The above copyright notice and this permission notice shall be
2098-
included in all copies or substantial portions of the Software.
2099-
2100-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2101-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2102-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2103-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2104-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2105-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2106-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2107-
21082109
--------------------------------------------------------------------
21092110
Dependency: github.com/shirou/gopsutil
21102111
Version: v2.18.06

filebeat/beater/filebeat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ func (fb *Filebeat) loadModulesPipelines(b *beat.Beat) error {
191191
callback := func(esClient *elasticsearch.Client) error {
192192
return fb.moduleRegistry.LoadPipelines(esClient, overwritePipelines)
193193
}
194-
elasticsearch.RegisterConnectCallback(callback)
194+
_, err := elasticsearch.RegisterConnectCallback(callback)
195195

196-
return nil
196+
return err
197197
}
198198

199199
func (fb *Filebeat) loadModulesML(b *beat.Beat, kibanaConfig *common.Config) error {

filebeat/fileset/factory.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package fileset
1919

2020
import (
21-
uuid "github.com/satori/go.uuid"
21+
"github.com/gofrs/uuid"
2222

2323
"github.com/elastic/beats/filebeat/channel"
2424
input "github.com/elastic/beats/filebeat/prospector"
@@ -147,7 +147,10 @@ func (p *inputsRunner) Start() {
147147
callback := func(esClient *elasticsearch.Client) error {
148148
return p.moduleRegistry.LoadPipelines(esClient, p.overwritePipelines)
149149
}
150-
p.pipelineCallbackID = elasticsearch.RegisterConnectCallback(callback)
150+
p.pipelineCallbackID, err = elasticsearch.RegisterConnectCallback(callback)
151+
if err != nil {
152+
logp.Err("Error registering connect callback for Elasticsearch to load pipelines: %v", err)
153+
}
151154
}
152155

153156
for _, input := range p.inputs {

filebeat/harvester/harvester.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package harvester
1919

2020
import (
21-
uuid "github.com/satori/go.uuid"
21+
"github.com/gofrs/uuid"
2222
)
2323

2424
// Harvester contains all methods which must be supported by each harvester

filebeat/harvester/registry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"errors"
2222
"sync"
2323

24-
uuid "github.com/satori/go.uuid"
24+
"github.com/gofrs/uuid"
2525

2626
"github.com/elastic/beats/libbeat/logp"
2727
)

filebeat/input/log/harvester.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"sync"
3838
"time"
3939

40-
"github.com/satori/go.uuid"
40+
"github.com/gofrs/uuid"
4141
"golang.org/x/text/transform"
4242

4343
"github.com/elastic/beats/libbeat/beat"
@@ -113,14 +113,19 @@ func NewHarvester(
113113
outletFactory OutletFactory,
114114
) (*Harvester, error) {
115115

116+
id, err := uuid.NewV4()
117+
if err != nil {
118+
return nil, err
119+
}
120+
116121
h := &Harvester{
117122
config: defaultConfig,
118123
state: state,
119124
states: states,
120125
publishState: publishState,
121126
done: make(chan struct{}),
122127
stopWg: &sync.WaitGroup{},
123-
id: uuid.NewV4(),
128+
id: id,
124129
outletFactory: outletFactory,
125130
}
126131

filebeat/input/redis/harvester.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"time"
2424

2525
rd "github.com/garyburd/redigo/redis"
26-
"github.com/satori/go.uuid"
26+
"github.com/gofrs/uuid"
2727

2828
"github.com/elastic/beats/libbeat/beat"
2929
"github.com/elastic/beats/libbeat/common"
@@ -61,12 +61,17 @@ type log struct {
6161
}
6262

6363
// NewHarvester creates a new harvester with the given connection
64-
func NewHarvester(conn rd.Conn) *Harvester {
64+
func NewHarvester(conn rd.Conn) (*Harvester, error) {
65+
id, err := uuid.NewV4()
66+
if err != nil {
67+
return nil, err
68+
}
69+
6570
return &Harvester{
66-
id: uuid.NewV4(),
71+
id: id,
6772
done: make(chan struct{}),
6873
conn: conn,
69-
}
74+
}, nil
7075
}
7176

7277
// Run starts a new redis harvester

filebeat/input/redis/input.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ func (p *Input) Run() {
9393
pool := CreatePool(host, p.config.Password, p.config.Network,
9494
p.config.MaxConn, p.config.IdleTimeout, p.config.IdleTimeout)
9595

96-
h := NewHarvester(pool.Get())
96+
h, err := NewHarvester(pool.Get())
97+
if err != nil {
98+
logp.Err("Failed to create harvester: %v", err)
99+
continue
100+
}
97101
h.forwarder = forwarder
98102

99103
if err := p.registry.Start(h); err != nil {

libbeat/beat/info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package beat
1919

20-
import "github.com/satori/go.uuid"
20+
import "github.com/gofrs/uuid"
2121

2222
// Info stores a beats instance meta data.
2323
type Info struct {

libbeat/cmd/instance/beat.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"strings"
3333
"time"
3434

35-
"github.com/satori/go.uuid"
35+
"github.com/gofrs/uuid"
3636
"go.uber.org/zap"
3737

3838
"github.com/elastic/go-sysinfo"
@@ -217,14 +217,19 @@ func NewBeat(name, indexPrefix, v string) (*Beat, error) {
217217
return nil, err
218218
}
219219

220+
id, err := uuid.NewV4()
221+
if err != nil {
222+
return nil, err
223+
}
224+
220225
b := beat.Beat{
221226
Info: beat.Info{
222227
Beat: name,
223228
IndexPrefix: indexPrefix,
224229
Version: v,
225230
Name: hostname,
226231
Hostname: hostname,
227-
UUID: uuid.NewV4(),
232+
UUID: id,
228233
},
229234
Fields: fields,
230235
}
@@ -625,7 +630,7 @@ func (b *Beat) loadMeta() error {
625630
}
626631

627632
f.Close()
628-
valid := !uuid.Equal(m.UUID, uuid.Nil)
633+
valid := m.UUID != uuid.Nil
629634
if valid {
630635
b.Info.UUID = m.UUID
631636
return nil

libbeat/cmd/instance/beat_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package instance
2222
import (
2323
"testing"
2424

25-
"github.com/satori/go.uuid"
25+
"github.com/gofrs/uuid"
2626
"github.com/stretchr/testify/assert"
2727
)
2828

@@ -57,5 +57,9 @@ func TestNewInstanceUUID(t *testing.T) {
5757
}
5858

5959
// Make sure the UUID's are different
60-
assert.NotEqual(t, b.Info.UUID, uuid.NewV4())
60+
differentUUID, err := uuid.NewV4()
61+
if err != nil {
62+
t.Fatalf("error while generating UUID: %v", err)
63+
}
64+
assert.NotEqual(t, b.Info.UUID, differentUUID)
6165
}

libbeat/cmd/instance/metrics_common.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ package instance
2020
import (
2121
"time"
2222

23-
"github.com/satori/go.uuid"
23+
"github.com/gofrs/uuid"
2424

25+
"github.com/elastic/beats/libbeat/logp"
2526
"github.com/elastic/beats/libbeat/monitoring"
2627
"github.com/elastic/beats/libbeat/monitoring/report/log"
2728
)
@@ -35,7 +36,11 @@ func init() {
3536
beatMetrics = monitoring.Default.NewRegistry("beat")
3637
monitoring.NewFunc(beatMetrics, "info", reportInfo, monitoring.Report)
3738

38-
ephemeralID = uuid.NewV4()
39+
var err error
40+
ephemeralID, err = uuid.NewV4()
41+
if err != nil {
42+
logp.Err("Error while generating ephemeral ID for Beat")
43+
}
3944
}
4045

4146
func reportInfo(_ monitoring.Mode, V monitoring.Visitor) {

libbeat/common/event_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323
"time"
2424

25-
uuid "github.com/satori/go.uuid"
25+
"github.com/gofrs/uuid"
2626
"github.com/stretchr/testify/assert"
2727

2828
"github.com/elastic/beats/libbeat/logp"
@@ -201,7 +201,10 @@ func TestNormalizeValue(t *testing.T) {
201201
var nilStringPtr *string
202202
var nilTimePtr *time.Time
203203
someString := "foo"
204-
uuidValue := uuid.NewV1()
204+
uuidValue, err := uuid.NewV1()
205+
if err != nil {
206+
t.Fatalf("error while generating uuid: %v", err)
207+
}
205208

206209
type mybool bool
207210
type myint int32

libbeat/management/management.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package management
1919

2020
import (
21-
"github.com/satori/go.uuid"
21+
"github.com/gofrs/uuid"
2222

2323
"github.com/elastic/beats/libbeat/common"
2424
"github.com/elastic/beats/libbeat/common/reload"

libbeat/outputs/elasticsearch/elasticsearch.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"fmt"
2323
"sync"
2424

25-
uuid "github.com/satori/go.uuid"
25+
"github.com/gofrs/uuid"
2626

2727
"github.com/elastic/beats/libbeat/beat"
2828
"github.com/elastic/beats/libbeat/common"
@@ -70,20 +70,24 @@ func newCallbacksRegistry() callbacksRegistry {
7070
// RegisterConnectCallback registers a callback for the elasticsearch output
7171
// The callback is called each time the client connects to elasticsearch.
7272
// It returns the key of the newly added callback, so it can be deregistered later.
73-
func RegisterConnectCallback(callback connectCallback) uuid.UUID {
73+
func RegisterConnectCallback(callback connectCallback) (uuid.UUID, error) {
7474
connectCallbackRegistry.mutex.Lock()
7575
defer connectCallbackRegistry.mutex.Unlock()
7676

7777
// find the next unique key
7878
var key uuid.UUID
79+
var err error
7980
exists := true
8081
for exists {
81-
key = uuid.NewV4()
82+
key, err = uuid.NewV4()
83+
if err != nil {
84+
return uuid.Nil, err
85+
}
8286
_, exists = connectCallbackRegistry.callbacks[key]
8387
}
8488

8589
connectCallbackRegistry.callbacks[key] = callback
86-
return key
90+
return key, nil
8791
}
8892

8993
// DeregisterConnectCallback deregisters a callback for the elasticsearch output

libbeat/outputs/elasticsearch/elasticsearch_test.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ func TestConnectCallbacksManagement(t *testing.T) {
2727
f1 := func(client *Client) error { fmt.Println("i am function #1"); return nil }
2828
f2 := func(client *Client) error { fmt.Println("i am function #2"); return nil }
2929

30-
_ = RegisterConnectCallback(f0)
31-
id1 := RegisterConnectCallback(f1)
32-
id2 := RegisterConnectCallback(f2)
30+
_, err := RegisterConnectCallback(f0)
31+
if err != nil {
32+
t.Fatalf("error while registering callback: %v", err)
33+
}
34+
id1, err := RegisterConnectCallback(f1)
35+
if err != nil {
36+
t.Fatalf("error while registering callback: %v", err)
37+
}
38+
id2, err := RegisterConnectCallback(f2)
39+
if err != nil {
40+
t.Fatalf("error while registering callback: %v", err)
41+
}
3342

3443
t.Logf("removing second callback")
3544
DeregisterConnectCallback(id1)

0 commit comments

Comments
 (0)