-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
capability: can't raise ambient and drop bounding caps for other process #171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,13 +2,13 @@ | |||||
// Use of this source code is governed by a BSD-style | ||||||
// license that can be found in the LICENSE file. | ||||||
|
||||||
package capability_test | ||||||
package capability | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have added this comment already but it looks like it is lost. I deliberately changed this in commit 7208f83 so these tests can change public API only, and I don't like changing it back. You have a few options here:
I would prefer way 2. |
||||||
|
||||||
import ( | ||||||
"errors" | ||||||
"os/exec" | ||||||
"runtime" | ||||||
"testing" | ||||||
|
||||||
. "github.com/moby/sys/capability" | ||||||
) | ||||||
|
||||||
// Based on the fact Go 1.18+ supports Linux >= 2.6.32, and | ||||||
|
@@ -151,3 +151,40 @@ func TestAmbientCapSet(t *testing.T) { | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
func TestApplyCapsForOtherProcess(t *testing.T) { | ||||||
if runtime.GOOS != "linux" { | ||||||
return | ||||||
} | ||||||
requirePCapSet(t) | ||||||
|
||||||
cmd := exec.Command("sleep", "sleep", "infinity") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error went unnoticed because this test is not being run, because the previous test (TestAmbientCapSet) removes CAP_SET_PCAP from the test process. Oh well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here |
||||||
if err := cmd.Start(); err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
defer func() { | ||||||
_ = cmd.Process.Kill() | ||||||
_, _ = cmd.Process.Wait() | ||||||
}() | ||||||
|
||||||
pid, err := NewPid(cmd.Process.Pid) | ||||||
if err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
|
||||||
if err = pid.Load(); err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
err = pid.Apply(BOUNDING) | ||||||
if !errors.Is(err, errBoundingNotMine) { | ||||||
t.Fatalf("expected not support error when drop bounding caps for other process, but got: %v", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
err = pid.Apply(CAPS) | ||||||
if err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
err = pid.Apply(AMBIENT) | ||||||
if !errors.Is(err, errAmbientNotMine) { | ||||||
t.Fatalf("expected not support error when rasing ambient caps for other process, but got: %v", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.