Compare commits

...

No commits in common. "main" and "docs" have entirely different histories.
main ... docs

25 changed files with 9 additions and 614 deletions

11
.gitignore vendored
View File

@ -1,11 +0,0 @@
# ---> Ansible
*.retry
plugins
library
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

View File

@ -1,15 +0,0 @@
---
ansible:
custom_modules:
- iptables_raw
- openssl_pkcs12
- proxmox_kvm
- ucr
- corenetworks_dns
- corenetworks_token
rules:
exclude_files:
- "LICENSE*"
- "**/*.md"
- "**/*.ini"

View File

@ -1,7 +0,0 @@
---
default: True
MD013: False
MD041: False
MD024: False
MD004:
style: dash

View File

@ -1 +0,0 @@
LICENSE

View File

@ -1,47 +0,0 @@
---
when:
- event: [pull_request]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
- name: generate
image: quay.io/thegeeklab/ansible-doctor
environment:
ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/
ANSIBLE_DOCTOR_FORCE_OVERWRITE: "true"
ANSIBLE_DOCTOR_LOG_LEVEL: INFO
ANSIBLE_DOCTOR_ROLE_NAME: ${CI_REPO_NAME}
ANSIBLE_DOCTOR_TEMPLATE: readme
- name: format
image: quay.io/thegeeklab/alpine-tools
commands:
- prettier -w README.md
- name: diff
image: quay.io/thegeeklab/alpine-tools
commands:
- git diff --color=always README.md
- name: publish
image: quay.io/thegeeklab/wp-git-action
settings:
action:
- commit
- push
author_email: ci-bot@rknet.org
author_name: ci-bot
branch: main
message: "[skip ci] automated docs update"
netrc_machine: gitea.rknet.org
netrc_password:
from_secret: gitea_token
when:
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
depends_on:
- test

View File

@ -1,30 +0,0 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
- name: ansible-later
image: quay.io/thegeeklab/ansible-later:4
commands:
- ansible-later
environment:
FORCE_COLOR: "1"
- name: python-format
image: docker.io/python:3.12
commands:
- pip install -qq ruff
- ruff format --check --diff .
environment:
PY_COLORS: "1"
- name: python-lint
image: docker.io/python:3.12
commands:
- pip install -qq ruff
- ruff .
environment:
PY_COLORS: "1"

View File

@ -1,26 +0,0 @@
---
when:
- event: [tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
runs_on: [success, failure]
steps:
- name: matrix
image: quay.io/thegeeklab/wp-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
username:
from_secret: matrix_username
when:
- status: [success, failure]
depends_on:
- docs

View File

@ -1,25 +0,0 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
variables:
- &molecule_base
image: quay.io/thegeeklab/molecule:6
group: molecule
secrets:
- source: molecule_hcloud_token
target: HCLOUD_TOKEN
environment:
PY_COLORS: "1"
steps:
- name: molecule-default
<<: *molecule_base
commands:
- molecule test -s default
depends_on:
- lint

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 Robert Kaussow <mail@thegeeklab.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,112 +0,0 @@
---
firewalld_enabled: True
firewalld_default_zone: public
firewalld_allow_zone_drifting: False
# @var firewalld_ipsets:description: A firewalld ipset configuration provides the information of an ip set for firewalld.
# @var firewalld_ipsets:example: >
# firewalld_ipsets:
# - name: appserver
# type: "hash:net"
# short: "App Servers"
# description: "Allow http access from all appservers"
# option: {}
# entry:
# - 192.168.2.1
# - 192.168.2.2
# @end
firewalld_ipsets: []
firewalld_ipsets_extra: []
# @var firewalld_services:description: >
# A firewalld service can be a list of local ports and destinations and additionally also a list of firewall helper modules
# automatically loaded if a service is enabled.
# @var firewalld_services:example: >
# - name: ""
# short: ""
# description: ""
# port: []
# protocol: []
# source_port: []
# module: []
# destination: {}
firewalld_services: []
firewalld_services_extra: []
# @var firewalld_zones:example: >
# firewalld_zones:
# - name: ""
# short: ""
# description: ""
# target: ""
# interface:
# - name: ""
# source:
# - address: ""
# - mac: ""
# - ipset: ""
# service:
# - name: ""
# port:
# - { port: "", protocol: "" }
# protocol:
# - value:
# icmp-block:
# - name:
# icmp-block-inversion: true
# masquerade: true
# forward: true
# forward-port:
# - { port: "", protocol: "" }
# source-port:
# - { port: "", protocol: "" }
# rule:
# - source: { address: "", mac: "", ipset: ""}
# destination: { address: "", mac: "", ipset: ""}
# service: {name: ""}
# port: {port: "", protocol: ""}
# protocol: {value: ""}
# icmp-block:
# name: ""
# icmp-type:
# name: ""
# masquerade: true
# forward-port:
# port: ""
# protocol: ""
# to-port: ""
# to-addr: ""
# source-port:
# port: ""
# protocol: ""
# log:
# prefix: ""
# level: ""
# limit: ""
# audit:
# limit: ""
# accept:
# limit: ""
# reject:
# rejecttype: ""
# limit: ""
# drop:
# limit: ""
# mark:
# set:
# limit: ""
# end
firewalld_zones:
- name: "public"
short: "Public"
description: >-
For use in public areas. You do not trust the other computers on networks
to not harm your computer. Only selected incoming connections are accepted.
service:
- name: ssh
- name: dhcpv6-client
- name: cockpit
firewalld_zones_extra: []
firewalld_zones_unmanaged: []

View File

@ -1,6 +0,0 @@
---
- name: Reload firewalld
ansible.builtin.service:
name: firewalld
state: reloaded
listen: __firewalld_reload

View File

@ -1,13 +1,16 @@
# xoxys.firewalld
---
title: firewalld
type: docs
---
[![Build Status](https://ci.rknet.org/api/badges/ansible/xoxys.firewalld/status.svg)](https://ci.rknet.org/repos/ansible/xoxys.firewalld)
[![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&amp;logoColor=white)](https://gitea.rknet.org/ansible/xoxys.firewalld)
[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.firewalld?logo=drone&amp;server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.firewalld)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](https://gitea.rknet.org/ansible/xoxys.firewalld/src/branch/main/LICENSE)
Setup and configure host firewall with firewalld.
## Table of content
<!--more-->
- [Requirements](#requirements)
- [Default Variables](#default-variables)
- [firewalld_allow_zone_drifting](#firewalld_allow_zone_drifting)
- [firewalld_default_zone](#firewalld_default_zone)
@ -20,15 +23,9 @@ Setup and configure host firewall with firewalld.
- [firewalld_zones_extra](#firewalld_zones_extra)
- [firewalld_zones_unmanaged](#firewalld_zones_unmanaged)
- [Dependencies](#dependencies)
- [License](#license)
- [Author](#author)
---
## Requirements
- Minimum Ansible version: `2.10`
## Default Variables
### firewalld_allow_zone_drifting
@ -219,14 +216,8 @@ firewalld_zones_extra: []
firewalld_zones_unmanaged: []
```
## Dependencies
None.
## License
MIT
## Author
[Robert Kaussow](https://gitea.rknet.org/xoxys)

View File

@ -1,21 +0,0 @@
---
galaxy_info:
# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys)
author: "Robert Kaussow <mail@thegeeklab.de>"
namespace: xoxys
role_name: firewalld
# @meta description: >
# [![Build Status](https://ci.rknet.org/api/badges/ansible/xoxys.firewalld/status.svg)](https://ci.rknet.org/repos/ansible/xoxys.firewalld)
# [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](https://gitea.rknet.org/ansible/xoxys.firewalld/src/branch/main/LICENSE)
#
# Setup and configure host firewall with firewalld.
# @end
description: Setup and configure host firewall with firewalld
license: MIT
min_ansible_version: "2.10"
platforms:
- name: EL
versions:
- "9"
galaxy_tags: []
dependencies: []

View File

@ -1,5 +0,0 @@
---
- name: Converge
hosts: all
roles:
- role: xoxys.firewalld

View File

@ -1,17 +0,0 @@
---
driver:
name: molecule_hetznercloud
dependency:
name: galaxy
options:
role-file: molecule/requirements.yml
requirements-file: molecule/requirements.yml
platforms:
- name: "rocky9-firewalld"
server_type: "cx11"
image: "rocky-9"
provisioner:
name: ansible
log: False
verifier:
name: testinfra

View File

@ -1,11 +0,0 @@
---
- name: Prepare
hosts: all
gather_facts: False
tasks:
- name: Bootstrap Python for Ansible
ansible.builtin.raw: |
command -v python3 python ||
((test -e /usr/bin/apt && (apt -y update && apt install -y python-minimal)) ||
echo "Warning: Python not boostrapped due to unknown platform.")
changed_when: False

View File

@ -1,18 +0,0 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def test_firewalld_installed(host):
firewalld = host.package("firewalld")
assert firewalld.is_installed
def test_firewalld_running_and_enabled(host):
firewalld = host.service("firewalld")
assert firewalld.is_running
assert firewalld.is_enabled

View File

@ -1,4 +0,0 @@
---
collections: []
roles: []

View File

@ -1,17 +0,0 @@
[tool.ruff]
exclude = [".git", "__pycache__"]
line-length = 99
indent-width = 4
[tool.ruff.lint]
ignore = ["W191", "E111", "E114", "E117", "S101", "S105"]
select = ["F", "E", "I", "W", "S"]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
line-ending = "lf"
[tool.pytest.ini_options]
filterwarnings = ["ignore::FutureWarning", "ignore::DeprecationWarning"]

View File

@ -1,114 +0,0 @@
---
- when: firewalld_enabled | bool
block:
- name: Install packages
ansible.builtin.package:
name: "{{ item }}"
loop:
- firewalld
- python3-firewall
- name: Configure firewalld
ansible.builtin.template:
src: etc/firewalld/firewalld.conf.j2
dest: /etc/firewalld/firewalld.conf
mode: "0644"
notify: __firewalld_reload
- name: Configure firewalld ipsets
ansible.builtin.template:
src: etc/firewalld/ipsets/ipset.xml.j2
dest: /etc/firewalld/ipsets/{{ item.name }}.xml
mode: "0640"
loop: "{{ __firewalld_ipsets }}"
loop_control:
label: "{{ item.name }}"
notify: __firewalld_reload
- name: Register active ipsets
ansible.builtin.find:
paths: /etc/firewalld/ipsets
file_type: file
patterns: "*.xml"
register: __firewalld_ipsets_active
changed_when: False
failed_when: False
- name: Remove unmanaged ipsets
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ __firewalld_ipsets_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
when: (item | basename | splitext | first) not in (__firewalld_ipsets | map(attribute='name') | list)
- name: Configure firewalld services
ansible.builtin.template:
src: etc/firewalld/services/service.xml.j2
dest: /etc/firewalld/services/{{ item.name }}.xml
mode: "0640"
loop: "{{ __firewalld_services }}"
loop_control:
label: "{{ item.name }}"
notify: __firewalld_reload
- name: Register active services
ansible.builtin.find:
paths: /etc/firewalld/services
file_type: file
patterns: "*.xml"
register: __firewalld_services_active
changed_when: False
failed_when: False
- name: Remove unmanaged services
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ __firewalld_services_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
when: (item | basename | splitext | first) not in (__firewalld_services | map(attribute='name') | list)
- name: Configure firewalld zones
ansible.builtin.template:
src: etc/firewalld/zones/zone.xml.j2
dest: /etc/firewalld/zones/{{ item.name }}.xml
mode: "0640"
loop: "{{ __firewalld_zones }}"
loop_control:
label: "{{ item.name }}"
when: item.name not in firewalld_zones_unmanaged
notify: __firewalld_reload
- name: Register active zones
ansible.builtin.find:
paths: /etc/firewalld/zones
file_type: file
patterns: "*.xml"
register: __firewalld_zones_active
changed_when: False
failed_when: False
- name: Remove unmanaged zones
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ __firewalld_zones_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
when:
- (item | basename | splitext | first) not in (__firewalld_zones | map(attribute='name') | list)
- (item | basename | splitext | first) not in firewalld_zones_unmanaged
- name: Validate deployed configuration
ansible.builtin.command: firewall-offline-cmd --check-config
register: __firewalld_check
changed_when: False
failed_when: __firewalld_check.rc != 0
- name: Ensure service has expected state
ansible.builtin.service:
name: firewalld
daemon_reload: True
enabled: "{{ firewalld_enabled | bool }}"
masked: "{{ not firewalld_enabled | bool }}"
state: "{{ firewalld_enabled | bool | ternary('started', 'stopped', 'started') }}"

View File

@ -1,13 +0,0 @@
#jinja2: lstrip_blocks: True
{{ ansible_managed | comment }}
DefaultZone={{ firewalld_default_zone }}
CleanupOnExit=yes
Lockdown=no
IPv6_rpfilter=yes
IndividualCalls=no
LogDenied=off
FirewallBackend=nftables
FlushAllOnReload=yes
RFC3964_IPv4=yes
AllowZoneDrifting={{ firewalld_allow_zone_drifting | bool | ternary("yes", "no", "no") }}

View File

@ -1,16 +0,0 @@
#jinja2: lstrip_blocks: True
<?xml version="1.0" encoding="utf-8"?>
<ipset type="{{ item.type | default('hash:ip') }}">
{% if item.short is defined %}
<short>{{ item.short }}</short>
{% endif %}
{% if item.description is defined %}
<description>{{ item.description }}</description>
{% endif %}
{% for name, value in (item.option | default({})).items() %}
<option name="{{ name }}" value="{{ value }}"/>
{% endfor %}
{% for entry in item.entry | default([]) %}
<entry>{{ entry }}</entry>
{% endfor %}
</ipset>

View File

@ -1,21 +0,0 @@
#jinja2: lstrip_blocks: True
<?xml version="1.0" encoding="utf-8"?>
<service>
{% if item.short is defined %}
<short>{{ item.short }}</short>
{% endif %}
{% if item.description is defined %}
<description>{{ item.description }}</description>
{% endif %}
{% for tag in item %}
{# Tags which can be used several times #}
{% if tag in ["port", "protocol", "source-port", "module"] %}
{% for subtag in item[tag] %}
<{{ tag }}{% for name, value in subtag.items() %} {{ name }}="{{ value }}"{% endfor %}/>
{% endfor %}
{# Tags which can be used once #}
{% elif tag in ["destination"] %}
<{{ tag }}{% for name, value in tag.items() | default({}) %} {{ name }}="{{ value }}"{% endfor %}/>
{% endif %}
{% endfor %}
</service>

View File

@ -1,34 +0,0 @@
#jinja2: lstrip_blocks: True
<?xml version="1.0" encoding="utf-8"?>
<zone{% if item.target is defined %} target="{{ item.target }}"{% endif %}>
<short>{{ item.short | default(item.name) | capitalize }}</short>
{% if item.description is defined %}
<description>{{ item.description }}</description>
{% endif %}
{% for tag in item %}
{# Settings which can be used several times #}
{% if tag in ["interface", "source", "service", "port", "protocol", "icmp-block", "forward-port", "source-port"] %}
{% for subtag in item[tag] %}
<{{ tag }}{% for name, value in subtag.items() %} {{ name }}="{{ value }}"{% endfor %}/>
{% endfor %}
{# Settings which can be used once #}
{% elif tag in ["icmp-block-inversion", "masquerade", "forward"] and item[tag] | bool %}
<{{ tag }}/>
{% endif %}
{% endfor %}
{% for rule in item.rule | default([]) %}
<rule{% if rule.family is defined %} family="{{ rule.family }}"{% endif %}>
{% for tag in rule %}
{% if tag in ["source", "destination", "service", "port", "icmp-block", "icmp-type", "masquerade", "forward-port"] %}
<{{ tag }}{% for name, value in tag.items() | default({}) %} {{ name }}="{{ value }}"{% endfor %}/>
{% elif tag in ["log", "audit", "accept", "drop", "mark", "reject"] %}
<{{ tag }}{% for name, value in tag.items() %} {{ name }}="{{ value }}"{% endfor %}>
{% endif %}
{% if tag.limit is defined %}
<limit value="{{ tag.limit }}"/>
{% endif %}
</{{ tag }}>
{% endfor %}
</rule>
{% endfor %}
</zone>

View File

@ -1,4 +0,0 @@
---
__firewalld_ipsets: "{{ firewalld_ipsets + firewalld_ipsets_extra }}"
__firewalld_services: "{{ firewalld_services + firewalld_services_extra }}"
__firewalld_zones: "{{ firewalld_zones + firewalld_zones_extra }}"