Network Security Groups and Firewall Rules That Hold Up
Firewall rules decay as teams change them under pressure. This guide covers the layers of cloud network control, writing readable rule sets, egress filtering and changing rules safely.
Network rules are the control most likely to be correct on the first day and wrong by the end of the year. They start tight, then a deployment fails at eleven at night, someone widens a rule to get the release out, and the temporary change becomes the configuration. Nobody is careless; the process simply has no step that puts the rule back.
Writing rules that survive contact with real operations is less about the rules themselves and more about making them readable, testable and easy to change safely.
The layers you are working with
Cloud network filtering happens at several places, and confusing them produces hours of fruitless debugging.
Instance-level groups attach to a resource and filter traffic reaching it. They are usually stateful, meaning a reply to an allowed outbound connection is permitted automatically, and they typically contain allow rules only.
Subnet-level lists apply to everything in a network segment. They are often stateless, so return traffic needs its own rule, and they generally support explicit deny, which makes them the right place for a broad block.
Host firewalls run inside the operating system. They still apply, they are invisible from the provider console, and they are a frequent cause of traffic that the cloud rules say should work.
Application-layer controls sit in front of web services and inspect requests rather than packets, which is a different job from everything above.
Traffic has to pass every applicable layer. When something is blocked and the security group looks correct, check the subnet list and then the host firewall before changing anything. The wider design context sits in our cloud networking baseline guide.
Default deny, and what it costs you
Start from denying everything inbound and permit only what is required. Every provider defaults this way for a reason, and the first thing most teams do is weaken it.
The cost of default deny is real: each new service needs a rule, and that is friction. The cost of the alternative is that a service nobody meant to expose, started by a container with a default port mapping, is reachable from the internet within minutes of being launched. Automated scanning finds open ports across the public address space continuously, so exposure is measured in minutes rather than weeks.
The way to make default deny tolerable is to make adding a rule fast and reviewable rather than to make the default looser. If a rule change takes a day of ticket queueing, people will route around it.
Rules you can still read in a year
A rule set becomes unmaintainable when nobody can tell which rules are still needed. Three habits prevent that.
Reference groups rather than addresses wherever the provider allows it. A rule saying the application tier may reach the database tier on the database port stays correct as instances are replaced, while a rule listing addresses needs editing every time something is rebuilt and quietly accumulates entries for machines that no longer exist.
Name groups after their function, not their contents. A group called “web-tier-inbound” explains itself. One called “sg-prod-2” explains nothing and will be copied by someone who does not know what it is for.
Write the reason in the description field on every rule, including who asked for it and when. This is the single highest-value habit in the whole topic, because the question during every cleanup is “can we remove this”, and the description is the only thing that answers it.
Stateful and stateless filtering
The difference catches people out often enough to deserve its own section. A stateful filter tracks connections, so allowing an inbound request on a port automatically permits the response. A stateless filter evaluates each packet independently, so a reply needs its own explicit rule on the ephemeral port range.
Symptoms of getting this wrong are distinctive: connections that establish and then hang, traffic that works in one direction only, or health checks that fail while manual tests succeed. If you see those, check whether the layer you are editing is stateless before adding more allow rules at the stateful layer.
The open-to-the-world rule
Allowing a port from every source address has exactly two legitimate uses: a public web service on the standard web ports, and a service genuinely intended for anonymous public access. Everything else wants a narrower source.
The rule that causes most incidents is administrative access open to the internet. Remote shell and remote desktop ports exposed publicly are scanned constantly, and the only thing standing between that and a compromise is the credential. There are better options. Restrict the source to a known network range. Put administrative access behind a private connection so the port is not publicly reachable at all. Use the provider’s own browser-based console access, which removes the need for an open port entirely. Or run a bastion host as the only machine accepting administrative connections, so there is one surface to harden instead of forty.
Databases, message queues, caches, metrics endpoints and internal dashboards should never be reachable from the public internet. They are frequently exposed by accident when an instance is created in a public subnet with a permissive group inherited from somewhere else.
The egress rules nobody writes
Almost every team filters inbound traffic carefully and allows all outbound traffic without thinking about it. Outbound filtering is harder, less satisfying, and considerably more useful than it looks.
Unrestricted egress means a compromised instance can reach anything: download further tooling, connect to a command channel, and move your data out. It also means a mistyped endpoint in configuration silently talks to the wrong place rather than failing visibly.
Full egress allow-listing is a large project, so start where the ratio is best. Lock down egress on the resources that hold data, since a database server has a short and knowable list of destinations. Block outbound traffic from private subnets to the internet except through a controlled path. Restrict the instance metadata endpoint to the processes that need it, because reaching it is a standard step for turning a server-side request flaw into stolen credentials.
Egress rules also have a cost dimension worth knowing about, since traffic leaving your network is billed by volume on metered providers. That interaction is explained in cloud egress fees explained.
Changing rules without locking yourself out
The failure mode specific to firewall work is removing your own access. It happens to everyone once.
Before tightening a rule set, confirm you have a second route in, whether that is the provider’s console access, a separate bastion, or another administrator on a different network. Make changes additive first: add the narrow rule, confirm traffic still flows, then remove the broad one. If the platform supports scheduling, apply risky changes with an automatic revert after a short window, so an error fixes itself when you can no longer reach the console.
Test from the outside rather than from inside the network. A port scan from an external host tells you what is actually reachable, which is frequently not what the rule set implies once overlapping groups are combined. Repeat that scan on a schedule, because the configuration you verified in March is not the configuration you have in September.
Keeping the rule set honest over time
Define rules as code and apply them through a reviewed pipeline. A change then arrives as a readable difference with an author, a reviewer and a date, and the drift problem mostly disappears. Console edits should be the exception, and ideally should trigger an alert so that an undocumented change is noticed rather than absorbed, which is one of the detections worth configuring per detecting and responding to unexpected cloud activity.
Run a quarterly review of every rule allowing traffic from any source, every rule with an empty description, and every group not attached to any resource. Delete what cannot be justified. Keeping environments in separate accounts helps here too, because a permissive development rule cannot reach a production system when no network path exists between them, as argued in separate cloud accounts per environment.
Provider capability varies more than you might expect. Some platforms offer multiple filtering layers, rule references between groups, flow logs showing what traffic was accepted or rejected, and private connectivity options. Others provide a single flat firewall with address-based rules and no flow visibility, which pushes more of the work into host firewalls and your own logging. The Vultr vs UpCloud comparison covers that gap in network tooling, and listings such as Buy Vultr Account and Buy UpCloud Account let you check the current feature set in the console before you design around it.