Skip to content

Commit d6cddb3

Browse files
committed
refactor: [#248] remove obsolete UFW tracker firewall configuration
- Delete configure-tracker-firewall.yml playbook (Docker bypasses UFW) - Delete ConfigureTrackerFirewallStep implementation - Remove step from configure command handler - Update ConfigureStep enum (remove ConfigureTrackerFirewall variant) - Update base firewall playbook with security comments explaining Docker/UFW interaction - Add ADR reference to system module documentation Since Docker bypasses UFW rules for published container ports, application port firewall rules in UFW are ineffective. Service exposure is controlled via Docker port bindings in docker-compose, not through UFW. UFW is now simplified to its actual effective scope: SSH access only. See ADR: docs/decisions/docker-ufw-firewall-security-strategy.md Related: #248
1 parent f039664 commit d6cddb3

File tree

8 files changed

+25
-235
lines changed

8 files changed

+25
-235
lines changed

src/application/command_handlers/configure/handler.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use super::errors::ConfigureCommandHandlerError;
88
use crate::adapters::ansible::AnsibleClient;
99
use crate::application::command_handlers::common::StepResult;
1010
use crate::application::steps::{
11-
ConfigureFirewallStep, ConfigureSecurityUpdatesStep, ConfigureTrackerFirewallStep,
12-
InstallDockerComposeStep, InstallDockerStep,
11+
ConfigureFirewallStep, ConfigureSecurityUpdatesStep, InstallDockerComposeStep,
12+
InstallDockerStep,
1313
};
1414
use crate::domain::environment::repository::{EnvironmentRepository, TypedEnvironmentRepository};
1515
use crate::domain::environment::state::{ConfigureFailureContext, ConfigureStep};
@@ -202,22 +202,6 @@ impl ConfigureCommandHandler {
202202
.map_err(|e| (e.into(), current_step))?;
203203
}
204204

205-
let current_step = ConfigureStep::ConfigureTrackerFirewall;
206-
// Configure tracker-specific firewall rules (conditional on tracker configuration)
207-
// If no tracker ports are configured in variables.yml, playbook tasks will be skipped
208-
if skip_firewall {
209-
info!(
210-
command = "configure",
211-
step = "configure_tracker_firewall",
212-
status = "skipped",
213-
"Skipping Tracker firewall configuration due to TORRUST_TD_SKIP_FIREWALL_IN_CONTAINER"
214-
);
215-
} else {
216-
ConfigureTrackerFirewallStep::new(Arc::clone(&ansible_client))
217-
.execute()
218-
.map_err(|e| (e.into(), current_step))?;
219-
}
220-
221205
// Transition to Configured state
222206
let configured = environment.clone().configured();
223207

src/application/steps/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ pub use rendering::{
3838
RenderDockerComposeTemplatesStep, RenderOpenTofuTemplatesStep,
3939
};
4040
pub use software::{InstallDockerComposeStep, InstallDockerStep};
41-
pub use system::{
42-
ConfigureFirewallStep, ConfigureSecurityUpdatesStep, ConfigureTrackerFirewallStep,
43-
WaitForCloudInitStep,
44-
};
41+
pub use system::{ConfigureFirewallStep, ConfigureSecurityUpdatesStep, WaitForCloudInitStep};
4542
pub use validation::{
4643
ValidateCloudInitCompletionStep, ValidateDockerComposeInstallationStep,
4744
ValidateDockerInstallationStep,

src/application/steps/system/configure_tracker_firewall.rs

Lines changed: 0 additions & 143 deletions
This file was deleted.

src/application/steps/system/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
* Current steps:
88
* - Cloud-init completion waiting
99
* - Automatic security updates configuration
10-
* - UFW firewall configuration
11-
* - Tracker firewall configuration
10+
* - UFW firewall configuration (SSH access only)
11+
*
12+
* Note: Tracker service ports are controlled via Docker port bindings in docker-compose,
13+
* not through UFW rules. Docker bypasses UFW for published container ports.
14+
* See ADR: docs/decisions/docker-ufw-firewall-security-strategy.md
1215
*
1316
* Future steps may include:
1417
* - User account setup and management
@@ -18,10 +21,8 @@
1821

1922
pub mod configure_firewall;
2023
pub mod configure_security_updates;
21-
pub mod configure_tracker_firewall;
2224
pub mod wait_cloud_init;
2325

2426
pub use configure_firewall::ConfigureFirewallStep;
2527
pub use configure_security_updates::ConfigureSecurityUpdatesStep;
26-
pub use configure_tracker_firewall::ConfigureTrackerFirewallStep;
2728
pub use wait_cloud_init::WaitForCloudInitStep;

src/domain/environment/state/configure_failed.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ pub enum ConfigureStep {
4747
InstallDockerCompose,
4848
/// Configuring automatic security updates
4949
ConfigureSecurityUpdates,
50-
/// Configuring UFW firewall
50+
/// Configuring UFW firewall (SSH access only)
5151
ConfigureFirewall,
52-
/// Configuring Tracker firewall rules
53-
ConfigureTrackerFirewall,
5452
}
5553

5654
/// Error state - Application configuration failed

src/infrastructure/templating/ansible/template/renderer/project_generator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ impl AnsibleProjectGenerator {
306306
"wait-cloud-init.yml",
307307
"configure-security-updates.yml",
308308
"configure-firewall.yml",
309-
"configure-tracker-firewall.yml",
310309
"create-tracker-storage.yml",
311310
"init-tracker-database.yml",
312311
"deploy-tracker-config.yml",

templates/ansible/configure-firewall.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
---
22
# Configure UFW Firewall with Safe SSH Access
3+
#
4+
# IMPORTANT SECURITY NOTE:
5+
# =======================
6+
# This playbook ONLY configures SSH firewall rules. Application service ports
7+
# (tracker, grafana, prometheus, etc.) are NOT controlled by UFW because Docker
8+
# bypasses UFW rules when publishing container ports.
9+
#
10+
# Docker Security Model:
11+
# - Docker manipulates iptables NAT table directly, bypassing UFW's INPUT/OUTPUT chains
12+
# - Service exposure is controlled via docker-compose port bindings, not UFW
13+
# - Internal services (MySQL, Prometheus) have NO port bindings - Docker network only
14+
# - Public services (Tracker, Grafana) have explicit port bindings in docker-compose
15+
#
16+
# For details, see ADR: docs/decisions/docker-ufw-firewall-security-strategy.md
17+
#
318
# This playbook configures UFW with restrictive policies while preserving SSH access.
419
# CRITICAL: SSH access is allowed BEFORE enabling firewall to prevent lockout.
520
#
621
# Variables are loaded from variables.yml for centralized management.
722

8-
- name: Configure UFW firewall safely
23+
- name: Configure UFW firewall safely (SSH access only)
924
hosts: all
1025
become: yes
1126
gather_facts: yes

templates/ansible/configure-tracker-firewall.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)