22 Commits

Author SHA1 Message Date
gyurix
48331871b4 fix(firewall): allow both forward and NAT rules in same policy
continuous-integration/drone/push Build is passing
Remove continue statements after applying FORWARD and NAT rules so
a single policy can specify both `from` and `nat` fields. Previously
only the first matched rule was applied and subsequent ones were
skipped. Also guard the unhandled-pattern warning to only log when
both fields are empty, preventing false warnings.
2026-06-17 10:18:24 +02:00
gyurix
67693d0398 fix(iptables): validate network parameters before rule insertion
continuous-integration/drone/push Build is passing
Add validation checks for empty network parameters (sourceIP, targetIP, destCIDR, targetCIDR) in PREROUTING, POSTROUTING, and FORWARD chain rule insertion functions. Skip rule creation with a warning log when required network addresses are undefined to prevent invalid iptables rules.
2026-06-16 13:42:32 +02:00
gyurix
d5757e623a Refactor iptables chain detection to centralize and default to DOCKER-USER
continuous-integration/drone/push Build is passing
Move chain detection logic from firewall to iptables manager for better encapsulation. The manager now auto-detects both the iptables binary and chain (DOCKER-USER or FORWARD) based on the presence of the Docker-managed chain, but always defaults to DOCKER-USER for consistency. This simplifies firewall code and ensures proper Docker integration regardless of iptables version.
2026-06-16 12:46:25 +02:00
gyurix
77f80dea1b feat: add idempotent route checks and container network routes
continuous-integration/drone/push Build is passing
- Make AddRouteInContainer idempotent by checking existing routes and handling "File exists" errors
- Add loop in firewall reconciler to add routes for containers to reach other networks
- Update iptables checks to include port for better rule distinction
2026-06-16 09:42:47 +02:00
gyurix
903bc1a7da fix: correct POSTROUTING MASQUERADE to use destination CIDR and port
continuous-integration/drone/push Build is passing
Modify InsertPostroutingMasquerade and InsertPostroutingMasqueradeInContainer functions to use destCIDR, proto, and destPort instead of sourceCIDR, proto, and sourcePort. This ensures the masquerade rule correctly targets destination traffic for proper NAT configuration.
2026-06-16 08:51:25 +02:00
gyurix
d1c8eaef3e refactor(iptables): make rule insertion functions idempotent
continuous-integration/drone/push Build is passing
Refactored PREROUTING DNAT, POSTROUTING MASQUERADE, and FORWARD ACCEPT rule insertion to first check for existing rules before inserting. This prevents duplicate rules when run multiple times and improves reliability of firewall configuration.
2026-06-16 08:16:29 +02:00
gyurix
04322b699e feat(iptables): make rule insertions idempotent and robust
continuous-integration/drone/push Build is passing
Add lineExistsInContainer helper to check for existing rules before insertion,
making InsertPreroutingRuleInContainer and InsertPostroutingMasqueradeInContainer
idempotent. Change cleanup errors from fatal to warnings for better fault tolerance.
2026-06-16 00:28:13 +02:00
gyurix
246346f8b1 feat(docker, firewall): Add stateful network connection check and optimize NAT rules
continuous-integration/drone/push Build is passing
This adds an IsConnected method to verify if a container is already connected to a network with the expected IP, preventing redundant operations. In reconcileIPs, it skips reconnections if the state is correct. In applyNATRule, MASQUERADE is now applied in the same namespace as DNAT (container or host) for consistent and accurate rule application.
2026-06-15 23:39:58 +02:00
gyurix
bf94206849 feat: Add POSTROUTING MASQUERADE and periodic state reconciliation
continuous-integration/drone/push Build is passing
- Add POSTROUTING MASQUERADE rule alongside DNAT rules to ensure return
  traffic from container targets can route back through the same interface,
  matching legacy shell script behavior
- Enhance FileWatcher to trigger periodic state reconciliation every tick
  regardless of config file changes, ensuring desired state is maintained
  after container restarts or iptables flushes
2026-06-15 22:40:43 +02:00
gyurix
27607d1a2e feat: add logging to Docker and iptables operations, fix iptables path
continuous-integration/drone/push Build is passing
- Create /var/log/network-go directory in Dockerfile for log storage
- Add comprehensive logging to Docker client creation, network management, and container operations
- Add logging to iptables rule management (list, delete, etc.)
- Fix iptables executable path resolution in deleteMatchingLinesInContainer to use configured binary path
2026-06-15 17:05:53 +02:00
gyurix
3172023254 fix: update iptables binary paths to use /usr/sbin instead of /sbin
continuous-integration/drone/push Build is passing
Standardize iptables paths across firewall scripts and Go code to ensure compatibility with systems where iptables is located in /usr/sbin. This affects both legacy and non-legacy iptables binaries.
2026-06-15 16:34:24 +02:00
gyurix
2d6e22b9e6 fix(network-go): handle reconnection gracefully and fix DNAT rule issues
continuous-integration/drone/push Build is passing
- Ignore "endpoint already exists" error in ConnectContainer on re-reconciliation
- Improve iptables comment generation to avoid trailing dashes
- Enhance DNAT rule logic: try multiple selectors and fall back to host rules
- Add missing "-t nat" flag in InsertPreroutingRuleOnInterface
2026-06-15 16:12:08 +02:00
gyurix
6c19e22deb refactor(docker): switch container lookup to use filtered ContainerList
continuous-integration/drone/push Build is passing
Replace ContainerInspect with ContainerList and name filters for exact and prefix matching. This improves efficiency and correctness by leveraging Docker's filtering capabilities, matching the old shell script's grep behavior more accurately. Add regexp import to properly escape container names in filters.
2026-06-15 15:25:38 +02:00
gyurix
aac9b83576 feat(network-go): add fuzzy container name resolution for firewall connections
continuous-integration/drone/push Build is passing
Implement FindContainerName method on DockerAPI that attempts exact match
first, then falls back to prefix-based matching (e.g., extracting prefix
before dash like "service-" in "service-abc") to replicate the old shell
script's `grep $D"-"` behavior. Update firewall orchestrator to use this
resolution before connecting containers to networks, improving robustness
when container names vary from configured selectors.
2026-06-15 14:58:29 +02:00
gyurix
c6ae1748cf fix: warn instead of error when IP forwarding fails in containers
continuous-integration/drone/push Build is passing
Downgrade the IP forwarding failure from an error to a warning,
as this is expected in containers with a read-only filesystem.
IP forwarding should be set at the host level, not inside a container.
Update comments to reflect this expectation and improve log clarity.
2026-06-15 12:21:12 +02:00
gyurix
e5e19835f9 fix: use prefix matching instead of dash stripping for container resolution
continuous-integration/drone/push Build is passing
The previous logic stripped dashes from both the lookup name and container/selector names, performing an exact match after removal. This failed for cases like "wireguardproxy-client" matching "wireguardproxyclient" or "app-1"/"app-2" matching "app-x", because the dash removal produced different strings.

Change to extract the prefix before the first dash in the lookup name, then match it against the beginning of container/selector names. This preserves the intended relationship while allowing matching of dashed variants with prefix-based patterns.
2026-06-15 12:00:26 +02:00
gyurix
f9513cd98a fix(resolver): strip all dashes when matching container names
continuous-integration/drone/push Build is failing
Instead of prefix matching on the part before the first dash, now strip
all dashes from both the lookup name and the stored container/selector
names and compare exactly. This improves matching accuracy for names
containing multiple dashes or dashes in varying positions.
2026-06-15 11:55:00 +02:00
gyurix
e990ecfeb4 updated drone steps
continuous-integration/drone/push Build was killed
2026-06-12 09:07:00 +02:00
gyurix
154de77259 added network go cicd pipeline
continuous-integration/drone/push Build was killed
2026-06-12 09:04:46 +02:00
gyurix
fcda599ec7 added test go implementation
continuous-integration/drone/push Build encountered an error
2026-06-08 17:02:13 +02:00
gyurix
a555cce680 reconfigured the network stack and modified readme file
continuous-integration/drone/push Build encountered an error
2026-06-08 16:37:44 +02:00
gyurix
c3de398f35 added network-go project
continuous-integration/drone/push Build encountered an error
2026-06-08 15:34:01 +02:00