Skip to main content
To connect a service to a tunnel, configure and run a tunnel agent. You’ll need the tunnel ID in the agent configuration.

Prerequisites

  1. Install and configure the Nebius AI Cloud CLI.
  2. Make sure you are in a group that has the admin role within your tenant or project; for example, the default admins group. 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.
  3. Get the project ID and the tenant ID, and save them to environment variables:
  4. 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:
  5. 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 admin role 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

  1. Create a service account and save its ID:
    To grant wider access instead of creating a dedicated group with the applicationtunnel.agent role, you can add the service account to the editors group.
  2. Create a group for Nebius Tunnels service accounts and save its ID:
  3. Grant the group the applicationtunnel.agent role for the tunnel:
    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.
  4. Add the service account to the group:

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.
  1. Create a key pair:
    The command creates the private_key.pem and public_key.pem files in the current directory.
  2. Upload the public key and save its ID:

Running the agent in Docker

  1. Install Docker Engine.
  2. In the directory with the private_key.pem file, create config.yaml for 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.
    In the agent configuration, services.name can 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 the services section like this:
  3. 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_name is the services.name value from the agent configuration.
    • tunnel_masked_ID is the mask of the tunnel ID without the applicationtunnel- prefix and regional routing code. For example, for applicationtunnel-e00abcdef123456789, the tunnel ID mask is abcdef123456789.
    • region is the region of the project where the tunnel was created, for example eu-north1.

Running the agent by using Helm

  1. Install Helm.
  2. Create custom.values.yaml with 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.
    In the agent configuration, services.name can 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 the config.services section:
  3. 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_name is the services.name value from the agent configuration.
    • tunnel_masked_ID is the mask of the tunnel ID without the applicationtunnel- prefix and regional routing code. For example, for applicationtunnel-e00abcdef123456789, the tunnel ID mask is abcdef123456789.
    • region is the region of the project where the tunnel was created, for example eu-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.
  1. 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.yaml in 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.
    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 tunna system user.
    • Authenticate by using the service account attached to the VM, through the instance metadata service. No key files are involved.
    • Create the web Nebius Tunnels service that exposes 127.0.0.1:8080 on the VM.
    In the agent configuration, services.name can 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 the services section of config.yaml in the cloud-init file:
  2. Create the VM:
    In the command, specify the subnet ID from Prerequisites and the ID of the service account you created earlier.
  3. Get the public IP address of the VM:
    In the command, specify the name of the VM you created.
    To connect from another VM in the same network, get the private IP address or FQDN instead.
  4. Connect to the VM:
  5. 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 status still shows active (running), but the agent retries indefinitely, showing IMDS token request failed: 404 Not Found followed by connection closed before registering. You can’t attach a service account to an existing VM. Create a new one with --service-account-id instead.
    • The attached service account doesn’t have the applicationtunnel.agent role. The agent authenticates, but the tunnel rejects the connection. Grant the role to the service account as described earlier in this guide.
    In the log output, the agent reports the public endpoint for each service. The endpoint format is:
    Where:
    • service_name is the services.name value from the agent configuration.
    • tunnel_masked_ID is the mask of the tunnel ID without the applicationtunnel- prefix and regional routing code. For example, for applicationtunnel-e00abcdef123456789, the tunnel ID mask is abcdef123456789.
    • region is the region of the project where the tunnel was created, for example eu-north1.