Skip to content

Commit

Permalink
[Elastic-Agent] Do not take ownership of Endpoint log path (elastic#2…
Browse files Browse the repository at this point in the history
…3444)

* Do not take ownership when custom log path is defined in spec.

* Add changelog.

* Empty commit.

(cherry picked from commit 71e406b)
  • Loading branch information
blakerouse committed Jan 12, 2021
1 parent bdaf54b commit 8ebfbe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Fix shell wrapper for deb/rpm packaging {pull}23038[23038]
- Fixed parsing of npipe URI {pull}22978[22978]
- Remove artifacts on transient download errors {pull}23235[23235]
- Do not take ownership of Endpoint log path {pull}23444[23444]

==== New features

Expand Down
12 changes: 10 additions & 2 deletions x-pack/elastic-agent/pkg/core/monitoring/beats/beats_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ func (b *Monitor) generateLoggingFile(spec program.Spec, pipelineID string) stri

func (b *Monitor) generateLoggingPath(spec program.Spec, pipelineID string) string {
return filepath.Dir(b.generateLoggingFile(spec, pipelineID))
}

func (b *Monitor) ownLoggingPath(spec program.Spec) bool {
// if the spec file defines a custom log path then agent will not take ownership of the logging path
_, ok := spec.LogPaths[b.operatingSystem]
return !ok
}

// EnrichArgs enriches arguments provided to application, in order to enable
Expand Down Expand Up @@ -139,6 +144,7 @@ func (b *Monitor) Cleanup(spec program.Spec, pipelineID string) error {

// Prepare executes steps in order for monitoring to work correctly
func (b *Monitor) Prepare(spec program.Spec, pipelineID string, uid, gid int) error {
takeOwnership := b.ownLoggingPath(spec)
drops := []string{b.generateLoggingPath(spec, pipelineID)}
if drop := b.monitoringDrop(spec, pipelineID); drop != "" {
drops = append(drops, drop)
Expand All @@ -161,8 +167,10 @@ func (b *Monitor) Prepare(spec program.Spec, pipelineID string, uid, gid int) er
}
}

if err := changeOwner(drop, uid, gid); err != nil {
return err
if takeOwnership {
if err := changeOwner(drop, uid, gid); err != nil {
return err
}
}
}

Expand Down

0 comments on commit 8ebfbe8

Please sign in to comment.