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.
2
Answers
There was a missing set on the set up. So before creating the tunnel I had to set the subscription id to the account: az account set --subscription xxxx-xxx-xxxx-xxx-xxxxxx
The
authtoken
error comes when you do not set theauth_token
environment 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-token
bash 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 bastion
command.Reference blog by @Sensación Térmica for the same issue.