paulo-raca / adb-proxy

Proxy to access android devices attached to a remote machine via ADB
61 stars 12 forks source link

Trying to use ngrok results in asyncssh.misc.PermissionDenied: Permission denied #3

Closed danielpaulus closed 1 year ago

danielpaulus commented 2 years ago

running poetry run adbproxy devicefarm --project="daniels-fun-project" --device-pool="mypool" --ngrok always fails with

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/danielpaulus/privaterepos/adb-proxy/adbproxy/main.py", line 121, in main
    return asyncio.run(main_async(), debug=True)
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/danielpaulus/privaterepos/adb-proxy/adbproxy/main.py", line 117, in main_async
    await use_tunnels(**args)
  File "/Users/danielpaulus/privaterepos/adb-proxy/adbproxy/adb_proxy.py", line 611, in use_tunnels
    async with asyncssh.connect(tunnel=ssh_client, **ssh_tunnels[0]) as ssh_client:
  File "/Users/danielpaulus/Library/Caches/pypoetry/virtualenvs/adbproxy-UCzCDHV7-py3.9/lib/python3.9/site-packages/asyncssh/misc.py", line 274, in __aenter__
    self._coro_result = await self._coro
  File "/Users/danielpaulus/Library/Caches/pypoetry/virtualenvs/adbproxy-UCzCDHV7-py3.9/lib/python3.9/site-packages/asyncssh/connection.py", line 7707, in connect
    return await asyncio.wait_for(
  File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
    return await fut
  File "/Users/danielpaulus/Library/Caches/pypoetry/virtualenvs/adbproxy-UCzCDHV7-py3.9/lib/python3.9/site-packages/asyncssh/connection.py", line 440, in _connect
    await options.waiter
asyncssh.misc.PermissionDenied: Permission denied

I set up my public key in ngrok and this one. ssh -R 443:localhost:80 tunnel.us.ngrok.com http works just fine.

paulo-raca commented 2 years ago

Weird, this works for me.

Is your private key in one of the default locations?

client_keys (see Specifying private keys) – (optional) A list of keys which will be used to authenticate this client via public key authentication. These keys will be used after trying keys from a PKCS11 provider or an ssh-agent, if either of those are configured. If no client keys are specified, an attempt will be made to load them from the files .ssh/id_ed25519_sk, .ssh/id_ecdsa_sk, .ssh/id_ed448, .ssh/id_ed25519, .ssh/id_ecdsa, .ssh/id_rsa, and .ssh/id_dsa in the user’s home directory, with optional certificates loaded from the files .ssh/id_ed25519_sk-cert.pub, .ssh/id_ecdsa_sk-cert.pub, .ssh/id_ed448-cert.pub, .ssh/id_ed25519-cert.pub, .ssh/id_ecdsa-cert.pub, .ssh/id_rsa-cert.pub, and .ssh/id_dsa-cert.pub. If this argument is explicitly set to None, client public key authentication will not be performed.

Also did it work before this weeks' changes? (Which shouldn't have affected this at all)

danielpaulus commented 2 years ago

It works on my Ubuntu box but my Macbook has problems. Not sure what the reason is.

danielpaulus commented 2 years ago
INFO:adb-proxy:Jumping through SSH proxy: :***@tunnel.us.ngrok.com:22
INFO:adb-proxy:Setting up ngrok for TCP
INFO:adb-proxy:ngrok:
INFO:adb-proxy:ngrok: ngrok (via SSH) (Ctrl+C to quit)
INFO:adb-proxy:ngrok:
INFO:adb-proxy:ngrok: Account     daniel@checklyhq.com (Plan: Free)
INFO:adb-proxy:ngrok: Region      us
INFO:adb-proxy:ngrok: Forwarding  tcp://4.tcp.ngrok.io:14542
INFO:adb-proxy:Listening for reverse connections: adb-proxy:***@4.tcp.ngrok.io:14542
INFO:DeviceFarm:Using project daniels-fun-project: arn:aws:devicefarm:us-west-2:692044953096:project:fd58c6d6-c02d-418a-b650-b9cef565ff35
INFO:DeviceFarm:Using device pool mypool: arn:aws:devicefarm:us-west-2:692044953096:devicepool:fd58c6d6-c02d-418a-b650-b9cef565ff35/2465046f-e89b-4bd9-91b8-31fb77293dbc
INFO:DeviceFarm:Uploaded dummy.apk (ANDROID_APP)
INFO:DeviceFarm:Uploaded dummy-test.apk (INSTRUMENTATION_TEST_PACKAGE)
INFO:DeviceFarm:Uploaded adb-proxy-testspec.yaml (INSTRUMENTATION_TEST_SPEC)
INFO:DeviceFarm:Job created: https://us-west-2.console.aws.amazon.com/devicefarm/home#/projects/fd58c6d6-c02d-418a-b650-b9cef565ff35/runs/266a0361-aca5-41c0-9e2f-e144e3a307f6
INFO:DeviceFarm:Job status changed to RUNNING
INFO:adb-proxy:Reverse connection received
INFO:adb-proxy:Connecting...
/home/ganjalf/publicrepos/adb-proxy/adbproxy/endpoint.py:13: RuntimeWarning: coroutine 'SSHClientConnection.run' was never awaited
Coroutine created at (most recent call last)
  File "<string>", line 1, in <module>
  File "/home/ganjalf/publicrepos/adb-proxy/adbproxy/main.py", line 121, in main
    return asyncio.run(main_async(), debug=True)
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
    self._run_once()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1851, in _run_once
    handle._run()
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/home/ganjalf/publicrepos/adb-proxy/adbproxy/adb_proxy.py", line 470, in connect_task
    await connect(ssh_client=ssh_client, **kwargs, **attach_opts)
  File "/home/ganjalf/publicrepos/adb-proxy/adbproxy/adb_proxy.py", line 420, in connect
    remote_endpoint = await Endpoint.of(device_adb_addr, ssh_client)
  File "/home/ganjalf/publicrepos/adb-proxy/adbproxy/endpoint.py", line 13, in of
    hostname = await ssh_client.run("hostname", stdin=asyncssh.DEVNULL, stderr=asyncssh.DEVNULL).stdout.strip() or None
  hostname = await ssh_client.run("hostname", stdin=asyncssh.DEVNULL, stderr=asyncssh.DEVNULL).stdout.strip() or None
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
INFO:adb-proxy:Connected to ADB server localhost:5037 @ ganjalf-IdeaPad-U430-Touch
INFO:adb-proxy:Connected to device R5CN20YGQ6L @ localhost (SM-G986U1)
INFO:adb-proxy:ADB Wrapper for R5CN20YGQ6L: SM-G986U1 disconnected!
INFO:adb-proxy:Reverse connection lost
INFO:DeviceFarm:Job status changed to COMPLETED
INFO:DeviceFarm:Deleted uploaded: dummy.apk (ANDROID_APP)
INFO:DeviceFarm:Deleted uploaded: dummy-test.apk (INSTRUMENTATION_TEST_PACKAGE)
INFO:DeviceFarm:Deleted uploaded: adb-proxy-testspec.yaml (INSTRUMENTATION_TEST_SPEC)

I got this error now on Linux. Does that make any sense to you?

paulo-raca commented 1 year ago

I just addressed this issue, should work now :)