Skip to content

Commit b645f66

Browse files
committed
fix: [#277] remove public MySQL port exposure for security
MySQL port 3306 was publicly accessible from outside the VM, allowing anyone on the network to connect to the database. This posed a security risk as the database credentials could be brute-forced. Changes: - Removed ports: - "3306:3306" from MySQL service in docker-compose - Added security comment explaining why port is not exposed - Updated unit test to verify port is NOT exposed MySQL remains accessible to the Tracker via Docker's internal database_network, and the healthcheck still works because mysqladmin ping runs inside the container. Closes #277
1 parent 91d2be5 commit b645f66

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)