-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move around librpm calls, add
setreuid()
safety net (#40436)
* tinkering with suid * cleanup setuid work * clean up debugging code * docs, experimenting with setreuid * remove go thread * final cleanup * crossbuild issues * fighting with ci * linter... * tinker with CI packges * more linter tinkering * cleanup * deref pointer * fix seccomp
- Loading branch information
1 parent
98211ea
commit d348654
Showing
11 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
x-pack/auditbeat/module/system/package/package_linux_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build linux | ||
|
||
package pkg | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/x-pack/auditbeat/module/system/user" | ||
"github.com/elastic/elastic-agent-libs/logp" | ||
) | ||
|
||
func TestRPMParallel(t *testing.T) { | ||
currentUID := os.Getuid() | ||
if currentUID != 0 { | ||
t.Skipf("can only run as root") | ||
} | ||
logp.DevelopmentSetup() | ||
|
||
count := 20 | ||
waiter := sync.WaitGroup{} | ||
waiter.Add(count) | ||
|
||
useUID := getUser(t) | ||
|
||
t.Logf("Starting...") | ||
for i := 0; i < count; i++ { | ||
inner := i | ||
go func() { | ||
defer waiter.Done() | ||
testMs := MetricSet{ | ||
log: logp.L(), | ||
config: config{ | ||
PackageSuidDrop: &useUID, | ||
}, | ||
} | ||
|
||
pkgList, err := testMs.getPackages() | ||
require.NoError(t, err) | ||
|
||
t.Logf("got %d packages from %d", len(pkgList), inner) | ||
}() | ||
|
||
} | ||
waiter.Wait() | ||
} | ||
|
||
func TestWithSuid(t *testing.T) { | ||
currentUID := os.Getuid() | ||
if currentUID != 0 { | ||
t.Skipf("can only run as root") | ||
} | ||
useUID := getUser(t) | ||
testMs := MetricSet{ | ||
log: logp.L(), | ||
config: config{ | ||
PackageSuidDrop: &useUID, | ||
}, | ||
} | ||
|
||
packages, err := testMs.getPackages() | ||
require.NoError(t, err) | ||
|
||
require.NotZero(t, packages) | ||
t.Logf("got %d packages", len(packages)) | ||
} | ||
|
||
func getUser(t *testing.T) int64 { | ||
// pick a user to drop to | ||
userList, err := user.GetUsers(false) | ||
require.NoError(t, err) | ||
|
||
var useUID int64 | ||
for _, user := range userList { | ||
if user.UID != "0" { | ||
newUID, err := strconv.ParseInt(user.UID, 10, 64) | ||
require.NoError(t, err) | ||
useUID = newUID | ||
break | ||
} | ||
} | ||
return useUID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.