Services and products mentioned in this article.
Get in touch with our expert team for professional cloud architecture and operations support.
Kaihu Cloud TeamCloud Security Practitioners
Kaihu Cloud Team configures and audits security groups for production ECS fleets, from single web servers to multi-tier VPC architectures.
All factual claims are cross-referenced against authoritative sources before publication. Data comes from verified primary references.
A security group is a stateful virtual firewall attached to ECS instances; rules match direction, protocol, port and source.
Open only what the workload needs — 22/3389 to your own IP, 80/443 to the world.
Most incidents come from 0.0.0.0/0 rules on management ports and forgotten test rules.
An Alibaba Cloud security group is a virtual firewall attached to your ECS instances. It controls inbound and outbound traffic at the instance level, and every instance must be associated with at least one security group. Rules are allow-only: you specify protocol, port range, and source or destination CIDR, and anything not explicitly allowed is dropped.
Security groups work as stateful instance-level filters. Traffic is evaluated against the rule list of every attached group; inbound rules define who can reach the instance, while outbound rules (allow all by default) define what the instance can reach. Because evaluation happens at the hypervisor boundary before traffic reaches your OS, misconfigured host firewalls cannot be blamed for unreachable services — check the security group first.
A typical web server setup: allow TCP 22 from your own IP only for SSH, TCP 80 and 443 from 0.0.0.0/0 for public HTTP and HTTPS traffic, TCP 3306 from 10.0.0.0/8 for MySQL reachable only inside the VPC, and keep outbound allow-all so the instance can download packages and call external APIs.
The reference rule set contains four inbound rules and one outbound rule: SSH 22 (your IP/32), HTTP 80 (0.0.0.0/0), HTTPS 443 (0.0.0.0/0), MySQL 3306 (10.0.0.0/8), and outbound All from 0.0.0.0/0.
Every open port is potential attack surface. Port 80 and 443 must be public for a website, but management and database ports do not have to be. The narrower the source CIDR you allow, the fewer hosts can even attempt a connection, and brute-force noise drops accordingly.
Three factors decide what to open: the service type (web, admin, database), the audience (public users, your team, internal services), and the network location of legitimate clients (internet, office IP, VPC subnet). Match each rule to all three rather than opening a port to everyone for convenience.
| Port | Purpose | Recommended Source | Public? |
|---|---|---|---|
| 22 | SSH administration | Your IP/32, bastion, or VPN range | No |
| 80 | HTTP web traffic | 0.0.0.0/0 | Yes |
| 443 | HTTPS web traffic | 0.0.0.0/0 | Yes |
| 3306 | MySQL database | 10.0.0.0/8 (VPC only) | No |
Public ports: only 80 and 443. Everything else — SSH, databases, caches, admin panels — gets a restricted source. If a service must be reached remotely, put it behind the VPC and use a bastion host or VPN instead of opening the port.
The most damaging mistake is opening all ports to 0.0.0.0/0 for convenience. This exposes SSH to credential brute-force bots and databases to direct connection attempts from the entire internet. Because security group rules are allow-only, one overly broad rule silently overrides all your careful restrictions — a single AuthorizeSecurityGroup call with a /0 source can undo your whole policy.
Three errors appear again and again: opening port 22 (SSH) or 3306 (MySQL) to 0.0.0.0/0, duplicating rules across a flat security group shared by web and database instances, and leaving stale rules for decommissioned services that nobody audits.
| Mistake | Risk | Fix |
|---|---|---|
| All ports open to 0.0.0.0/0 | Brute-force attacks and unauthorized access | Restrict each rule to specific IPs or CIDR blocks |
| SSH 22 open to the world | Credential brute-forcing of root/admin accounts | Allow your IP/32 only; use bastion host or VPN |
| Database ports publicly reachable | Direct data theft attempts | Limit to VPC CIDR such as 10.0.0.0/8 |
| One flat group for all tiers | A breach in one tier exposes the others | Separate security groups per tier (web, app, database) |
Follow the principle of least privilege, separate security groups by tier, and audit rules regularly — remove any rule whose service no longer exists. Before adding a broad rule, ask whether a bastion or VPN path can serve the same need.
Create the group in the console (ECS Console > Security Groups > Create Security Group, select VPC and region), add inbound rules for SSH 22, HTTP 80 and HTTPS 443 with SSH restricted to known IPs, keep outbound allow-all unless needed otherwise, then attach it to the instance from its details page. The same flow via CLI:
# Create security group
aliyun ecs CreateSecurityGroup --RegionId cn-hangzhou --VpcId vpc-xxx
# Add inbound rule for SSH (port 22)
aliyun ecs AuthorizeSecurityGroup \
--SecurityGroupId sg-xxx \
--IpProtocol tcp \
--PortRange 22/22 \
--SourceCidrIp YOUR_IP/32 \
--Description "SSH access"
# Add inbound rule for HTTP (port 80)
aliyun ecs AuthorizeSecurityGroup \
--SecurityGroupId sg-xxx \
--IpProtocol tcp \
--PortRange 80/80 \
--SourceCidrIp 0.0.0.0/0 \
--Description "HTTP access"Maintain one security group per tier: a web group with 80/443 public and SSH from the bastion only, an app group accepting traffic from the web group, and a database group accepting traffic from the app subnet only. This tiered layout scales cleanly as services multiply.
Single web server: one group, 22 restricted to your IP, 80/443 public, database ports closed. Web plus database: two groups, database reachable only from the app or web subnet. Regulated or sensitive workloads: tiered groups, VPN-only administration, and a periodic audit that reconciles rules against running services.
Service Type: Account Setup Service
Use Cases