Skip to content
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

logging missing firewall rules reason #3283

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion azurelinuxagent/ga/firewall_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def _execute_delete_command(self, command):
def check(self):
missing_rules = []
existing_rules = []
missing_rules_reasons = []

for rule, command in self._get_commands(self._get_check_command_option()):
try:
Expand All @@ -194,14 +195,18 @@ def check(self):
except CommandError as e:
if e.returncode == 1: # rule does not exist
missing_rules.append(rule)
# Issue: Even though the drop rule exists, the agent perceives it as missing when checking all rules.
# This might occur because we mark the rule as missing due to the same error code being returned for other reasons.
# So logging the error message to understand the reason for the rule being marked as missing.
missing_rules_reasons.append(e.stderr)
else:
raise

if len(missing_rules) == 0: # all rules are present
return True

if len(existing_rules) > 0: # some rules are present, but not all
raise FirewallStateError("The following rules are missing: {0}".format(missing_rules))
raise FirewallStateError("The following rules are missing: {0} due to: {1}".format(missing_rules, missing_rules_reasons))

return False

Expand Down
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ def _initialize_firewall(wire_server_address):
firewall_manager.setup()
event.info(WALAEventOperation.Firewall, "Created firewall rules for Azure Fabric:\n{0}", firewall_manager.get_state())
except FirewallStateError as e:
event.warn(WALAEventOperation.Firewall, "The firewall rules for Azure Fabric are not setup correctly (the environment thread will fix it): {0}", ustr(e))
event.warn(WALAEventOperation.Firewall, "The firewall rules for Azure Fabric are not setup correctly (the environment thread will fix it): {0}. Current state:\n{1}", ustr(e), firewall_manager.get_state())

#
# Ensure firewall rules are persisted across reboots
Expand Down
Loading