Azure / Azure/azure-cli

az bastion ssh fails when missing read permissions on vm nic without throwing meaningful error

Open
#27,595 13 comments 4 reactions 0 assignees View on GitHub
act-quality-productivity-squad Auto-Resolve customer-reported Network - Bastion question Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

Whenever I try to access a virtual machine through `az bastion ssh`, it fails when I don't have read access to the nic without throwing a meaningful error:

```
Exception in thread Thread-1 (_start_tunnel):
Traceback (most recent call last):
File "threading.py", line 1016, in _bootstrap_inner
File "threading.py", line 953, in run
File "C:\Users\CarlintVeld\.azadmin\cliextensions\bastion\azext_bastion\custom.py", line 335, in _start_tunnel
tunnel_server.start_server()
File "C:\Users\CarlintVeld\.azadmin\cliextensions\bastion\azext_bastion\tunnel.py", line 194, in start_server
self._listen()
File "C:\Users\CarlintVeld\.azadmin\cliextensions\bastion\azext_bastion\tunnel.py", line 123, in _listen
auth_token = self._get_auth_token()
File "C:\Users\CarlintVeld\.azadmin\cliextensions\bastion\azext_bastion\tunnel.py", line 112, in _get_auth_token
self.last_token = response_json["authToken"]
KeyError: 'authToken'
```

### Related command

`az bastion ssh`

### Errors

See above.

### Issue script & Debug output

N/A

### Expected behavior

It should passthrough the error that is given back from the rest api, e.g.
```
(AuthorizationFailed) The client 'admin@suppressed' with object id 'suppressed' does not have authorization to perform action 'Microsoft.Network/networkInterfaces/read' over scope '/subscriptions/suppressed/resourceGroups/rg-myresourcegroup/providers/Microsoft.Network/networkInterfaces/nic-mynic' or the scope is invalid. If access was recently granted, please refresh your credentials.
Code: AuthorizationFailed
```

### Environment Summary

```json
{
"azure-cli": "2.52.0",
"azure-cli-core": "2.52.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"bastion": "0.2.5",
"resource-graph": "2.1.0",
"ssh": "2.0.1"
}
}
```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.