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

Add DNS TCP Firewall rule - Simplified logic #2429

Merged
merged 40 commits into from
Dec 16, 2021

Conversation

dhivyaganesan
Copy link
Contributor

Modified the way to add the New rule to be more readable

The new rule : iptables -t security -I OUTPUT -d 168.63.129.16 -p tcp --destination-port 53 -j ACCEPT -w

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made

Quality of Code and Contribution Guidelines

nagworld9 and others added 25 commits June 24, 2021 10:20
Co-authored-by: Kevin Clark <kevin.clark@microsoft.com>
…develop

� Conflicts:
�	azurelinuxagent/common/cgroupconfigurator.py
�	azurelinuxagent/common/version.py
�	azurelinuxagent/ga/exthandlers.py
�	tests/ga/test_multi_config_extension.py
azurelinuxagent/common/osutil/default.py Show resolved Hide resolved
azurelinuxagent/common/utils/networkutil.py Outdated Show resolved Hide resolved
azurelinuxagent/common/utils/networkutil.py Outdated Show resolved Hide resolved
azurelinuxagent/ga/update.py Show resolved Hide resolved
azurelinuxagent/ga/update.py Outdated Show resolved Hide resolved
tests/ga/test_update.py Outdated Show resolved Hide resolved
tests/ga/test_update.py Outdated Show resolved Hide resolved
tests/ga/test_update.py Outdated Show resolved Hide resolved
tests/ga/test_update.py Outdated Show resolved Hide resolved
tests/ga/test_update.py Outdated Show resolved Hide resolved
@dhivyaganesan
Copy link
Contributor Author

drop_check_command = TestOSUtil._command_to_string(osutil.get_firewall_drop_command(mock_iptables.wait, AddFirewallRules.CHECK_COMMAND, mock_iptables.destination))

# Filtering the mock iptable command calls with only the once related to this test.
filtered_mock_iptable_calls = [cmd for cmd in mock_iptables.command_calls if cmd in [drop_check_command]]
Copy link
Contributor

Choose a reason for hiding this comment

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

This will only filter out the drop calls but if the APPEND/CHECK calls for accept_dns rules are there, this test would still succeed. Along with checking if the DROP rule was called, also check if the others were not called to have a more complete test.

Copy link
Contributor Author

@dhivyaganesan dhivyaganesan Dec 15, 2021

Choose a reason for hiding this comment

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

I agree with the suggestion of adding all the applicable rule to filtered_mock_iptable_calls and I addressed it. However, since we are testing the length of filtered_mock_iptable_calls in each test and then checking the order and the particular rule that is called, I don't think it's necessary to check if a rule is not called. If in case a rule that is unintended is called, then the length check will fail(if that is called on top of the normal rules) if not checks where we test the order will fail. Thoughts on this?

Copy link
Contributor

@larohra larohra Dec 15, 2021

Choose a reason for hiding this comment

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

Yeah I agree, just the length check is good enough

tests/ga/test_update.py Outdated Show resolved Hide resolved
Copy link
Contributor

@larohra larohra left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, please fix the requested changes. Thanks!

@dhivyaganesan
Copy link
Contributor Author

set_command(osutil._get_firewall_drop_command(wait, "-A", destination))
set_command(osutil._get_firewall_accept_command(wait, "-A", destination, uid))
version_command = set_command(osutil.get_iptables_version_command(), output=str(version))
list_command = set_command(osutil.get_firewall_list_command("-w" if wait else ""), output="Mock Output")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where my comment got lost, but since you're using the "-w" if wait else "" in every line, can you make it a variable to keep the code clean? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

larohra
larohra previously approved these changes Dec 15, 2021
azurelinuxagent/ga/update.py Show resolved Hide resolved
@@ -223,7 +258,9 @@ def __execute_firewalld_commands(command, dst_ip, uid):

@staticmethod
def add_firewalld_rules(dst_ip, uid):
# Firwalld.service fails if we set `-w` in the iptables command, so not adding it at all for firewalld commands
# Firewalld.service fails if we set `-w` in the iptables command, so not adding it at all for firewalld commands
# Firewalld.service with the "--permanent --passthrough" parameter ensures that a firewall rule is set only once even if command is executed multiple times
Copy link
Contributor

Choose a reason for hiding this comment

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

Good comment. I'm having similar question like same rule applying multiple times.

@dhivyaganesan dhivyaganesan merged commit 5e3cfe2 into Azure:develop Dec 16, 2021
nazunalika pushed a commit to rocky-linux/WALinuxAgent that referenced this pull request Dec 27, 2021
* release prepare-2.4.0.0 (Azure#2280)

* Fix bug with dependent extensions with no settings (Azure#2285)

* update test-requirements to pin pylint. (Azure#2288) (Azure#2299)

Co-authored-by: Kevin Clark <kevin.clark@microsoft.com>

* Do not create placeholder status file for AKS extensions (Azure#2298)

* Exception for Linux Patch Extension for creating placeholder status file (Azure#2307)

* update release version (Azure#2308)

* Dont create default status file for Single-Config extensions (Azure#2318)

* version update (Azure#2319)

* Update

* Added new rule

* Fixed failing test cases

* Added delete and fixed test cases

* Added logic to insert the new rule if not present

* Added logic to insert the new rule if not present

* Added logic to insert the new rule if not present

* pylint fix

* used  insert in permentant firewall

* used  insert throughout

* used  insert throughout

* used  insert throughout

* addressed PR comments

* addressed PR comments

* addressed PR comments

* addressed PR comments

* addressed PR comments

* addressed PR comments

* addressed PR comments

Co-authored-by: Nageswara Nandigam <84482346+nagworld9@users.noreply.github.com>
Co-authored-by: Laveesh Rohra <larohra@microsoft.com>
Co-authored-by: Kevin Clark <kevin.clark@microsoft.com>
Co-authored-by: Norberto Arrieta <narrieta@users.noreply.github.com>
Co-authored-by: narrieta <narrieta>
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