Example of configuring security groups for cloud servers in the same subnet
Configuration goal
Configure security groups for two cloud servers to restrict the servers' access to each other and access to the servers from the internet.
Requirements
In the configuration example, we used two cloud servers located in the same pool:
- a web server is deployed on one server, and the server is connected to the internet via a public floating IP address;
- the other server is running a MySQL database that accepts requests from the web server on the standard port 3306.
The servers are added to the same private subnet. In the private network and on the server ports in this network, traffic filtering (port security) is enabled.
Configuration result
Two security groups have been created and assigned to the server ports:
- for the web server — the group allows incoming HTTP and HTTPS traffic from the internet;
- for the database server — the group allows incoming traffic from the web server on the database's standard port.
All outgoing traffic from the servers is allowed.
Configuration steps
Control panel
OpenStack CLI
Terraform
1. Create a security group for the web server
-
In the Control panel, in the top menu, click Products and select Cloud Servers.
-
Go to Security groups.
-
Click Create security group.
-
Select the location where the web server is located.
-
Create a rule that allows incoming HTTP traffic for the web server:
5.1. Click Add inbound traffic rule.
5.2. Select the protocol — TCP.
5.3. Select traffic source (Source) — CIDR and enter the default subnet IP address
0.0.0.0/0.5.4. Enter the port (Dst. port) allowed to receive traffic —
80.5.5. Optional: enter a comment for the rule.
5.6. Click Add.
-
Create a rule that allows HTTPS traffic for the web server:
6.1. Click Add inbound traffic rule.
6.2. Select the protocol — TCP.
6.3. Select traffic source (Source) — CIDR and enter the default subnet IP address
0.0.0.0/0.6.4. Enter the port (Dst. port) allowed to receive traffic, in the example —
443.6.5. Optional: enter a comment for the rule.
6.6. Click Add.
-
In the Ports block, select the web server port to which the security group will be assigned. After the group is created, all active sessions on the port that do not match the group rules will be terminated.
-
Enter a group name or leave the name created automatically.
-
Optional: enter a comment for the group.
-
Click Create security group.
2. Create a security group for the database server
-
In the Control panel, in the top menu, click Products and select Cloud Servers.
-
Go to Security groups.
-
Click Create security group.
-
Select the location where the database server is located.
-
Create a rule that allows incoming traffic from the web server group:
5.1. Click Add inbound traffic rule.
5.2. Select the protocol — TCP.
5.3. Select traffic source (Source) — SG and select the security group you created for the web server.
5.4. Enter the port (Dst. port) allowed to receive traffic —
3306.5.5. Optional: enter a comment for the rule.
5.6. Click Add.
-
In the Ports block, select the web server port to which the security group will be assigned. After the group is created, all active sessions on the port that do not match the group rules will be terminated.
-
Enter a group name or leave the name created automatically.
-
Optional: enter a comment for the group.
-
Click Create security group.