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

Pipelines add logging iptables #719

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions ci/docker/tester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ COPY requirements.txt /tmp/requirements.txt

# Install Debian packages
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \
DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install vim linux-modules-6.8.0-49-generic \
# linux app
apt-utils curl git iputils-ping sudo kmod systemd \
apt-utils curl git iputils-ping sudo kmod systemd ulogd2 \
# preinstall deps required by nordvpn
libxml2 iproute2 iptables \
# install wireguard tools for tests
Expand All @@ -23,6 +23,8 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN modprobe nfnetlink_log

# Install Python packages for tests
RUN python3 -m pip install --no-cache-dir -r /tmp/requirements.txt && rm -rf /tmp/*

Expand Down
21 changes: 21 additions & 0 deletions daemon/firewall/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func (ipt *IPTables) applyRule(rule firewall.Rule, add bool) error {
continue
}
for _, ipTableRule := range ipTablesRules {
if !rule.Allow {
prefix := fmt.Sprintf("-j NFLOG --nflog-prefix \"LOG-post-%s\"", rule.Name)
log.Println(internal.DebugPrefix, "[iptables-debug], add rule: ", prefix)
logRule := strings.Replace(ipTableRule, "-j DROP", prefix, -1)
args := fmt.Sprintf("%s %s -w"+internal.SecondsToWaitForIptablesLock, flag, logRule)
out, err := exec.Command(iptableVersion, strings.Split(args, " ")...).CombinedOutput()
if err != nil {
log.Printf(internal.ErrorPrefix+" [iptables-debug]"+" failed to add rule: %ss: %s", err, string(out))
}
}
// -w does not accept arguments on older iptables versions
args := fmt.Sprintf("%s %s -w "+internal.SecondsToWaitForIptablesLock, flag, ipTableRule)
// #nosec G204 -- input is properly sanitized
Expand All @@ -116,6 +126,17 @@ func (ipt *IPTables) applyRule(rule firewall.Rule, add bool) error {
}
return fmt.Errorf("%s %s rule '%s': %w: %s", errStr, iptableVersion, ipTableRule, err, string(out))
}

if !rule.Allow {
prefix := fmt.Sprintf("-j NFLOG --nflog-prefix \"LOG-pre-%s\"", rule.Name)
log.Println(internal.DebugPrefix, "[iptables-debug], add rule: ", prefix)
logRule := strings.Replace(ipTableRule, "-j DROP", prefix, -1)
args := fmt.Sprintf("%s %s -w"+internal.SecondsToWaitForIptablesLock, flag, logRule)
out, err := exec.Command(iptableVersion, strings.Split(args, " ")...).CombinedOutput()
if err != nil {
log.Printf(internal.ErrorPrefix+"[iptables-debug]"+" failed to add rule: %s: %s", err, string(out))
}
}
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion magefiles/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
imageSnapPackager = registryPrefix + "snaper:0.0.4"
imageProtobufGenerator = registryPrefix + "generator:1.4.1"
imageScanner = registryPrefix + "scanner:1.1.0"
imageTester = registryPrefix + "tester:1.3.2"
imageTester = registryPrefix + "tester:ulog"
imageQAPeer = registryPrefix + "qa-peer:1.0.4"
imageRuster = registryPrefix + "ruster:1.3.0"

Expand Down
13 changes: 13 additions & 0 deletions test/qa/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@

import lib
from lib import daemon, info, logging, login, network, server
import os

import shutil

Check failure on line 12 in test/qa/test_connect.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

test/qa/test_connect.py:12:8: F401 `shutil` imported but unused
import subprocess

CONNECT_ALIAS = [
"connect",
"c"
]

def setup_module():
subprocess.call(['sudo','/etc/init.d/ulogd2','start'])
time.sleep(5)

def setup_function(function): # noqa: ARG001
daemon.start()
login.login_as("default")
Expand All @@ -23,6 +31,11 @@
logging.log(data=info.collect())
logging.log()

project_root = os.environ["WORKDIR"]

# shutil.copy("/var/log/syslogemu.log", f"{project_root}/dist/logs")
subprocess.call(['sudo','cp', "/var/log/ulog/syslogemu.log", f"{project_root}/dist/logs"])

sh.nordvpn.logout("--persist-token")
sh.nordvpn.set.defaults()
daemon.stop()
Expand Down
Loading