I am trying locally to connect to a database. using:
az network bastion tunnel --name name --resource-group group --target-resource-id subscriptionid --resource-port 22 --port 2222 --subscription subscription
The tunnel is successfully created: Opening tunnel on port: 2222 Tunnel is ready, connect on port 2222
But when I try the connection via SSH:
Exception in thread Thread-1 (_start_tunnel):
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "/Users/user/.azure/cliextensions/bastion/azext_bastion/custom.py", line 364, in _start_tunnel
tunnel_server.start_server()
File "/Users/user/.azure/cliextensions/bastion/azext_bastion/tunnel.py", line 195, in start_server
self._listen()
File "/Users/user/.azure/cliextensions/bastion/azext_bastion/tunnel.py", line 123, in _listen
auth_token = self._get_auth_token()
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/.azure/cliextensions/bastion/azext_bastion/tunnel.py", line 112, in _get_auth_token
self.last_token = response_json["authToken"]
~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'authToken'
I have the versions up to date.
The
authtokenerror comes when you do not set theauth_tokenenvironment variable before opening a network tunnel in Azure cloud shell.Set auth_token as an environment variable:
Generate an authorization token with
az account get-access-tokenbash command and export it as shown below.Check if the network bastion is existed under your connected subscription with the below command.
Now execute the tunnel command to connect to it with Azure bash command as detailed below.
I tried in my environment, and it was connected successfully with the given port.
Note:
az extension update -n bastioncommand.Reference blog by @Sensación Térmica for the same issue.