Skip to content

Commit 9c64c52

Browse files
[8.18](backport #46372) libbeat: add 'eventfd2' to default seccomp policy (#46447)
* libbeat: add 'eventfd2' to default seccomp policy (#46372) Since Go introduced https://go.dev/cl/560615 it uses `eventfd2`, which was not part of our default seccomp policy. Due to the `google.golang.org/protobuf` dependency `eventfd2` during its initialisation, before our seccomp policy be applied, thus it worked. However once filebeat is reexeced, for example, due to a CA change, the seccomp policy would be in place and prevent `eventfd2` call, crashing filebeat. This change adds `eventfd2` to the default seccomp policy This also adjusts Beat.doReexec to use os.Executable isntead of manually building the binary path. (cherry picked from commit 7162773) # Conflicts: # libbeat/tests/integration/elasticsearch_test.go --------- Co-authored-by: Anderson Queiroz <[email protected]>
1 parent 63f647f commit 9c64c52

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
8080
- Lower logging level to debug when attempting to configure beats with unknown fields from autodiscovered events/environments {pull}[37816][37816]
8181
- Set timeout of 1 minute for FQDN requests {pull}37756[37756]
8282
- 'add_cloud_metadata' processor - improve AWS provider HTTP client overriding to support custom certificate bundle handling {pull}44189[44189]
83+
- Fixed a panic when the beat restarts itself by adding 'eventfd2' to default seccomp policy {issue}46372[46372]
8384
- Update Go version to 1.24.7 {pull}46070[46070].
8485

8586
*Auditbeat*

libbeat/cmd/instance/beat_reexec_unix.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ package instance
2222
import (
2323
"fmt"
2424
"os"
25-
"path/filepath"
2625

2726
"golang.org/x/sys/unix"
2827
)
2928

3029
func (b *Beat) doReexec() error {
31-
pwd, err := os.Getwd()
30+
binary, err := os.Executable()
3231
if err != nil {
3332
return fmt.Errorf("could not get working directory: %w", err)
3433
}
3534

36-
binary := filepath.Join(pwd, os.Args[0])
3735
if err := unix.Exec(binary, os.Args, os.Environ()); err != nil {
3836
return fmt.Errorf("could not exec '%s', err: %w", binary, err)
3937
}

libbeat/common/seccomp/policy_linux_386.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func init() {
4646
"epoll_create1",
4747
"epoll_ctl",
4848
"epoll_wait",
49+
"eventfd2",
4950
"execve",
5051
"exit",
5152
"exit_group",

libbeat/common/seccomp/policy_linux_amd64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func init() {
5151
"epoll_ctl",
5252
"epoll_pwait",
5353
"epoll_wait",
54+
"eventfd2",
5455
"execve",
5556
"exit",
5657
"exit_group",

libbeat/tests/integration/elasticsearch_test.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ package integration
2121

2222
import (
2323
"errors"
24+
"fmt"
2425
"io"
2526
"net/http"
27+
"os"
28+
"path/filepath"
2629
"testing"
2730
"time"
2831

2932
"github.com/gofrs/uuid/v5"
3033
"github.com/rcrowley/go-metrics"
3134
"github.com/stretchr/testify/require"
3235

36+
"github.com/elastic/elastic-agent-libs/testing/certutil"
3337
"github.com/elastic/mock-es/pkg/api"
3438
)
3539

@@ -94,6 +98,61 @@ func TestESOutputRecoversFromNetworkError(t *testing.T) {
9498
s.Close()
9599
}
96100

101+
func TestReloadCA(t *testing.T) {
102+
mockbeat := NewBeat(t, "mockbeat", "../../libbeat.test")
103+
104+
esAddr := "localhost:4242"
105+
s, _ := startMockES(t, esAddr)
106+
defer s.Close()
107+
108+
_, _, pair, err := certutil.NewRootCA()
109+
require.NoError(t, err, "could not generate root CA")
110+
caPath := filepath.Join(os.TempDir(), "ca.pem")
111+
err = os.WriteFile(caPath, pair.Cert, 0644)
112+
require.NoError(t, err, "could not write CA")
113+
114+
mockbeat.WriteConfigFile(fmt.Sprintf(`
115+
output.elasticsearch:
116+
allow_older_versions: true
117+
hosts: ["%s"]
118+
ssl:
119+
certificate_authorities: "%s"
120+
restart_on_cert_change.enabled: true
121+
restart_on_cert_change.period: 1s
122+
logging.level: debug
123+
`, esAddr, caPath))
124+
125+
mockbeat.Start()
126+
127+
// 1. wait mockbeat to start
128+
mockbeat.WaitForLogs(
129+
fmt.Sprint("mockbeat start running"),
130+
10*time.Second,
131+
"did not find 'mockbeat start running' log")
132+
133+
// 2. "rotate" the CA. Just write it again
134+
err = os.WriteFile(caPath, pair.Cert, 0644)
135+
require.NoError(t, err, "could not rotate CA")
136+
137+
// 3. Wait for cert change detection logs
138+
mockbeat.WaitForLogs(
139+
fmt.Sprintf("some of the following files have been modified: [%s]", caPath),
140+
10*time.Second,
141+
"did not detect CA rotation")
142+
143+
// 4. Wait for CA load log
144+
mockbeat.WaitForLogs(
145+
fmt.Sprintf("Successfully loaded CA certificate: %s", caPath),
146+
10*time.Second,
147+
"did not find 'Successfully loaded CA' log")
148+
149+
// 5. wait mockbeat to start again
150+
mockbeat.WaitForLogs(
151+
fmt.Sprint("mockbeat start running"),
152+
10*time.Second,
153+
"did not find 'mockbeat start running' log again")
154+
}
155+
97156
func startMockES(t *testing.T, addr string) (*http.Server, metrics.Registry) {
98157
uid := uuid.Must(uuid.NewV4())
99158
mr := metrics.NewRegistry()
@@ -107,9 +166,9 @@ func startMockES(t *testing.T, addr string) (*http.Server, metrics.Registry) {
107166
}()
108167

109168
require.Eventually(t, func() bool {
110-
resp, err := http.Get("http://" + addr) //nolint: noctx // It's just a test
169+
resp, err := http.Get("http://" + addr) //nolint:noctx // It's just a test
111170
if err != nil {
112-
//nolint: errcheck // We're just draining the body, we can ignore the error
171+
//nolint:errcheck // We're just draining the body, we can ignore the error
113172
io.Copy(io.Discard, resp.Body)
114173
resp.Body.Close()
115174
return false

0 commit comments

Comments
 (0)