Skip to content

Feature/swarm#28

Open
zbitname wants to merge 13 commits intomainfrom
feature/swarm
Open

Feature/swarm#28
zbitname wants to merge 13 commits intomainfrom
feature/swarm

Conversation

@zbitname
Copy link
Collaborator

@zbitname zbitname commented Nov 18, 2025

Summary by CodeRabbit

  • New Features

    • Added command-line options for WireGuard port, Swarm DB Gossip port, a swarm-init boot mode, and an allow-untrusted flag.
    • Port forwarding now includes WireGuard (UDP), Swarm DB Gossip (UDP/TCP) and optional PKI port.
  • Documentation

    • Help/usage updated to document the new options and their defaults.
  • Diagnostics

    • Runtime/debug output reports configured ports and validates swarm-init/allow-untrusted usage.

- Introduced DEFAULT_SWARM_DB_GOSSIP_PORT variable with a default value of 7946.
- Updated usage function to include --swarm_db_gossip_port option.
- Modified parameter parsing to handle the new gossip port argument.
- Enhanced network settings to forward UDP and TCP traffic for the Swarm DB Gossip Port.
- Introduced DEFAULT_WG_PORT and DEFAULT_WG_PORT_RANGE variables for WireGuard configuration.
- Updated usage function to include --wg_port and --wg_port_range options.
- Enhanced parameter parsing to handle WireGuard port and range arguments.
- Modified network settings to forward UDP traffic for the specified WireGuard port and range.
- Deleted DEFAULT_WG_PORT_RANGE variable and its associated logic from the script.
- Updated usage function to remove --wg_port_range option.
- Simplified network settings by eliminating the conditional handling for WireGuard port range.
- Introduced DEFAULT_ROOT_WRITABLE variable to manage root filesystem writability.
- Updated usage function to include --root_writable option.
- Enhanced parameter parsing to handle the new root writable argument.
- Modified kernel command line and image drive settings based on the root writable option.
- Updated logic to create a qcow2 overlay when ROOT_WRITABLE is true, allowing for an immutable base image while enabling writes.
- Added checks to create or use an existing overlay image, improving the management of writable root filesystems.
- Removed the check for existing overlay image and added logic to always create a new qcow2 overlay.
- Simplified the overlay management by ensuring the previous overlay is removed before creation, enhancing the script's reliability.
- Removed unnecessary conditional statement to ensure the qcow2 overlay is always created after the previous one is removed.
- Improved script reliability by streamlining the overlay management process.

NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$WG_PORT-:51820"
NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
NETWORK_SETTINGS+=",hostfwd=tcp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erroneous duplication?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different protos (tcp/udp)


IMAGE_DRIVE=" -drive file=${IMAGE_PATH},if=virtio,format=raw"
if [[ "${ROOT_WRITABLE}" == "true" ]]; then
# Use qcow2 overlay to keep the base image immutable while allowing writes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this is not an overlay, but an addition image file.

@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

Adds CLI flags and defaults for WireGuard, Swarm DB Gossip, PKI port, and an allow‑untrusted option; wires these ports into QEMU hostfwd rules (UDP 51820, UDP/TCP 7946, TCP 8443 if set); adds --swarm-init mode and enforces --allow-untrusted only with swarm-init.

Changes

Cohort / File(s) Summary
Port configuration, CLI, and QEMU forwarding
scripts/start_super_protocol.sh
Add DEFAULT_WG_PORT, DEFAULT_SWARM_DB_GOSSIP_PORT, DEFAULT_ALLOW_UNTRUSTED, and PKI_PORT; introduce --wg_port, --swarm_db_gossip_port, and --allow-untrusted flags with WG_PORT, SWARM_DB_GOSSIP_PORT, and ALLOW_UNTRUSTED variables; extend usage/help and debug output; add hostfwd rules for UDP 51820 (WireGuard), UDP/TCP 7946 (Swarm DB Gossip), and TCP 8443 (PKI when PKI_PORT set).
VM mode, kernel cmdline, and gating
scripts/start_super_protocol.sh
Add DEFAULT_SWARM_INIT and SWARM_INIT plus --swarm-init flag; append vm_mode=swarm-init to kernel command line when enabled; append allow_untrusted=true when --allow-untrusted is set and enforce that --allow-untrusted can only be used with --swarm-init; reflect these in parameter checks and debug logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through flags and ports with glee,
Gossip, WireGuard, and PKI.
A switch for swarm and trust set free,
Forwarded lanes for packets to be.
The rabbit nods — it’s wired, safe, and spree! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/swarm' is vague and generic, failing to describe the specific changes made to the script such as WireGuard port forwarding, swarm initialization, or network configuration enhancements. Replace with a more descriptive title like 'Add WireGuard and Swarm DB port forwarding support' to clearly communicate the main changes to reviewers.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/swarm

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0337a21 and ea432ef.

📒 Files selected for processing (1)
  • scripts/start_super_protocol.sh (6 hunks)
🔇 Additional comments (6)
scripts/start_super_protocol.sh (6)

31-32: LGTM!

The default port values are correct: 51820 is the standard WireGuard port and 7946 is the standard Docker Swarm gossip port.


121-121: LGTM!

Variable initialization follows the established pattern and correctly uses the default values.

Also applies to: 124-124


151-151: LGTM!

Argument parsing is correct and follows the established pattern.

Also applies to: 154-154


785-786: LGTM!

Debug output formatting is consistent with existing debug messages and correctly displays the new port values.


943-943: Clarification: This is NOT a duplicate.

Addressing the past review comment: Line 943 (TCP forwarding) is intentional and necessary. Docker Swarm's gossip protocol requires both UDP and TCP on port 7946 for proper operation—UDP for gossip messaging and TCP for failure detection and state synchronization.


941-943: Verify the IP binding choice for the new port forwards.

The new port forwards use 0.0.0.0 (all interfaces), while HTTP/HTTPS ports use $IP_ADDRESS (lines 935, 938). This difference might be intentional to allow WireGuard VPN and Swarm clustering to listen on all interfaces, but please confirm this is the desired behavior for your security model.

echo " --wg_port <port> WireGuard port (default: ${DEFAULT_WG_PORT})"
echo " --http_port <port> HTTP port (default: no port forward)"
echo " --https_port <port> HTTPS port (default: no port forward)"
echo " --swarm_db_gossip_port <port> Swarm DB Gossip Port"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add default value to help text for consistency.

The --swarm_db_gossip_port option is missing its default value in the help text, unlike other port options (e.g., line 88 for --wg_port).

🔎 Apply this diff to add the default value:
-  echo "  --swarm_db_gossip_port <port> Swarm DB Gossip Port"
+  echo "  --swarm_db_gossip_port <port> Swarm DB Gossip Port (default: ${DEFAULT_SWARM_DB_GOSSIP_PORT})"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo " --swarm_db_gossip_port <port> Swarm DB Gossip Port"
echo " --swarm_db_gossip_port <port> Swarm DB Gossip Port (default: ${DEFAULT_SWARM_DB_GOSSIP_PORT})"
🤖 Prompt for AI Agents
In scripts/start_super_protocol.sh around line 91, the help text for
"--swarm_db_gossip_port" lacks the default value; update the echo to include the
same default-value format used by other port options (e.g., append " (default:
<port>)") so the help output is consistent—set the default port to the same
value used in the script/config for swarm DB gossip.

Villain88 and others added 2 commits December 25, 2025 04:17
* allow_untrusted flag

* pki port

* unified options style

* no default pki port
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
scripts/start_super_protocol.sh (2)

843-847: Consider clarifying the error message.

The error message could be more explicit about the requirement:

Suggested improvement
     # Validate allow-untrusted requires swarm-init=true
     if [[ "${ALLOW_UNTRUSTED}" == "true" ]] && [[ "${SWARM_INIT}" == "false" ]]; then
-        echo "Error: --allow-untrusted can only be used with --swarm-init"
+        echo "Error: --allow-untrusted=true can only be used when --swarm-init=true"
         exit 1
     fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start_super_protocol.sh` around lines 843 - 847, Update the error
text in the ALLOW_UNTRUSTED / SWARM_INIT validation so it explicitly states the
requirement and suggested fix: change the echo in the if block that checks [[
"${ALLOW_UNTRUSTED}" == "true" ]] && [[ "${SWARM_INIT}" == "false" ]] to
something like "Error: --allow-untrusted requires --swarm-init (use --swarm-init
to enable swarm mode)" so users know the exact flag to add; keep the same exit 1
behavior.

159-173: Inconsistent option naming convention.

The new options mix underscore (--wg_port, --pki_port, --swarm_db_gossip_port) and hyphen (--swarm-init, --allow-untrusted) conventions. Consider standardizing to one convention for better UX consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start_super_protocol.sh` around lines 159 - 173, The CLI option names
use mixed conventions (underscores like --wg_port, --pki_port,
--swarm_db_gossip_port vs hyphens like --swarm-init, --allow-untrusted), so
standardize them to one style (prefer hyphenated POSIX style) and update
corresponding variable parsing and assignments (e.g., map --wg-port -> WG_PORT,
--pki-port -> PKI_PORT, --swarm-db-gossip-port -> SWARM_DB_GOSSIP_PORT) while
keeping existing variable names (WG_PORT, PKI_PORT, SWARM_DB_GOSSIP_PORT,
SWARM_INIT, ALLOW_UNTRUSTED) so callers and downstream code keep working; ensure
you update every occurrence in the argument parsing switch and any documentation
or help text to match the chosen hyphenated names (--wg-port, --pki-port,
--swarm-db-gossip-port) and keep the existing --swarm-init and --allow-untrusted
names unchanged if you choose hyphens.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/start_super_protocol.sh`:
- Around line 981-987: The port-forward bindings are inconsistent: PKI_PORT uses
$IP_ADDRESS while WG_PORT and SWARM_DB_GOSSIP_PORT are bound to 0.0.0.0; update
the NETWORK_SETTINGS assembly in start_super_protocol.sh so WG_PORT and
SWARM_DB_GOSSIP_PORT use $IP_ADDRESS (same as the PKI case) unless you
intentionally want them on all interfaces—adjust the hostfwd entries that
reference WG_PORT and SWARM_DB_GOSSIP_PORT to use $IP_ADDRESS instead of
0.0.0.0, or add a clear comment explaining why 0.0.0.0 is required for those
ports.
- Around line 717-723: After the PKI_PORT availability check, add equivalent
port-binding checks for WG_PORT and SWARM_DB_GOSSIP_PORT: for each variable
(WG_PORT, SWARM_DB_GOSSIP_PORT) test whether it's non-empty, print a descriptive
"Checking ... port availability..." message, use nc -z "$IP_ADDRESS" "$WG_PORT"
(and similarly for SWARM_DB_GOSSIP_PORT) to detect an already-bound port, and if
bound echo which port is already bound and exit 1; place these checks
immediately after the existing PKI_PORT block so forwarding of WG_PORT and
SWARM_DB_GOSSIP_PORT is guarded the same way.

---

Nitpick comments:
In `@scripts/start_super_protocol.sh`:
- Around line 843-847: Update the error text in the ALLOW_UNTRUSTED / SWARM_INIT
validation so it explicitly states the requirement and suggested fix: change the
echo in the if block that checks [[ "${ALLOW_UNTRUSTED}" == "true" ]] && [[
"${SWARM_INIT}" == "false" ]] to something like "Error: --allow-untrusted
requires --swarm-init (use --swarm-init to enable swarm mode)" so users know the
exact flag to add; keep the same exit 1 behavior.
- Around line 159-173: The CLI option names use mixed conventions (underscores
like --wg_port, --pki_port, --swarm_db_gossip_port vs hyphens like --swarm-init,
--allow-untrusted), so standardize them to one style (prefer hyphenated POSIX
style) and update corresponding variable parsing and assignments (e.g., map
--wg-port -> WG_PORT, --pki-port -> PKI_PORT, --swarm-db-gossip-port ->
SWARM_DB_GOSSIP_PORT) while keeping existing variable names (WG_PORT, PKI_PORT,
SWARM_DB_GOSSIP_PORT, SWARM_INIT, ALLOW_UNTRUSTED) so callers and downstream
code keep working; ensure you update every occurrence in the argument parsing
switch and any documentation or help text to match the chosen hyphenated names
(--wg-port, --pki-port, --swarm-db-gossip-port) and keep the existing
--swarm-init and --allow-untrusted names unchanged if you choose hyphens.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 31e88e4 and 148b63c.

📒 Files selected for processing (1)
  • scripts/start_super_protocol.sh

Comment on lines +717 to +723
if [[ -n "$PKI_PORT" ]]; then
echo "Checking pki port aviability..."
if nc -z "$IP_ADDRESS" "$PKI_PORT"; then
echo "pki port $PKI_PORT already bound!"
exit 1
fi
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing availability checks for WireGuard and Swarm DB Gossip ports.

WG_PORT and SWARM_DB_GOSSIP_PORT are always forwarded but lack availability checks, unlike HTTP_PORT, HTTPS_PORT, and PKI_PORT. If these ports are already bound, QEMU will fail.

Suggested fix - add checks after PKI_PORT check
     if [[ -n "$PKI_PORT" ]]; then
         echo "Checking pki port aviability..."
         if nc -z "$IP_ADDRESS" "$PKI_PORT"; then
             echo "pki port $PKI_PORT already bound!"
             exit 1
         fi
     fi
+
+    echo "Checking WireGuard port availability..."
+    if nc -z -u "0.0.0.0" "$WG_PORT"; then
+        echo "WireGuard port $WG_PORT already bound!"
+        exit 1
+    fi
+
+    echo "Checking Swarm DB Gossip port availability..."
+    if nc -z -u "0.0.0.0" "$SWARM_DB_GOSSIP_PORT"; then
+        echo "Swarm DB Gossip UDP port $SWARM_DB_GOSSIP_PORT already bound!"
+        exit 1
+    fi
+    if nc -z "0.0.0.0" "$SWARM_DB_GOSSIP_PORT"; then
+        echo "Swarm DB Gossip TCP port $SWARM_DB_GOSSIP_PORT already bound!"
+        exit 1
+    fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$PKI_PORT" ]]; then
echo "Checking pki port aviability..."
if nc -z "$IP_ADDRESS" "$PKI_PORT"; then
echo "pki port $PKI_PORT already bound!"
exit 1
fi
fi
if [[ -n "$PKI_PORT" ]]; then
echo "Checking pki port aviability..."
if nc -z "$IP_ADDRESS" "$PKI_PORT"; then
echo "pki port $PKI_PORT already bound!"
exit 1
fi
fi
echo "Checking WireGuard port availability..."
if nc -z -u "0.0.0.0" "$WG_PORT"; then
echo "WireGuard port $WG_PORT already bound!"
exit 1
fi
echo "Checking Swarm DB Gossip port availability..."
if nc -z -u "0.0.0.0" "$SWARM_DB_GOSSIP_PORT"; then
echo "Swarm DB Gossip UDP port $SWARM_DB_GOSSIP_PORT already bound!"
exit 1
fi
if nc -z "0.0.0.0" "$SWARM_DB_GOSSIP_PORT"; then
echo "Swarm DB Gossip TCP port $SWARM_DB_GOSSIP_PORT already bound!"
exit 1
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start_super_protocol.sh` around lines 717 - 723, After the PKI_PORT
availability check, add equivalent port-binding checks for WG_PORT and
SWARM_DB_GOSSIP_PORT: for each variable (WG_PORT, SWARM_DB_GOSSIP_PORT) test
whether it's non-empty, print a descriptive "Checking ... port availability..."
message, use nc -z "$IP_ADDRESS" "$WG_PORT" (and similarly for
SWARM_DB_GOSSIP_PORT) to detect an already-bound port, and if bound echo which
port is already bound and exit 1; place these checks immediately after the
existing PKI_PORT block so forwarding of WG_PORT and SWARM_DB_GOSSIP_PORT is
guarded the same way.

Comment on lines +981 to +987
if [[ -n "$PKI_PORT" ]]; then
NETWORK_SETTINGS+=",hostfwd=tcp:$IP_ADDRESS:$PKI_PORT-:8443"
fi

NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$WG_PORT-:51820"
NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
NETWORK_SETTINGS+=",hostfwd=tcp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent IP binding for port forwards.

PKI port uses $IP_ADDRESS (line 982), but WireGuard and Swarm DB Gossip ports are hardcoded to 0.0.0.0 (lines 985-987). This means these ports will always bind to all interfaces regardless of the --ip_address setting.

If this is intentional (e.g., WireGuard must be reachable from all interfaces), consider documenting this behavior. Otherwise, use $IP_ADDRESS consistently:

Suggested fix for consistency
-    NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$WG_PORT-:51820"
-    NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
-    NETWORK_SETTINGS+=",hostfwd=tcp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
+    NETWORK_SETTINGS+=",hostfwd=udp:$IP_ADDRESS:$WG_PORT-:51820"
+    NETWORK_SETTINGS+=",hostfwd=udp:$IP_ADDRESS:$SWARM_DB_GOSSIP_PORT-:7946"
+    NETWORK_SETTINGS+=",hostfwd=tcp:$IP_ADDRESS:$SWARM_DB_GOSSIP_PORT-:7946"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$PKI_PORT" ]]; then
NETWORK_SETTINGS+=",hostfwd=tcp:$IP_ADDRESS:$PKI_PORT-:8443"
fi
NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$WG_PORT-:51820"
NETWORK_SETTINGS+=",hostfwd=udp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
NETWORK_SETTINGS+=",hostfwd=tcp:0.0.0.0:$SWARM_DB_GOSSIP_PORT-:7946"
if [[ -n "$PKI_PORT" ]]; then
NETWORK_SETTINGS+=",hostfwd=tcp:$IP_ADDRESS:$PKI_PORT-:8443"
fi
NETWORK_SETTINGS+=",hostfwd=udp:$IP_ADDRESS:$WG_PORT-:51820"
NETWORK_SETTINGS+=",hostfwd=udp:$IP_ADDRESS:$SWARM_DB_GOSSIP_PORT-:7946"
NETWORK_SETTINGS+=",hostfwd=tcp:$IP_ADDRESS:$SWARM_DB_GOSSIP_PORT-:7946"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start_super_protocol.sh` around lines 981 - 987, The port-forward
bindings are inconsistent: PKI_PORT uses $IP_ADDRESS while WG_PORT and
SWARM_DB_GOSSIP_PORT are bound to 0.0.0.0; update the NETWORK_SETTINGS assembly
in start_super_protocol.sh so WG_PORT and SWARM_DB_GOSSIP_PORT use $IP_ADDRESS
(same as the PKI case) unless you intentionally want them on all
interfaces—adjust the hostfwd entries that reference WG_PORT and
SWARM_DB_GOSSIP_PORT to use $IP_ADDRESS instead of 0.0.0.0, or add a clear
comment explaining why 0.0.0.0 is required for those ports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants