Skip to content

Commit 9c9ae35

Browse files
[Heartbeat] Add prctl dumpable flag reset after cap drop (elastic#38269)
Enforce dumpable attribute on heartbeat process for /proc/io to be readable by elastic-agent. --------- Co-authored-by: Vignesh Shanmugam <[email protected]>
1 parent 361a62f commit 9c9ae35

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ fields added to events containing the Beats version. {pull}37553[37553]
107107
- Fix panics when parsing dereferencing invalid parsed url. {pull}34702[34702]
108108
- Fix setuid root when running under cgroups v2. {pull}37794[37794]
109109
- Adjust State loader to only retry when response code status is 5xx {pull}37981[37981]
110+
- Reset prctl dumpable flag after cap drop. {pull}38269[38269]
110111

111112
*Metricbeat*
112113

heartbeat/security/security.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strconv"
2727
"syscall"
2828

29+
"golang.org/x/sys/unix"
2930
"kernel.org/pub/linux/libs/security/libcap/cap"
3031
)
3132

@@ -46,6 +47,9 @@ func init() {
4647
// The beat should use `getcap` at a later point to examine available capabilities
4748
// rather than relying on errors from `setcap`
4849
_ = setCapabilities()
50+
51+
// Make heartbeat dumpable so elastic-agent can access process metrics.
52+
_ = setDumpable()
4953
}
5054

5155
func setNodeProcAttr(localUserName string) error {
@@ -99,3 +103,13 @@ func setCapabilities() error {
99103

100104
return nil
101105
}
106+
107+
// Enforce PR_SET_DUMPABLE=true to allow user-level access to /proc/<pid>/io.
108+
func setDumpable() error {
109+
_, err := cap.Prctl(unix.PR_SET_DUMPABLE, 1)
110+
if err != nil {
111+
return fmt.Errorf("error setting dumpable flag via prctl: %w", err)
112+
}
113+
114+
return nil
115+
}

0 commit comments

Comments
 (0)