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

Support input interface specification to dns server #215

Merged
merged 1 commit into from
Nov 24, 2023
Merged
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
19 changes: 19 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,22 @@ allow DHCPv6 requests in to a host

manage in dns

#### Examples

##### Allow access to stub dns resolver from docker containers

```puppet
class { 'nftables::rules::dns':
iifname => ['docker0'],
}
```

#### Parameters

The following parameters are available in the `nftables::rules::dns` class:

* [`ports`](#-nftables--rules--dns--ports)
* [`iifname`](#-nftables--rules--dns--iifname)

##### <a name="-nftables--rules--dns--ports"></a>`ports`

Expand All @@ -540,6 +551,14 @@ Specify ports for dns.

Default value: `[53]`

##### <a name="-nftables--rules--dns--iifname"></a>`iifname`

Data type: `Optional[Array[String[1],1]]`

Specify input interface names.

Default value: `undef`

### <a name="nftables--rules--docker_ce"></a>`nftables::rules::docker_ce`

The configuration distributed in this class represents the default firewall
Expand Down
17 changes: 15 additions & 2 deletions manifests/rules/dns.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# @summary manage in dns
# @param ports Specify ports for dns.
# @param iifname Specify input interface names.
#
# @example Allow access to stub dns resolver from docker containers
# class { 'nftables::rules::dns':
# iifname => ['docker0'],
# }
#
class nftables::rules::dns (
Array[Stdlib::Port,1] $ports = [53],
Optional[Array[String[1],1]] $iifname = undef,
) {
$_iifname = $iifname ? {
Undef => '',
default => "iifname {${join($iifname, ', ')}} ",
}

nftables::rule {
'default_in-dns_tcp':
content => "tcp dport {${join($ports,', ')}} accept";
content => "${_iifname}tcp dport {${join($ports,', ')}} accept";
'default_in-dns_udp':
content => "udp dport {${join($ports,', ')}} accept";
content => "${_iifname}udp dport {${join($ports,', ')}} accept";
}
}
12 changes: 12 additions & 0 deletions spec/classes/rules/dns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
it { is_expected.to contain_nftables__rule('default_in-dns_tcp').with_content('tcp dport {55, 60} accept') }
it { is_expected.to contain_nftables__rule('default_in-dns_udp').with_content('udp dport {55, 60} accept') }
end

context 'with input interfaces set' do
let(:params) do
{
iifname: %w[docker0 eth0],
}
end

it { is_expected.to compile }
it { is_expected.to contain_nftables__rule('default_in-dns_tcp').with_content('iifname {docker0, eth0} tcp dport {53} accept') }
it { is_expected.to contain_nftables__rule('default_in-dns_udp').with_content('iifname {docker0, eth0} udp dport {53} accept') }
end
end
end
end
Loading