How chaifeng/ufw-docker works
Major Steps & Considerations:
Project Type and Purpose
• This is not a full-stack web application but a systems-level utility. It provides a mechanism (via a script and optional agent for Swarm mode) to safely bridge Docker’s automatic iptables management with UFW’s firewall configuration.
• The README explains the “problem” (Docker published ports getting exposed despite UFW rules) and the “solution” (manipulating UFW’s after.rules file with additional rules). The project also offers a CLI (ufw-docker script) to install, check, update, and manipulate these firewall rules.
File Structure
• Top-Level Files: Configuration files (Dockerfile, .dockerignore, Vagrantfile, .travis.yml, GitHub workflows) indicate CI/CD integration and container testing.
• The main executable/script is “ufw-docker” (without an extension) which implements the core logic.
• Test directories and helper scripts (docker-entrypoint.sh, test.sh, test subdirectory) indicate a suite for integration testing.
• Presence of Docker and Vagrant files signals that the solution is tested in isolated environments (containers and virtual machines).
Defining the Main Components
▸ Client / Command Line Interface (CLI):
• Represents the user (sysadmin) executing ufw-docker commands (install, allow/deny, check) on the Docker host.
▸ Docker Engine:
• Docker as the runtime environment that manages container lifecycle and networking.
• That Docker continues to manage its own iptables rules.
▸ UFW (Uncomplicated Firewall) System:
• UFW configuration, in particular the ‘after.rules’ file where ufw-docker appends its special rules.
• Interaction where UFW filters traffic between public and private networks.
▸ ufw-docker Integration Layer:
• Ufw-docker script that reads/modifies UFW’s firewall configuration (and installs required rules).
• If the project runs in Swarm mode, include the “ufw-docker-agent” container/service deployed on manager nodes.
▸ Network Zones:
• That internal container-to-container and container-to-private network communications are allowed, whereas public traffic is managed through UFW’s rules.
▸ CI/CD & Testing Environment:
• Symbolic references to CI interfaces (Travis, GitHub Workflows) and Vagrant testing.
• This shows how changes are automatically validated across environments.
Relationships and Interactions
• How the ufw-docker CLI (or agent in swarm) updates or installs configuration to UFW.
• That UFW rules (including specialized DOCKER-USER chain modifications) influence packet flows between the external/public network and Docker networks.
• How Docker publishes container ports and how ufw-docker’s injected rules block unauthorized access while letting allowed traffic (as managed via ufw route allow/deny commands) pass.
• Data flow from user (admin) commands to modifications in UFW configuration, then the effect on both container networking and external access.
Architectural Patterns and Design Principles
• Separation of Concerns: The tool separates the firewall management (UFW) from Docker’s networking. UFW remains the centralized place to manage public access and container port exposure.
• Integration Layer: ufw-docker serves as an overlay that adjusts iptables rules within UFW without altering Docker’s default settings.
• Extensibility: The design shows how administrator commands (allow, deny, list) dynamically change the firewall configuration.
• Environment Testing: Including CI/CD pipeline components and Vagrant test environments demonstrates robust validation practices.