Creating a distributed infrastructure with secure access
- Yandex Cloud resource placement chart
- Get your cloud ready
- Create a security folder
- Create a virtual network and subnets
- Create web app folders
- Connect the web app folders to the load balancer's internal subnets
- Configure security groups
- Configure the security profile
- Create resources
- Configure the load balancer
- Test your infrastructure
- How to delete the resources you created
In this tutorial, you will create an infrastructure for secure access to web apps hosted in different Yandex Cloud folders. For traffic control purposes, all requests to your web applications will be forwarded to a single IP address and then checked by the Yandex Smart Web Security profile rules.
This approach allows you to isolate resources used by different teams while also enforcing a common security policy for incoming traffic.
This tutorial explores a specific use case under Centralized online publication and protection against DDoS attacks of applications hosted in different Yandex Cloud folders, giving you an example of how to create the entire infrastructure from scratch.
The minimum roles required for this tutorial are as follows:
-
For a cloud:
resource-manager.admin: To create folders and assign roles.
-
For folders:
vpc.admin: To create Yandex Virtual Private Cloud resources.smart-web-security.editor: To create a security profile.compute.editor: To create VM instances.alb.editor: To create Yandex Application Load Balancer resources.
Yandex Cloud resource placement chart
The chart displays the following resources:
-
IP address: Public IP address or domain that receives requests to your web apps.
-
Security folder,
secured-entry-point: Folder accessible only to company resource administrators and information security employees. This folder will house the following resources:- ALB,
app-load-balancer: L7 Yandex Application Load Balancer used to publish web apps online. - SWS profile,
sws-profile: Yandex Smart Web Security profile to implement traffic protection at the application layer (L7). - Management VM,
work-station: Yandex Compute Cloud VM instance to initiate connections to the VMs in your web app folders.
- ALB,
-
VPC,
alb-network: Yandex Virtual Private Cloud cloud network to consolidate subnets across different folders:- alb-subnet-a, alb-subnet-b, and alb-subnet-d: Subnets with ALB nodes in three availability zones.
- subnet-service-1 and subnet-service-2: Subnets hosting your web app resources.
-
Web app folders,
service-1andservice-2: Folders housing web app targets,vm-service-1andvm-service-2. These folders will be accessible to teams developing your web services.
To create the infrastructure and set up secure access to your web applications:
- Get your cloud ready.
- Create a security folder.
- Create a virtual network and subnets.
- Create web app folders.
- Connect the web app folders to the load balancer's internal subnets.
- Configure security groups.
- Configure the security profile.
- Create resources.
- Configure the load balancer.
- Test your infrastructure.
If you no longer need the resources you created, delete them.
Get your cloud ready
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The infrastructure support cost includes:
- Fee for continuously running VMs (see Yandex Compute Cloud pricing).
- Fee for using Application Load Balancer (see Yandex Application Load Balancer pricing).
- Fee for using public IP addresses and outgoing traffic (see Yandex Virtual Private Cloud pricing).
- Fee for the number of requests to Smart Web Security (see Yandex Smart Web Security pricing).
Create a security folder
The security folder will house your load balancer, cloud network, subnets, and security profile.
Create a folder without a network
- In the management console
, select a cloud and click Create folder. - Name your folder, e.g.,
secured-entry-point. - In the Advanced field, disable Create a default network. You will create a network and subnets in the next step.
- Click Create.
Assign roles for the folder
Provide your infrastructure and security administrators with access to the folder to manage your network, load balancer, and security profile.
-
In the management console
, navigate tosecured-entry-point. -
Navigate to the Access bindings tab.
-
Click Configure access.
-
In the window that opens, select User accounts.
-
Select a user from the list or use the user search option.
-
Click
Add role and select the role from the list or use the search bar. The minimum required roles are as follows:alb.editor: To manage Application Load Balancer resources.vpc.user: To connect to and use Virtual Private Cloud network resources.smart-web-security.editor: To use and manage Smart Web Security profiles.compute.editor: To be able to create, update, and delete Compute Cloud instances.
-
Click Save.
Create a virtual network and subnets
In the security folder, create a network with subnets for your L7 load balancer and web app folders. This will ensure network connectivity between the load balancer and web app resources.
-
Go to the new folder,
secured-entry-point. -
In the list of services, select Virtual Private Cloud.
-
At the top right, click Create network.
-
In the Name field, enter
alb-network. -
In the Advanced field, disable Create subnets.
-
Click Create network.
-
In the left-hand panel, select
Subnets. -
At the top right, click Create subnet and specify the settings for the subnet to host the web app folder:
- Name:
subnet-service-1. - Availability zone:
ru-central1-a. - Network:
alb-network. - CIDR:
10.121.0.0/24. - Click Create subnet.
- Name:
-
Repeat the steps to create a subnet named
subnet-service-2in theru-central1-bavailability zone with10.122.0.0/24as its IP address range. -
Create subnets for your L7 load balancer in different availability zones with the following address ranges:
subnet-alb-a:ru-central1-aand10.131.0.0/24subnet-alb-b:ru-central1-band10.132.0.0/24subnet-alb-d:ru-central1-dand10.133.0.0/24
Create web app folders
These folders will house resources of your web applications. In this tutorial, such resources include VM instances running your test web services. Create the folders and grant your users access permissions to connect to the network resources and manage the VMs.
-
Select a cloud and click
Create folder. -
Name your folder, e.g.,
service-1. -
In the Advanced field, disable Create a default network.
-
Click Create.
-
Repeat these steps to create the
service-2folder. -
To restrict access to the folders, assign user roles based on the resources you will host in each folder. The minimum required roles for
service-1andservice-2are as follows:vpc.user: To connect to and use Virtual Private Cloud network resources.compute.editor: To be able to create, update, and delete VM instances.
Connect the web app folders to the load balancer's internal subnets
To consolidate folder resources into a single network, move the virtual network subnets to the web app folders.
- In the management console
, navigate tosecured-entry-point. - In the list of services, select Virtual Private Cloud.
- Select the
alb-networkcloud network. - Click
in thesubnet-service-1row and select Move. - Select
service-1from the drop-sown list. - Click Move.
- Similarly, move
subnet-service-2toservice-2.
Configure security groups
With security groups, you can set up incoming and outgoing traffic rules. In this tutorial, a L7 load balancer receives incoming internet traffic and routes it over the internal network to your web app VMs. Follow these best practices to configure security groups in each folder.
Create security groups for your web app VMs
The rules should allow outgoing and incoming traffic from the load balancer subnet.
-
In the management console
, selectservice-1. -
In the list of services, select Virtual Private Cloud.
-
In the left-hand panel, select
Security groups. -
At the top right, click Create security group.
-
In the Name field, specify
service-1-security-group. -
In the Network field, select
alb-networkfrom thesecured-entry-pointfolder. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
destinationCIDR blocks Ingresshttp8000TCPCIDR10.131.0.0/2410.132.0.0/2410.133.0.0/24Ingressssh22TCPCIDR10.133.0.0/24Egressany0-65535AnyCIDR10.131.0.0/2410.132.0.0/2410.133.0.0/24To create a rule:
- Navigate to the Ingress or Egress tab.
- Click Add.
- Add the new rule in accordance with the table.
- Click Save.
-
Click Create.
-
Repeat these steps to create
service-2-security-groupin theservice-2folder.
Create a security group for the L7 load balancer
The rules should allow incoming internet traffic on port 80 as well as traffic for load balancer node health checks on port 30080 with the Load balancer healthchecks source.
-
In the management console
, selectsecured-entry-point. -
In the list of services, select Virtual Private Cloud.
-
In the left-hand panel, select
Security groups. -
At the top right, click Create security group.
-
In the Name field, specify
alb-security-group. -
In the Network field, select
alb-network. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
destinationCIDR blocks Ingresshttp80TCPCIDR0.0.0.0/0Inboundhealthchecks30080TCPLoad balancer healthchecks— Egresshttp8000AnyCIDR10.121.0.0/2410.122.0.0/24To create a rule:
- Navigate to the Ingress or Egress tab.
- Click Add.
- Add the new rule in accordance with the table.
- Click Save.
-
Click Create.
Create security groups for the management VM
The rules should allow outgoing traffic from the management VM to port 22 on your web app VM.
-
In the management console
, selectsecured-entry-point. -
In the list of services, select Virtual Private Cloud.
-
In the left-hand panel, select
Security groups. -
At the top right, click Create security group.
-
In the Name field, specify
vm-security-group. -
In the Network field, select
alb-network. -
Under Rules, create the following rules using the instructions below the table:
Traffic
directionDescription Port range Protocol Source /
destinationCIDR blocks Ingressssh22TCPCIDR0.0.0.0/0*Egressssh22TCPCIDR10.121.0.0/2410.122.0.0/24* We recommend replacing
0.0.0.0/0with CIDRs of the public IP addresses from which you want to allow connections to your management VM.To create a rule:
- Navigate to the Ingress or Egress tab.
- Click Add.
- Add the new rule in accordance with the table.
- Click Save.
-
Click Create.
Configure the security profile
A security profile contains traffic filtering rules for protecion against cybersecurity threats at OSI application layer (L7).
Create a security profile using a preset template:
- In the management console
, selectsecured-entry-point. - In the list of services, select Smart Web Security.
- In the left-hand panel, select Security profiles and click Create profile.
- Select From a preset template.
- Enter
sws-profileas the profile name. - In the Action for the default base rule field, select
Allow. - Click Create profile.
Create resources
Here, by resources we mean VM instances, one per folder. The VM residing in the secured-entry-point security folder will be used to access your web application VMs over the internal network. In this tutorial, we refer to it as the management VM.
To restrict external traffic, web app VMs will not have external IP addresses.
Create the VM to manage your web applications
-
In the management console
, selectsecured-entry-point. -
In the list of services, select Compute Cloud.
-
In the left-hand panel, select
Virtual machines. -
Click Create virtual machine.
-
Under Boot disk image, select Ubuntu 24.04.
-
Under Location, select the
ru-central1-davailability zone. -
Under Network settings:
- In the Subnet field, make sure to select
subnet-alb-d. - In the Public IP address field, leave
Auto. - In the Security groups field, select
vm-security-group.
- In the Subnet field, make sure to select
-
Under Access, select SSH key.
-
Enter the VM user name in the Login field, Do not use
root,admin, or any other usernames reserved for the OS purposes. -
In the SSH key field, select the SSH key saved in your organization user profile.
To add a new key, do the following:
-
Click Add key.
-
Enter a name for the SSH key.
-
Select one of the following:
Enter manually: Paste the contents of the public SSH key. You need to create an SSH key pair on your own.Load from file: Upload the public part of the SSH key. You need to create an SSH key pair on your own.Generate key: Automatically create an SSH key pair.
-
Click Add.
-
-
Under General information, specify the VM name:
work-station. -
Click Create VM.
Create VMs for your web applications
Repeat the above steps to create VMs in the service-1 and service-2 folders, configured as follows:
- Select the
ru-central1-aandru-central1-bavailability zones, respectively. - Select
subnet-service-1andsubnet-service-2as the subnets for your VMs, respectively. - In the Public IP address field, select
No address. - In the Security groups field, select
service-1-security-groupandservice-2-security-group. - Specify the VM names,
vm-service-1andvm-service-2.
Configure the load balancer
To create and configure the load balancer, use the wizard.
Warning
You can only use the wizard to create and add resources from a single folder, i.e., one target group and one backend group. You will need to manually add resources from the second folder.
Start the wizard
- In the management console
, selectsecured-entry-point. - In the list of services, select Application Load Balancer.
- Click Create L7 load balancer and select Wizard. The wizard will take you to the target group creation page.
Configure a target group
Target groups include VMs created in the web app folders. These groups will be connected to your load balancer over the internal subnets.
Create a target group for the service-1 folder:
-
Specify the target group name:
target-group-1. -
The list of targets will only include the IP address of your management VM. Add a new target to the list of resources:
- Below the list of resources, in the section with the Add target resource button, specify the
vm-service-1internal IP address. - Also, select
subnet-service-1from the drop-down list with theNot selectedplaceholder. To find the subnet, checkAll folders. - Click Add target resource.
- Activate your new target in the list of resources.
- Make sure the management VM resource is deactivated.
- Below the list of resources, in the section with the Add target resource button, specify the
-
Click Create and continue. The wizard will take you to the backend group creation page.
Configure backend groups
Backend groups contain settings for traffic balancing and target health checks. The wizard will automatically create one backend and one health check group. It will also use the group you created earlier as the target group.
-
Enable Advanced settings.
-
Specify the backend group name:
backend-group-1. -
Leave
HTTPas the group type. -
To ensure the same backend resource handles requests from a single user session, activate Session affinity.
-
Under Backends:
- Specify the backend name:
backend-1. - Leave
Target groupas the backend type. - Leave the target group you created earlier,
target-group-1. - Specify your service's TCP port you opened in
service-1-security-group. In this tutorial, this is port8000.
- Specify the backend name:
-
Under HTTP health check:
- Specify the same port as above, i.e.,
8000. - Do not change the Path value as the test service does not have a dedicated endpoint for health checks.
- Specify the same port as above, i.e.,
-
Click Create and continue. The wizard will take you to the HTTP router setup page.
Configure an HTTP router
HTTP routers implement rules for client-to-backend traffic and allow you to modify requests at the load balancer layer. The wizard will automatically create a virtual host and a routing rule. It will also use the group you created earlier as the backend group.
-
Specify the router name:
alb-http-router. -
Enable Advanced settings.
-
Under Virtual hosts:
- In the Name field, enter
alb-virtual-host. - Leave the Authority field blank.
- In the Security profile field, select the profile you created previously,
sws-profile.
- In the Name field, enter
-
Specify these route properties:
- Route name:
app-1. - Path: Starts with followed by
/app1. - Action:
Routing. - Backend group: Leave the group you created earlier.
- Rewrite path or start: Specify the
/path.
- Route name:
-
Click Create and continue. The wizard will take you to the load balancer setup page.
Configure an L7 load balancer
A load balancer distributes incoming requests across target group VMs according to the rules specified in the HTTP router. Load balancers use listeners to receive traffic. The wizard will create a listener automatically. It will also use the router you created earlier as the HTTP router in this configuration.
-
Specify the load balancer name:
app-load-balancer. -
Enable Advanced settings.
-
Under Network settings, select the network you created earlier, i.e.,
alb-network. -
For Security groups, select From list and then the security group associated with the
alb-security-groupload balancer. -
Under Allocation, select the subnets you created previously, i.e.,
subnet-alb-a,subnet-alb-b, andsubnet-alb-d, in their respective availability zones and enable incoming traffic in those subnets. -
Configure the listener:
-
Specify the listener name:
alb-listener. -
Under Receiving and processing traffic, specify:
- Listener type:
HTTP. - Protocol:
HTTP. - HTTP router: Select the router you created earlier.
- Listener type:
-
-
Click Create.
Add resources from the second folder
When creating a load balancer using the wizard, you can add resources only from one folder. This means you need to manually create and add the target group and backend group from the service-2 folder.
-
In the management console
, selectsecured-entry-point. -
In the list of services, select Application Load Balancer.
-
In the left-hand panel, select
Target groups. -
Click Create target group.
-
Repeat the steps you followed to create a target group for the
service-1folder and create theservice-2target group. Configure the target as follows:- Name:
target-group-2. - VM internal IP address:
vm-service-2. - Subnet:
subnet-service-2.
- Name:
-
In the left-hand panel, select
Backend groups. -
Click Create backend group.
-
Create a backend group by repeating the steps you followed to create a backend group for the
service-1folder. Configure the backend as follows:- Backend group name:
backend-group-2. - Backend name:
backend-2. - Target group:
target-group-2. - Path: Use the same path as for
backend-group-1. - Port: Specify your service's TCP port opened in
service-2-security-group. In this tutorial, this is port8000.
- Backend group name:
-
In the left-hand panel, select
HTTP routers. -
Select
alb-http-routeras the HTTP router. -
Under Virtual hosts, to the right of
alb-virtual-host, click → Edit. -
At the bottom of the window that opens, click Add route.
-
Configure the route as follows:
- Route name:
app-2. - Path: Starts with followed by
/app2. - Action:
Routing. - Backend group:
backend-group-2. - Rewrite path or start: Specify the
/path. - Timeout, s: Clear the value and leave the field empty.
- Route name:
-
Click Save.
Test your infrastructure
- Run test web services on your web app VMs.
- Review the health check details.
- Check availability of your web applications.
- Test the security profile.
Run test web services on your web app VMs
-
Connect to the
work-stationmanagement VM in the security folder:ssh -l <username> <VM_public_IP_address>If using different keys for different VMs, specify the path to the relevant key in the connection command, as in this example:
ssh -i ~/.ssh/<key_name> -l <username> <VM_public_IP_address>Where:
<key_name>: Name of the private SSH key file used to create the VM.<username>: Username specified when creating the VM.<VM_public_IP_address>: VM IP address.
Tip
You can copy the VM connection command from the VM description page under Access.
-
Connect to
vm-service-1from your management VM:-
Place the private SSH key file of
vm-service-1in the~/.sshfolder of your management VM. -
Connect to
vm-service-1:ssh -i ~/.ssh/<key_name> -l <username> <VM_internal_IP_address>Where:
<key_name>: Name of the private SSH key file used to create the VM.<username>: Username specified when creating the VM.<VM_internal_IP_address>:vm-service-1internal IP address.
-
-
Start the test web service by running this command:
mkdir test-server; \ echo 'HELLO!' > test-server/hello_3.txt; \ echo 'TEST SERVER 1' > test-server/test_3.txt; \ python3 -m http.server -d test-server 8000Running this command will:
- Create a
test-serverfolder containing two files,hello_1.txtandtest_1.txt. - Start the built-in Python web service on port
8000.
Result:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... 10.133.0.10 - - [30/May/2025 09:55:41] "GET / HTTP/1.1" 200 - 10.133.0.15 - - [30/May/2025 09:55:41] "GET / HTTP/1.1" 200 - 10.133.0.10 - - [30/May/2025 09:55:42] "GET / HTTP/1.1" 200 - 10.133.0.15 - - [30/May/2025 09:55:42] "GET / HTTP/1.1" 200 - 10.133.0.10 - - [30/May/2025 09:55:43] "GET / HTTP/1.1" 200 - 10.133.0.15 - - [30/May/2025 09:55:43] "GET / HTTP/1.1" 200 - ... - Create a
-
Open a new terminal window and repeat the above steps to start the test service on
vm-service-2. Use different file names in the startup command so that your web applications’ responses vary.
Review the health check details
- Go to the
app-load-balancerpage. - Select Health checks on the left.
- Make sure the targets have the
HEALTHYstatus in all load balancer subnets.
Check availability of your web applications
To check the availability of your web applications, go to the following address in your browser:
http://<load_balancer_public_IP_address>/<route_prefix>
Where:
<load_balancer_public_IP_address>:app-load-balancerIP address.<route_prefix>: Prefix specified in the Starts with field when configuring the HTTP router. In this tutorial, these areapp1andapp2.
A page will open, listing root folder files for the specified application, as in this example:
Directory listing for /
hello_1.txt
test_1.txt
Test the security profile
-
Check that the
Smart Protectionrule allows traffic:-
In the browser, go to:
http://<load_balancer_public_IP_address>/<route_prefix> -
In another browser tab, go to the
app-load-balancerpage. -
Select
Logs on the left. -
In the Query field, specify the filter expression:
json_payload.smartwebsecurity.matched_rule.rule_type = SMART_PROTECTION and json_payload.smartwebsecurity.matched_rule.verdict = ALLOW -
Click Run.
The log list will contain entries about successful GET requests.
-
-
Add a basic deny rule:
-
Go to the
sws-profilepage. -
Under Security rules, click
Add rule. -
Enter the rule name,
deny-rule. -
Set Priority to
1000. -
Under Rule type:, keep the Base value.
-
Leave Action set to Deny.
-
Set Traffic to
On condition. -
Then select the following values:
- Conditions:
IP. - Conditions for IP:
Matches or falls within the range. - IP matches or falls within the range: Specify the IP address of the device you are using to test the web service.
- Conditions:
-
Click Add.
-
-
Test the basic rule:
-
In the browser, go to:
http://<load_balancer_public_IP_address>/<route_prefix> -
In another browser tab, go to the
app-load-balancerpage. -
Select
Logs on the left. -
In the Query field, specify the filter expression:
json_payload.smartwebsecurity.matched_rule.rule_type = RULE_CONDITION and json_payload.smartwebsecurity.matched_rule.verdict = DENY -
Click Run.
The log list will contain entries about GET requests blocked by the rule.
-
How to delete the resources you created
To stop paying for the resources, delete the folders where your infrastructure was deployed.
If you deployed the infrastructure in the existing folders, do the following:
-
Delete the
app-load-balancerL7 load balancer. -
Delete the HTTP router named
alb-http-router. -
Delete the
backend-group-1andbackend-group-2backend groups. -
Delete the
target-group-1andtarget-group-2target groups. -
Delete the VMs:
work-stationvm-service-1vm-service-2
-
Delete the
sws-profilesecurity profile. -
Delete the security groups:
alb-security-groupvm-security-groupservice-1-security-groupservice-2-security-group
-
Delete the subnets:
subnet-service-1subnet-service-2subnet-alb-asubnet-alb-bsubnet-alb-d
-
Delete the
alb-networkcloud network.