Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unprivileged mode flag to gRPC, client API #116

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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