diff --git a/NOTICE.txt b/NOTICE.txt index 76680d020df..85573c823b2 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -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 diff --git a/docs/component-specs.md b/docs/component-specs.md index 5379bda30cd..47c5b094db4 100644 --- a/docs/component-specs.md +++ b/docs/component-specs.md @@ -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`. diff --git a/go.mod b/go.mod index c2104603657..ae76355de2e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c5e773d7d2d..d38fd34eb96 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/pkg/agent/application/info/inject_config.go b/internal/pkg/agent/application/info/inject_config.go index 03f57a6ddcd..4bedfed1cf3 100644 --- a/internal/pkg/agent/application/info/inject_config.go +++ b/internal/pkg/agent/application/info/inject_config.go @@ -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(), @@ -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, diff --git a/internal/pkg/agent/application/info/inject_config_test.go b/internal/pkg/agent/application/info/inject_config_test.go new file mode 100644 index 00000000000..1ea96fa5cd4 --- /dev/null +++ b/internal/pkg/agent/application/info/inject_config_test.go @@ -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) +} diff --git a/pkg/component/component.go b/pkg/component/component.go index d9100a6dd98..455f8ad0e48 100644 --- a/pkg/component/component.go +++ b/pkg/component/component.go @@ -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, diff --git a/pkg/component/component_test.go b/pkg/component/component_test.go index b6b49546fce..368145e3909 100644 --- a/pkg/component/component_test.go +++ b/pkg/component/component_test.go @@ -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, diff --git a/pkg/component/platforms.go b/pkg/component/platforms.go index 552adde716c..afb232e94db 100644 --- a/pkg/component/platforms.go +++ b/pkg/component/platforms.go @@ -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. @@ -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) diff --git a/pkg/component/platforms_test.go b/pkg/component/platforms_test.go new file mode 100644 index 00000000000..35052a9474d --- /dev/null +++ b/pkg/component/platforms_test.go @@ -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) +} diff --git a/specs/endpoint-security.spec.yml b/specs/endpoint-security.spec.yml index 4f3a2ff7e42..1f9f7cca787 100644 --- a/specs/endpoint-security.spec.yml +++ b/specs/endpoint-security.spec.yml @@ -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: