On this page
Security groups
Security groups are virtual firewalls for your instances. Each rule allows specific inbound or outbound traffic, so you decide exactly which ports and sources are permitted.
A security group is a set of allow rules that attach to an instance's network ports. There are no deny rules: traffic that no rule allows is simply dropped. That makes a group easy to reason about, you read it as the complete list of what is permitted.
Rules are stateful. If you allow an inbound connection, the reply traffic is allowed back automatically, so you rarely need matching outbound rules for the same flow. You can attach several groups to one instance and reuse a group across many instances, which keeps a common policy in one place.
Key concepts
Security group — A named set of allow rules attached to instance ports.
Rule — One allow entry: a direction, protocol, port range and source or destination.
Direction — ingress for inbound traffic to the instance, egress for outbound.
Remote IP prefix — The CIDR a rule allows traffic from (ingress) or to (egress), e.g. 203.0.113.0/24.
Ethertype — Whether the rule applies to IPv4 or IPv6.
Before you start
- An instance (or a plan to create one) whose traffic you want to control.
- The list of ports your service actually listens on.
Step by step
- Open Security groups
Go to Networking and open Security groups.
Screenshot — The Security groups listThe Security groups list - Create a group
Create a group with a clear name such as
web-serversso its purpose is obvious.Screenshot — The Create security group formThe Create security group form - Add rules
- Add an ingress rule for each port you must expose, for example 443 for HTTPS.
- Set the protocol (TCP, UDP or ICMP), the port range, and the ethertype.
- Restrict the remote IP prefix to a trusted range where possible.
Screenshot — The add-rule form with direction, protocol, port and source fieldsThe add-rule form with direction, protocol, port and source fields - Attach to instances
Attach the group to your instances. An instance keeps the rules of every group attached to it.
Examples
patrii security-group create --name web-servers patrii security-group list # note the group ID patrii security-group rule add <group-id> \ --direction ingress --protocol tcp --port 443 \ --cidr 0.0.0.0/0
patrii security-group rule add <group-id> \ --direction ingress --protocol tcp --port 22 \ --cidr 203.0.113.0/24
resource "patrii_security_group" "web" {
name = "web-servers"
description = "HTTPS from anywhere, SSH from the office"
}
resource "patrii_security_group_rule" "https" {
security_group_id = patrii_security_group.web.id
direction = "ingress"
protocol = "tcp"
port_range_min = 443
port_range_max = 443
remote_ip_prefix = "0.0.0.0/0"
}
resource "patrii_security_group_rule" "ssh" {
security_group_id = patrii_security_group.web.id
direction = "ingress"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "203.0.113.0/24"
}Limits & specifications
Fields on a security-group rule:
| Field | Values / meaning |
|---|---|
direction | ingress (inbound) or egress (outbound). |
ethertype | IPv4 or IPv6. |
protocol | tcp, udp, icmp, or left empty for all protocols. |
port range | A single port or a range, e.g. 443 or 8000-8080. |
remote IP prefix | The allowed source/destination CIDR, e.g. 203.0.113.0/24. |
Best practices
- Start from deny-by-default: add only the rules you need and nothing more.
- Scope sources to specific CIDRs; avoid 0.0.0.0/0 for management ports like SSH and RDP.
- Group by role (web, app, data) and reuse the group instead of recreating rules per instance.
- Review groups periodically and remove rules for services you no longer run.
FAQ
Do I need an outbound rule for the reply to an allowed request?
What happens if two attached groups disagree?
My instance is unreachable even though the port is listening.
Learn more
Everything you can do here in the console is also available through the Patrii Cloud API for automation and scripting.