Mastering Secure Hosted Environments: Best Practices for Web-Database Security

Securing the connection between your web and database servers is vital for safeguarding your data’s confidentiality and integrity. Here are some pointers on firewall setup between these servers:

  1. Firewall Selection:

    Decide between a hardware or software firewall. Software firewalls like iptables (Linux) or Windows Firewall (Windows) are commonly used and can be deployed on the servers themselves.

  2. Database Isolation:

    Consider housing the database server on a separate network, segregated from the web server by a hardware firewall. This reduces the attack surface. If they share a network, rely on server-level firewalls to filter traffic.

  3. Configuring Firewall Rules:

    • Permit Essential Ports: Open only necessary ports (e.g., 3306 for MySQL) to communication from the web server’s IP addresses.

    • Deny All Other Traffic: Establish a default rule denying incoming traffic, allowing only explicitly permitted connections.

      Example iptables rule for MySQL on a Linux database server:
      iptables -A INPUT -p tcp –dport 3306 -s webserver_ip -j ACCEPT

      Example iptables rule to deny all other incoming traffic:
      iptables -A INPUT -j DROP
  4. Securing the Web Server:

    Ensure the web server is secure by updating software, using robust authentication for database connections, and following web app security best practices.

  5. Encrypt Data Traffic:

    Utilize SSL/TLS or other encryption for data transit between servers, preventing eavesdropping.

  6. Authentication and Authorization:

    Implement robust authentication mechanisms on both servers and create database users with minimal privileges.

  7. Regular Updates and Monitoring:

    Keep servers patched, monitor logs for suspicious activities, and configure NTP for synchronized logs.

  8. Backup and Recovery:

    Regularly back up data and have a disaster recovery plan in place.

  9. Security Testing:

    Conduct regular vulnerability scanning and penetration testing.

  10. Documentation:

    Document firewall rules, configurations, and security procedures for ease of management and troubleshooting.

Remember, security is a continuous process. Stay vigilant, adapt to evolving threats, and regularly update security measures to fortify against potential attacks.


Kieran Davies (33three.eu) 12th December 2023