A firewall is a set of allow rules in a project, attached to network interfaces. Firewalls are stateful: replies to allowed traffic are allowed in both directions. An interface’s policy is the union of its firewalls’ rules:
- Inbound traffic is denied unless a rule allows it.
- Outbound traffic is allowed only as rules allow it; a new firewall allows all outbound traffic. An interface with no firewalls allows all outbound traffic and no inbound.
- Traffic no rule allows is dropped silently.
In the console, open Compute, then Firewalls.
Rules
| Field | Values |
|---|---|
direction |
inbound (to the instance) or outbound (from it) |
protocol |
tcp, udp, icmp (IPv4), icmpv6 (IPv6), all, or an IANA protocol number ("47") |
ports |
{ from, to }, 1–65535, for tcp and udp. null: every port |
icmp |
{ type, code } for icmp and icmpv6; a null code is every code. null: every type |
peer |
{ cidr }: an IPv4 or IPv6 prefix, such as 0.0.0.0/0 or 2001:db8::/32. Or { firewallId }: the interfaces attached to that firewall, in the same project (it may be this firewall). Or { loadBalancer }: traffic a load balancer in this project sends to your targets. Or { mountTarget }: a Files mount target in this project, IPv4 only. Or { sandboxSubnet }: the sandboxes created in that subnet of this project |
description |
Up to 255 characters |
- A CIDR peer is one address family: a rule for both IPv4 and IPv6 traffic from anywhere is two
rules,
0.0.0.0/0and::/0. A firewall peer covers both families. - Duplicates are refused (
409 rule_duplicate): two rules can’t share direction, protocol, ports, ICMP and peer. - A rule can’t be changed except for its description: delete it and add another.
In the console, Edit rules on a firewall’s Rules tab edits the inbound and outbound rules and saves them together. With the API:
| API | Does |
|---|---|
| CreateFirewall | rules omitted: the two outbound allow-all rules; rules: []: none |
| AddFirewallRules | Adds 1–50 rules |
| ReplaceFirewallRules | Makes the rules exactly these (0–200). An unchanged rule keeps its ID. If-Match with the firewall’s ETag guards against a concurrent change |
| DeleteFirewallRule, UpdateFirewallRule | Deletes a rule, or changes its description |
From the CLI:
ezgh compute firewalls create web
ezgh compute firewalls rules add web --direction inbound --protocol tcp --ports 443 --cidr 0.0.0.0/0
ezgh compute firewalls rules add web --direction inbound --protocol tcp --ports 443 --cidr ::/0
ezgh compute firewalls rules add db --direction inbound --protocol tcp --ports 5432 --peer-firewall web
ezgh compute firewalls get web -o json > web.json # edit its rules, then:
ezgh compute firewalls rules replace web -f web.jsonChanges are synchronous; an interface’s Firewalls tab shows Applying until they’re in force on it, then Applied.
The default firewall
Each project has a firewall named default, made the first time an interface is created without
choosing firewalls. Launches and new interfaces get it unless you choose others. It allows:
| Direction | Protocol | Peer |
|---|---|---|
| Inbound | All | Interfaces with the default firewall |
| Inbound | ICMP echo request | 0.0.0.0/0 |
| Inbound | ICMPv6 echo request | ::/0 |
| Outbound | All | 0.0.0.0/0 and ::/0 |
So instances in a project reach each other, and can be pinged, with no setup. It doesn’t allow
SSH or anything else from the internet: attach another firewall for that, as the console’s
Allow SSH from: Anywhere does with ssh-anywhere. The default firewall can be edited but not
deleted (409 default_firewall_protected).
VPC default firewalls
Each VPC has its own default firewall, which private interfaces in it get
unless you choose others. It allows all inbound traffic from the VPC’s IPv4 range and IPv6 /56,
and all outbound traffic. It can be edited but not deleted on its own
(409 default_firewall_protected); deleting the VPC deletes it. It attaches only to interfaces in
its VPC (409 firewall_vpc_mismatch elsewhere), and the console marks it VPC default. Other
firewalls attach to public and private interfaces alike.
A firewall peer in a private interface’s rules admits only that firewall’s members in the same VPC,
with all their private addresses and any public IPv6 /64, and their delegated prefixes; in a public interface’s rules, only public interfaces.
Always allowed
Whatever the rules, interfaces always allow what the network needs to work: IPv6 neighbor discovery and router advertisements from the gateway, ICMP and ICMPv6 errors (destination unreachable, packet too big, time exceeded, parameter problem), and the metadata service. ICMP echo isn’t among them: it’s a rule like any other.
Attachments
An interface has at most 5 firewalls; a firewall is attached to at most 1,000 interfaces, and an interface’s firewalls can reference at most 8 firewalls or load balancers as peers.
| Console | API | |
|---|---|---|
| A firewall’s Attachments tab, Attach to interface | AttachFirewall, DetachFirewall | One firewall, one interface |
| An interface’s Firewalls tab, Edit firewalls | SetInterfaceFirewalls | All of an interface’s firewalls at once |
| At launch | networkInterfaces[].firewallIds |
See Instances |
From the CLI (--firewall sets them at launch):
ezgh compute firewalls attachments attach web eni_7hq2m0x9ka3c
ezgh compute firewalls attachments detach web eni_7hq2m0x9ka3c
ezgh compute network-interfaces firewalls set eni_7hq2m0x9ka3c web ssh-anywhereAn attachment’s state is applying until the rules are in force, then applied. Attaching,
detaching and changing rules work on running instances.
Effective rules
GetInterfaceEffectiveRules answers the rules in
force on an interface: its firewalls’ rules merged, with each firewall peer expanded to its
members’ addresses. From the CLI, ezgh compute network-interfaces effective-rules <interface>.
Delete a firewall
A firewall can’t be deleted while it’s attached (409 firewall_in_use, which gives the count) or
while another firewall’s rule names it as a peer (409 firewall_referenced). Its rules are deleted
with it.