Skip to content

[FIX] Use server SSH port for default Firewall Rules#1086

Open
RichardAnderson wants to merge 1 commit into
vitodeploy:3.xfrom
RichardAnderson:fix/1082
Open

[FIX] Use server SSH port for default Firewall Rules#1086
RichardAnderson wants to merge 1 commit into
vitodeploy:3.xfrom
RichardAnderson:fix/1082

Conversation

@RichardAnderson
Copy link
Copy Markdown
Member

This pull request updates the way the SSH port is handled during firewall rule creation and UFW installation, allowing for custom SSH ports instead of assuming the default port 22. It also adds comprehensive tests to ensure this behavior is correct. The main improvements are grouped into logic updates, template changes, and new tests.

Firewall logic and behavior updates:

  • The SSH firewall rule now uses the server's custom SSH port if set, defaulting to 22 otherwise, in AbstractFirewall.php.
  • The UFW installation process now passes the correct SSH port to the installation script, using the server's configured port or defaulting to 22, in Ufw.php.

Template/script changes:

  • The UFW install script template (install-ufw.blade.php) now dynamically uses the provided SSH port instead of hardcoding port 22.

Testing improvements:

  • Added a new test suite (UfwInstallTest.php) to verify that:
    • The SSH firewall rule uses a custom port if set, or 22 by default.
    • HTTP/HTTPS rules remain unchanged regardless of SSH port configuration.

Resolves #1082

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes firewall/UFW installation behavior to respect a server’s configured SSH port (instead of hardcoding port 22), addressing the lockout scenario described in issue #1082.

Changes:

  • Seed the default “SSH” firewall rule using the server’s configured SSH port (fallback 22).
  • Pass the server SSH port into the UFW install script template and use it when opening the SSH rule.
  • Add unit tests to validate firewall rule seeding behavior for custom/default SSH ports.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
app/Services/Firewall/AbstractFirewall.php Seeds the SSH firewall rule with the server’s configured SSH port (fallback 22).
app/Services/Firewall/Ufw.php Passes sshPort into the UFW install view so the script can open the correct port.
resources/views/ssh/services/firewall/ufw/install-ufw.blade.php Uses the provided sshPort instead of hardcoding 22 in the UFW allow command.
tests/Unit/SSH/Services/Firewall/UfwInstallTest.php Adds tests for seeding SSH rule with custom/default port and keeping HTTP/HTTPS unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Unit/SSH/Services/Firewall/UfwInstallTest.php
Comment thread app/Services/Firewall/AbstractFirewall.php
Comment thread app/Services/Firewall/Ufw.php
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.

[Bug]: Alternative SSH port Firewall issue

2 participants