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

testcase for bgp container in container hardening #8694

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions tests/container_hardening/test_container_hardening.py
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))
1 change: 1 addition & 0 deletions tests/python3_test_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ console/test_console_loopback.py
console/test_console_reversessh.py
console/test_console_udevrule.py
container_checker/test_container_checker.py
container_hardening/test_container_hardening.py
copp/test_copp.py
crm/test_crm.py
dash/test_dash_vnet.py
Expand Down