-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Container net host remove #15176
Container net host remove #15176
Changes from 8 commits
b9bf960
5ee5af7
8e537a1
238a198
5296455
621b54a
9169746
f568e64
10c37ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -486,7 +486,12 @@ start() { | |
{%- endif %} | ||
|
||
if [ -z "$DEV" ]; then | ||
NET="host" | ||
{%- if docker_container_name == "snmp" %} | ||
ycoheNvidia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NET="bridge" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried image built by this PR yesterday, version: SONiC.master-15176.360116-6bb24c135. Looks like rsyslog inside snmp container cannot work well. I cannot find any syslog generated by snmp container (contains 'snmp#') in local host syslog file or our syslog server, and process There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ycoheNvidia could check if change like this is needed. #4738 |
||
{%- else %} | ||
NET="host" | ||
{%- endif %} | ||
|
||
|
||
# For Multi-ASIC platform we have to mount the redis paths for database instances running in different | ||
# namespaces, into the single instance dockers like snmp, pmon on linux host. These global dockers | ||
|
@@ -526,6 +531,8 @@ start() { | |
{%- if docker_container_name == "database" %} | ||
NET="bridge" | ||
DB_OPT=$DB_OPT" -v /var/run/redis$DEV:/var/run/redis:rw " | ||
{%- elif docker_container_name == "snmp" %} | ||
NET="bridge" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking best practice (https://docs.docker.com/network/network-tutorial-standalone/), default bridge network is not best choice for production. User-defined bridge networks is best choice for production. Can we use user-defined bridge network here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, defining a user-defined bridge is the best case solution for this item. |
||
{%- else %} | ||
NET="container:database$DEV" | ||
DB_OPT="" | ||
|
@@ -541,10 +548,45 @@ start() { | |
{%- endif %} | ||
{%- if sonic_asic_platform == "mellanox" %} | ||
# TODO: Mellanox will remove the --tmpfs exception after SDK socket path changed in new SDK version | ||
{%- endif %} | ||
{%- if docker_container_name == "snmp" %} | ||
# get snmp listening address and port list from redis | ||
ycoheNvidia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
addr_port_values=$(python3 -c 'from swsscommon.swsscommon import ConfigDBConnector; cfg_db = ConfigDBConnector(); cfg_db.connect(wait_for_init=True, retry_on=True); [print(k[0] + "|" + k[1]) for k in cfg_db.get_keys("SNMP_AGENT_ADDRESS_CONFIG|*")]') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this logic moved here instead of doing in snmpd.conf.j2 file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved here because port and address forwarding can only be done during docker create. What it means that in order to harden this container's network - each address/port change for this service will require docker removal and creation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR will kill the feature of SNMP_AGENT_ADDRESS_CONFIG/port. Do you want to implement the same feature here or in another PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I understand your question. This PR and sonic-net/sonic-snmpagent#281 moves the logic of snmp networking management from the container to the host. The host will forward the relevant packets only (SNMP_AGENT_ADDRESS_CONFIG for example) and the container will take all packets sent to port 161 |
||
NAMESPACE_COUNT=$NUM_ASIC | ||
if [ -z $addr_port_values ]; then | ||
if [ -z $NAMESPACE_COUNT ] || [ $NAMESPACE_COUNT -lt 2 ]; then | ||
addr_port_values=$(python3 -c 'from swsscommon.swsscommon import ConfigDBConnector; cfg_db = ConfigDBConnector(); cfg_db.connect(wait_for_init=True, retry_on=True); [print(k[1].split("/")[0].lower() + "%" + k[0]) if len(k) == 2 and k[1].split('/')[0].lower().startswith("fe80") else print(k[1].split("/")[0].lower()) for k in cfg_db.get_keys("LOOPBACK_INTERFACE|*")+cfg_db.get_keys("MGMT_INTERFACE|*") if len(k) == 2]') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here currently only Loopback and Mgmt IP addresses are used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SuvarnaMeenakshi you either missed line 556 which addresses the specific SNMP_AGENT_ADDRESS_CONFIG table, or I miss something. I followed the logic that was found in snmpd.conf.j2 and translated it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is throwing a syntax error. Why do we need the "fe80" check? |
||
fi | ||
fi | ||
fwd_port_values="" | ||
# Loop over each value in the list | ||
while read -r value; do | ||
# Split the value and port number (if any) | ||
parts=(${value//|/ }) | ||
value="${parts[0]}" | ||
port="${parts[1]:-}" | ||
if [ -z $port ]; then | ||
port=161 | ||
fi | ||
# Check if the value is an IPv4 address | ||
if [ "$fwd_port_values" != "" ]; then | ||
fwd_port_values="$fwd_port_values"$'\n' | ||
fi | ||
if [[ $value =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
# IPv4 address, use as is | ||
fwd_port_values="$fwd_port_values$value:$port:161/udp" | ||
else | ||
# Not an IPv4 address, wrap in [] | ||
fwd_port_values="$fwd_port_values[$value]:$port:161/udp" | ||
fi | ||
done <<< "$addr_port_values" | ||
|
||
{%- endif %} | ||
docker create {{docker_image_run_opt}} \ | ||
{%- if docker_container_name != "dhcp_server" %} | ||
--net=$NET \ | ||
{%- elif docker_container_name == "snmp" %} | ||
$(echo "$fwd_port_values" | sed 's/^/-p /' | tr '\n' ' ') \ | ||
{%- endif %} | ||
-e RUNTIME_OWNER=local \ | ||
--uts=host \{# W/A: this should be set per-docker, for those dockers which really need host's UTS namespace #} | ||
|
@@ -660,6 +702,9 @@ stop() { | |
/usr/local/bin/container stop -t 60 $DOCKERNAME | ||
{%- else %} | ||
/usr/local/bin/container stop $DOCKERNAME | ||
{%- if docker_container_name == "snmp" %} | ||
docker rm $DOCKERNAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docker container behavior requires that port forwarding is done during "docker run", and cannot be changed afterwards. Using port forwarding as a method of support net host remove will require removing docker stop, as it is called as part of service restart (docker stop + docker run).
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is hot patches inside docker container, original behavior is that the patches will survive config reload or reboot. But this PR lose the capabilities. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there real use-cases where a docker is being loaded with patches inside it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is possible in production environment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still applicable. |
||
{%- endif %} | ||
{%- endif %} | ||
} | ||
|
||
|
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.
This feature is still useful, and there are some other PRs trying to extend it. #Closed
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.
I am sorry, I wasn't aware of the other PR's for this feature.
The logic of address/port/vrf was moved to the docker create port and address forwarding. Since only user defined ports and addresses will be forwarded, this logic will no longer be relevant here
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.
I have updated the code to include the latest merged PR
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.
Could you explain "The logic of address/port/vrf was moved to the docker create port and address forwarding"?
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.
In the current implementation, snmpd has its configuration in snmpd.conf which defines which addresses and ports can be used for query, how and if vrf is being used, etc.
Removing snmp container from host network means that it is not exposed to any of these addresses by default,
What we did here was to use docker address:port forwarding as the method to implement the logic for it. When a user configures address and port to be used for snmp queries - this address:port tuple will be used when snmp docker is created, similar to a firewall. In what we offer here, the snmp demon inside the container will listen to all packets, and the docker networking logic (address:port forwarding) will forward only the relevant packets, as configured by user