Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
381 stars 1.2k forks source link

Using bastion extension v1.2.0 may cause tunnel creation to fail #8003

Open mhiro2 opened 2 hours ago

mhiro2 commented 2 hours ago

Describe the bug

When using the bastion extension version 1.2.0, I encountered an issue where tunnel creation fails.

$ az network bastion tunnel \
  --name MyBastionHost \
  --resource-group my-resource-group \
  --target-resource-id vmResourceId \
  --resource-port 22 \
  --port 50022
InvalidArgumentValue: Missing required field: -n

This issue did not occur in version 1.1.0 and 1.1.1.

Related command

az network bastion tunnel

Errors

InvalidArgumentValue: Missing required field: -n

Issue script & Debug output

cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x10330b560>, <function OutputProducer.on_global_arguments at 0x10366ca40>, <function CLIQuery.on_global_arguments at 0x10368e520>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'network': ['azure.cli.command_modules.network', 'azure.cli.command_modules.privatedns', 'azext_bastion']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: network                   0.231       117       355
cli.azure.cli.core: privatedns                0.005        14        60
cli.azure.cli.core: Total (2)                 0.236       131       415
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
cli.azure.cli.core: bastion                   0.002         2         9  /Users/mhiro2/.azure/cliextensions/bastion
cli.azure.cli.core: Total (1)                 0.002         2         9
cli.azure.cli.core: Loaded 131 groups, 424 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : network bastion tunnel
cli.azure.cli.core: Command table: network bastion tunnel
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x1048e63e0>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/Users/mhiro2/.azure/commands/2024-09-20.16-47-00.network_bastion_tunnel.17940.log'.
az_command_data_logger: command args: network bastion tunnel --name {} --resource-group {} --target-resource-id {} --resource-port {} --port {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x104917f60>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x10493b560>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x10493b6a0>, <function register_upcoming_breaking_change_info.<locals>.update_breaking_change_info at 0x10493b740>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x10366cae0>, <function CLIQuery.handle_query_parameter at 0x10368e5c0>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x10493b600>]
az_command_data_logger: extension name: bastion
az_command_data_logger: extension version: 1.2.0
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command_ctx.py", line 53, in format_args
    self.args._schema._fmt(ctx=self, value=self.args)
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_arg_fmt.py", line 415, in __call__
    raise AAZInvalidArgValueError(
azure.cli.core.aaz.exceptions.AAZInvalidArgValueError: InvalidArgumentValue: Missing required field: -n

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 733, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/mhiro2/.azure/cliextensions/bastion/azext_bastion/custom.py", line 420, in create_bastion_tunnel
    bastion = Show(cli_ctx=cmd.cli_ctx)(command_args={
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command.py", line 155, in __call__
    return self._handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mhiro2/.azure/cliextensions/bastion/azext_bastion/aaz/latest/network/bastion/_show.py", line 32, in _handler
    super()._handler(command_args)
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command.py", line 165, in _handler
    self.ctx.format_args()
  File "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command_ctx.py", line 55, in format_args
    raise InvalidArgumentValueError(str(err))
azure.cli.core.azclierror.InvalidArgumentValueError: InvalidArgumentValue: Missing required field: -n

cli.azure.cli.core.azclierror: InvalidArgumentValue: Missing required field: -n
az_command_data_logger: InvalidArgumentValue: Missing required field: -n
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x1048e6660>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 0.336 seconds (init: 0.074, invoke: 0.263)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 3970 in cache file under /Users/mhiro2/.azure/telemetry/20240920164700732
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/opt/homebrew/Cellar/azure-cli/2.64.0/libexec/bin/python /opt/homebrew/Cellar/azure-cli/2.64.0/libexec/lib/python3.11/site-packages/azure/cli/telemetry/__init__.py /Users/mhiro2/.azure /Users/mhiro2/.azure/telemetry/20240920164700732"
telemetry.process: Return from creating process 17963
telemetry.main: Finish creating telemetry upload process.

Expected behavior

Open a tunnel through Azure Bastion to a target virtual machine properly.

Environment Summary

{
  "azure-cli": "2.64.0",
  "azure-cli-core": "2.64.0",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {
    "bastion": "1.2.0"
  }
}

Additional context

If I downgrade the version of bastion extension to 1.1.0 or 1.1.1, I have confirmed that it works correctly.

az extension remove --name bastion
az extension add --name bastion --version 1.1.1

ref: https://github.com/Azure/azure-cli-extensions/blob/main/src/bastion/HISTORY.rst

yonzhan commented 2 hours ago

Thank you for opening this issue, we will look into it.

microsoft-github-policy-service[bot] commented 2 hours ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub.

microsoft-github-policy-service[bot] commented 2 hours ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @bastionsuppgithub.