From e8b17220055d4cfd71fcc34d1d7215aaa750500d Mon Sep 17 00:00:00 2001 From: Mai Bui Date: Fri, 26 Jan 2024 13:43:35 -0500 Subject: [PATCH] [docker-nat] limit privileged flag for nat container (#17756) ### Why I did it HLD implementation: Container Hardening (https://github.com/sonic-net/SONiC/pull/1364) ### How I did it Reduce linux capabilities in privileged flag #### How to verify it Check container's settings: Privileged is false and container only has default Linux caps, does not have extended caps. ``` admin@vlab-01:~$ docker inspect nat | grep Privi "Privileged": false, admin@vlab-01:~$ docker exec -it nat bash root@vlab-01:/# capsh --print Current: cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap=ep ``` --- rules/docker-nat.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/docker-nat.mk b/rules/docker-nat.mk index f4022547ff..0298ace831 100644 --- a/rules/docker-nat.mk +++ b/rules/docker-nat.mk @@ -29,7 +29,7 @@ SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_NAT_DBG) endif $(DOCKER_NAT)_CONTAINER_NAME = nat -$(DOCKER_NAT)_RUN_OPT += --privileged -t +$(DOCKER_NAT)_RUN_OPT += -t --cap-add=NET_ADMIN $(DOCKER_NAT)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro $(DOCKER_NAT)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro $(DOCKER_NAT)_RUN_OPT += -v /host/warmboot:/var/warmboot