Skip to content

Commit

Permalink
add unprivileged mode flag (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Jun 21, 2024
1 parent 5895004 commit 1f92439
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 256 deletions.
2 changes: 2 additions & 0 deletions elastic-agent-client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ message AgentInfo {
bool snapshot = 3;
// AgentManagedMode reports what config mode agent is running in.
AgentManagedMode mode = 4;
// Unprivileged reports if agent is running in Unprivileged mode
bool Unprivileged = 5;
}

// Feature flags configurations.
Expand Down
11 changes: 7 additions & 4 deletions pkg/client/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type AgentInfo struct {
Snapshot bool
// IsStandalone reports if the agent is running in standalone or managed mode
ManagedMode proto.AgentManagedMode
// Unprivileged reports if the agent is running in unprivileged mode.
Unprivileged bool
}

// VersionInfo is the version information for the connecting client.
Expand Down Expand Up @@ -575,10 +577,11 @@ func (c *clientV2) applyExpected(expected *proto.CheckinExpected) {
if expected.AgentInfo != nil {
c.agentInfoMu.Lock()
c.agentInfo = &AgentInfo{
ID: expected.AgentInfo.Id,
Version: expected.AgentInfo.Version,
Snapshot: expected.AgentInfo.Snapshot,
ManagedMode: expected.AgentInfo.Mode,
ID: expected.AgentInfo.Id,
Version: expected.AgentInfo.Version,
Snapshot: expected.AgentInfo.Snapshot,
ManagedMode: expected.AgentInfo.Mode,
Unprivileged: expected.AgentInfo.Unprivileged,
}
c.agentInfoMu.Unlock()
}
Expand Down
19 changes: 11 additions & 8 deletions pkg/client/client_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie
packageVersion := "8.13.0+build20060102"
wantBuildHash := "build_hash"
wantAgentInfo := AgentInfo{
ID: "elastic-agent-id",
Version: packageVersion,
Snapshot: true,
ManagedMode: proto.AgentManagedMode_STANDALONE,
ID: "elastic-agent-id",
Version: packageVersion,
Snapshot: true,
ManagedMode: proto.AgentManagedMode_STANDALONE,
Unprivileged: true,
}
vInfo := VersionInfo{
Name: "program",
Expand All @@ -183,10 +184,11 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie

return &proto.CheckinExpected{
AgentInfo: &proto.AgentInfo{
Id: wantAgentInfo.ID,
Version: wantAgentInfo.Version,
Snapshot: wantAgentInfo.Snapshot,
Mode: wantAgentInfo.ManagedMode,
Id: wantAgentInfo.ID,
Version: wantAgentInfo.Version,
Snapshot: wantAgentInfo.Snapshot,
Mode: wantAgentInfo.ManagedMode,
Unprivileged: wantAgentInfo.Unprivileged,
},
Features: &proto.Features{
Fqdn: &proto.FQDNFeature{Enabled: wantFQDN},
Expand Down Expand Up @@ -306,6 +308,7 @@ func testClientV2CheckinInitial(t *testing.T, localRPC string, serverCreds, clie
assert.Equal(t, wantAgentInfo.Version, agentInfo.Version)
assert.True(t, wantAgentInfo.Snapshot, agentInfo.Snapshot)
assert.Equal(t, wantAgentInfo.ManagedMode, agentInfo.ManagedMode)
assert.Equal(t, wantAgentInfo.Unprivileged, agentInfo.Unprivileged)
}

assert.Truef(t, gotFQDN, "FQND should be true")
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ func NewV2FromReader(reader io.Reader, ver VersionInfo, opts ...V2ClientOption)

if info.AgentInfo != nil {
opts = append(opts, WithAgentInfo(AgentInfo{
ID: info.AgentInfo.Id,
Version: info.AgentInfo.Version,
Snapshot: info.AgentInfo.Snapshot,
ManagedMode: info.AgentInfo.Mode,
ID: info.AgentInfo.Id,
Version: info.AgentInfo.Version,
Snapshot: info.AgentInfo.Snapshot,
ManagedMode: info.AgentInfo.Mode,
Unprivileged: info.AgentInfo.Unprivileged,
}))
}

Expand Down
Loading

0 comments on commit 1f92439

Please sign in to comment.