Révision baad986e
add ftp helper
This adds ability to enable a connection tracker helper and provides typical ftp rules
Co-authored-by: Vadym Chepkov <vchepkov@gmail.com>
Co-authored-by: Yury Bushmelev <jay4mail@gmail.com>
REFERENCE.md | ||
---|---|---|
20 | 20 |
* [`nftables::rules::dhcpv6_client`](#nftables--rules--dhcpv6_client): allow DHCPv6 requests in to a host |
21 | 21 |
* [`nftables::rules::dns`](#nftables--rules--dns): manage in dns |
22 | 22 |
* [`nftables::rules::docker_ce`](#nftables--rules--docker_ce): Default firewall configuration for Docker-CE |
23 |
* [`nftables::rules::ftp`](#nftables--rules--ftp): manage in ftp (with conntrack helper) |
|
23 | 24 |
* [`nftables::rules::http`](#nftables--rules--http): manage in http |
24 | 25 |
* [`nftables::rules::https`](#nftables--rules--https): manage in https |
25 | 26 |
* [`nftables::rules::icinga2`](#nftables--rules--icinga2): manage in icinga2 |
... | ... | |
96 | 97 |
* [`nftables::chain`](#nftables--chain): manage a chain |
97 | 98 |
* [`nftables::config`](#nftables--config): manage a config snippet |
98 | 99 |
* [`nftables::file`](#nftables--file): Insert a file into the nftables configuration |
100 |
* [`nftables::helper`](#nftables--helper): manage a conntrack helper |
|
99 | 101 |
* [`nftables::rule`](#nftables--rule): Provides an interface to create a firewall rule |
100 | 102 |
* [`nftables::rules::dnat4`](#nftables--rules--dnat4): manage a ipv4 dnat rule |
101 | 103 |
* [`nftables::rules::masquerade`](#nftables--rules--masquerade): masquerade all outgoing traffic |
... | ... | |
584 | 586 |
|
585 | 587 |
Default value: `true` |
586 | 588 |
|
589 |
### <a name="nftables--rules--ftp"></a>`nftables::rules::ftp` |
|
590 |
|
|
591 |
manage in ftp (with conntrack helper) |
|
592 |
|
|
593 |
#### Parameters |
|
594 |
|
|
595 |
The following parameters are available in the `nftables::rules::ftp` class: |
|
596 |
|
|
597 |
* [`enable_passive`](#-nftables--rules--ftp--enable_passive) |
|
598 |
* [`passive_ports`](#-nftables--rules--ftp--passive_ports) |
|
599 |
|
|
600 |
##### <a name="-nftables--rules--ftp--enable_passive"></a>`enable_passive` |
|
601 |
|
|
602 |
Data type: `Boolean` |
|
603 |
|
|
604 |
Enable FTP passive mode support |
|
605 |
|
|
606 |
Default value: `true` |
|
607 |
|
|
608 |
##### <a name="-nftables--rules--ftp--passive_ports"></a>`passive_ports` |
|
609 |
|
|
610 |
Data type: `Nftables::Port::Range` |
|
611 |
|
|
612 |
Set the FTP passive mode port range |
|
613 |
|
|
614 |
Default value: `'10090-10100'` |
|
615 |
|
|
587 | 616 |
### <a name="nftables--rules--http"></a>`nftables::rules::http` |
588 | 617 |
|
589 | 618 |
manage in http |
... | ... | |
1610 | 1639 |
|
1611 | 1640 |
Default value: `'file-'` |
1612 | 1641 |
|
1642 |
### <a name="nftables--helper"></a>`nftables::helper` |
|
1643 |
|
|
1644 |
manage a conntrack helper |
|
1645 |
|
|
1646 |
#### Examples |
|
1647 |
|
|
1648 |
##### FTP helper |
|
1649 |
|
|
1650 |
```puppet |
|
1651 |
nftables::helper { 'ftp-standard': |
|
1652 |
content => 'type "ftp" protocol tcp;', |
|
1653 |
} |
|
1654 |
``` |
|
1655 |
|
|
1656 |
#### Parameters |
|
1657 |
|
|
1658 |
The following parameters are available in the `nftables::helper` defined type: |
|
1659 |
|
|
1660 |
* [`content`](#-nftables--helper--content) |
|
1661 |
* [`table`](#-nftables--helper--table) |
|
1662 |
* [`helper`](#-nftables--helper--helper) |
|
1663 |
|
|
1664 |
##### <a name="-nftables--helper--content"></a>`content` |
|
1665 |
|
|
1666 |
Data type: `String` |
|
1667 |
|
|
1668 |
Conntrack helper definition. |
|
1669 |
|
|
1670 |
##### <a name="-nftables--helper--table"></a>`table` |
|
1671 |
|
|
1672 |
Data type: `Pattern[/^(ip|ip6|inet)-[a-zA-Z0-9_]+$/]` |
|
1673 |
|
|
1674 |
The name of the table to add this helper to. |
|
1675 |
|
|
1676 |
Default value: `'inet-filter'` |
|
1677 |
|
|
1678 |
##### <a name="-nftables--helper--helper"></a>`helper` |
|
1679 |
|
|
1680 |
Data type: `Pattern[/^[a-zA-Z0-9_][A-z0-9_-]*$/]` |
|
1681 |
|
|
1682 |
The symbolic name for the helper. |
|
1683 |
|
|
1684 |
Default value: `$title` |
|
1685 |
|
|
1613 | 1686 |
### <a name="nftables--rule"></a>`nftables::rule` |
1614 | 1687 |
|
1615 | 1688 |
Provides an interface to create a firewall rule |
files/config/puppet-inet-filter.nft | ||
---|---|---|
1 |
include "inet-filter-helper-*.nft" |
|
1 | 2 |
include "inet-filter-chain-*.nft" |
manifests/helper.pp | ||
---|---|---|
1 |
# @summary manage a conntrack helper |
|
2 |
# |
|
3 |
# @example FTP helper |
|
4 |
# nftables::helper { 'ftp-standard': |
|
5 |
# content => 'type "ftp" protocol tcp;', |
|
6 |
# } |
|
7 |
# |
|
8 |
# @param content |
|
9 |
# Conntrack helper definition. |
|
10 |
# @param table |
|
11 |
# The name of the table to add this helper to. |
|
12 |
# @param helper |
|
13 |
# The symbolic name for the helper. |
|
14 |
define nftables::helper ( |
|
15 |
String $content, |
|
16 |
Pattern[/^(ip|ip6|inet)-[a-zA-Z0-9_]+$/] $table = 'inet-filter', |
|
17 |
Pattern[/^[a-zA-Z0-9_][A-z0-9_-]*$/] $helper = $title, |
|
18 |
) { |
|
19 |
$concat_name = "nftables-${table}-helper-${helper}" |
|
20 |
|
|
21 |
concat { |
|
22 |
$concat_name: |
|
23 |
path => "/etc/nftables/puppet-preflight/${table}-helper-${helper}.nft", |
|
24 |
owner => root, |
|
25 |
group => root, |
|
26 |
mode => $nftables::default_config_mode, |
|
27 |
ensure_newline => true, |
|
28 |
require => Package['nftables'], |
|
29 |
} ~> Exec['nft validate'] -> file { |
|
30 |
"/etc/nftables/puppet/${table}-helper-${helper}.nft": |
|
31 |
ensure => file, |
|
32 |
source => "/etc/nftables/puppet-preflight/${table}-helper-${helper}.nft", |
|
33 |
owner => root, |
|
34 |
group => root, |
|
35 |
mode => $nftables::default_config_mode, |
|
36 |
} ~> Service['nftables'] |
|
37 |
|
|
38 |
concat::fragment { |
|
39 |
default: |
|
40 |
target => $concat_name; |
|
41 |
"${concat_name}-header": |
|
42 |
order => '00', |
|
43 |
content => "# Start of fragment order:00 ${helper} header\nct helper ${helper} {"; |
|
44 |
"${concat_name}-body": |
|
45 |
order => '98', |
|
46 |
content => $content; |
|
47 |
"${concat_name}-footer": |
|
48 |
order => '99', |
|
49 |
content => "# Start of fragment order:99 ${helper} footer\n}"; |
|
50 |
} |
|
51 |
} |
manifests/rules/ftp.pp | ||
---|---|---|
1 |
# @summary manage in ftp (with conntrack helper) |
|
2 |
# |
|
3 |
# @param enable_passive |
|
4 |
# Enable FTP passive mode support |
|
5 |
# |
|
6 |
# @param passive_ports |
|
7 |
# Set the FTP passive mode port range |
|
8 |
# |
|
9 |
class nftables::rules::ftp ( |
|
10 |
Boolean $enable_passive = true, |
|
11 |
Nftables::Port::Range $passive_ports = '10090-10100', |
|
12 |
) { |
|
13 |
nftables::helper { 'ftp-standard': |
|
14 |
content => ' type "ftp" protocol tcp;', |
|
15 |
} |
|
16 |
nftables::chain { 'PRE': } |
|
17 |
nftables::rule { |
|
18 |
'PRE-type': |
|
19 |
order => '01', |
|
20 |
content => 'type filter hook prerouting priority filter'; |
|
21 |
'PRE-policy': |
|
22 |
order => '02', |
|
23 |
content => 'policy accept'; |
|
24 |
'PRE-helper': |
|
25 |
order => '03', |
|
26 |
content => 'tcp dport 21 ct helper set "ftp-standard"'; |
|
27 |
} |
|
28 |
nftables::rule { 'default_in-ftp': |
|
29 |
content => 'tcp dport 21 accept', |
|
30 |
} |
|
31 |
if $enable_passive { |
|
32 |
nftables::rule { 'INPUT-ftp': |
|
33 |
order => '10', |
|
34 |
content => "ct helper \"ftp\" tcp dport ${passive_ports} accept", |
|
35 |
} |
|
36 |
} else { |
|
37 |
nftables::rule { 'INPUT-ftp': |
|
38 |
order => '10', |
|
39 |
content => 'ct helper "ftp" accept', |
|
40 |
} |
|
41 |
} |
|
42 |
} |
spec/acceptance/all_rules_spec.rb | ||
---|---|---|
91 | 91 |
include nftables::rules::mdns |
92 | 92 |
include nftables::rules::igmp |
93 | 93 |
include nftables::rules::wsd |
94 |
include nftables::rules::ftp |
|
94 | 95 |
include nftables::rules::out::igmp |
95 | 96 |
include nftables::rules::out::mldv2 |
96 | 97 |
include nftables::rules::out::mdns |
spec/classes/rules/ftp_spec.rb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 |
|
|
3 |
require 'spec_helper' |
|
4 |
|
|
5 |
describe 'nftables::rules::ftp' do |
|
6 |
on_supported_os.each do |os, os_facts| |
|
7 |
context "on #{os}" do |
|
8 |
let(:facts) { os_facts } |
|
9 |
# Required for nftables::helper (default_config_mode) |
|
10 |
let(:pre_condition) { 'include nftables' } |
|
11 |
|
|
12 |
context 'default options' do |
|
13 |
it { is_expected.to contain_nftables__helper('ftp-standard') } |
|
14 |
it { is_expected.to contain_nftables__chain('PRE') } |
|
15 |
it { is_expected.to contain_nftables__rule('PRE-type') } |
|
16 |
it { is_expected.to contain_nftables__rule('PRE-policy') } |
|
17 |
it { is_expected.to contain_nftables__rule('PRE-helper') } |
|
18 |
it { is_expected.to contain_nftables__rule('default_in-ftp') } |
|
19 |
it { is_expected.to contain_nftables__rule('INPUT-ftp').with_content('ct helper "ftp" tcp dport 10090-10100 accept') } |
|
20 |
end |
|
21 |
|
|
22 |
context 'with passive_ports set' do |
|
23 |
let(:params) { { passive_ports: '12345-23456' } } |
|
24 |
|
|
25 |
it { is_expected.to contain_nftables__rule('INPUT-ftp').with_content('ct helper "ftp" tcp dport 12345-23456 accept') } |
|
26 |
end |
|
27 |
|
|
28 |
context 'with passive mode disabled' do |
|
29 |
let(:params) { { enable_passive: false } } |
|
30 |
|
|
31 |
it { is_expected.to contain_nftables__rule('INPUT-ftp').with_content('ct helper "ftp" accept') } |
|
32 |
end |
|
33 |
end |
|
34 |
end |
|
35 |
end |
Formats disponibles : Unified diff