aws-iot-device-client: Unable to connect via secure tunnel when using authorized_keys and keyfile instead of password auth
Describe the bug
I’ve got a repo at https://github.com/Trellis-Logic/meta-aws-iot-demo which leverages the meta-aws layer for demonstrating secure tunneling and jobs features with AWS IoT on Yocto Poky distribution (currently using the kirkstone branch).
Everything works great with SSH connection through the procedure described at https://github.com/Trellis-Logic/meta-aws-iot-demo/wiki/Creating-a-Secure-Tunnel as long as I use username/password authentication.
When I attempt to switch to private key authentication and authorized_keys I am unable to connect to the device through the secure tunnel. I’m able to connect with the same private key over the local network without issue.
To Reproduce
- Start with https://github.com/Trellis-Logic/meta-aws-iot-demo and a raspberry pi target.
- Create a key pair using
ssh-keygenand no password. I’ve tried-t rsa-sha2-512,-t rsa-sha2-256or-t ed25519. - Copy the .pub key to
/home/root/.ssh/authorized_keys - Verify
ssh -i <private key> root@ipcan connect successfully. - Attempt to use the private key with Secure Tunneling and steps in https://github.com/Trellis-Logic/meta-aws-iot-demo/wiki/Creating-a-Secure-Tunnel instead of username and password authentication.
Expected behavior
I’m able to login with either password or private key authentication.
Actual behavior
The attempt to login with private key authentication fails with message “Failed to authenticate. Try again”
Logs
With verbose logging enabled in sshd (DEBUG3), I see this when I successfully login with the ssh key (over local network)
Apr 24 04:34:24 raspberrypi4-64 auth.info sshd[1854]: Accepted key RSA SHA256:KFmgrZ/JVrQAnUKqKXAZdSwcOupeMEYBN3a0aLo0F0E found at /home/root/.ssh/authorized_keys:1
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug2: check_authkeys_file: /home/root/.ssh/authorized_keys: processed 1/1 lines
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug1: restore_uid: 0/0
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_answer_keyallowed: publickey authentication: RSA key is allowed
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_send: entering, type 23
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_sshkey_verify: entering [preauth]
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_send: entering, type 24 [preauth]
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_sshkey_verify: waiting for MONITOR_ANS_KEYVERIFY [preauth]
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_receive_expect: entering, type 25 [preauth]
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_receive: entering [preauth]
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_receive: entering
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: monitor_read: checking request 24
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_answer_keyverify: publickey RSA signature using rsa-sha2-512 verified
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug1: auth_activate_options: setting new authentication options
Apr 24 04:34:24 raspberrypi4-64 auth.debug sshd[1854]: debug3: mm_request_send: entering, type 25
Apr 24 04:34:24 raspberrypi4-64 auth.info sshd[1854]: Accepted publickey for root from 192.168.99.22 port 25994 ssh2: RSA SHA256:KFmgrZ/JVrQAnUKqKXAZdSwcOupeMEYBN3a0aLo0F0E
And I see this on the failure case when using AWS Secure Tunnel with the same private key
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: trying public key file /home/root/.ssh/authorized_keys
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: fd 5 clearing O_NONBLOCK
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: /home/root/.ssh/authorized_keys:1: matching key found: RSA SHA256:KFmgrZ/JVrQAnUKqKXAZdSwcOupeMEYBN3a0aLo0F0E
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: /home/root/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Apr 24 04:24:27 raspberrypi4-64 auth.info sshd[1673]: Accepted key RSA SHA256:KFmgrZ/JVrQAnUKqKXAZdSwcOupeMEYBN3a0aLo0F0E found at /home/root/.ssh/authorized_keys:1
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug2: check_authkeys_file: /home/root/.ssh/authorized_keys: processed 1/1 lines
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: restore_uid: 0/0
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_answer_keyallowed: publickey authentication: RSA key is allowed
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_send: entering, type 23
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_sshkey_verify: entering [preauth]
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_send: entering, type 24 [preauth]
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_sshkey_verify: waiting for MONITOR_ANS_KEYVERIFY [preauth]
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_receive_expect: entering, type 25 [preauth]
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_receive: entering [preauth]
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_receive: entering
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: monitor_read: checking request 24
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_answer_keyverify: publickey RSA signature using rsa-sha2-512 unverified: error in libcrypto
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug1: auth_activate_options: setting new authentication options
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_request_send: entering, type 25
Apr 24 04:24:27 raspberrypi4-64 auth.info sshd[1673]: Failed publickey for root from 127.0.0.1 port 34720 ssh2: RSA SHA256:KFmgrZ/JVrQAnUKqKXAZdSwcOupeMEYBN3a0aLo0F0E
Difference appears to be:
Apr 24 04:24:27 raspberrypi4-64 auth.debug sshd[1673]: debug3: mm_answer_keyverify: publickey RSA signature using rsa-sha2-512 unverified: error in libcrypto
Environment (please complete the following information):
- OS: Yocto poky (https://github.com/Trellis-Logic/meta-aws-iot-demo)
- Version kirkstone
- Architecture: raspberrypi4-64 (same issue with RPI3)
- Device Client commit: https://github.com/awslabs/aws-iot-device-client/commit/cf761074367fa50b80b1e8a5c1efb4599ce2a85e (from this line)
Thanks for reviewing!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (11 by maintainers)
@HarshGandhi-AWS thanks for the response. I’ll try to reproduce a successful connection to an AWS image using the same setup and compare logs. It looks like this configuration is very similar to the
kirkstoneconfiguration I have above.OK thanks.
Yes I’m doing this, however it’s not a suitable solution for production deployment.
You should also be able to reproduce if you build an image using https://github.com/Trellis-Logic/meta-aws-iot-demo/?tab=readme-ov-file#host-dependencies for RPI 3 or 4.
Sure. We will work on updating the documentation. Thank you for confirming the fix is working for you. cc: @ig15
@HarshGandhi-AWS
Hi, indeed RSA PEM is working, but shall we update documentation to reflect current state? Currently it says:
While I believe
ssh-keygengenerates open ssh key and it doesn’t work.Hi @HarshGandhi-AWS thanks I can confirm this fixes the issue.
I can also continue to use my existing key after converting to pem with
Hello @dwalkes , upon speaking with console team we found that only PEM formatted (256 & 512) RSA keys are working with IoT Secure Tunneling console. Can you create the key in PEM format and retry?
@RogerZhongAWS thanks that helps, I can confirm I’m able to use this command to start the proxy:
and then from the same host, I can use this command to reach the remote client
So this is in fact a workaround for me until the web console is fixed.
@HarshGandhi-AWS
I wasn’t able to get this to work either, as described at https://github.com/awslabs/aws-iot-device-client/issues/455#issuecomment-2167209111 - if you have further details about how you were able to make this work please share.
Hello @dwalkes , we were able to reproduce this issue locally. We suspect the issue is not the the device client itself but is on the web based secure tunneling which you were using to connect to the tunnel as a source. We are currently working with the console team to resolve this issue. Meanwhile if you want to connect to the device using private key you can use Local Proxy on your source device to connect to the tunnel. Team already tested it and it works fine when trying to connect as source using a device private key.