-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove GNMI privilege #24751
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
base: master
Are you sure you want to change the base?
Remove GNMI privilege #24751
Conversation
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Pull request overview
This PR improves container security by replacing the --privileged flag in the docker-gnmi container with specific Linux capabilities. Instead of granting all privileges, the container now receives only the capabilities needed for GNMI/GNOI operations: SYS_ADMIN, SYS_BOOT, SYS_PTRACE, NET_ADMIN, and DAC_OVERRIDE. This follows the principle of least privilege for container hardening.
Key Changes:
- Removed
--privilegedflag from GNMI container runtime options - Added five specific Linux capabilities (SYS_ADMIN, SYS_BOOT, SYS_PTRACE, NET_ADMIN, DAC_OVERRIDE)
- Added security options for apparmor and seccomp to enable nsenter access to host namespaces
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $(DOCKER_GNMI)_RUN_OPT += --cap-add=DAC_OVERRIDE | ||
| # Security options needed for nsenter to access host namespaces from within container | ||
| $(DOCKER_GNMI)_RUN_OPT += --security-opt apparmor=unconfined | ||
| $(DOCKER_GNMI)_RUN_OPT += --security-opt seccomp=unconfined |
Copilot
AI
Dec 4, 2025
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 combination of --security-opt seccomp=unconfined with multiple powerful capabilities (SYS_ADMIN, SYS_BOOT, SYS_PTRACE) significantly reduces the security benefit of removing --privileged. Disabling seccomp removes syscall filtering, which is a critical security layer.
While --security-opt apparmor=unconfined is used in other containers (e.g., docker-orchagent.mk:39, docker-platform-monitor.mk:53), seccomp=unconfined is unique to this container and should be justified. Consider:
- Identifying the specific syscalls needed by the GNMI container
- Creating a custom seccomp profile that allows only those syscalls
- Removing the
seccomp=unconfinedoption if it's not strictly necessary
This would provide better defense-in-depth while maintaining functionality.
| $(DOCKER_GNMI)_RUN_OPT += --security-opt seccomp=unconfined |
Why I did it
Implement container hardening for the GNMI container as per the SONiC Container Hardening HLD. This improves security by following the principle of least privilege, replacing the
--privilegedflag with specific Linux capabilities.Fixes #24542
How I did it
Modified
rules/docker-gnmi.mkto replace--privilegedwith specific Linux capabilities and security options:Capabilities added:
CAP_SYS_ADMIN: For system administration operationsCAP_SYS_BOOT: For reboot operations via gNOICAP_SYS_MODULE: For kernel module operationsCAP_DAC_OVERRIDE: To bypass file permission checksCAP_DAC_READ_SEARCH: To read files regardless of permissionsCAP_NET_ADMIN: For network administrationCAP_NET_BIND_SERVICE: To bind to privileged portsCAP_SYS_PTRACE: To access /proc/[pid]/ns/* of other processes (required for nsenter)CAP_IPC_OWNER: For IPC namespace accessSecurity options added:
--security-opt apparmor=unconfined--security-opt seccomp=unconfinedThese security options are required for nsenter to access host namespaces from within the container.
How to verify it
Testing performed on vlab-01:
Modified the container startup script:
Verified container is running without --privileged:
Key Test - nsenter from INSIDE the container (this is how gNOI operates):
Verified capabilities inside the container:
Tested reboot functionality:
Important: The testing confirms that gNOI can execute host commands (sonic-installer, reboot) from within the container using nsenter, which is the actual use case. Without
SYS_PTRACEcapability and the security options, nsenter would fail with "Permission denied" when trying to access/proc/1/ns/*.Which release branch to backport (provide reason below if selected)
Description for the changelog
Replace --privileged flag with specific Linux capabilities and security options for GNMI container to improve security while maintaining gNOI functionality including nsenter operations from within the container.