Skip to content

Commit

Permalink
Elastic Defend arm64 is not supported on Windows yet (#4155)
Browse files Browse the repository at this point in the history
* Elastic Defend arm64 is not supported on Windows yet

* fix lint

* correct platform condition

* machine architecture constants from MSDN

* fix const declaration

* refactoring; test fix

* return fix

* refactoring

* refactoring

* fix lint errors on legacy code

* remove unnecessary access query mask

* use updated go-sysinfo

* fix unit test

* revert accidental change

* update go-sysinfo to official release

* go mod tidy

* update go-sysinfo

* go mod tidy

* hex edit version

* Revert "hex edit version"

This reverts commit 39a4ee9.

* hex edit

* go-sysinfo HostInfo.Architecture and HostInfo.NativeArchitecture use x86_64 instead of amd64

* unify amd64 arch in Agent

* aarch64 to arm64

* lint fix: don't use Yoda ifs

* try to increase test coverage ratio

* fix goimports

---------

Co-authored-by: Michal Pristas <[email protected]>
  • Loading branch information
intxgo and michalpristas authored Feb 13, 2024
1 parent c099110 commit e0a2204
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 23 deletions.
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2222,11 +2222,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0.

--------------------------------------------------------------------------------
Dependency : github.com/elastic/go-sysinfo
Version: v1.11.2
Version: v1.13.1
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.11.2/LICENSE.txt:
Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.13.1/LICENSE.txt:


Apache License
Expand Down
1 change: 1 addition & 0 deletions docs/component-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The variables that can be accessed by a condition are:

- `runtime.os`: the operating system, either `"windows"`, `"darwin"`, `"linux"`, or `"container"`.
- `runtime.arch`: the CPU architecture, either `"amd64"` or `"arm64"`.
- `runtime.native_arch`: the machine CPU architecture, either `"amd64"` or `"arm64"`.
- `runtime.platform`: a string combining the OS and architecture, e.g. `"windows/amd64"`, `"darwin/arm64"`.
- `runtime.family`: OS family, e.g. `"debian"`, `"redhat"`, `"windows"`, `"darwin"`
- `runtime.major`, `runtime.minor`: the operating system version. Note that these are strings not integers, so they must be converted in order to use numeric comparison. For example to check if the OS major version is at most 12, use `number(runtime.major) <= 12`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/elastic/elastic-transport-go/v8 v8.3.0
github.com/elastic/go-elasticsearch/v8 v8.10.1
github.com/elastic/go-licenser v0.4.1
github.com/elastic/go-sysinfo v1.11.2
github.com/elastic/go-sysinfo v1.13.1
github.com/elastic/go-ucfg v0.8.6
github.com/fatih/color v1.15.0
github.com/fsnotify/fsnotify v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ github.com/elastic/go-structform v0.0.10 h1:oy08o/Ih2hHTkNcRY/1HhaYvIp5z6t8si8gn
github.com/elastic/go-structform v0.0.10/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
github.com/elastic/go-sysinfo v1.7.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
github.com/elastic/go-sysinfo v1.11.2 h1:mcm4OSYVMyws6+n2HIVMGkln5HOpo5Ie1ZmbbNn0jg4=
github.com/elastic/go-sysinfo v1.11.2/go.mod h1:GKqR8bbMK/1ITnez9NIsIfXQr25aLhRJa7AfT8HpBFQ=
github.com/elastic/go-sysinfo v1.13.1 h1:U5Jlx6c/rLkR72O8wXXXo1abnGlWGJU/wbzNJ2AfQa4=
github.com/elastic/go-sysinfo v1.13.1/go.mod h1:GKqR8bbMK/1ITnez9NIsIfXQr25aLhRJa7AfT8HpBFQ=
github.com/elastic/go-ucfg v0.8.6 h1:stUeyh2goTgGX+/wb9gzKvTv0YB0231LTpKUgCKj4U0=
github.com/elastic/go-ucfg v0.8.6/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/agent/application/info/inject_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func agentGlobalConfig() (map[string]interface{}, error) {
return nil, err
}

nativeArch := hostInfo.Info().NativeArchitecture
if nativeArch == "x86_64" {
nativeArch = "amd64"
}
if nativeArch == "aarch64" {
nativeArch = "arm64"
}

return map[string]interface{}{
"path": map[string]interface{}{
"data": paths.Data(),
Expand All @@ -47,6 +55,7 @@ func agentGlobalConfig() (map[string]interface{}, error) {
},
"runtime.os": runtime.GOOS,
"runtime.arch": runtime.GOARCH,
"runtime.native_arch": nativeArch,
"runtime.osinfo.type": hostInfo.Info().OS.Type,
"runtime.osinfo.family": hostInfo.Info().OS.Family,
"runtime.osinfo.version": hostInfo.Info().OS.Version,
Expand Down
25 changes: 25 additions & 0 deletions internal/pkg/agent/application/info/inject_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package info

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/elastic-agent/internal/pkg/config"
)

func TestInjectAgentConfig(t *testing.T) {
c := config.New()
err := InjectAgentConfig(c)
assert.NoError(t, err)
}

func TestAgentGlobalConfig(t *testing.T) {
c, err := agentGlobalConfig()
assert.NoError(t, err)
assert.NotEmpty(t, c)
}
13 changes: 7 additions & 6 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,13 @@ func varsForPlatform(platform PlatformDetail) (*transpiler.Vars, error) {
"in_default": paths.ArePathsEqual(paths.Top(), paths.InstallPath(paths.DefaultBasePath)) || pkgmgr.InstalledViaExternalPkgMgr(),
},
"runtime": map[string]interface{}{
"platform": platform.String(),
"os": platform.OS,
"arch": platform.Arch,
"family": platform.Family,
"major": platform.Major,
"minor": platform.Minor,
"platform": platform.String(),
"os": platform.OS,
"arch": platform.Arch,
"native_arch": platform.NativeArch,
"family": platform.Family,
"major": platform.Major,
"minor": platform.Minor,
},
"user": map[string]interface{}{
"root": hasRoot,
Expand Down
13 changes: 7 additions & 6 deletions pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1980,12 +1980,13 @@ func TestPreventionsAreValid(t *testing.T) {
"in_default": true,
},
"runtime": map[string]interface{}{
"platform": "platform",
"os": "os",
"arch": "arch",
"family": "family",
"major": "major",
"minor": "minor",
"platform": "platform",
"os": "os",
"arch": "arch",
"native_arch": "native_arch",
"family": "family",
"major": "major",
"minor": "minor",
},
"user": map[string]interface{}{
"root": false,
Expand Down
25 changes: 19 additions & 6 deletions pkg/component/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ func (p Platforms) Exists(platform string) bool {
type PlatformDetail struct {
Platform

Family string
Major string
Minor string
NativeArch string
Family string
Major string
Minor string
}

// PlatformModifier can modify the platform details before the runtime specifications are loaded.
Expand All @@ -118,15 +119,27 @@ func LoadPlatformDetail(modifiers ...PlatformModifier) (PlatformDetail, error) {
return PlatformDetail{}, err
}
os := info.Info().OS
nativeArch := info.Info().NativeArchitecture
if nativeArch == "x86_64" {
// go-sysinfo Architecture and NativeArchitecture prefer x64_64
// but GOARCH prefers amd64
nativeArch = "amd64"
}
if nativeArch == "aarch64" {
// go-sysinfo Architecture and NativeArchitecture prefer aarch64
// but GOARCH prefers arm64
nativeArch = "arm64"
}
detail := PlatformDetail{
Platform: Platform{
OS: goruntime.GOOS,
Arch: goruntime.GOARCH,
GOOS: goruntime.GOOS,
},
Family: os.Family,
Major: strconv.Itoa(os.Major),
Minor: strconv.Itoa(os.Minor),
NativeArch: nativeArch,
Family: os.Family,
Major: strconv.Itoa(os.Major),
Minor: strconv.Itoa(os.Minor),
}
for _, modifier := range modifiers {
detail = modifier(detail)
Expand Down
17 changes: 17 additions & 0 deletions pkg/component/platforms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package component

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadPlatformDetail(t *testing.T) {
platformDetail, err := LoadPlatformDetail()
assert.NoError(t, err)
assert.NotEmpty(t, platformDetail)
}
2 changes: 2 additions & 0 deletions specs/endpoint-security.spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ inputs:
message: "Elastic Defend requires Elastic Agent be running as Administrator or SYSTEM"
- condition: ${install.in_default} == false
message: "Elastic Defend requires Elastic Agent be installed at the default installation path"
- condition: ${runtime.native_arch} != 'amd64'
message: "Elastic Defend cannot be installed on Windows running on non-AMD64 CPU"
service:
cport: 6788
log:
Expand Down

0 comments on commit e0a2204

Please sign in to comment.