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 match parameter to ipset resource to enable matching dst against ipsets #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ ferm::ipset { 'CONSUL':
}
```

##### Create an iptables rule that allows outbound traffic that matches the ipset `internet`

```puppet
ferm::ipset { 'allow_outbound_ipsets':
table => 'OUTPUT',
match => 'dst',
sets => {
'internet' => 'ACCEPT'
},
}
```

##### create two matches for IPv6, both at the end of the `INPUT` chain. Explicitly mention the `filter` table.

```puppet
Expand All @@ -424,6 +436,7 @@ The following parameters are available in the `ferm::ipset` defined type:
* [`table`](#-ferm--ipset--table)
* [`ip_version`](#-ferm--ipset--ip_version)
* [`prepend_to_chain`](#-ferm--ipset--prepend_to_chain)
* [`match`](#-ferm--ipset--match)

##### <a name="-ferm--ipset--sets"></a>`sets`

Expand Down Expand Up @@ -463,6 +476,14 @@ By default, ipset rules are added to the top of the chain. Set this to false to

Default value: `true`

##### <a name="-ferm--ipset--match"></a>`match`

Data type: `Enum['dst', 'src']`

Define if 'sets' should match for 'src' or 'dst'. Default: 'src'

Default value: `'src'`

### <a name="ferm--rule"></a>`ferm::rule`

This defined resource manages a single rule in a specific chain
Expand Down
14 changes: 14 additions & 0 deletions manifests/ipset.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
# },
# }
#
# @example Create an iptables rule that allows outbound traffic that matches the ipset `internet`
# ferm::ipset { 'allow_outbound_ipsets':
# table => 'OUTPUT',
# match => 'dst',
# sets => {
# 'internet' => 'ACCEPT'
# },
# }
#
# @example create two matches for IPv6, both at the end of the `INPUT` chain. Explicitly mention the `filter` table.
# ferm::ipset { 'INPUT':
# prepend_to_chain => false,
Expand All @@ -35,12 +44,16 @@
# @param prepend_to_chain
# By default, ipset rules are added to the top of the chain. Set this to false to append them to the end instead.
#
# @param match
# Define if 'sets' should match for 'src' or 'dst'. Default: 'src'
#
define ferm::ipset (
Hash[String[1], Ferm::Actions] $sets,
String[1] $chain = $name,
Ferm::Tables $table = 'filter',
Enum['ip','ip6'] $ip_version = 'ip',
Boolean $prepend_to_chain = true,
Enum['dst', 'src'] $match = 'src',
) {
$suffix = $prepend_to_chain ? {
true => 'aaa',
Expand All @@ -56,6 +69,7 @@
'table' => $table,
'chain' => $chain,
'sets' => $sets,
'match' => $match,
}
),
order => "${table}-${chain}-${suffix}",
Expand Down
1 change: 1 addition & 0 deletions spec/defines/ipset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
context 'default params creates INPUT2 chain' do
let :params do
{
match: 'src',
sets: {
office: 'ACCEPT',
internet: 'DROP'
Expand Down
3 changes: 2 additions & 1 deletion templates/ferm-chain-ipset.epp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
Ferm::Tables $table,
String[1] $chain,
Hash[String[1], Ferm::Actions] $sets,
Enum['dst', 'src'] $match,
| -%>

domain (<%= $ip %>) table <%= $table %> {
chain <%= $chain %> {
<%- $sets.each |$ipset, $action| { -%>
mod set set <%= $ipset %> src <%= $action %>;
mod set set <%= $ipset %> <%= $match %> <%= $action %>;
<%- } -%>
}
}
Loading