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 icinga2 rule for outgoing traffic #260

Open
wants to merge 1 commit 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
19 changes: 19 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and Manager Daemons (MGR).
* [`nftables::rules::out::hkp`](#nftables--rules--out--hkp): allow outgoing hkp connections to gpg keyservers
* [`nftables::rules::out::http`](#nftables--rules--out--http): manage out http
* [`nftables::rules::out::https`](#nftables--rules--out--https): manage out https
* [`nftables::rules::out::icinga2`](#nftables--rules--out--icinga2): allow outgoing icinga2
* [`nftables::rules::out::icmp`](#nftables--rules--out--icmp): control outbound icmp packages
* [`nftables::rules::out::igmp`](#nftables--rules--out--igmp): allow outgoing IGMP messages
* [`nftables::rules::out::imap`](#nftables--rules--out--imap): allow outgoing imap
Expand Down Expand Up @@ -1013,6 +1014,24 @@ manage out http

manage out https

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

allow outgoing icinga2

#### Parameters

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

* [`ports`](#-nftables--rules--out--icinga2--ports)

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

Data type: `Array[Stdlib::Port,1]`

icinga2 ports

Default value: `[5665]`

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

control outbound icmp packages
Expand Down
10 changes: 10 additions & 0 deletions manifests/rules/out/icinga2.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @summary allow outgoing icinga2
# @param ports icinga2 ports
class nftables::rules::out::icinga2 (
Array[Stdlib::Port,1] $ports = [5665],
) {
nftables::rule {
'default_out-icinga2':
content => "tcp dport {${join($ports,', ')}} accept",
}
}
1 change: 1 addition & 0 deletions spec/acceptance/all_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'nftables class' do
context 'configure all nftables rules' do
it 'works idempotently with no errors' do

Check failure on line 7 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

nftables class configure all nftables rules works idempotently with no errors Failure/Error: apply_manifest(pp, catch_failures: true) Beaker::Host::CommandFailure: Host 'ubuntu2004-64-puppet8.example.com' exited with 6 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_124333781.w4tU5k.pp Last 10 lines of output were: Warning: /Stage[main]/Nftables/Service[nftables]: Skipping because of failed dependencies Info: /Stage[main]/Nftables/Service[nftables]: Unscheduling all events on Service[nftables] Info: Class[Nftables]: Unscheduling all events on Class[Nftables] Info: Nftables::Chain[PRE]: Unscheduling all events on Nftables::Chain[PRE] Info: Nftables::Chain[default_in]: Unscheduling all events on Nftables::Chain[default_in] Info: Nftables::Chain[default_out]: Unscheduling all events on Nftables::Chain[default_out] Info: Nftables::Chain[default_fwd]: Unscheduling all events on Nftables::Chain[default_fwd] Info: Stage[main]: Unscheduling all events on Stage[main] Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml �[mNotice: Applied catalog in 5.22 seconds

Check failure on line 7 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

nftables class configure all nftables rules works idempotently with no errors Failure/Error: apply_manifest(pp, catch_failures: true) Beaker::Host::CommandFailure: Host 'ubuntu2004-64-puppet7.example.com' exited with 6 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_124340485.vDGopY.pp Last 10 lines of output were: Warning: /Stage[main]/Nftables/Service[nftables]: Skipping because of failed dependencies Info: /Stage[main]/Nftables/Service[nftables]: Unscheduling all events on Service[nftables] Info: Class[Nftables]: Unscheduling all events on Class[Nftables] Info: Nftables::Chain[PRE]: Unscheduling all events on Nftables::Chain[PRE] Info: Nftables::Chain[default_in]: Unscheduling all events on Nftables::Chain[default_in] Info: Nftables::Chain[default_out]: Unscheduling all events on Nftables::Chain[default_out] Info: Nftables::Chain[default_fwd]: Unscheduling all events on Nftables::Chain[default_fwd] Info: Stage[main]: Unscheduling all events on Stage[main] Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml �[mNotice: Applied catalog in 6.42 seconds
pp = <<-EOS
# Default ArchLinux rules contain "destroy" that requires kernel >= 6.3
# https://gitlab.archlinux.org/archlinux/packaging/packages/nftables/-/commit/f26a7145b2885d298925819782a5302905332dbe
Expand Down Expand Up @@ -107,6 +107,7 @@
include nftables::rules::out::mldv2
include nftables::rules::out::mdns
include nftables::rules::out::ssdp
include nftables::rules::out::icinga2
include nftables::services::dhcpv6_client
include nftables::services::openafs_client
$config_path = $facts['os']['family'] ? {
Expand Down Expand Up @@ -143,16 +144,16 @@
end

describe service('nftables') do
it { is_expected.to be_running }

Check failure on line 147 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

nftables class configure all nftables rules Service "nftables" is expected to be running Failure/Error: it { is_expected.to be_running } expected Service "nftables" to be running

Check failure on line 147 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

nftables class configure all nftables rules Service "nftables" is expected to be running Failure/Error: it { is_expected.to be_running } expected Service "nftables" to be running
it { is_expected.to be_enabled }

Check failure on line 148 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

nftables class configure all nftables rules Service "nftables" is expected to be enabled Failure/Error: it { is_expected.to be_enabled } expected Service "nftables" to be enabled

Check failure on line 148 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

nftables class configure all nftables rules Service "nftables" is expected to be enabled Failure/Error: it { is_expected.to be_enabled } expected Service "nftables" to be enabled
end

describe file('/etc/nftables/puppet.nft', '/etc/systemd/system/nftables.service.d/puppet_nft.conf') do
it { is_expected.to be_file }

Check failure on line 152 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

nftables class configure all nftables rules File "/etc/nftables/puppet.nft" is expected to be file Failure/Error: it { is_expected.to be_file } expected `File "/etc/nftables/puppet.nft".file?` to be truthy, got false

Check failure on line 152 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

nftables class configure all nftables rules File "/etc/nftables/puppet.nft" is expected to be file Failure/Error: it { is_expected.to be_file } expected `File "/etc/nftables/puppet.nft".file?` to be truthy, got false
end

describe file('/etc/nftables/puppet') do
it { is_expected.to be_directory }

Check failure on line 156 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

nftables class configure all nftables rules File "/etc/nftables/puppet" is expected to be directory Failure/Error: it { is_expected.to be_directory } expected `File "/etc/nftables/puppet".directory?` to be truthy, got false

Check failure on line 156 in spec/acceptance/all_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

nftables class configure all nftables rules File "/etc/nftables/puppet" is expected to be directory Failure/Error: it { is_expected.to be_directory } expected `File "/etc/nftables/puppet".directory?` to be truthy, got false
end
end
end
27 changes: 27 additions & 0 deletions spec/classes/rules/out/icinga2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'nftables::rules::out::icinga2' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

context 'default options' do
it { is_expected.to compile }
it { is_expected.to contain_nftables__rule('default_out-icinga2').with_content('tcp dport {5665} accept') }
end

context 'with ports set' do
let(:params) do
{
ports: [55, 60],
}
end

it { is_expected.to compile }
it { is_expected.to contain_nftables__rule('default_out-icinga2').with_content('tcp dport {55, 60} accept') }
end
end
end
end
Loading