From 0fe3b3950f5d1a239e7764606c50687f3d046ab0 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 4 Apr 2019 08:52:23 -0400 Subject: [PATCH 1/8] Uses a string for License.UUID instead of uuid.UUID There are some case where the license UUID is a valid license but not a valid UUID. Fixes: #11640 --- x-pack/libbeat/licenser/elastic_fetcher_test.go | 3 +-- x-pack/libbeat/licenser/license.go | 4 +--- x-pack/libbeat/licenser/manager.go | 2 +- x-pack/libbeat/licenser/manager_test.go | 10 +++++----- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/x-pack/libbeat/licenser/elastic_fetcher_test.go b/x-pack/libbeat/licenser/elastic_fetcher_test.go index 708ae1d833fe..6538d2c08e4c 100644 --- a/x-pack/libbeat/licenser/elastic_fetcher_test.go +++ b/x-pack/libbeat/licenser/elastic_fetcher_test.go @@ -14,7 +14,6 @@ import ( "testing" "time" - "github.com/gofrs/uuid" "github.com/stretchr/testify/assert" "github.com/elastic/beats/libbeat/outputs/elasticsearch" @@ -133,7 +132,7 @@ func TestParseJSON(t *testing.T) { return } - id, _ := uuid.FromString("936183d8-f48c-4a3f-959a-a52aa2563279") + id := "936183d8-f48c-4a3f-959a-a52aa2563279" assert.Equal(t, id, license.UUID) assert.NotNil(t, license.Type) diff --git a/x-pack/libbeat/licenser/license.go b/x-pack/libbeat/licenser/license.go index 5634a86a28a1..c633892c6bd7 100644 --- a/x-pack/libbeat/licenser/license.go +++ b/x-pack/libbeat/licenser/license.go @@ -6,8 +6,6 @@ package licenser import ( "time" - - "github.com/gofrs/uuid" ) // License represents the license of this beat, the license is fetched and returned from @@ -27,7 +25,7 @@ import ( // mode is the license in operation. (effective license) // status is the type installed is active or not. type License struct { - UUID uuid.UUID `json:"uid"` + UUID string `json:"uid"` Type LicenseType `json:"type"` Mode LicenseType `json:"mode"` Status State `json:"status"` diff --git a/x-pack/libbeat/licenser/manager.go b/x-pack/libbeat/licenser/manager.go index 632d988a399f..29495311c548 100644 --- a/x-pack/libbeat/licenser/manager.go +++ b/x-pack/libbeat/licenser/manager.go @@ -29,7 +29,7 @@ func mustUUIDV4() uuid.UUID { // OSSLicense default license to use. var ( OSSLicense = &License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: OSS, Mode: OSS, Status: Active, diff --git a/x-pack/libbeat/licenser/manager_test.go b/x-pack/libbeat/licenser/manager_test.go index f17994179e12..a18e56bedca0 100644 --- a/x-pack/libbeat/licenser/manager_test.go +++ b/x-pack/libbeat/licenser/manager_test.go @@ -61,7 +61,7 @@ func (m *mockFetcher) Close() { func TestRetrieveLicense(t *testing.T) { i := &License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: Basic, Mode: Basic, Status: Active, @@ -124,7 +124,7 @@ func TestRetrieveLicense(t *testing.T) { } i := &License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: Platinum, Mode: Platinum, Status: Active, @@ -144,7 +144,7 @@ func TestRetrieveLicense(t *testing.T) { func TestWatcher(t *testing.T) { i := &License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: Basic, Mode: Basic, Status: Active, @@ -246,7 +246,7 @@ func TestWatcher(t *testing.T) { if c == 0 { assert.Equal(t, Basic, license.Get()) mock.Insert(&License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: Platinum, Mode: Platinum, Status: Active, @@ -288,7 +288,7 @@ func TestWatcher(t *testing.T) { func TestWaitForLicense(t *testing.T) { i := &License{ - UUID: mustUUIDV4(), + UUID: mustUUIDV4().String(), Type: Basic, Mode: Basic, Status: Active, From 7788effd4e611c1f003e59a95a4aac0570f381f7 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 4 Apr 2019 08:54:10 -0400 Subject: [PATCH 2/8] changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index f732e24f3881..247bb0e219ad 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -45,6 +45,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Report faulting file when config reload fails. {pull}[11304]11304 - Fix a typo in libbeat/outputs/transport/client.go by updating `c.conn.LocalAddr()` to `c.conn.RemoteAddr()`. {pull}11242[11242] - Management configuration backup file will now have a timestamps in their name. {pull}11034[11034] +- Relax License UUID validation. {issue}11640[11640] *Auditbeat* From 8770cb596b6ea07cf36d56b3e2151d690b97485a Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 4 Apr 2019 10:42:24 -0400 Subject: [PATCH 3/8] The License check should correctly parse the expiry_time on 32 bits system --- CHANGELOG.next.asciidoc | 3 ++- x-pack/libbeat/licenser/elastic_fetcher.go | 2 +- x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json | 2 +- x-pack/libbeat/licenser/testdata/xpack-6.4.0.json | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 247bb0e219ad..f7712d7c08d1 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -45,7 +45,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Report faulting file when config reload fails. {pull}[11304]11304 - Fix a typo in libbeat/outputs/transport/client.go by updating `c.conn.LocalAddr()` to `c.conn.RemoteAddr()`. {pull}11242[11242] - Management configuration backup file will now have a timestamps in their name. {pull}11034[11034] -- Relax License UUID validation. {issue}11640[11640] +- Relax validation of the X-Pack license UID value. {issue}11640[11640] +- Fix a parsing error with the X-Pack license check on 32bits system. {issue}11650[11650] *Auditbeat* diff --git a/x-pack/libbeat/licenser/elastic_fetcher.go b/x-pack/libbeat/licenser/elastic_fetcher.go index 854591ccb083..c9199e92f3f7 100644 --- a/x-pack/libbeat/licenser/elastic_fetcher.go +++ b/x-pack/libbeat/licenser/elastic_fetcher.go @@ -76,7 +76,7 @@ func (et *expiryTime) UnmarshalJSON(b []byte) error { return fmt.Errorf("invalid value for expiry time, received: '%s'", string(b)) } - ts, err := strconv.Atoi(string(b)) + ts, err := strconv.ParseInt(string(b), 0, 64) if err != nil { return errors.Wrap(err, "could not parse value for expiry time") } diff --git a/x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json b/x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json index b0741cc9d190..363684208916 100644 --- a/x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json +++ b/x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json @@ -8,7 +8,7 @@ "type": "trial", "mode": "trial", "status": "active", - "expiry_date_in_millis": 1538060781728 + "expiry_date_in_millis": 1588291199999 }, "features": { "graph": { diff --git a/x-pack/libbeat/licenser/testdata/xpack-6.4.0.json b/x-pack/libbeat/licenser/testdata/xpack-6.4.0.json index a527dec82f35..116247ae6321 100644 --- a/x-pack/libbeat/licenser/testdata/xpack-6.4.0.json +++ b/x-pack/libbeat/licenser/testdata/xpack-6.4.0.json @@ -7,7 +7,8 @@ "uid": "936183d8-f48c-4a3f-959a-a52aa2563279", "type": "platinum", "mode": "platinum", - "status": "active" + "status": "active", + "expiry_date_in_millis": 1588291199999 }, "features": { "graph": { From b84b34c133009e9f8c5507912ad8c9e93551cd41 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 4 Apr 2019 10:48:27 -0400 Subject: [PATCH 4/8] make sure we test with a relax license --- .../libbeat/licenser/elastic_fetcher_test.go | 3 +- ...rial-6.4.0.json => xpack-trial-6.4.0.json} | 0 .../xpack-with-relax-license-uuid.json | 43 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) rename x-pack/libbeat/licenser/testdata/{x-pack-trial-6.4.0.json => xpack-trial-6.4.0.json} (100%) create mode 100644 x-pack/libbeat/licenser/testdata/xpack-with-relax-license-uuid.json diff --git a/x-pack/libbeat/licenser/elastic_fetcher_test.go b/x-pack/libbeat/licenser/elastic_fetcher_test.go index 6538d2c08e4c..6d07eae30a4d 100644 --- a/x-pack/libbeat/licenser/elastic_fetcher_test.go +++ b/x-pack/libbeat/licenser/elastic_fetcher_test.go @@ -132,8 +132,7 @@ func TestParseJSON(t *testing.T) { return } - id := "936183d8-f48c-4a3f-959a-a52aa2563279" - assert.Equal(t, id, license.UUID) + assert.True(t, len(license.UUID) > 0) assert.NotNil(t, license.Type) assert.NotNil(t, license.Mode) diff --git a/x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json b/x-pack/libbeat/licenser/testdata/xpack-trial-6.4.0.json similarity index 100% rename from x-pack/libbeat/licenser/testdata/x-pack-trial-6.4.0.json rename to x-pack/libbeat/licenser/testdata/xpack-trial-6.4.0.json diff --git a/x-pack/libbeat/licenser/testdata/xpack-with-relax-license-uuid.json b/x-pack/libbeat/licenser/testdata/xpack-with-relax-license-uuid.json new file mode 100644 index 000000000000..2208b470a81d --- /dev/null +++ b/x-pack/libbeat/licenser/testdata/xpack-with-relax-license-uuid.json @@ -0,0 +1,43 @@ +{ + "build": { + "hash": "053779d", + "date": "2018-07-20T05:25:16.206115Z" + }, + "license": { + "uid": "hello-license", + "type": "platinum", + "mode": "platinum", + "status": "active", + "expiry_date_in_millis": 1588291199999 + }, + "features": { + "graph": { + "available": false, + "enabled": true + }, + "logstash": { + "available": false, + "enabled": true + }, + "ml": { + "available": false, + "enabled": true + }, + "monitoring": { + "available": true, + "enabled": true + }, + "rollup": { + "available": true, + "enabled": true + }, + "security": { + "available": false, + "enabled": true + }, + "watcher": { + "available": false, + "enabled": true + } + } +} From cdab676e0d80f46ebc8679cdee324262bf71ea4e Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Thu, 4 Apr 2019 10:53:54 -0400 Subject: [PATCH 5/8] correct set gvm for 64 or 32 bit system --- Vagrantfile | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index b795898812db..a851be38692f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -69,17 +69,19 @@ if [ -d "/vagrant" ] && [ ! -e "beats" ]; then ln -s /vagrant beats; fi SCRIPT # Linux GVM -$linuxGvmProvision = <