forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testcase for bgp container in container hardening (sonic-net#8694)
Description of PR HLD implementation: Container Hardening (sonic-net/SONiC#1364) Dependency: sonic-net/sonic-buildimage#14932 #### What is the motivation for this PR? Check bgp container has access to /dev/sda* or /dev/vda* after limiting privileged flag to less Linux capabilities. #### How did you do it? #### How did you verify/test it? ``` container_hardening/test_container_hardening.py::test_bgp_dev PASSED [100%] ``` Signed-off-by: Mai Bui <[email protected]>
- Loading branch information
1 parent
c63b3fc
commit 9d19eda
Showing
2 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
import logging | ||
from tests.common.helpers.assertions import pytest_assert | ||
|
||
pytestmark = [ | ||
pytest.mark.topology('any'), | ||
] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
NO_PRIVILEGED_CONTAINERS = [ | ||
'bgp', | ||
] | ||
|
||
|
||
def test_container_privileged(duthost): | ||
""" | ||
Test container without --privileged flag has no access to /dev/vda* or /dev/sda* | ||
""" | ||
for container_name in NO_PRIVILEGED_CONTAINERS: | ||
docker_exec_cmd = 'docker exec {} bash -c '.format(container_name) | ||
cmd = duthost.shell(docker_exec_cmd + "'df -h | grep /etc/hosts' | awk '{print $1}'") | ||
rc, device = cmd['rc'], cmd['stdout'] | ||
pytest_assert(rc == 0, 'Failed to get the device name.') | ||
pytest_assert(device.startswith('/dev/'), 'Invalid device {}.'.format(device)) | ||
output = duthost.shell(docker_exec_cmd + "'ls {}'".format(device), module_ignore_errors=True)['stdout'] | ||
pytest_assert(not output, 'The partition {} exists.'.format(device)) |
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