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

win_firewall_rule only change arguments passed by user #54297

Merged
merged 5 commits into from
Apr 9, 2019

Conversation

mhunsber
Copy link
Contributor

defaults are controlled by com object
integration test for built in rule

SUMMARY

the current win_firewall_rule module will reset an existing firewall rule's options to the defaults for any unspecified parameters. This is especially a problem when trying to enable a built-in windows firewall rule since changing them is protected.
This just keeps unspecified parameters as null so that they can be checked for existence when changing an existing rule.

Fixes #34392

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_firewall_rule

ADDITIONAL INFORMATION

This is the result of the change, instead of needing to pass back in the port and protocol, the module only changes action, because it was different from the existing rule.

tasks:
- name: Add firewall rule
  win_firewall_rule:
    name: http
    enabled: yes
    state: present
    localport: 80
    action: allow
    direction: in
    protocol: tcp

- name: Change firewall rule
  win_firewall_rule:
    name: http
    state: present
    action: block
    direction: in

output (diff):

TASK [win_firewall_rule : Add firewall rule] *********************************************************************************************************************
+[Name='http']
+[Description='']
+[Direction='1']
+[Action='1']
+[ApplicationName='']
+[ServiceName='']
+[Enabled='True']
+[Profiles='2147483647']
+[LocalAddresses='*']
+[RemoteAddresses='*']
+[LocalPorts='80']
+[RemotePorts='*']
+[Protocol='6']
+[InterfaceTypes='All']
+[EdgeTraversalOptions='0']
+[SecureFlags='0']
changed: [testhost]

TASK [win_firewall_rule : Change firewall rule] ******************************************************************************************************************
-[Action='1']
+[Action='0']
changed: [testhost]

defaults are controlled by com object
integration test for built in rule
@ansibot
Copy link
Contributor

ansibot commented Mar 23, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. windows Windows community labels Mar 23, 2019
@ansibot
Copy link
Contributor

ansibot commented Mar 23, 2019

The test ansible-test sanity --test pslint [explain] failed with 1 error:

test/sanity/pslint/ignore.txt:75:1: A102 Remove since "lib/ansible/modules/windows/win_firewall_rule.ps1" passes "PSAvoidUsingCmdletAliases" test

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Mar 23, 2019
@ansibot
Copy link
Contributor

ansibot commented Mar 25, 2019

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 25, 2019
@jborean93
Copy link
Contributor

I've only done a brief look through but I have a few things;

  • If we wanted to move ahead with this, we need to update the documentation around the default values. You've "removed" the default values but the docs don't reflect that
  • We still need to continue the existing behaviour where when we create a brand new rule the existing default still apply.
  • I see you've added a test but I don't fully see how that tests this change. I would have liked to see something simple like disabling a rule by setting only name and enabled

Let me know your thoughts on this

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Mar 29, 2019
@mhunsber
Copy link
Contributor Author

@jborean93 thanks for the feedback, and I have a few questions about what should be done for the documentation

  • I've "removed" the default values, but if you look at the previous code inside the New-FwRule function, it doesn't use the defaults to set any values, but relies on the defaults for the constructor of the HNetCfg.FWRule com object. e.g. if ($protocol -and $protocol -ne "any") { $rule.Protocol = Parse-ProtocolType -protocol $protocol }. The exception is enabled, which has the opposite default from the COM object. Since my changes behave similarly, I didn't know if the defaults should be changed in the documentation. If you think it is better to remove the default flag from the documentation, we would need to add in the description that it defaults to those values for new rules.
  • The first point somewhat answers the second point: even though the Get-AnsibleParam call has the default parameter removed, it doesn't change the behavior that if the user does not specify the value, it "defaults" to those values if the firewall rule is created, because they're driven by the defaults for the com object.
  • I agree the test is confusing. With the previous module, that call would fail because the built in firewall rules don't allow you to modify any properties except the enabled flag. I'll change it to be more like the example in the issue I referenced, but that will mean changing some of the required parameters.

Micah Hunsberger added 2 commits March 29, 2019 16:46
program and service respect default values
documentation updated to reflect that defaults apply to rule creation
added test to disable a rule and verify other values have not changed
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Mar 29, 2019
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed new_contributor This PR is the first contribution by a new community member. labels Apr 7, 2019
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 9, 2019
@jborean93
Copy link
Contributor

@mhunsber thanks for the changes, I've make some slight tweaks to the documentation but everything else seems good to me. As for your questions;

I didn't know if the defaults should be changed in the documentation

The default: key in the documentation is meant to signify the default value for the option as set by the arg spec (or Get-AnsibleParam). If there is a default based on the state of the rule during execution, i.e. creating a new rule, then what you've done is correct by documenting it in the description.

it doesn't change the behavior that if the user does not specify the value, it "defaults" to those values if the firewall rule is created, because they're driven by the defaults for the com object.

Somewhat, the defaults still indicate the default for the module options which was correct before the PR and based on the changes you are still correct. Because of the defaults were set on the options and the property checks done later on I still think the rules would have changed if a user chose a non-default constructor option but agree it is slightly confusing and convoluted how it was done before.

I'll change it to be more like the example in the issue I referenced, but that will mean changing some of the required parameters.

The tests look good now, easy to see how/why it works and you have a good assertion which is great to see.

@jborean93 jborean93 merged commit 2b04923 into ansible:devel Apr 9, 2019
@mhunsber
Copy link
Contributor Author

Awesome! Thanks for the feedback and clarifications.

@mhunsber mhunsber deleted the win_firewall_rule branch June 28, 2019 21:33
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

win_firewall_rule module defaults prevents use of "leave existing"
3 participants