-
Notifications
You must be signed in to change notification settings - Fork 115
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
NetworkManager: do not use FW rule numbers in shared dispatcher script #3429
Conversation
meta-balena-common/recipes-connectivity/networkmanager/balena-files/90shared
Outdated
Show resolved
Hide resolved
info "Found shared FORWARD rule 'nm-shared-${IFNAME}' at index ${FW_RULE_NO}, moving down" | ||
|
||
FW_RULE_ARGS="$(${IPTABLES} -S FORWARD ${FW_RULE_NO})" | ||
info "Found shared FORWARD rule 'nm-shared-${IFNAME}', moving down" |
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 feels informational and ambiguous - what I'd prefer is a final check that actually makes sure the rule is last, and then print a message stating it has been moved. Printing the intention to move is not useful.
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.
Updated
|
||
# Append the rule to the bottom | ||
# Do not quote ${FW_RULE_ARGS}, this needs to expand | ||
${IPTABLES} ${FW_RULE_ARGS} | ||
|
||
# Remove the rule from its original position | ||
${IPTABLES} -D FORWARD "${FW_RULE_NO}" | ||
${IPTABLES} -D ${FW_RULE_ARGS#-A } |
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 like not using line numbers, but a final check to make sure all has worked and err out (or retry) if not would make it more robust.
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.
Added this into a loop that tries 5 times before bailing out.
76bcb36
to
95c64e4
Compare
Manipulating the firewall rules by index introduces a race condition. Both NetworkManager and balenaEngine add the rules to the top of the FORWARD chain instead of appending, so if we first look up a rule by number and then use the number to refer to it, we can not guarantee that the rule number has not changed (iow the rule has not been moved down) in the meantime. This patch removes the use of rule numbers completely and makes the "shared" dispatcher script refer to the rules by definition. Change-type: patch Signed-off-by: Michal Toman <michalt@balena.io>
95c64e4
to
ab8d611
Compare
@resin-jenkins retest this please |
Manipulating the firewall rules by index introduces a race condition. Both NetworkManager and balenaEngine add the rules to the top of the
FORWARD
chain instead of appending, so if we first look up a rule by number and then use the number to refer to it, we can not guarantee that the rule number has not changed (iow the rule has not been moved down) in the meantime.This patch removes the use of rule numbers completely and makes the "shared" dispatcher script refer to the rules by definition.
Contributor checklist
Change-type
present on at least one commitSigned-off-by
is presentReviewer Guidelines