Issues with Aptible CLI on Windows

Getting this error when attempting to tunnel into a database or view logs with the Aptible CLI:

  • Windows 10
  • Aptible Toolbelt v0.19.1
Tunnel did not come up: C:/aptible-toolbelt/embedded/lib/ruby/gems/2.3.0/gems/aptible-cli-0.19.1/lib/aptible/cli/helpers/tunnel.rb:46: warning: cannot close fd before spawn

Any advice on how to debug/resolve this issue?

Commands that utilize an SSH tunnel like aptible db:tunnel, aptible logs, and aptible ssh it use the ssh-keygen executable that comes bundled with the toolbelt to generate a SSH key for use with the tunnel. We believe the error you shared, warning: cannot close fd before spawn, as well as some others are caused by Windows blocking the bundled ssh-keygen executable from running.

You can test for this issue by running the following commands in the “Command Prompt” app:

mkdir "%HOMEPATH%\.aptible\ssh"
cd "%HOMEPATH%\.aptible\ssh"
C:\aptible-toolbelt\embedded\bin\ssh-keygen -t rsa -N "" -f id_rsa

The ssh-keygen command should output Generating public/private rsa key pair. along with some details about the key being generated. If the command does not output anything, then you should contact your system administrator for help determining why the executable is being blocked.

Unfortunately, we haven’t been unable to reproduce the issue ourselves so we do not know exactly what steps are necessary to resolve this issue. If you are able to resolve the issue please share what you did so that other users can benefit from your experience.

Hello – following up on this thread as I have the same exact issue. Have also spent hours trying to troubleshoot with no luck.

Are there any new updates or suggestions to try?

@joshraker - I even went through (successfully) steps you proposed above and still get same error.

Windows 11
Aptible toolbelt v0.19.6
Error code:
“Tunnel did not come up: C:/aptible-toolbelt/embedded/lib/ruby/gems/2.3.0/gems/aptible-cli-0.19.6/lib/aptible/cli/helpers/tunnel.rb:46: warning: cannot close fd before spawn”

I think this may be a problem with your public/private keypair. I am having the same issue. I opened up the file mentioned “C:/aptible-toolbelt/embedded/lib/ruby/gems/2.3.0/gems/aptible-cli-0.19.6/lib/aptible/cli/helpers/tunnel.rb” and navigated to line 46. It is ultimately opening up an ssh connection but failing to do so. I added a print statement for the command params as seen in the code below

          tunnel_cmd = @ssh_cmd + [
            '-L', "#{@local_port}:#{@socket_path}",
            '-o', 'ExitOnForwardFailure=yes'
          ]
          #print contents of tunnel_cmd
          print(tunnel_cmd)

          out_read, out_write = IO.pipe
          err_read, err_write = IO.pipe

          @pid = Process.spawn(@env, *tunnel_cmd, SPAWN_OPTS
            .merge(in: :close, out: out_write, err: err_write))

This gave me output similar to this:

["ssh", [dynamically-generated-user]@[system-generated-name]", "-p", "1022", "-i", "C:/Users/[my-username]/AppData/Local/Temp/d20230126-23620-o2mpt5/id_rsa", "-o", "IdentitiesOnly=yes", "-o", "UserKnownHostsFile=C:/Users/[my-username]/AppData/Local/Temp/d20230126-23620-zas3rk/known_hosts", "-o", "StrictHostKeyChecking=yes", "-T", "-o", "TCPKeepAlive=yes", "-o", "KeepAlive=yes", "-o", "ServerAliveInterval=60", "-o", "LogLevel=ERROR", "-o", "ControlMaster=no", "-o", "ControlPath=none", "-F", "C:\\Users\\cestel/.aptible/ssh/config", "-o", "SendEnv=ACCESS_TOKEN", "-L", "60699:/var/run/port-forward/c5ef3ca7-3ff1-4682-a46f-46cac336d530", "-o", "ExitOnForwardFailure=yes", "-vvv"]Tunnel did not come up: C:/aptible-toolbelt/embedded/lib/ruby/gems/2.3.0/gems/aptible-cli-0.19.6/lib/aptible/cli/helpers/tunnel.rb:47: warning: cannot close fd before spawn

From there, I was able to pull the components out and stitch together a standard ssh command. Substitute accordingly from the values above.

ssh [username-from-above]@[host-from-above] -p 1022 -i ~/.aptible/ssh/id_rsa -o IdentitiesOnly=yes -o SendEnv=ACCESS_TOKEN -L 57473:/var/run/port-forward/f53ddd86-1fc3-478f-b21d-290cbd02390c

You could be thorough and add every field, but the ones I used above should be good enough to find your issue.

The output when trying to connect with raw ssh was this below:

[user-from-above]@[host-from-above]: Permission denied (publickey).

I still have not been able to correct or connect. My public key was uploaded to my ssh keys section. I attempted to create a new key and upload that and was still unsuccessful in establishing a connection. I then attempted to delete my keys and re-upload them in aptible. It let me delete them but then was giving me a system error when trying to re-add them from the website. I assume I may have hit some sort of excess failure limit with my user or something and plan to wait it out and try again, but it definitely seems key related.

An issue with the key would make sense as the code appears to be failing to open the connection and is closing something that wasn’t open. Even though (at time of writing) I haven’t solved this, I think it’s likely the issue and hopefully helps. If anyone else wants to see how things work with a bad private key, I suspect you can use that to replicate the issue.

I was finally able to resolve my issue. I had been using the default ssh-keygen program that ships with ubuntu and also with git bash when attempting this in windows. I found no way to get it to work and was having constant key issues causing failure to establish the tunnel, and then in turn the result warning: cannot close fd before spawnerror.

I then used the ssh-keygen.exe file that ships with aptible-toolkit and the key was successful at allowing the connection. Running the below command from a windows command prompt and ensuring the private key was in the ~/.aptible/ssh directory and copying the public key to my key location in the aptible website worked for me.

C:\aptible-toolbelt\embedded\bin\ssh-keygen -t rsa -N "" -f id_rsa

I suspect this is an issue with the version of openssh that is being used, but as my issue is resolved I don’t plan to dig any further. Hope this helps.