Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

az ssh exit code always 0, even if subcommand fails #6831

Open
pwandl opened this issue Oct 4, 2023 · 3 comments
Open

az ssh exit code always 0, even if subcommand fails #6831

pwandl opened this issue Oct 4, 2023 · 3 comments
Assignees
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. VM SSH

Comments

@pwandl
Copy link

pwandl commented Oct 4, 2023

Describe the bug

When using az ssh vm, the exit code is always 0, even if ssh command itself failed. When using openssh, the exit code of the ssh process returns the exit code of the executed command, but when using az ssh, the exit code is ignored, which makes it hard to determined whether the command was executed successfully.

Related command

az ssh vm

Errors

No actual error, but exit code is wrongly set to 0

[pwandl@fedora ~]$ az ssh vm -n some-vm -g some-group "exit 1"
OpenSSH_9.0p1, OpenSSL 3.0.9 30 May 2023
Transferred: sent 5540, received 4636 bytes, in 0.7 seconds
Bytes per second: sent 7414.5, received 6204.6
[pwandl@fedora ~]$ echo $?
0

Issue script & Debug output

az ssh vm --debug -n some-vm -g some-group "exit 1"

[...]
OpenSSH_9.0p1, OpenSSL 3.0.9 30 May 2023
[..]
debug1: Sending command: exit 1
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i0 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: chan_shutdown_read: channel 0: (i0 o3 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 io 0x00/0x00)

debug3: send packet: type 1
Transferred: sent 5540, received 4636 bytes, in 0.7 seconds
Bytes per second: sent 7602.6, received 6362.0
debug1: Exit status 1
cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x7f4b46483240>, <function _x509_from_base64_to_hex_transform at 0x7f4b464832e0>]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.cli: Event: Cli.SuccessfulExecute []
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f4b46799940>]
az_command_data_logger: exit code: 0
cli.__main__: Command ran in 4.526 seconds (init: 0.173, invoke: 4.353)
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 4444 in cache
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/usr/bin/python3 /home/pwandl/.local/lib/python3.11/site-packages/azure/cli/telemetry/__init__.py /home/pwandl/.azure"
telemetry.process: Return from creating process
telemetry.main: Finish creating telemetry upload process.

Expected behavior

The exit code should match the exit code of the subcommand, similar when using ssh like this:

[pwandl@fedora ~]$ ssh -F devconf some-host "exit 1"
[pwandl@fedora ~]$ echo $?
1

Environment Summary

azure-cli 2.51.0 *

core 2.51.0 *
telemetry 1.1.0

Extensions:
containerapp 0.3.37
front-door 1.0.17
interactive 0.5.3
ssh 2.0.1

Dependencies:
msal 1.24.0b1
azure-mgmt-resource 23.1.0b2

Additional context

No response

@pwandl pwandl added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Oct 4, 2023
@yonzhan
Copy link
Collaborator

yonzhan commented Oct 4, 2023

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

@microsoft-github-policy-service microsoft-github-policy-service bot added question The issue doesn't require a change to the product in order to be resolved. Most issues start as that customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot VM SSH Service Attention This issue is responsible by Azure service team. labels Oct 4, 2023
@yonzhan yonzhan removed the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Oct 4, 2023
@techmantel
Copy link

Any updates on this?
Facing the same problem when building a script executing this command that I expected to get an exit code from if the az ssh arc... command fails to connect to the Arc machine.

@tomi
Copy link

tomi commented Aug 28, 2024

Would love to see this getting fixed. I believe it would be expected behavior to propagate the exit code from the ssh command to az cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. VM SSH
Projects
None yet
Development

No branches or pull requests

5 participants