-
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
Conversation
There is a compatibility issue either way. With the second way, the behavior of this package has changed:
So, for some code which does, for example, So I think the first way is better. If someone is doing something wrong, it's better to return an error so they know they are doing it wrong, rather than silently stop doing something. |
5f831f3
to
a782713
Compare
Agree, I have changed to return an error. |
capability/capability.go
Outdated
ErrBoundingNotMine = errors.New("not support drop bounding cap of other process") | ||
ErrAmbientNotMine = errors.New("not support modify ambient cap of other process") |
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.
Do we need these errors as part of a public API? If yes, why?
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.
Maybe someone use it to check the error type, like what to do in the test?
But maybe no, so I'll change it.
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.
Maybe someone use it to check the error type, like what to do in the test?
For the test case, you can add export_test.go
file having something like this:
package capability
// Make some internal details available for tests.
var ErrBoundingNotMine = errBoundingNotMine
Signed-off-by: lfbzhm <[email protected]>
a782713
to
d85f137
Compare
d85f137
to
0b9a879
Compare
Signed-off-by: lifubang <[email protected]>
0b9a879
to
f298c15
Compare
} | ||
requirePCapSet(t) | ||
|
||
cmd := exec.Command("sleep", "sleep", "infinity") |
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.
I think this should be
cmd := exec.Command("sleep", "sleep", "infinity") | |
cmd := exec.Command("sleep", "infinity") |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
See here
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.
We have a big problem
=== RUN TestAmbientCapSet
--- PASS: TestAmbientCapSet (0.00s)
=== RUN TestApplyCapsForOtherProcess
capability_test.go:159: The test needs `CAP_SETPCAP`.
--- SKIP: TestApplyCapsForOtherProcess (0.00s)
TestAmbientCapSet removes some capabilities from the binary, and thus all other tests that require CAP_SETPCAP
(or root) won't work.
Glad we found it now before it's too late.
The solution here is to spawn such test cases in a separate binary, so it won't affect others.
I will come up with a patch.
errBoundingNotMine = errors.New("not support drop bounding cap of other process") | ||
errAmbientNotMine = errors.New("not support modify ambient cap of other process") |
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.
errBoundingNotMine = errors.New("not support drop bounding cap of other process") | |
errAmbientNotMine = errors.New("not support modify ambient cap of other process") | |
errBoundingNotMine = errors.New("unable to modify bounding capabilities of another process") | |
errAmbientNotMine = errors.New("unable to modify ambient capabilities of another process") |
} | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatalf("expected not support error when drop bounding caps for other process, but got: %v", err) | |
t.Fatalf("want error %v, got %v", errBoundingNotMine, 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 comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatalf("expected not support error when rasing ambient caps for other process, but got: %v", err) | |
t.Fatalf("want error %v, got %v", errAmbientNotMine, err) |
package capability_test | ||
package capability |
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.
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:
- Just check for an error.
- export errors (as described in capability: can't raise ambient and drop bounding caps for other process #171 (comment)).
- create a different test file which will have
package capability
and thus would be able to test and access internals.
I would prefer way 2.
See #173. |
There may be two ways to fix #168:
I think we should choose the second way, because besides the bug fix,
we can also have a compatibility with before.