Skip to content

[docker-orchagent] limit privileged flag for swss container #17598

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

Merged
merged 4 commits into from
Dec 30, 2024

Conversation

maipbui
Copy link
Contributor

@maipbui maipbui commented Dec 21, 2023

Why I did it

HLD implementation: Container Hardening (sonic-net/SONiC#1364)

Work item tracking
  • Microsoft ADO (number only): 14807420

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, and NET_ADMIN cap.

admin@vlab-01:~$ docker inspect swss | grep Privi
            "Privileged": false,


admin@vlab-01:~$ docker exec -it swss 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_net_admin,cap_audit_write,cap_setfcap=ep

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@maipbui
Copy link
Contributor Author

maipbui commented Dec 27, 2023

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maipbui
Copy link
Contributor Author

maipbui commented Jan 2, 2024

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maipbui maipbui closed this Jan 9, 2024
@maipbui maipbui deleted the swss_priv branch January 9, 2024 14:51
@maipbui maipbui restored the swss_priv branch December 17, 2024 17:24
Signed-off-by: Mai Bui <[email protected]>
@maipbui maipbui reopened this Dec 17, 2024
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -37,7 +37,7 @@ SONIC_BOOKWORM_DBG_DOCKERS += $(DOCKER_ORCHAGENT_DBG)
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_ORCHAGENT_DBG)

$(DOCKER_ORCHAGENT)_CONTAINER_NAME = swss
$(DOCKER_ORCHAGENT)_RUN_OPT += --privileged -t
$(DOCKER_ORCHAGENT)_RUN_OPT += -t --cap-add=NET_ADMIN --security-opt apparmor=unconfined --security-opt="systempaths=unconfined"
Copy link
Contributor Author

@maipbui maipbui Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--security-opt apparmor=unconfined --security-opt="systempaths=unconfined"

These arguments are necessary for arp/test_arp_extended.py test case

arp/test_arp_extended.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.8/dist-packages/ptf/testutils.py:3250: in verify_packet
    test.fail(
        device     = 0
        pkt        = <Ether  dst=b'fe:54:00:a3:80:01' src=22:48:23:27:33:d8 type=ARP |<ARP  op=is-at hwsrc=22:48:23:27:33:d8 psrc=192.168.0...:a3:80:01' pdst=192.168.0.3 |<Raw  load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>>>
        port       = 1
        port_id    = 1
        result     = PollFailure(device=None, port=None, packet=None, time=None)
        test       = <tests.common.plugins.ptfadapter.ptfadapter.PtfTestAdapter testMethod=runTest>
        timeout    = 10
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tests.common.plugins.ptfadapter.ptfadapter.PtfTestAdapter testMethod=runTest>
msg = 'Expected packet was not received on device 0, port 1.\n========== EXPECTED ==========\ndst        : DestMACField     ...00 00 00              ............\n========== RECEIVED ==========\n0 total packets.\n==============================\n'

    def fail(self, msg=None):
        """Fail immediately, with the given message."""
>       raise self.failureException(msg)
E       AssertionError: Expected packet was not received on device 0, port 1.
E       ========== EXPECTED ==========
E       dst        : DestMACField                        = b'fe:54:00:a3:80:01' ('None')
E       src        : SourceMACField                      = '22:48:23:27:33:d8' ('None')
E       type       : XShortEnumField                     = 2054            ('36864')
E       --
E       hwtype     : XShortEnumField                     = 1               ('1')
E       ptype      : XShortEnumField                     = 2048            ('2048')
E       hwlen      : FieldLenField                       = None            ('None')
E       plen       : FieldLenField                       = None            ('None')
E       op         : ShortEnumField                      = 2               ('1')
E       hwsrc      : MultipleTypeField (SourceMACField, StrFixedLenField) = '22:48:23:27:33:d8' ('None')
E       psrc       : MultipleTypeField (SourceIPField, SourceIP6Field, StrFixedLenField) = '192.168.0.4'   ('None')
E       hwdst      : MultipleTypeField (MACField, StrFixedLenField) = b'fe:54:00:a3:80:01' ('None')
E       pdst       : MultipleTypeField (IPField, IP6Field, StrFixedLenField) = '192.168.0.3'   ('None')
E       --
E       load       : StrField                            = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ("b''")
E       --
E       0000  FE 54 00 A3 80 01 22 48 23 27 33 D8 08 06 00 01  .T...."H#'3.....
E       0010  08 00 06 04 00 02 22 48 23 27 33 D8 C0 A8 00 04  ......"H#'3.....
E       0020  FE 54 00 A3 80 01 C0 A8 00 03 00 00 00 00 00 00  .T..............
E       0030  00 00 00 00 00 00 00 00 00 00 00 00              ............
E       ========== RECEIVED ==========
E       0 total packets.
E       ==============================
``` #Closed

@maipbui
Copy link
Contributor Author

maipbui commented Dec 18, 2024

@prsunny can you help review?

Copy link
Contributor

@prsunny prsunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on the plan for reducing previlege. Do you know what functionalities would be limited due to this change?

@maipbui
Copy link
Contributor Author

maipbui commented Dec 27, 2024

@kperumalbfn kperumalbfn merged commit df50618 into sonic-net:master Dec 30, 2024
21 checks passed
@maipbui maipbui deleted the swss_priv branch December 30, 2024 18:25
github-actions bot pushed a commit to bradh352/sonic-buildimage that referenced this pull request Jan 2, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
github-actions bot pushed a commit to bradh352/sonic-buildimage that referenced this pull request Jan 2, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
github-actions bot pushed a commit to bradh352/sonic-buildimage that referenced this pull request Jan 2, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
VladimirKuk pushed a commit to Marvell-switching/sonic-buildimage that referenced this pull request Jan 21, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
prabhataravind pushed a commit to prabhataravind/sonic-buildimage that referenced this pull request Mar 5, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
yanjundeng pushed a commit to yanjundeng/sonic-buildimage that referenced this pull request Apr 23, 2025
…t#17598)

[docker-orchagent] limit privileged flag for swss container

Signed-off-by: Mai Bui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants