Skip to content

Commit e0a2204

Browse files
intxgomichalpristas
andauthoredFeb 13, 2024
Elastic Defend arm64 is not supported on Windows yet (#4155)
* 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 <michal.pristas@gmail.com>
1 parent c099110 commit e0a2204

11 files changed

+92
-23
lines changed
 

‎NOTICE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2222,11 +2222,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-licenser@v0.
22222222

22232223
--------------------------------------------------------------------------------
22242224
Dependency : github.com/elastic/go-sysinfo
2225-
Version: v1.11.2
2225+
Version: v1.13.1
22262226
Licence type (autodetected): Apache-2.0
22272227
--------------------------------------------------------------------------------
22282228

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

22312231

22322232
Apache License

‎docs/component-specs.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ The variables that can be accessed by a condition are:
8787

8888
- `runtime.os`: the operating system, either `"windows"`, `"darwin"`, `"linux"`, or `"container"`.
8989
- `runtime.arch`: the CPU architecture, either `"amd64"` or `"arm64"`.
90+
- `runtime.native_arch`: the machine CPU architecture, either `"amd64"` or `"arm64"`.
9091
- `runtime.platform`: a string combining the OS and architecture, e.g. `"windows/amd64"`, `"darwin/arm64"`.
9192
- `runtime.family`: OS family, e.g. `"debian"`, `"redhat"`, `"windows"`, `"darwin"`
9293
- `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`.

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/elastic/elastic-transport-go/v8 v8.3.0
2020
github.com/elastic/go-elasticsearch/v8 v8.10.1
2121
github.com/elastic/go-licenser v0.4.1
22-
github.com/elastic/go-sysinfo v1.11.2
22+
github.com/elastic/go-sysinfo v1.13.1
2323
github.com/elastic/go-ucfg v0.8.6
2424
github.com/fatih/color v1.15.0
2525
github.com/fsnotify/fsnotify v1.7.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ github.com/elastic/go-structform v0.0.10 h1:oy08o/Ih2hHTkNcRY/1HhaYvIp5z6t8si8gn
820820
github.com/elastic/go-structform v0.0.10/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
821821
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
822822
github.com/elastic/go-sysinfo v1.7.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
823-
github.com/elastic/go-sysinfo v1.11.2 h1:mcm4OSYVMyws6+n2HIVMGkln5HOpo5Ie1ZmbbNn0jg4=
824-
github.com/elastic/go-sysinfo v1.11.2/go.mod h1:GKqR8bbMK/1ITnez9NIsIfXQr25aLhRJa7AfT8HpBFQ=
823+
github.com/elastic/go-sysinfo v1.13.1 h1:U5Jlx6c/rLkR72O8wXXXo1abnGlWGJU/wbzNJ2AfQa4=
824+
github.com/elastic/go-sysinfo v1.13.1/go.mod h1:GKqR8bbMK/1ITnez9NIsIfXQr25aLhRJa7AfT8HpBFQ=
825825
github.com/elastic/go-ucfg v0.8.6 h1:stUeyh2goTgGX+/wb9gzKvTv0YB0231LTpKUgCKj4U0=
826826
github.com/elastic/go-ucfg v0.8.6/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
827827
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=

‎internal/pkg/agent/application/info/inject_config.go

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ func agentGlobalConfig() (map[string]interface{}, error) {
3535
return nil, err
3636
}
3737

38+
nativeArch := hostInfo.Info().NativeArchitecture
39+
if nativeArch == "x86_64" {
40+
nativeArch = "amd64"
41+
}
42+
if nativeArch == "aarch64" {
43+
nativeArch = "arm64"
44+
}
45+
3846
return map[string]interface{}{
3947
"path": map[string]interface{}{
4048
"data": paths.Data(),
@@ -47,6 +55,7 @@ func agentGlobalConfig() (map[string]interface{}, error) {
4755
},
4856
"runtime.os": runtime.GOOS,
4957
"runtime.arch": runtime.GOARCH,
58+
"runtime.native_arch": nativeArch,
5059
"runtime.osinfo.type": hostInfo.Info().OS.Type,
5160
"runtime.osinfo.family": hostInfo.Info().OS.Family,
5261
"runtime.osinfo.version": hostInfo.Info().OS.Version,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package info
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
12+
"github.com/elastic/elastic-agent/internal/pkg/config"
13+
)
14+
15+
func TestInjectAgentConfig(t *testing.T) {
16+
c := config.New()
17+
err := InjectAgentConfig(c)
18+
assert.NoError(t, err)
19+
}
20+
21+
func TestAgentGlobalConfig(t *testing.T) {
22+
c, err := agentGlobalConfig()
23+
assert.NoError(t, err)
24+
assert.NotEmpty(t, c)
25+
}

‎pkg/component/component.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,13 @@ func varsForPlatform(platform PlatformDetail) (*transpiler.Vars, error) {
867867
"in_default": paths.ArePathsEqual(paths.Top(), paths.InstallPath(paths.DefaultBasePath)) || pkgmgr.InstalledViaExternalPkgMgr(),
868868
},
869869
"runtime": map[string]interface{}{
870-
"platform": platform.String(),
871-
"os": platform.OS,
872-
"arch": platform.Arch,
873-
"family": platform.Family,
874-
"major": platform.Major,
875-
"minor": platform.Minor,
870+
"platform": platform.String(),
871+
"os": platform.OS,
872+
"arch": platform.Arch,
873+
"native_arch": platform.NativeArch,
874+
"family": platform.Family,
875+
"major": platform.Major,
876+
"minor": platform.Minor,
876877
},
877878
"user": map[string]interface{}{
878879
"root": hasRoot,

‎pkg/component/component_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1980,12 +1980,13 @@ func TestPreventionsAreValid(t *testing.T) {
19801980
"in_default": true,
19811981
},
19821982
"runtime": map[string]interface{}{
1983-
"platform": "platform",
1984-
"os": "os",
1985-
"arch": "arch",
1986-
"family": "family",
1987-
"major": "major",
1988-
"minor": "minor",
1983+
"platform": "platform",
1984+
"os": "os",
1985+
"arch": "arch",
1986+
"native_arch": "native_arch",
1987+
"family": "family",
1988+
"major": "major",
1989+
"minor": "minor",
19891990
},
19901991
"user": map[string]interface{}{
19911992
"root": false,

‎pkg/component/platforms.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ func (p Platforms) Exists(platform string) bool {
103103
type PlatformDetail struct {
104104
Platform
105105

106-
Family string
107-
Major string
108-
Minor string
106+
NativeArch string
107+
Family string
108+
Major string
109+
Minor string
109110
}
110111

111112
// PlatformModifier can modify the platform details before the runtime specifications are loaded.
@@ -118,15 +119,27 @@ func LoadPlatformDetail(modifiers ...PlatformModifier) (PlatformDetail, error) {
118119
return PlatformDetail{}, err
119120
}
120121
os := info.Info().OS
122+
nativeArch := info.Info().NativeArchitecture
123+
if nativeArch == "x86_64" {
124+
// go-sysinfo Architecture and NativeArchitecture prefer x64_64
125+
// but GOARCH prefers amd64
126+
nativeArch = "amd64"
127+
}
128+
if nativeArch == "aarch64" {
129+
// go-sysinfo Architecture and NativeArchitecture prefer aarch64
130+
// but GOARCH prefers arm64
131+
nativeArch = "arm64"
132+
}
121133
detail := PlatformDetail{
122134
Platform: Platform{
123135
OS: goruntime.GOOS,
124136
Arch: goruntime.GOARCH,
125137
GOOS: goruntime.GOOS,
126138
},
127-
Family: os.Family,
128-
Major: strconv.Itoa(os.Major),
129-
Minor: strconv.Itoa(os.Minor),
139+
NativeArch: nativeArch,
140+
Family: os.Family,
141+
Major: strconv.Itoa(os.Major),
142+
Minor: strconv.Itoa(os.Minor),
130143
}
131144
for _, modifier := range modifiers {
132145
detail = modifier(detail)

‎pkg/component/platforms_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package component
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestLoadPlatformDetail(t *testing.T) {
14+
platformDetail, err := LoadPlatformDetail()
15+
assert.NoError(t, err)
16+
assert.NotEmpty(t, platformDetail)
17+
}

‎specs/endpoint-security.spec.yml

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ inputs:
7777
message: "Elastic Defend requires Elastic Agent be running as Administrator or SYSTEM"
7878
- condition: ${install.in_default} == false
7979
message: "Elastic Defend requires Elastic Agent be installed at the default installation path"
80+
- condition: ${runtime.native_arch} != 'amd64'
81+
message: "Elastic Defend cannot be installed on Windows running on non-AMD64 CPU"
8082
service:
8183
cport: 6788
8284
log:

0 commit comments

Comments
 (0)