diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index ea6d358..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,56 +0,0 @@ ---- -driver: - name: docker - -driver_config: - use_sudo: false - privileged: true - provision_command: mkdir -p /run/sshd - run_command: /lib/systemd/systemd - -platforms: - - name: debian-9 - driver_config: - provision_command: - - apt-get install udev net-tools -y - - name: ubuntu-18.04 - driver_config: - provision_command: - - apt-get install udev net-tools -y - - name: centos-7 - driver_config: - provision_command: - - yum install udev net-tools -y - -provisioner: - name: salt_solo - log_level: info - require_chef: false - salt_version: latest - formula: firewalld - salt_copy_filter: - - .kitchen - - .git - pillars-from-files: - firewalld.sls: pillar.example - pillars: - top.sls: - base: - '*': - - firewalld - -verifier: - name: inspec - sudo: true - reporter: - - cli - inspec_tests: - - path: test/integration/default - -suites: - - name: default - provisioner: - state_top: - base: - '*': - - firewalld diff --git a/.travis.yml b/.travis.yml index dde9c8f..09b0205 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +stages: + - test + sudo: required cache: bundler language: ruby @@ -5,7 +8,7 @@ language: ruby services: - docker -before_install: +install: - bundle install env: @@ -16,4 +19,3 @@ env: script: - bundle exec kitchen verify ${INSTANCE} - diff --git a/Gemfile b/Gemfile index d177b65..e95eb27 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,5 @@ source "https://rubygems.org" -gem "test-kitchen", '>=1.23.2' -gem "kitchen-docker" -gem "kitchen-salt", ">=0.2.5" -gem "kitchen-inspec" - +gem "kitchen-docker", ">= 2.9" +gem "kitchen-salt", ">= 0.6.0" +gem "kitchen-inspec", '>= 1.1' diff --git a/firewalld/files/service.xml b/firewalld/files/service.xml index 7f82938..7d92f35 100644 --- a/firewalld/files/service.xml +++ b/firewalld/files/service.xml @@ -5,25 +5,68 @@ Modify the salt pillar for firewalld instead --> - {% if 'short' in service %}{{ service.short }}{%- else %}{{ name }}{%- endif %} - {% if 'description' in service %}{{ service.description }}{%- endif %} -{%- if 'ports' in service %} -{%- if 'tcp' in service.ports %} - {%- for v in service.ports.tcp %} - - {%- endfor %} +{%- if 'short' in service %} + {{ service.short }} +{%- else %} + {{ name }} {%- endif %} -{%- if 'udp' in service.ports %} - {%- for v in service.ports.udp %} +{%- if 'description' in service %} + {{ service.description }} +{%- endif %} +{%- if 'ports' in service %} + {%- if 'tcp' in service.ports %} + {%- for v in service.ports.tcp %} + + {%- endfor %} + {%- endif %} + {%- if 'udp' in service.ports %} + {%- for v in service.ports.udp %} + {%- endfor %} + {%- endif %} + {%- if 'sctp' in service.ports %} + {%- for v in service.ports.sctp %} + + {%- endfor %} + {%- endif %} + {%- if 'dccp' in service.ports %} + {%- for v in service.ports.dccp %} + + {%- endfor %} + {%- endif %} +{%- endif %} +{%- if 'protocols' in service %} + {%- for v in service.protocols %} + {%- endfor %} {%- endif %} +{%- if 'source_ports' in service %} + {%- if 'tcp' in service.source_ports %} + {%- for v in service.source_ports.tcp %} + + {%- endfor %} + {%- endif %} + {%- if 'udp' in service.source_ports %} + {%- for v in service.source_ports.udp %} + + {%- endfor %} + {%- endif %} + {%- if 'sctp' in service.source_ports %} + {%- for v in service.source_ports.sctp %} + + {%- endfor %} + {%- endif %} + {%- if 'dccp' in service.source_ports %} + {%- for v in service.source_ports.dccp %} + + {%- endfor %} + {%- endif %} +{%- endif %} {%- if 'modules' in service %} {%- for v in service.modules %} {%- endfor %} {%- endif %} -{%- endif %} {%- if 'destinations' in service %} {%- if 'ipv4' in service.destinations %} {%- for v in service.destinations.ipv4 %} diff --git a/firewalld/files/zone.xml b/firewalld/files/zone.xml index 728a56c..ca96e47 100644 --- a/firewalld/files/zone.xml +++ b/firewalld/files/zone.xml @@ -43,7 +43,12 @@ {%- if 'comment' in v %} {%- endif %} - + + {%- endfor %} +{%- endif %} +{%- if 'protocols' in zone %} + {%- for v in zone.protocols %} + {%- endfor %} {%- endif %} {%- if 'icmp_blocks' in zone %} @@ -51,6 +56,9 @@ {%- endfor %} {%- endif %} +{%- if 'icmp_block_inversion' in zone %} + +{%- endif %} {%- if 'masquerade' in zone %} {%- if zone.masquerade %} @@ -64,6 +72,14 @@ {%- endfor %} {%- endif %} +{%- if 'source_ports' in zone %} + {%- for v in zone.source_ports %} + {%- if 'comment' in v %} + + {%- endif %} + + {%- endfor %} +{%- endif %} {%- if 'rich_rules' in zone %} {%- for rule in zone.rich_rules %} @@ -73,25 +89,28 @@ {%- endif %} {%- if 'ipset' in rule %} - + {%- endif %} {%- if 'source' in rule %} - + {%- endif %} {%- if 'destination' in rule %} - + {%- endif %} {%- if 'service' in rule %} - + {%- endif %} {%- if 'port' in rule %} - + {%- endif %} {%- if 'protocol' in rule %} - + {%- endif %} {%- if 'icmp_block' in rule %} - + + {%- endif %} + {%- if 'icmp_type' in rule %} + {%- endif %} {%- if 'masquerade' in rule %} {%- if rule.masquerade %}{%- endif %} @@ -102,6 +121,12 @@ {%- endif %} {%- endif %} + {%- if 'source_port' in rule %} + {%- if 'comment' in rule.source_port %} + + {%- endif %} + + {%- endif %} {%- if 'log' in rule %} {%- if 'limit' in rule.log %} @@ -114,9 +139,9 @@ {%- endif %} {%- if 'accept' in rule %} - {%- endif %} + {%- endif %} {%- if 'reject' in rule %} - + {%- endif %} {%- if 'drop' in rule %} diff --git a/firewalld/ipsets.sls b/firewalld/ipsets.sls index f16622d..3fbcc66 100644 --- a/firewalld/ipsets.sls +++ b/firewalld/ipsets.sls @@ -77,7 +77,7 @@ directory_firewalld_ipsets: - cmd: reload_firewalld # reload firewalld config - context: name: {{ z_name }} - ipset: {{ v }} + ipset: {{ v|json }} {% endfor %} {%- endif %} diff --git a/kitchen.yml b/kitchen.yml new file mode 100644 index 0000000..40f2e7a --- /dev/null +++ b/kitchen.yml @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +driver: + name: docker + +driver_config: + use_sudo: false + privileged: true + provision_command: mkdir -p /run/sshd + run_command: /lib/systemd/systemd + pid_one_command: /usr/lib/systemd/systemd + +platforms: + - name: centos-7 + driver_config: + image: centos:7 + provision_command: + - yum install udev net-tools glibc-common -y + - echo "LANG=en_US.UTF-8" >> /etc/locale.conf + - localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 + platform: rhel + + - name: debian-9 + driver_config: + image: debian:9 + provision_command: + - apt-get install udev net-tools locales -y + - echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen + - locale-gen en_US.UTF-8 + platform: debian + - name: ubuntu-18.04 + driver_config: + image: ubuntu:18.04 + provision_command: + - apt-get install udev net-tools locales -y + - localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 + - echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen + - locale-gen en_US.UTF-8 + platform: ubuntu + +provisioner: + name: salt_solo + log_level: info + require_chef: false + salt_version: latest + formula: firewalld + salt_copy_filter: + - .kitchen + - .git + pillars_from_files: + firewalld.sls: pillar.example + pillars: + top.sls: + base: + '*': + - firewalld + state_top: + base: + '*': + - firewalld + +verifier: + name: inspec + sudo: true + reporter: + - cli + inspec_tests: + - path: test/integration/default + +suites: + - name: default diff --git a/pillar.example b/pillar.example index 6035fe3..193f749 100644 --- a/pillar.example +++ b/pillar.example @@ -28,6 +28,11 @@ firewalld: - 5252 modules: - some_module_to_load + protocols: + - igmp + source_ports: + tcp: + - 21 destinations: ipv4: - 224.0.0.251 @@ -89,6 +94,8 @@ firewalld: - https - ssh - salt-minion + protocols: + - igmp rich_rules: - family: ipv4 source: @@ -117,6 +124,13 @@ firewalld: - comment: vsftpd port: 21 protocol: tcp + source_ports: + - comment: something + port: 2222 + protocol: tcp + - comment: something_else + port: 4444 + protocol: tcp direct: chain: