Version information
This version is compatible with:
- Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
- Puppet >= 4.7.0 < 7.0.0
- windows
This module has been deprecated by its author since Jan 4th 2021.
The author has suggested webalex-windows_firewall as its replacement.
Start using this module
Documentation
windows_firewall
Table of Contents
- Description
- Usage - Configuration options and additional functionality
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Description
Manage the windows firewall with Puppet (netsh
and PowerShell as required).
Features
- Create/edit/delete individual firewall rules (
windows_firewall_rule
) - Enable/disable firewall groups (
windows_firewall_group
) - Adjust global settings (
windows_firewall_global
) - Adjust per-profile settings (
windows_firewall_profile
)
Usage
windows_firewall_rule
Manage individual firewall rules
Listing firewall rules
The type and provider is able to enumerate the firewall rules existing on the system:
C:\>puppet resource windows_firewall_rule
...
windows_firewall_rule { '{FCC26AEB-5C68-481A-96DA-8A404F73714C}':
ensure => 'present',
action => 'allow',
description => 'Mail and Calendar',
direction => 'inbound',
display_group => 'Mail and Calendar',
display_name => 'Mail and Calendar',
edge_traversal_policy => 'allow',
enabled => 'true',
icmp_type => 'any',
interface_type => ['any'],
local_address => 'any',
local_port => 'any',
profile => ['domain', 'private', 'public'],
program => 'Any',
protocol => 'any',
remote_address => 'any',
remote_port => 'any',
}
You can limit output to a single rule by passing its name as an argument, eg:
C:\>puppet resource windows_firewall_rule winrm
windows_firewall_rule { 'winrm':
ensure => 'present',
action => 'allow',
direction => 'inbound',
display_name => 'winrm',
edge_traversal_policy => 'block',
enabled => 'true',
interface_type => ['any'],
local_address => 'any',
local_port => '5985',
profile => ['domain', 'private', 'public'],
protocol => 'tcp',
remote_address => 'any',
remote_port => 'any',
}
Ensuring a rule
The basic syntax for ensuring rules is:
windows_firewall_rule { "name of rule":
ensure => present,
...
}
If a rule with the same name but different properties already exists, it will be
deleted and re-created to ensure it is defined correctly. To delete a rule, set
ensure => absent
.
Managing ICMP
windows_firewall_rule { "puppet - all icmpv4":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "icmpv4",
}
You can also create a rule that only allows a specific ICMP type and code:
windows_firewall_rule { "puppet - allow icmp echo":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "icmpv4",
icmp_type => "8:10",
}
You need to create one rule for each icmp_type
value (see limitations).
Managing Ports
Use the local_port
and remote_port
properties to set the ports a rule refers
to. You can set an individual ports, a range or combination:
windows_firewall_rule { "puppet - allow ports 1000-2000":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "tcp",
local_port => "80,443,4243,5000-5010",
}
Managing local/remote addresses
Use the local_address
and remote_address
properties to target rules at
particular address. You can use individual or multiple addresses:
windows_firewall_rule { "puppet - multiple remote and local addresses":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "tcp",
profile => ["private", "domain"],
local_port => 7777,
remote_port => 7777,
local_address => "192.168.1.1,10.10.10.10",
remote_address => "192.168.1.2,192.168.2.11",
}
Managing Programs
windows_firewall_rule { "puppet - allow messenger":
ensure => present,
direction => "inbound",
action => "allow",
program => "C:\\programfiles\\messenger\\msnmsgr.exe",
}
Creating rules in specific profiles
windows_firewall_rule { "puppet - open port in specific profiles":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "tcp",
profile => ["private", "domain"],
local_port => "666",
}
Purging rules
You can choose to purge unmanaged rules from the system (be careful! - this will remove any rule that is not manged by Puppet including those created by Windows itself):
resources { "windows_firewall_rule":
purge => true,
}
windows_firewall_rule { "puppet - allow all":
ensure => present,
direction => "inbound",
action => "allow",
protocol => "tcp",
local_port => "any",
}
windows_firewall_group
Enable/Disable named groups of firewall rules. Not that it is only possible to enable/disable existing groups, not create or edit them.
Enabling a group of rules
windows_firewall_group { "File and Printer Sharing":
enabled => true,
}
Disabling a group of rules
windows_firewall_group { "File and Printer Sharing":
enabled => false,
}
windows_firewall_global
Global settings always exist (there is no ensure
).
Displaying settings
You can use puppet resource windows_firewall_global
to check what Puppet
thinks the current values are:
C:\vagrant>puppet resource windows_firewall_global
windows_firewall_global { 'global':
authzcomputergrp => 'none',
authzcomputergrptransport => 'none',
authzusergrp => 'none',
authzusergrptransport => 'none',
boottimerulecategory => 'windows firewall',
consecrulecategory => 'windows firewall',
defaultexemptions => ['dhcp', 'neighbordiscovery'],
firewallrulecategory => 'windows firewall',
forcedh => 'yes',
ipsecthroughnat => 'serverbehindnat',
keylifetime => '485min,0sess',
saidletimemin => '6',
secmethods => 'dhgroup2:aes128-sha1,dhgroup2:3des-sha1',
statefulftp => 'disable',
statefulpptp => 'disable',
stealthrulecategory => 'windows firewall',
strongcrlcheck => '1',
}
Note: some properties are read-only.
Managing global settings
A single resource with an arbitrary title should be used to manage the desired settings, eg:
windows_firewall_global { 'global':
authzcomputergrp => 'none',
authzusergrp => 'none',
defaultexemptions => ['neighbordiscovery','dhcp'],
forcedh => 'yes',
ipsecthroughnat => 'serverbehindnat',
keylifetime => '485min,0sess',
saidletimemin => '6',
secmethods => 'dhgroup2:aes128-sha1,dhgroup2:3des-sha1',
statefulftp => 'disable',
statefulpptp => 'disable',
strongcrlcheck => '1',
}
windows_firewall_profile
There are three firewall profiles that the module supports:
- private
- domain
- public
Depending on the network the node is connected to, one of these profiles will be active. They map to three Puppet resources which cannot be ensured:
Windows_firewall_profile[private]
Windows_firewall_profile[domain]
Windows_firewall_profile[public]
Displaying settings
Use puppet resource windows_firewall_profile
to see what puppet thinks the
settings are:
C:\vagrant>puppet resource windows_firewall_profile
windows_firewall_profile { 'domain':
filename => '%systemroot%\system32\logfiles\firewall\pfirewall.log',
firewallpolicy => 'blockinbound,allowoutbound',
inboundusernotification => 'disable',
localconsecrules => 'n/a (gpo-store only)',
localfirewallrules => 'n/a (gpo-store only)',
logallowedconnections => 'disable',
logdroppedconnections => 'disable',
maxfilesize => '4096',
remotemanagement => 'disable',
state => 'on',
unicastresponsetomulticast => 'enable',
}
windows_firewall_profile { 'private':
filename => '%systemroot%\system32\logfiles\firewall\pfirewall.log',
firewallpolicy => 'blockinbound,allowoutbound',
inboundusernotification => 'disable',
localconsecrules => 'n/a (gpo-store only)',
...
Note that some settings are read-only
Turning profile firewalls on/off
Use the state
property on some or all of the profiles:
windows_firewall_profile { 'private':
state => false, # off
}
windows_firewall_profile { ['public', 'domain']:
state => true, # on
}
The values true
/on
or false
/off
are acceptable. If supplying data from
YAML files in Hiera, on
and off
will be implicitly
converted to boolean
Managing settings
Manage the settings for each of the three profiles you want to manage. To set
everything to the same value, use an array for title
:
windows_firewall_profile { ['domain', 'private']:
inboundusernotification => 'enable',
firewallpolicy => 'allowinbound,allowoutbound',
logallowedconnections => 'enable',
logdroppedconnections => 'enable',
maxfilesize => '4000',
remotemanagement => 'enable',
state => 'on',
unicastresponsetomulticast => 'disable',
}
Troubleshooting
- Try running puppet in debug mode (
--debug
) - To reset firewall to default rules:
netsh advfirewall reset
You need this if your gettingno rules match
errors or errors from global settings - You may get
missing parameter
errors from Puppet after upgrading the module. These can normally be fixed by removing older versions and restarting Puppet Master - Print all firewall rules using netsh
netsh advfirewall firewall show rule all verbose
- Print all firewall rules as read by Puppet
powershell -file lib\ps\windows_firewall\ps-bridge.ps1 show
- Print firewall global settings
netsh advfirewall show global
- Print firewall profile settings
netsh advfirewall show allprofiles
- Use the "Windows Firewall with advanced security" program if you would like a GUI to view/edit firewall status
- Help on how to create firewall rules
- Help on how to
change global settings (obtained from:
netsh advfirewall set global
) - Help on how to change profile settings
(obtained from:
netsh advfirewall set private
)
Limitations
-
netsh
is used to enumerate most rules and is very fast. In some casesnetsh
will be unable to resolve names for some rules so we fallback to PowerShell instead. This is handled by theps-bridge.ps1
-
Enumerate rules using PowerShell API is very slow. There's not much more that can be done about this short of deleting the offending rules.
-
Deleting (purging) rules is very slow (~5-10 minutes) This is because deleting these rules with PowerShell is slow. There's not much that can be done about this but once unwanted rules are deleted (Windows 10 ships with ~300 rules) future operations will be a lot faster
-
Requires the
netsh advfirewall
command and PowerShell -
Property names match those used by PowerShell (groups, rules) and
netsh
for everything else so there is inconsistency in the equivalent puppet property names and values (some names are run-together, others separated by underscores). This is deliberate and makes the module code much simpler as names map exactly -
It is not possible to edit the
grouping
for rules (netsh does not support this) -
It is not possible to edit the
localfirewallrules
orlocalconsecrules
for profiles (this needs corresponding group policy) -
The Windows Advanced Firewall GUI allows multiple individual types to be set for ICMPv4 and ICMPv6 however this does not seem to be possible through the
netsh
CLI. Therefore you must create individual rules if for each type you wish to allow if you want to limit a rule in this way, eg:windows_firewall_rule { "allow icmp echo": ensure => present, protocol => "icmpv4", icmp_type => "8", action => "allow", } windows_firewall_rule { "allow icmp time exceeded": ensure => present, protocol => "icmpv4", icmp_type => "11", action => "allow", }
Development
PRs accepted :)
Testing
Automatic testing using PDQTest 2. Needs to be run in a throw-away VM since its impossible to manage the firewall in containerised Windows:
Reference
Table of Contents
Resource types
windows_firewall_global
: Manage windows global firewall settingswindows_firewall_group
: Enable/Disable windows firewall groupwindows_firewall_profile
: Enable/Disable windows firewall profilewindows_firewall_rule
: Manage Windows Firewall with Puppet
Resource types
windows_firewall_global
Manage windows global firewall settings
Properties
The following properties are available in the windows_firewall_global
type.
strongcrlcheck
Configures how CRL checking is enforced
saidletimemin
Configures the security association idle time in minutes.
defaultexemptions
Valid values: none, neighbordiscovery, icmp, dhcp, notconfigured
Configures the default IPsec exemptions. Default is to exempt IPv6 neighbordiscovery protocol and DHCP from IPsec.
ipsecthroughnat
Valid values: never, serverbehindnat, serverandclientbehindnat, notconfigured
Configures when security associations can be established with a computer behind a network address translator
authzusergrp
Configures the users that are authorized to establish tunnel mode connections.
authzcomputergrp
Configures the computers that are authorized to establish tunnel mode connections
authzusergrptransport
Authz user group transport
authzcomputergrptransport
Authz computer transport
statefulftp
Valid values: enable, disable, notconfigured
Stateful FTP
statefulpptp
Valid values: enable, disable, notconfigured
Stateful PPTP
keylifetime
Sets main mode key lifetime in minutes and sessions
secmethods
configures the main mode list of proposals
forcedh
Valid values: yes, no
configures the option to use DH to secure key exchange
boottimerulecategory
Boot time rule category
firewallrulecategory
Firewall rule category
stealthrulecategory
Stealth rule category
consecrulecategory
con sec rule category
Parameters
The following parameters are available in the windows_firewall_global
type.
name
namevar
Not used (reference only)
windows_firewall_group
Enable/Disable windows firewall group
Properties
The following properties are available in the windows_firewall_group
type.
enabled
Valid values: true
, false
Whether the rule group is enabled (true
or false
)
Default value: true
Parameters
The following parameters are available in the windows_firewall_group
type.
name
namevar
Name of the rule group to enable/disable
windows_firewall_profile
Enable/Disable windows firewall profile
Properties
The following properties are available in the windows_firewall_profile
type.
state
Valid values: on, off
State of this firewall profile
firewallpolicy
Configures default inbound and outbound behavior
localfirewallrules
Valid values: enable, disable, notconfigured
Merge local firewall rules with Group Policy rules. Valid when configuring a Group Policy store
localconsecrules
Valid values: enable, disable, notconfigured
Merge local connection security rules with Group Policy rules. Valid when configuring a Group Policy store
inboundusernotification
Valid values: enable, disable, notconfigured
Notify user when a program listens for inbound connections.
remotemanagement
Valid values: enable, disable, notconfigured
Allow remote management of Windows Firewall
unicastresponsetomulticast
Valid values: enable, disable, notconfigured
Control stateful unicast response to multicast.
logallowedconnections
Valid values: enable, disable, notconfigured
log allowed connections
logdroppedconnections
Valid values: enable, disable, notconfigured
log dropped connections
maxfilesize
maximum size of log file in KB
filename
Name and location of the firewall log
Parameters
The following parameters are available in the windows_firewall_profile
type.
name
namevar
Name of the profile to work on
windows_firewall_rule
Manage Windows Firewall with Puppet
Properties
The following properties are available in the windows_firewall_rule
type.
ensure
Valid values: present, absent
How to ensure this firewall rule (present
or absent
)
Default value: present
enabled
Valid values: true
, false
Whether the rule is enabled (true
or false
)
Default value: true
display_name
Display name for this rule
description
Description of this rule
direction
Valid values: inbound, outbound
Direction the rule applies to (inbound
/outbound
)
profile
Valid values: domain, private, public, any
Which profile(s) this rule belongs to, use an array to pass more then one
display_group
group that the rule belongs to (read-only)
local_address
the local IP the rule targets (hostname not allowed)
remote_address
the remote IP the rule targets (hostname not allowed)
protocol
Valid values: tcp, udp, icmpv4, icmpv6
the protocol the rule targets
icmp_type
Protocol type to use (with ICMPv4/ICMPv6)"
Values should be:
- Just the type (3) ICMP type code: 0 through 255.
- ICMP type code pairs: 3:4 (type 3, code 4)
any
local_port
the local port the rule targets
remote_port
the remote port the rule targets
edge_traversal_policy
Valid values: block, allow, defer_to_user, defer_to_app
Apply rule to encapsulated traffic (?) - see: https://serverfault.com/questions/89824/windows-advanced-firewall-what-does-edge-traversal-mean#89846
Default value: block
action
Valid values: block, allow
What to do when this rule matches (Accept/Reject)
program
Path to program this rule applies to
interface_type
Valid values: any, wired, wireless, remote_access
Interface types this rule applies to
Default value: any
Parameters
The following parameters are available in the windows_firewall_rule
type.
name
namevar
Name of this rule
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.