Skip to content
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

add a test for runc exec --cap #4406

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/integration/capabilities.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ function teardown() {
[[ "${output}" == *"CapPrm: 0000000000200000"* ]]
[[ "${output}" == *"NoNewPrivs: 1"* ]]
}

@test "runc exec --cap" {
update_config '.process.terminal = false'
update_config '.process.args = ["sleep", "infinity"]'
update_config '.process.user = {"uid":0}'
update_config '.process.capabilities.bounding = ["CAP_KILL", "CAP_CHOWN", "CAP_SYSLOG"]'
update_config '.process.capabilities.effective = ["CAP_KILL"]'
update_config '.process.capabilities.permitted = ["CAP_KILL", "CAP_CHOWN"]'
update_config '.process.capabilities.inheritable = ["CAP_CHOWN", "CAP_SYSLOG"]'
update_config '.process.capabilities.ambient = ["CAP_CHOWN"]'
__runc run -d test_some_caps
[ "$status" -eq 0 ]
Copy link
Contributor

@kolyshkin kolyshkin Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not checking runc exit code here, because __runc doesn't use bats' run which sets $status.

If you copied this code from some other place -- that place is also wrong.


runc exec test_some_caps /bin/cat /proc/self/status
[[ "${output}" == *"CapInh: 0000000400000001"* ]]
[[ "${output}" == *"CapBnd: 0000000400000021"* ]]
[[ "${output}" == *"CapEff: 0000000000000021"* ]]
[[ "${output}" == *"CapPrm: 0000000000000021"* ]]
[[ "${output}" == *"CapAmb: 0000000000000001"* ]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add comments to help understanding these bitmasks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll add them later.

[[ "${output}" == *"NoNewPrivs: 1"* ]]

runc exec --cap CAP_SYSLOG test_some_caps /bin/cat /proc/self/status
[[ "${output}" == *"CapInh: 0000000400000001"* ]]
[[ "${output}" == *"CapBnd: 0000000400000021"* ]]
[[ "${output}" == *"CapEff: 0000000400000021"* ]]
[[ "${output}" == *"CapPrm: 0000000400000021"* ]]
[[ "${output}" == *"CapAmb: 0000000400000001"* ]]
[[ "${output}" == *"NoNewPrivs: 1"* ]]
}
Loading