Purpose
This tutorial explains how to secure a Giotto VM by restricting public network exposure and allowing only the traffic that is actually required.
The goal is to ensure that:
- Only SSH and services intentionally exposed through the reverse proxy are reachable from the public network
- Internal service-to-service communication remains possible through the private network
- Containerized services can still communicate through the Docker internal network
- All other unsolicited public traffic is blocked
Overview
A Giotto deployment includes many services, and some of them need to expose ports on the VM so that nodes can communicate with one another in a multi-node setup.
However, these ports should not generally be exposed to the public internet.
The recommended model is:
- Keep SSH open for administration
- Keep only reverse-proxy-facing ports open to the public
- Keep internal service ports open only on the private network and Docker bridge networks
- Explicitly drop everything else
This makes firewall configuration an important part of the platform setup.
Why this matters
Some services in Giotto must listen on the VM because they participate in:
- Multi-node communication
- Orchestration traffic
- Distributed compute traffic
- Internal service integration
That does not mean those services should be reachable from the public internet.
A good security baseline is:
- Public users only see the entry points you intend to expose
- Internal services remain reachable only from trusted internal networks
- Unexpected inbound access is denied by default
This reduces the attack surface of the deployment while preserving normal platform operation.
Security goal
The firewall policy described in this tutorial is based on a simple principle:
Allow only what is needed, and drop everything else.
In practice, this means:
- allow already-established traffic
- allow loopback
- allow private node-to-node traffic
- allow Docker bridge traffic reaching the host
- allow only a small set of public TCP ports
- drop all remaining inbound traffic
This is a strong default posture for a VM hosting Giotto.
Example firewall script
The following script is one working example of the firewall rules used to implement this policy:
#!/usr/bin/env bash
set -euo pipefail
set -a
source .env
set +a
# Allow established/related traffic
iptables -I INPUT 1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
iptables -I INPUT 2 -i lo -j ACCEPT
# Allow private node-to-node traffic
iptables -I INPUT 3 -s ${RAY_HEAD_IP}/24 -j ACCEPT
# Allow Docker bridge traffic reaching the host
iptables -I INPUT 4 -s 172.17.0.0/16 -j ACCEPT
iptables -I INPUT 5 -s 172.18.0.0/16 -j ACCEPT
# Publicly exposed ports only
iptables -I INPUT 6 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT 7 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 8 -p tcp --dport 443 -j ACCEPT
iptables -I INPUT 9 -p tcp --dport 9443 -j ACCEPT
# Drop everything else
iptables -I INPUT 10 -j DROP
What this script does
This script inserts inbound firewall rules into the INPUT chain using iptables.
The rules are ordered deliberately. That matters because iptables evaluates rules in order, and the first matching rule wins.
The script implements the following logic:
- allow existing connection traffic
- allow local loopback traffic
- allow internal private network traffic
- allow Docker bridge traffic
- allow only selected public ports
- drop everything else
This is exactly the kind of policy that works well for Giotto deployments.
Step-by-step explanation
Step 1 — Load environment variables
The script starts with:
set -a
source .env
set +a
This loads variables from a local .env file and exports them into the shell environment.
In this script, that is used to provide:
RAY_HEAD_IP
This is important because the private network rule depends on the correct internal head-node IP range.
Why this matters
Using .env avoids hard-coding the private network source directly in the script and makes the firewall easier to adapt to different environments.
Step 2 — Allow established and related traffic
The first rule is:
iptables -I INPUT 1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
This allows packets that belong to already-established connections or are related to them.
Why this matters
Without this rule, return traffic for valid connections could be blocked. This rule is a standard part of a sensible firewall baseline.
Step 3 — Allow loopback traffic
The second rule is:
iptables -I INPUT 2 -i lo -j ACCEPT
This allows traffic on the loopback interface.
Why this matters
Many services rely on local host-to-host communication through localhost or loopback networking. Blocking this would break normal local behavior on the VM.
Step 4 — Allow private node-to-node traffic
The next rule is:
iptables -I INPUT 3 -s ${RAY_HEAD_IP}/24 -j ACCEPTThis allows traffic from the private node network.
Why this matters
Some Giotto services need to expose ports on the VM for multi-node communication. Those ports should remain reachable from trusted internal nodes, even if they are not exposed publicly.
This is one of the main reasons firewall rules need to distinguish between:
- the public network
- the private node network
Important note
The exact private CIDR and the meaning of ${RAY_HEAD_IP}/24 should match your deployment topology. The key point is that internal node-to-node traffic must be allowed.
Step 5 — Allow Docker bridge traffic
The next two rules are:
iptables -I INPUT 4 -s 172.17.0.0/16 -j ACCEPT
iptables -I INPUT 5 -s 172.18.0.0/16 -j ACCEPT
These allow traffic from Docker bridge networks to reach the host.
Why this matters
Many Giotto services run in containers, and containerized services often need to reach host-exposed ports. Blocking Docker bridge traffic would break important internal communication patterns.
This rule ensures that services remain reachable on the internal Docker network even while public exposure is tightly restricted.
Why multiple Docker ranges may appear
Different Docker networks may use different subnets. In this example:
172.17.0.0/16172.18.0.0/16
are both allowed.
Step 6 — Allow only selected public ports
The script then explicitly allows a small set of public TCP ports:
iptables -I INPUT 6 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT 7 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 8 -p tcp --dport 443 -j ACCEPT
iptables -I INPUT 9 -p tcp --dport 9443 -j ACCEPT
These correspond to:
22→ SSH80→ HTTP443→ HTTPS9443→ an explicitly exposed secure/public endpoint used in the deployment
Why this matters
These are the only ports intentionally exposed to the public network in this setup.
This matches the intended security model:
- SSH stays open for administration
- reverse-proxy-facing entry points remain reachable
- internal service ports remain internal only
Security principle
If a service does not need to be publicly reachable, it should not appear in this allowlist.
Step 7 — Drop everything else
Finally, the script inserts:
iptables -I INPUT 10 -j DROP
This drops every other inbound packet that did not match an earlier allow rule.
Why this matters
This is what makes the setup secure by default. Any inbound traffic that is not:
- established
- local
- private-network
- Docker-network
- or explicitly public
is rejected.
This prevents unintended exposure of internal services.
What this protects
With this policy in place:
- publicly reachable ports are tightly limited
- internal cluster communication still works
- container-to-host communication still works
- stray or accidental public exposure is reduced
This is especially important on a VM where multiple services may bind to host ports for operational reasons.
Where this fits in a Giotto installation
This firewall setup should be part of the VM hardening and platform preparation phase.
A typical order is:
- install GPU and container prerequisites
- install Docker and Docker Compose
- configure internal/private networking assumptions
- apply firewall rules
- install and deploy Giotto
This helps ensure that the platform is not accidentally exposed while the deployment is being assembled.
How to verify the result
After applying the rules, validate them carefully.
Check the active rules
Run:
iptables -L INPUT -n --line-numbers
This should show the rules in the expected order.
Check SSH remains reachable
Before applying rules remotely in production, make sure that port 22 remains open, otherwise you may lock yourself out of the VM.
Check public entry points
Verify that only the intended public ports are reachable externally:
22804439443
Check internal communication
Validate that:
- private node traffic still works
- Dockerized services can still reach host services where expected
Common mistakes
Allowing too many public ports
It is common to leave internal service ports exposed by mistake. This weakens the security posture significantly.
Blocking private node traffic
If internal node-to-node traffic is blocked, multi-node functionality may break.
Blocking Docker bridge traffic
If Docker bridge traffic is blocked, containers may fail to reach host services that are required for normal operation.
Forgetting rule order
With iptables, order matters. A drop rule inserted too early can block valid traffic.
Applying rules remotely without validating SSH access
This can result in losing access to the VM.
Best practices
Expose only SSH and reverse-proxy-facing ports publicly
All other ports should remain restricted to internal networks unless there is a very specific operational reason not to do so.
Distinguish clearly between public and internal traffic
Some services need to expose host ports for internal connectivity, but that does not imply public exposure.
Keep Docker and private network ranges explicit
Document which subnets are expected and why they are allowed.
Treat firewall configuration as part of platform installation
Security rules should not be an afterthought. They are part of the deployment architecture.
Re-validate after topology changes
If your head node IP, Docker network ranges, or reverse-proxy ports change, the firewall rules should be reviewed.
Comments
0 comments
Article is closed for comments.