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

Terraform provisioner connection - support for OpenSSH agent on Windows #35608

Open
jexnator opened this issue Aug 17, 2024 · 2 comments
Open

Comments

@jexnator
Copy link

jexnator commented Aug 17, 2024

Terraform Version

Terraform v1.9.4

Use Cases

Terraform's Provisioner Connection block on Windows currently only supports Pageant (PuTTY's SSH agent) for SSH agent forwarding using remote-exec. However, with the further development of OpenSSH as by default pre-installed SSH tool on Windows 10/11, it would be a nice-to-have to support the OpenSSH SSH agent in addition to Pageant.

Background

I've created a small automation tool to help admins keep the hosting environment for WordPress on AWS Lightsail up to date. More information can be found in this GitHub repository.

The tool currently works perfectly on Unix-based systems (I use macOS) with SSH-agent forwarding via OpenSSH. It would be great if Windows users could also utilize the tool without having to adapt the setup specifically to Pageant.

Attempted Solutions

  1. Manual SSH Command via PowerShell (Successful):

    When running the following sequence in PowerShell on Windows, SSH agent forwarding with OpenSSH works as expected:

    # Add the key to the OpenSSH SSH agent
    ssh-add C://path/to/key
    
    # Connect to Host A
    ssh -A bitnami@<host_A_ip>
    
    # From Host A, connect to Host B and export the wordpress database for migration
    ssh -A bitnami@<host_B_ip> "cd /opt/bitnami/wordpress && sudo wp --allow-root db export --quiet /tmp/exported-wp-sql.sql > /dev/null"

    This process succeeds using OpenSSH (v9.5.0.0) in PowerShell (v7.4.4).

  2. Remote Provisioner in Terraform (Failure):

    When attempting the same with Terraform's remote-exec provisioner, it fails as only Pageant is supported:

    # Add the key to the OpenSSH SSH agent
    ssh-add C://path/to/key
    resource "null_resource" "example" {
      connection {
        type        = "ssh"
        user        = "bitnami"
        private_key = file("C://path/to/key")
        host        = var.host_A_ip
        agent       = true # Pageant
      }
    
      provisioner "remote-exec" {
        inline = [
          "ssh -A bitnami@<host_B_ip> 'cd /opt/bitnami/wordpress && sudo wp --allow-root db export --quiet /tmp/exported-wp-sql.sql > /dev/null'"
        ]
      }
    }

    Error Output:

    null_resource.remote_exec: Error: permission denied (publickey)
    

Proposal

Allow Terraform on Windows to support OpenSSH as an SSH agent, similar to how it functions on Unix-based systems. This would remove the dependency on Pageant and and would provide a uniform approach across operating systems.

Example:

connection {
    type        = "ssh"
    user        = "bitnami"
    private_key = file("C://path/to/key")
    host        = var.host_A_ip
    agent       = true # Support OpenSSH agent in addition to Pageant.
  }

References

N/A

@jexnator jexnator added enhancement new new issue not yet triaged labels Aug 17, 2024
@jexnator jexnator changed the title Support for OpenSSH Agent in Terraform Provisioner Connection on Windows Terraform provisioner connection - support for OpenSSH agent on Windows Aug 19, 2024
@jbardin
Copy link
Member

jbardin commented Aug 19, 2024

Hi @jexnator,

Thanks for filing the issue! I think this is a result of how the upstream github.com/xanzy/ssh-agent sets up a connection to pageant. While the windows usage of the OpenSSH agent is a little more in line with the standard implementation, it may still not be directly accessible via the usual methods (golang/go#61383).

@jbardin jbardin added provisioner/remote-exec and removed new new issue not yet triaged labels Aug 19, 2024
@crw crw added the upstream label Aug 19, 2024
@crw
Copy link
Collaborator

crw commented Aug 19, 2024

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions.

Please note that provisioners are effectively deprecated, however upvoting issues such as this can help make a case for working on it. Thanks again!

jexnator added a commit to jexnator/wordpress-bitnami-lightsail-patch-migrate-update that referenced this issue Aug 20, 2024
…eployment due to restrictions related to SSH agent forwarding with remote-exec provisioners. See hashicorp/terraform#35608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants