Skip to content

Commit

Permalink
Fixes license check issue with invalid license UUID and check on 32 b…
Browse files Browse the repository at this point in the history
…its system. (elastic#11649)

- Relax validation of the X-Pack license UID value.
- Fix a parsing error with the X-Pack license check on 32-bit system. 

Fixes: elastic#11640
Fixes: elastic#11650
(cherry picked from commit 4b7823b)
  • Loading branch information
ph committed Apr 4, 2019
1 parent c38bafc commit ff72ae4
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 29 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ https://github.com/elastic/beats/compare/v7.0.0-rc1...master[Check the HEAD diff

*Affecting all Beats*

- Ensure all beat commands respect configured settings. {pull}10721[10721]
- Add missing fields and test cases for libbeat add_kubernetes_metadata processor. {issue}11133[11133], {pull}11134[11134]
- decode_json_field: process objects and arrays only {pull}11312[11312]
- decode_json_field: do not process arrays when flag not set. {pull}11318[11318]
- 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 validation of the X-Pack license UID value. {issue}11640[11640]
- Fix a parsing error with the X-Pack license check on 32-bit system. {issue}11650[11650]

*Auditbeat*

*Filebeat*
Expand Down
30 changes: 21 additions & 9 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,19 @@ if [ -d "/vagrant" ] && [ ! -e "beats" ]; then ln -s /vagrant beats; fi
SCRIPT

# Linux GVM
$linuxGvmProvision = <<SCRIPT
def linuxGvmProvision(arch="amd64")
return <<SCRIPT
mkdir -p ~/bin
if [ ! -e "~/bin/gvm" ]; then
curl -sL -o ~/bin/gvm https://github.com/andrewkroh/gvm/releases/download/v0.1.0/gvm-linux-amd64
curl -sL -o ~/bin/gvm https://github.com/andrewkroh/gvm/releases/download/v0.1.0/gvm-linux-#{arch}
chmod +x ~/bin/gvm
~/bin/gvm $GO_VERSION
~/bin/gvm #{GO_VERSION}
echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
echo 'export PATH=$HOME/bin:$GOPATH/bin:$PATH' >> ~/.bash_profile
echo 'eval "$(gvm #{GO_VERSION})"' >> ~/.bash_profile
fi
SCRIPT
end

Vagrant.configure(2) do |config|

Expand Down Expand Up @@ -141,7 +143,17 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2226, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
end

config.vm.define "precise32", primary: true do |c|
c.vm.box = "ubuntu/precise32"
c.vm.network :forwarded_port, guest: 22, host: 2226, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision("386"), privileged: false

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
end
Expand All @@ -151,7 +163,7 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2229, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: "yum install -y make gcc python-pip python-virtualenv git"

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
Expand All @@ -162,7 +174,7 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2227, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: "dnf install -y make gcc python-pip python-virtualenv git"

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
Expand All @@ -173,7 +185,7 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2228, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: "pacman -Sy && pacman -S --noconfirm make gcc python-pip python-virtualenv git"

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
Expand All @@ -184,7 +196,7 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2229, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: "apt-get update && apt-get install -y make gcc python-pip python-virtualenv git"

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
Expand All @@ -195,7 +207,7 @@ Vagrant.configure(2) do |config|
c.vm.network :forwarded_port, guest: 22, host: 2230, id: "ssh", auto_correct: true

c.vm.provision "shell", inline: $unixProvision, privileged: false
c.vm.provision "shell", inline: $linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: linuxGvmProvision, privileged: false
c.vm.provision "shell", inline: "pip install virtualenv"

c.vm.synced_folder ".", "/vagrant", type: "virtualbox"
Expand Down
6 changes: 1 addition & 5 deletions x-pack/libbeat/licenser/elastic_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ func (st *State) UnmarshalJSON(b []byte) error {

// UnmarshalJSON takes a bytes array and transform the int64 to a golang time.
func (et *expiryTime) UnmarshalJSON(b []byte) error {
if len(b) < 0 {
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")
}
Expand Down
4 changes: 1 addition & 3 deletions x-pack/libbeat/licenser/elastic_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"testing"
"time"

"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"

"github.com/elastic/beats/libbeat/outputs/elasticsearch"
Expand Down Expand Up @@ -133,8 +132,7 @@ func TestParseJSON(t *testing.T) {
return
}

id, _ := uuid.FromString("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)
Expand Down
6 changes: 2 additions & 4 deletions x-pack/libbeat/licenser/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand All @@ -54,7 +52,7 @@ type Base struct {
Available bool `json:"available"`
}

// Defines all the avaiables features
// Defines all the available features
type graph struct{ *Base }
type logstash struct{ *Base }
type ml struct{ *Base }
Expand Down
2 changes: 1 addition & 1 deletion x-pack/libbeat/licenser/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions x-pack/libbeat/licenser/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestRetrieveLicense(t *testing.T) {
}

i := &License{
UUID: mustUUIDV4(),
UUID: mustUUIDV4().String(),
Type: Platinum,
Mode: Platinum,
Status: Active,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/libbeat/licenser/testdata/xpack-6.4.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "trial",
"mode": "trial",
"status": "active",
"expiry_date_in_millis": 1538060781728
"expiry_date_in_millis": 1588291199999
},
"features": {
"graph": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit ff72ae4

Please sign in to comment.