Skip to content

[action] [PR:22460] Add a test to test_container_hardening to check privilege via docker#22781

Merged
bingwang-ms merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/22460
Mar 7, 2026
Merged

[action] [PR:22460] Add a test to test_container_hardening to check privilege via docker#22781
bingwang-ms merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/22460

Conversation

@mssonicbld
Copy link
Collaborator

Description of PR

Summary:

Previously this test was checking whether the block device that /etc/hosts was mounted on was mounted in the container to determine whether the container was privileged. This isn't fully effective, as this just checks the block device of the partition, the entire block device might also be mounted.

Expanded this check to see whether the entire block device is mounted.

To check for the privileged flag directly to hopefully prevent any more containers being added with --privileged, we'll get a list of all the containers running on the dut and check all of them against the allow-list of privileged containers. We'll check this by docker inspect'ing the containers.

Future work: Check various other attributes that come along with --privileged to ensure only allowed containers add them. For example, capabilities, /sys filesystem, other devices.

Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
  • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

The previous test didn't check what it claimed to check. Dockers with just some /dev/ mounts could be considered privileged, which they were not.

How did you do it?

Check the docker description of each container to see if it was privileged directly

How did you verify/test it?

On a device with containers privileged and unprivileged.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

…onic-net#22460)

What is the motivation for this PR
The previous test didn’t reliably detect privileged containers; it only checked partition block devices and could misclassify containers.

How did you do it
Check each running container’s docker config for privileged status, and extend the mount check to include raw block devices in addition to partitions.

How did you verify/test it
Verified on a device with privileged and unprivileged containers.

Signed-off-by: Nate White <nate@nexthop.ai>
Signed-off-by: mssonicbld <sonicbld@microsoft.com>
@mssonicbld
Copy link
Collaborator Author

Original PR: #22460

@github-actions github-actions bot requested review from hdwhdw and maipbui March 6, 2026 19:14
@mssonicbld
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bingwang-ms
Copy link
Collaborator

Retriggered PR test and set to auto merge

@bingwang-ms bingwang-ms enabled auto-merge (squash) March 7, 2026 03:29
@bingwang-ms bingwang-ms merged commit 42d36c0 into sonic-net:202511 Mar 7, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants