Skip to content

Commit 2a786c2

Browse files
graphaellimergify[bot]
authored andcommitted
Update user agent (#45251)
distinguish between all beat modes: * Standalone indicates that the beat is not running under agent. * Unmanaged indicates that the beat is running under agent but not managed by Fleet. * Managed indicates that the beat is running under agent and managed by Fleet. privilege mode information is only exposed under agent (cherry picked from commit 2a99bfa) # Conflicts: # NOTICE.txt # go.mod # go.sum
1 parent fd3c6b4 commit 2a786c2

File tree

6 files changed

+73
-23
lines changed

6 files changed

+73
-23
lines changed

CHANGELOG.next.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
1212

1313
- Fix FQDN being lowercased when used as `host.hostname` {issue}39993[39993]
1414
- Beats won't log start up information when running under the Elastic Agent {40390}40390[40390]
15+
- Drop support for Debian 10 and upgrade statically linked glibc from 2.28 to 2.31 {pull}41402[41402]
16+
- Fix metrics not being ingested, due to "Limit of total fields [10000] has been exceeded while adding new fields [...]". The total fields limit has been increased to 12500. No significant performance impact on Elasticsearch is anticipated. {pull}41640[41640]
17+
- Set default kafka version to 2.1.0 in kafka output and filebeat. {pull}41662[41662]
18+
- Replace default Ubuntu-based images with UBI-minimal-based ones {pull}42150[42150]
19+
- Fix templates and docs to use correct `--` version of command line arguments. {issue}42038[42038] {pull}42060[42060]
20+
- removed support for a single `-` to precede multi-letter command line arguments. Use `--` instead. {issue}42117[42117] {pull}42209[42209]
21+
- The Beats logger and file output rotate files when necessary. The beat now forces a file rotation when unexpectedly writing to a file through a symbolic link.
22+
- Allow faccessat(2) in seccomp. {pull}43322[43322]
23+
- Update user agent used by beats http clients {pull}45251[45251]
1524

1625
*Auditbeat*
1726

NOTICE.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12317,11 +12317,19 @@ SOFTWARE
1231712317

1231812318
--------------------------------------------------------------------------------
1231912319
Dependency : github.com/elastic/elastic-agent-libs
12320+
<<<<<<< HEAD
1232012321
Version: v0.20.0
1232112322
Licence type (autodetected): Apache-2.0
1232212323
--------------------------------------------------------------------------------
1232312324

1232412325
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.20.0/LICENSE:
12326+
=======
12327+
Version: v0.21.2
12328+
Licence type (autodetected): Apache-2.0
12329+
--------------------------------------------------------------------------------
12330+
12331+
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-libs@v0.21.2/LICENSE:
12332+
>>>>>>> 2a99bfaa5 (Update user agent (#45251))
1232512333

1232612334
Apache License
1232712335
Version 2.0, January 2004

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,15 @@ require (
174174
github.com/aws/smithy-go v1.22.1
175175
github.com/dgraph-io/badger/v4 v4.6.0
176176
github.com/elastic/bayeux v1.0.5
177+
<<<<<<< HEAD
177178
github.com/elastic/ebpfevents v0.6.0
178179
github.com/elastic/elastic-agent-autodiscover v0.9.0
179180
github.com/elastic/elastic-agent-libs v0.20.0
181+
=======
182+
github.com/elastic/ebpfevents v0.7.0
183+
github.com/elastic/elastic-agent-autodiscover v0.9.2
184+
github.com/elastic/elastic-agent-libs v0.21.2
185+
>>>>>>> 2a99bfaa5 (Update user agent (#45251))
180186
github.com/elastic/elastic-agent-system-metrics v0.11.11
181187
github.com/elastic/go-elasticsearch/v8 v8.17.1
182188
github.com/elastic/go-quark v0.3.0

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,13 @@ github.com/elastic/elastic-agent-autodiscover v0.9.0 h1:+iWIKh0u3e8I+CJa3FfWe9h0
348348
github.com/elastic/elastic-agent-autodiscover v0.9.0/go.mod h1:5iUxLHhVdaGSWYTveSwfJEY4RqPXTG13LPiFoxcpFd4=
349349
github.com/elastic/elastic-agent-client/v7 v7.15.0 h1:nDB7v8TBoNuD6IIzC3z7Q0y+7bMgXoT2DsHfolO2CHE=
350350
github.com/elastic/elastic-agent-client/v7 v7.15.0/go.mod h1:6h+f9QdIr3GO2ODC0Y8+aEXRwzbA5W4eV4dd/67z7nI=
351+
<<<<<<< HEAD
351352
github.com/elastic/elastic-agent-libs v0.20.0 h1:MPjenwuEr+QfMeQRV4BK817ZbiNS38SXJE7QGHDwhUs=
352353
github.com/elastic/elastic-agent-libs v0.20.0/go.mod h1:1HNxREH8C27kGrJCtKZh/ot8pV8joH8VREP21+FrH5s=
354+
=======
355+
github.com/elastic/elastic-agent-libs v0.21.2 h1:r4Tokxx8OvFUVw28foiZT/WHwGUM7JFdlb4TVJ25v9M=
356+
github.com/elastic/elastic-agent-libs v0.21.2/go.mod h1:xSeIP3NtOIT4N2pPS4EyURmS1Q8mK0lWZ8Wd1Du6q3w=
357+
>>>>>>> 2a99bfaa5 (Update user agent (#45251))
353358
github.com/elastic/elastic-agent-system-metrics v0.11.11 h1:Qjh3Zef23PfGlG91AF+9ciNLNQf/8cDJ4CalnLZtV3g=
354359
github.com/elastic/elastic-agent-system-metrics v0.11.11/go.mod h1:GNqmKfvOt8PwORjbS6GllNdMfkLpOWyTa7P8oQq4E5o=
355360
github.com/elastic/elastic-transport-go/v8 v8.6.1 h1:h2jQRqH6eLGiBSN4eZbQnJLtL4bC5b4lfVFRjw2R4e4=

libbeat/beat/beat.go

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,47 @@ type Beat struct {
8888
Registry *reload.Registry // input, & output registry for configuration manager, should be instantiated in NewBeat
8989
}
9090

91+
func (beat *Beat) userAgentMode() useragent.AgentManagementMode {
92+
if beat.Manager == nil {
93+
return useragent.AgentManagementModeUnknown
94+
}
95+
if !beat.Manager.Enabled() {
96+
return useragent.AgentManagementModeStandalone
97+
}
98+
99+
info := beat.Manager.AgentInfo()
100+
switch info.ManagedMode {
101+
case proto.AgentManagedMode_MANAGED:
102+
return useragent.AgentManagementModeManaged
103+
case proto.AgentManagedMode_STANDALONE:
104+
return useragent.AgentManagementModeUnmanaged
105+
}
106+
// this is probably not reachable
107+
return useragent.AgentManagementModeUnknown
108+
}
109+
110+
func (beat *Beat) userAgentUnprivilegedMode() useragent.AgentUnprivilegedMode {
111+
if beat.Manager == nil || !beat.Manager.Enabled() {
112+
return useragent.AgentUnprivilegedModeUnknown
113+
}
114+
if beat.Manager.AgentInfo().Unprivileged {
115+
return useragent.AgentUnprivilegedModeUnprivileged
116+
}
117+
return useragent.AgentUnprivilegedModePrivileged
118+
}
119+
91120
// GenerateUserAgent populates the UserAgent field on the beat.Info struct
92121
func (beat *Beat) GenerateUserAgent() {
93-
// if we're in fleet mode, construct some additional elements for the UA comment field
94-
comments := []string{}
95-
if beat.Manager != nil && beat.Manager.Enabled() {
96-
info := beat.Manager.AgentInfo()
97-
if info.ManagedMode == proto.AgentManagedMode_MANAGED {
98-
comments = append(comments, "Managed")
99-
} else if info.ManagedMode == proto.AgentManagedMode_STANDALONE {
100-
comments = append(comments, "Standalone")
101-
}
102-
103-
if info.Unprivileged {
104-
comments = append(comments, "Unprivileged")
105-
}
122+
userAgentProduct := "Libbeat"
123+
if beat.Info.Beat != "" {
124+
userAgentProduct = beat.Info.Beat
106125
}
107126

108-
UserAgentProduct := beat.Info.Beat
109-
if UserAgentProduct == "" {
110-
UserAgentProduct = "Libbeat"
111-
}
127+
mode := beat.userAgentMode()
128+
unprivileged := beat.userAgentUnprivilegedMode()
112129

113-
finalUserAgent := useragent.UserAgent(UserAgentProduct, version.GetDefaultVersion(),
114-
version.Commit(), version.BuildTime().String(), comments...)
115-
beat.Info.UserAgent = finalUserAgent
130+
beat.Info.UserAgent = useragent.UserAgentWithBeatTelemetry(userAgentProduct, version.GetDefaultVersion(),
131+
mode, unprivileged)
116132
}
117133

118134
// BeatConfig struct contains the basic configuration of every beat

libbeat/beat/beat_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,30 @@ func TestUserAgentString(t *testing.T) {
7373
name: "unmanaged-privileged",
7474
beat: &Beat{Info: Info{Beat: "testbeat"},
7575
Manager: testManager{isEnabled: true, isUnpriv: false, mgmtMode: proto.AgentManagedMode_STANDALONE}},
76-
expectedComments: []string{"Standalone"},
76+
expectedComments: []string{"Unmanaged"},
7777
},
7878
{
7979
name: "unmanaged-unprivileged",
8080
beat: &Beat{Info: Info{Beat: "testbeat"},
8181
Manager: testManager{isEnabled: true, isUnpriv: true, mgmtMode: proto.AgentManagedMode_STANDALONE}},
82-
expectedComments: []string{"Standalone", "Unprivileged"},
82+
expectedComments: []string{"Unmanaged", "Unprivileged"},
8383
},
8484
{
8585
name: "management-disabled",
8686
beat: &Beat{Info: Info{Beat: "testbeat"},
8787
Manager: testManager{isEnabled: false}},
88+
expectedComments: []string{"Standalone"},
89+
},
90+
{
91+
name: "no-management",
92+
beat: &Beat{Info: Info{Beat: "testbeat"},
93+
Manager: nil},
8894
expectedComments: []string{},
8995
},
9096
}
9197

9298
// User-Agent will take the form of
93-
// Elastic-testbeat/8.15.0 (linux; amd64; unknown; 0001-01-01 00:00:00 +0000 UTC; Standalone; Unprivileged)
99+
// Elastic-testbeat/9.2.0 (linux; arm64; Managed; Unprivileged)
94100
// the RFC (https://www.rfc-editor.org/rfc/rfc9110#name-user-agent) says the comment field can basically be anything,
95101
// but we put metadata in it, delimited by '; '
96102
uaReg := regexp.MustCompile(`Elastic-testbeat/([\d.]+) \(([\w-:+; ]+)\)`)

0 commit comments

Comments
 (0)