Prerequisites
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
- Install and configure the Nebius AI Cloud CLI.
-
Make sure you are in a group that has the
adminrole within your tenant or project; for example, the defaultadminsgroup. You can check this in the Administration → IAM section of the web console. You need this role to create a group and grant it a role for the tunnel. -
Get the project ID and the tenant ID, and save them to environment variables:
-
Get the tunnel ID by listing tunnels in your project:
The command uses the project ID from your CLI profile configuration. Copy the ID of the tunnel that you want to connect to and save it to an environment variable:
-
If you plan to run the agent on a VM, get the subnet ID for the VM you want to create.
You also need the
adminrole to create a VM with a service account attached. Create the service account in the same project as the VM. The tunnel agent authenticates as this service account, so it only needs the applicationtunnel.agent role for the tunnel. It doesn’t need any Compute permissions.A VM’s service account is set only at creation and can’t be changed afterwards. To attach a different service account, create a new VM.
Connecting a service
To connect to a tunnel, first set up access for the tunnel agent and then launch this agent.Setting up access for the tunnel agent
-
Create a service account and save its ID:
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
To grant wider access instead of creating a dedicated group with theapplicationtunnel.agentrole, you can add the service account to theeditorsgroup. -
Create a group for Nebius Tunnels service accounts and save its ID:
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
-
Grant the group the
applicationtunnel.agentrole for the tunnel:- CLI
- Go SDK
- Python SDK
- JavaScript SDK
To grant access to more tunnels, create the permit on a broader resource: a project or a tenant. A permit on a project applies to all tunnels in that project. A permit on a tenant applies to all tunnels in all projects in the tenant. -
Add the service account to the group:
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
Installing and running the agent
You can run the tunnel agent in Docker, in a Kubernetes cluster by using Helm or on a Nebius VM.Creating an authorized key for Docker and Helm
In Docker and Kubernetes, the agent authenticates as the service account by using an authorized key. On a Nebius VM, the agent doesn’t need a key, so go to Running the agent on a VM.-
Create a key pair:
The command creates the
private_key.pemandpublic_key.pemfiles in the current directory. -
Upload the public key and save its ID:
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
Running the agent in Docker
- Install Docker Engine.
-
In the directory with the
private_key.pemfile, createconfig.yamlfor the agent:In the file, replace:<tunnel_ID>with the tunnel ID. If you use the CLI, it’s the value of$TUNNEL_ID.<service_account_ID>with the service account ID. If you use the CLI, it’s the value of$SA_ID.<authorized_key_ID>with the ID of the authorized key. If you use the CLI, it’s the value of$PUBLIC_KEY_ID.
services.namecan contain up to 20 characters and must use only lowercase Latin letters and digits ([a-z0-9]). Don’t use dashes or dots. For multiple services, configure theservicessection like this: -
Run the agent using a cross-platform Docker image:
When the agent connects, it returns the public endpoint for each service. The endpoint format is:Where:
service_nameis theservices.namevalue from the agent configuration.tunnel_masked_IDis the mask of the tunnel ID without theapplicationtunnel-prefix and regional routing code. For example, forapplicationtunnel-e00abcdef123456789, the tunnel ID mask isabcdef123456789.regionis the region of the project where the tunnel was created, for exampleeu-north1.
Running the agent by using Helm
- Install Helm.
-
Create
custom.values.yamlwith the service account credentials and agent config:In the file, replace:<tunnel_ID>with the tunnel ID. If you use the CLI, it’s the value of$TUNNEL_ID.<service_account_ID>with the service account ID. If you use the CLI, it’s the value of$SA_ID.<authorized_key_ID>with the ID of the authorized key. If you use the CLI, it’s the value of$PUBLIC_KEY_ID.- The private key placeholder with the contents of
private_key.pem.
services.namecan contain up to 20 characters and must use only lowercase Latin letters and digits ([a-z0-9]). Don’t use dashes or dots. For multiple services, add them to theconfig.servicessection: -
Install the agent in your Kubernetes cluster:
When the agent connects, it returns the public endpoint for each service. The endpoint format is:Where:
service_nameis theservices.namevalue from the agent configuration.tunnel_masked_IDis the mask of the tunnel ID without theapplicationtunnel-prefix and regional routing code. For example, forapplicationtunnel-e00abcdef123456789, the tunnel ID mask isabcdef123456789.regionis the region of the project where the tunnel was created, for exampleeu-north1.
Running the agent on a VM
On a Nebius VM, the agent authenticates through the instance metadata service. This requires attaching a service account to the VM when you create it, as described in Prerequisites.-
Prepare the cloud-init configuration file. You’ll attach it to the VM when you create it.
Save the following configuration to a file named
cloud-init.yamlin your working directory. Before saving, replace:<username>with the username you’ll use to connect.<public_SSH_key>with your SSH public key.<tunnel_ID>with the tunnel ID. If you use the CLI, it’s the value of$TUNNEL_ID.
In the agent configuration,cloud-init.yaml
This configuration enables the following actions:- Add a username and a public SSH key to the VM.
- Download the tunnel agent, verify its checksum and install it as a systemd service running under a dedicated
tunnasystem user. - Authenticate by using the service account attached to the VM, through the instance metadata service. No key files are involved.
- Create the
webNebius Tunnels service that exposes127.0.0.1:8080on the VM.
services.namecan contain up to 20 characters and must use only lowercase Latin letters and digits ([a-z0-9]). Don’t use dashes or dots. For multiple services, add them to theservicessection ofconfig.yamlin thecloud-initfile: -
Create the VM:
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
In the command, specify the subnet ID from Prerequisites and the ID of the service account you created earlier. -
Get the public IP address of the VM:
To connect from another VM in the same network, get the private IP address or FQDN instead.
- CLI
- Go SDK
- Python SDK
- JavaScript SDK
In the command, specify the name of the VM you created. -
Connect to the VM:
-
Verify that the agent registered with the tunnel:
To confirm that the agent registered with the tunnel, check the status of the service:
For live logs, run:If the agent doesn’t register, check the logs for these common causes:
- The VM has no service account attached.
systemctl statusstill showsactive (running), but the agent retries indefinitely, showingIMDS token request failed: 404 Not Foundfollowed byconnection closed before registering. You can’t attach a service account to an existing VM. Create a new one with--service-account-idinstead. - The attached service account doesn’t have the
applicationtunnel.agentrole. The agent authenticates, but the tunnel rejects the connection. Grant the role to the service account as described earlier in this guide.
Where:service_nameis theservices.namevalue from the agent configuration.tunnel_masked_IDis the mask of the tunnel ID without theapplicationtunnel-prefix and regional routing code. For example, forapplicationtunnel-e00abcdef123456789, the tunnel ID mask isabcdef123456789.regionis the region of the project where the tunnel was created, for exampleeu-north1.
- The VM has no service account attached.