Skip to content

Commit

Permalink
[Heartbeat] Remove containerized check from setuid logic (#37794)
Browse files Browse the repository at this point in the history
Removed isContainerized from setuid check, as it fails to detect containers running under cgroups v2 and prevents switching users when running as root.
  • Loading branch information
emilioalvap authored Jan 31, 2024
1 parent 2840dac commit 5d1c592
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
*Heartbeat*

- Fix panics when parsing dereferencing invalid parsed url. {pull}34702[34702]
- Fix setuid root when running under cgroups v2. {pull}37794[37794]

*Metricbeat*

Expand Down
10 changes: 1 addition & 9 deletions heartbeat/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"strconv"
"syscall"

sysinfo "github.com/elastic/go-sysinfo"

"kernel.org/pub/linux/libs/security/libcap/cap"
)

Expand All @@ -36,13 +34,7 @@ func init() {
// In the context of a container, where users frequently run as root, we follow BEAT_SETUID_AS to setuid/gid
// and add capabilities to make this actually run as a regular user. This also helps Node.js in synthetics, which
// does not want to run as root. It's also just generally more secure.
sysInfo, err := sysinfo.Host()
isContainer := false
if err == nil && sysInfo.Info().Containerized != nil {
isContainer = *sysInfo.Info().Containerized
}

if localUserName := os.Getenv("BEAT_SETUID_AS"); isContainer && localUserName != "" && syscall.Geteuid() == 0 {
if localUserName := os.Getenv("BEAT_SETUID_AS"); localUserName != "" && syscall.Geteuid() == 0 {
err := setNodeProcAttr(localUserName)
if err != nil {
panic(err)
Expand Down

0 comments on commit 5d1c592

Please sign in to comment.