Skip to content

Commit 2d24c49

Browse files
committed
Merge #278: fix: [#277] remove public MySQL port exposure for security
b645f66 fix: [#277] remove public MySQL port exposure for security (Jose Celano) Pull request description: ## Summary Fixes a security vulnerability where MySQL port 3306 was publicly accessible from outside the VM, allowing anyone on the network to connect to the database. ## Problem The MySQL service in the Docker Compose template exposed port 3306 to all network interfaces: ```yaml ports: - "3306:3306" ``` This allowed external connections to the database: ```bash $ mysql -h <VM_IP> -P 3306 -u tracker_user -p -e "SELECT 1;" +---+ | 1 | +---+ | 1 | +---+ ``` ## Solution Removed the `ports` section from the MySQL service. The database remains accessible to the Tracker container through Docker's internal `database_network`, and the healthcheck still works because `mysqladmin ping` runs inside the container. ## Changes - Removed `ports: - "3306:3306"` from MySQL service in `docker-compose.yml.tera` - Added security comment explaining why port is not exposed - Updated unit test to verify port is NOT exposed ## Verification Tested by deploying a MySQL environment and confirming: - ✅ `nc -zv <VM_IP> 3306` times out (port not accessible externally) - ✅ All containers report healthy status including MySQL - ✅ Tracker can still connect to MySQL via internal Docker network ## Related Closes #277 --- **Issue Specification**: [docs/issues/277-mysql-port-publicly-exposed.md](docs/issues/277-mysql-port-publicly-exposed.md) ACKs for top commit: josecelano: ACK b645f66 Tree-SHA512: 12e23b9a0769e7afe51b4e8151739e856e35a5cbcf7707e77f6f3c6b312ca87a1ad958190540baa77623aa1f6b1009c2bda094936af9720bea3d740d9874382c
2 parents 91d2be5 + b645f66 commit 2d24c49

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/infrastructure/templating/docker_compose/template/renderer/docker_compose.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ mod tests {
301301
"Volume should use local driver"
302302
);
303303

304-
// Verify port mapping
304+
// Verify port is NOT exposed (security fix: https://github.com/torrust/torrust-tracker-deployer/issues/277)
305305
assert!(
306-
content.contains("3306:3306"),
307-
"Should expose MySQL port 3306"
306+
!content.contains("3306:3306"),
307+
"MySQL port 3306 should NOT be exposed externally for security"
308308
);
309309
}
310310

templates/docker-compose/docker-compose.yml.tera

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ services:
176176
{%- for network in mysql.networks %}
177177
- {{ network }}
178178
{%- endfor %}
179-
ports:
180-
- "3306:3306"
179+
# SECURITY: MySQL port is NOT exposed to the host/external network.
180+
# - Only the tracker container can access MySQL via Docker's internal database_network
181+
# - The healthcheck runs inside the container, so no external port is needed
182+
# - This prevents unauthorized external access to the database
183+
# See: https://github.com/torrust/torrust-tracker-deployer/issues/277
181184
volumes:
182185
- mysql_data:/var/lib/mysql
183186
command: --mysql-native-password=ON

0 commit comments

Comments
 (0)