Menu ⌃

Security groups

Security groups control VM-to-VM traffic on your private networks. A group is a reusable rule set in one region; attach it to any VMs there. Without groups, your VMs talk freely within their VPC.

How rules apply

  • Per direction — rules are ingress (traffic arriving at members) or egress (traffic leaving them). A direction with no rules stays unrestricted.
  • Empty groups don't block — attaching a group with no rules changes nothing. Once a VM's groups have rules for a direction, only traffic those rules allow gets through in that direction.
  • Combined — with several groups attached, their rules for a direction are combined.
  • Both ends count — a flow between two VMs must be allowed by the sender's egress rules and the receiver's ingress rules, where each has rules for that direction.
  • Deny can't be overridden — a deny at either end blocks the flow, whatever the other end allows.
  • Families count too — once a direction has any rule, traffic of an IP family no rule covers is denied. Rules that are all IPv4 block IPv6 in that direction.
  • Stateful — replies to an allowed connection are allowed automatically.
  • Private traffic only — security groups don't apply to internet traffic. That's the firewall.

Rule fields

FieldValues
Directioningress or egress
Actionallow or deny
ProtocolTCP, UDP, or ICMP (ICMP has no ports)
Port or rangeone port or an inclusive range
Peera CIDR (IPv4 or IPv6), another security group, or any VM in the project
IP familyIPv4, IPv6, or both
Priority1–1000; lower numbers win, and deny wins a tie
Client source portoptional range of the connecting side's port (advanced)

A security-group peer means "any VM that's a member of that group", and follows membership as VMs join and leave.

Example: a database tier

To make database VMs accept Postgres only from your application VMs:

  1. Create a group app and attach it to your application VMs. It needs no rules.
  2. Create a group db with one ingress rule: allow TCP 5432 from group app.
  3. Attach db to your database VMs.

The database VMs now have ingress rules, so other inbound private traffic to them is dropped. Their egress is untouched because db has no egress rules.

Create a group

Networking → security groups → Create security group. Pick the datacenter, name the group, and add rules. Priority, IP family, and client source ports are under the advanced settings.

Attach and detach

  • At create — pick groups in the VM create form.
  • Later — VM → networking, then Attach group or Detach group.

Membership changes don't restart the VM. The page shows when the change has been enforced.

What's next