manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.42k stars 205 forks source link

Enhance SSH Key Handling: support use of specified SSH private key #822

Closed nohzafk closed 9 months ago

nohzafk commented 9 months ago

This change

Rectify the misuse of the name ssh_pub_key

Issue: The original code utilized a function named ssh_pub_key that misleadingly suggested it use a public SSH key to login SSH remote server. However, it is the private SSH key that are used for paramiko connection. This wrong naming could lead to confusion and potential misuse in the future.

You can look at the documentation https://docs.paramiko.org/en/latest/api/client.html#paramiko.client.SSHClient.connect

key_filename (str) – the filename, or list of filenames, of optional private key(s) and/or certs to try for authentication

look_for_keys (bool) – set to False to disable searching for discoverable private key files in ~/.ssh/

why it works even using the wrong file (SSH public key)?

because look_for_keys is default to True, and paramiko will search for the default private key files in ~/.ssh

Resolution: Renamed ssh_pub_key to ssh_private_key. This change aligns the function name with its actual purpose, improving code readability and maintainability.

Introduction an new option lsp-bridge-user-ssh-private-key

Enhancement: Added the capability for users to explicitly specify the path to their SSH private key through a new configuration variable, lsp-bridge-user-ssh-private-key.

Benefit: This change empowers users with custom SSH configurations or multiple SSH keys to precisely define which key should be used for SSH connections. It significantly increases the flexibility and adaptability of the LSP Bridge to various user environments.

This option is necessary and useful when using dynamically generated SSH key pair to connect to a remote ssh server in a docker/container setting.

conditional look_for_keys handling

When the lsp-bridge-user-ssh-private-key is set, look_for_keys is explicitly set to False to ensure that Paramiko uses the user-specified key instead of searching for keys in the default ~/.ssh directory.

This adjustment ensures that the SSH connection uses the correct private key as defined by the user, thereby enhancing the security and reliability of the SSH connection.

manateelazycat commented 9 months ago

@werhner can you help to review this pr? thanks