Skip to content

Firewalls

A Cloud Firewall decides what traffic reaches the Droplets it’s applied to, before it reaches them. It drops everything inbound that no rule allows. Apply it to Droplets by id, or by tag so that every Droplet with the tag, now or later, is covered.

alloweddroppedWeb firewallapplies to tag webbrowsertcp 443scannertcp 22WebDroplet · tag weballoweddroppedWeb firewallapplies to tag webbrowsertcp 443scannertcp 22WebDroplet · tag web
The firewall allows HTTPS from anywhere and drops everything else, including SSH from addresses not on its list.
yield* DigitalOcean.Firewall("Web", {
tags: ["web"],
inboundRules: [
{ protocol: "tcp", ports: "443", addresses: ["0.0.0.0/0", "::/0"] },
{ protocol: "tcp", ports: "22", addresses: ["203.0.113.4/32"] },
],
outboundRules: [{ protocol: "tcp", ports: "1-65535", addresses: ["0.0.0.0/0", "::/0"] }],
});

ports is one port or a range like "8000-8100". A rule’s sources can also be Droplet ids, load balancer ids, Kubernetes cluster ids or tags.

tags covers every Droplet with the tag, including ones created later; dropletIds: [host.dropletId] names specific ones. Give a Droplet the tag with its own tags prop.

  • A firewall with no outbound rules blocks all outbound traffic, including package installs.
  • Cloud Firewalls apply to Droplets and Kubernetes nodes; managed databases have their own trusted sources.