Skip to content

Commit 81c38fc

Browse files
authored
[Heartbeat][Agent] Seccomp / synthetics bugfix improvements (#28514)
Fixes a variety of seccomp and synthetics execution related issues: Adds the setcap syscall, which chrome invokes to drop all privileges. Chrome crashes w/o this. Adds the getgroups syscall, which we use to log the active groups Improves logging for process execution failures with more detail
1 parent 0a24250 commit 81c38fc

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

heartbeat/beater/heartbeat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/elastic/beats/v7/libbeat/management"
4040
"github.com/elastic/beats/v7/x-pack/functionbeat/function/core"
4141

42+
_ "github.com/elastic/beats/v7/heartbeat/security"
4243
_ "github.com/elastic/beats/v7/libbeat/processors/script"
4344
)
4445

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//go:build linux
2020
// +build linux
2121

22-
package main
22+
package security
2323

2424
import (
2525
"fmt"
@@ -139,6 +139,7 @@ func setSeccompRules() error {
139139
"bind",
140140
"brk",
141141
"capget",
142+
"capset",
142143
"chdir",
143144
"chmod",
144145
"chown",
@@ -165,6 +166,7 @@ func setSeccompRules() error {
165166
"getdents64",
166167
"getegid",
167168
"geteuid",
169+
"getgroups",
168170
"getgid",
169171
"getpeername",
170172
"getpgrp",

heartbeat/security/security_all.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package security
19+
20+
// Empty file so that non-linux platforms have *something*
21+
// to import, thus preventing mage from complaining
22+
// no files are imported from the package

x-pack/heartbeat/monitors/browser/synthexec/synthexec.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ func runCmd(
173173
wg.Done()
174174
}()
175175
err = cmd.Start()
176+
if err != nil {
177+
logp.Warn("Could not start command %s: %s", cmd, err)
178+
return nil, err
179+
}
176180

177181
// Kill the process if the context ends
178182
go func() {
179-
select {
180-
case <-ctx.Done():
181-
cmd.Process.Kill()
182-
}
183+
<-ctx.Done()
184+
cmd.Process.Kill()
183185
}()
184186

185187
// Close mpx after the process is done and all events have been sent / consumed
@@ -194,7 +196,7 @@ func runCmd(
194196
Type: "cmd/status",
195197
Error: &SynthError{Name: "cmdexit", Message: str},
196198
})
197-
logp.Warn("Error executing command '%s': %s", cmd.String(), err)
199+
logp.Warn("Error executing command '%s' (%d): %s", cmd.String(), cmd.ProcessState.ExitCode(), err)
198200
}
199201
wg.Wait()
200202
mpx.Close()

0 commit comments

Comments
 (0)