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

Use nftables to configure firewall #800

Open
wants to merge 50 commits into
base: v2.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
11886d7
Replace iptables with nftables
badrogger Nov 15, 2024
dbc886e
Add nftables dependency to GA workflow
badrogger Nov 15, 2024
990484d
Update GA test pipeline
badrogger Nov 15, 2024
13dc975
Switch to ubuntu to 22.04 in GA pipeline
badrogger Nov 15, 2024
41ee41c
Fix build
badrogger Nov 15, 2024
4badf7a
Fix Dockerfile deps installation
badrogger Nov 18, 2024
4c0b27b
Fix Dockerfile
badrogger Nov 18, 2024
e96a667
Fix tests
badrogger Nov 18, 2024
5da857c
Fix tests pipeline
badrogger Nov 18, 2024
a657276
Remove python-iptables from dependencies
badrogger Nov 18, 2024
cab4d91
Update Markupsafe to 3.0.2
badrogger Nov 18, 2024
c4ad6a9
Bump dependencies
badrogger Nov 18, 2024
f5ccf8b
Do not fail if cannot import iptc
badrogger Nov 18, 2024
13fb2f2
Upgrade setuptools
badrogger Nov 18, 2024
a754578
Do not set pythonpath globally
badrogger Nov 18, 2024
9cec757
Try with no setuptools
badrogger Nov 20, 2024
28016b9
Remove libxtwrapper
badrogger Nov 20, 2024
0006b95
Remove allow_ssh function
badrogger Nov 20, 2024
8e976b0
Add firewall cleanup to update
badrogger Nov 22, 2024
8dc9b80
Apply migrations during update for sync node
badrogger Nov 25, 2024
d405b36
Bump version
badrogger Nov 26, 2024
af55f11
Remove deprecated iptables module
badrogger Nov 26, 2024
8cde8b1
Use lowercase chains. Do not import if not needed
badrogger Nov 26, 2024
fe34b64
Fix migration condition
badrogger Nov 26, 2024
8b871ba
Fix core and sync tests
badrogger Nov 26, 2024
faa92b1
Add missing migration and nftables tests
badrogger Nov 26, 2024
d0d1efc
Extract nftables and migration tests into another action
badrogger Nov 26, 2024
3ce7856
Reduce log level of pytest
badrogger Nov 26, 2024
2c8930b
Use ip family by default
badrogger Nov 26, 2024
202d68e
Remove duplicate setup_firewall execution
badrogger Nov 28, 2024
d0ef85d
Add firewall configuration to restore
badrogger Nov 28, 2024
d420f58
Configure chain properly
badrogger Nov 28, 2024
7a7ffe1
Fix duplicates
badrogger Nov 29, 2024
418f70a
Switch to new version of docker compose
badrogger Nov 29, 2024
240f7b3
Improve run_nftables_tests script
badrogger Dec 3, 2024
0609568
Fix tests
badrogger Dec 4, 2024
498511a
Fix linter
badrogger Dec 4, 2024
3f9de98
Fix GA pipline
badrogger Dec 4, 2024
f25d4b6
Optional monitoring ports
badrogger Dec 4, 2024
baff173
Fix tcp port condition
badrogger Dec 5, 2024
d9d2410
Remove iptables-persistant from required checks
badrogger Dec 5, 2024
1925849
Save nftables rules at the end of node configuration
badrogger Dec 9, 2024
b311103
Move configure_nftables to operations.base
badrogger Dec 9, 2024
2080b74
Add include to the nftables conf file
badrogger Dec 16, 2024
ef5ac86
Fix turn-off
badrogger Dec 17, 2024
1ceae64
Fix migration
badrogger Dec 18, 2024
fbc27e7
Small improvements
badrogger Dec 23, 2024
cd0bce6
Fix tests
badrogger Dec 23, 2024
35e33aa
Fix migration tests
badrogger Dec 23, 2024
20bff35
Remove comments
badrogger Dec 23, 2024
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tests
helper-scripts
dist
build
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
create_release:
if: github.event.pull_request.merged
name: Create release
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.export_outputs.outputs.version }}
Expand All @@ -26,6 +26,7 @@ jobs:

- name: Checkout submodules
run: git submodule update --init

- name: Install ubuntu dependencies
run: |
sudo apt-get update
Expand Down Expand Up @@ -68,7 +69,7 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
asset_name: skale-${{ needs.create_release.outputs.version }}-Linux-x86_64
steps:
- uses: actions/checkout@v2
Expand All @@ -78,7 +79,7 @@ jobs:
python-version: 3.11

- name: Install ubuntu dependencies
if: matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get update

Expand Down Expand Up @@ -127,7 +128,7 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
asset_name: skale-${{ needs.create_release.outputs.version }}-Linux-x86_64-sync
steps:
- uses: actions/checkout@v2
Expand All @@ -137,7 +138,7 @@ jobs:
python-version: 3.11

- name: Install ubuntu dependencies
if: matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get update

Expand Down
32 changes: 14 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.11]
Expand All @@ -23,20 +23,19 @@ jobs:
- name: Install ubuntu dependencies
run: |
sudo apt-get update
sudo apt-get install python-setuptools iptables
sudo apt-get install iptables nftables python3-nftables

- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
# pip install setuptools==75.5.0
pip install -e .[dev]
pip install --upgrade 'setuptools<45.0.0'

- name: Lint with flake8
run: |
flake8 .

- name: Build binary in Ubuntu 18.04 environment - normal
- name: Build binary - normal
run: |
mkdir -p ./dist
docker build . -t node-cli-builder
Expand All @@ -46,13 +45,7 @@ jobs:
- name: Check build - normal
run: sudo /home/ubuntu/dist/skale-test-Linux-x86_64

- name: Build binary in Ubuntu 20.04 environment - normal
run: |
scripts/build.sh test test normal

- name: Check build - sync
run: sudo /home/ubuntu/dist/skale-test-Linux-x86_64
- name: Build sync binary in Ubuntu 18.04 environment
- name: Build binary - sync
run: |
mkdir -p ./dist
docker build . -t node-cli-builder
Expand All @@ -62,12 +55,15 @@ jobs:
- name: Check build - sync
run: sudo /home/ubuntu/dist/skale-test-Linux-x86_64-sync

- name: Build sync binary in Ubuntu 20.04 environment
- name: Run prepare test build
run: |
scripts/build.sh test test sync

- name: Check build - sync
run: sudo /home/ubuntu/dist/skale-test-Linux-x86_64-sync
scripts/build.sh test test normal

- name: Run tests
run: bash ./scripts/run_tests.sh
run: |
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python3/dist-packages/
bash ./scripts/run_tests.sh

- name: Run nftables tests
run: |
scripts/run_nftables_test.sh
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
FROM python:3.11-buster
FROM python:3.11-bookworm

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y software-properties-common
RUN apt-get install -y \
RUN apt-get update && apt install -y \
git \
build-essential \
software-properties-common \
zlib1g-dev \
libssl-dev \
libffi-dev \
swig \
iptables
iptables \
nftables \
python3-nftables \
libxslt-dev \
kmod


RUN mkdir /app
WORKDIR /app

COPY . .

ENV PATH=/app/buildvenv/bin:$PATH
ENV PYTHONPATH="{PYTHONPATH}:/usr/lib/python3/dist-packages"

RUN python3.11 -m venv /app/buildvenv && \
pip install --upgrade pip && \
pip install wheel setuptools==63.2.0 && \
Expand Down
3 changes: 0 additions & 3 deletions main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import importlib.util

libxtwrapper_path = importlib.util.find_spec('libxtwrapper').origin


block_cipher = None

a = Analysis(
['node_cli/main.py'],
pathex=['.'],
binaries=[(libxtwrapper_path, '.')],
datas=[
("./text.yml", "data"),
("./datafiles/skaled-ssl-test", "data/datafiles")
Expand Down
2 changes: 1 addition & 1 deletion node_cli/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.5.0'
__version__ = '2.6.0'

if __name__ == "__main__":
print(__version__)
9 changes: 5 additions & 4 deletions node_cli/cli/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import click

from node_cli.core.node import configure_firewall_rules
from node_cli.core.node import (
configure_firewall_rules,
get_node_signature,
init,
restore,
Expand Down Expand Up @@ -239,12 +239,13 @@ def check(network):
run_checks(network)


@node.command(help='Reconfigure iptables rules')
@node.command(help='Reconfigure nftables rules')
@click.option('--monitoring', is_flag=True)
@click.option('--yes', is_flag=True, callback=abort_if_false,
expose_value=False,
prompt='Are you sure you want to reconfigure firewall rules?')
def configure_firewall():
configure_firewall_rules()
def configure_firewall(monitoring):
configure_firewall_rules(enable_monitoring=monitoring)


@node.command(help='Show node version information')
Expand Down
2 changes: 2 additions & 0 deletions node_cli/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ def _get_env():
TELEGRAF_TEMPLATE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf.j2')
TELEGRAF_CONFIG_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf')
NODE_DOCKER_CONFIG_PATH = os.path.join(NODE_DATA_PATH, 'docker.json')

NFTABLES_RULES_PATH = '/etc/nftables.conf'
16 changes: 6 additions & 10 deletions node_cli/core/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ def _check_apt_package(self, package_name: str,
else:
return self._ok(name=package_name, info=info)

@preinstall
def iptables_persistent(self) -> CheckResult:
return self._check_apt_package('iptables-persistent')

@preinstall
def lvm2(self) -> CheckResult:
return self._check_apt_package('lvm2')
Expand Down Expand Up @@ -415,26 +411,26 @@ def docker_api(self) -> CheckResult:

@preinstall
def docker_compose(self) -> CheckResult:
name = 'docker-compose'
cmd = shutil.which('docker-compose')
name = 'docker'
cmd = shutil.which('docker')
if cmd is None:
info = 'No such command: "docker-compose"'
info = 'No such command: "docker"'
return self._failed(name=name, info=info)

v_cmd_result = run_cmd(
['docker-compose', '-v'],
['docker', 'compose', 'version'],
check_code=False,
separate_stderr=True
)
output = v_cmd_result.stdout.decode('utf-8').rstrip()
if v_cmd_result.returncode != 0:
info = f'Checking docker-compose version failed with: {output}'
info = f'Checking docker compose version failed with: {output}'
return self._failed(name=name, info=output)

actual_version = output.split(',')[0].split()[-1].strip()
expected_version = self.requirements['docker-compose']

info = f'Expected docker-compose version {expected_version}, actual {actual_version}' # noqa
info = f'Expected docker compose version {expected_version}, actual {actual_version}' # noqa
if version_parse(actual_version) < version_parse(expected_version):
return self._failed(name=name, info=info)
else:
Expand Down
Loading
Loading