Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Tilde (~) not recognized in key file path #9

Open
Samyak2 opened this issue Sep 4, 2021 · 2 comments · May be fixed by #10
Open

Tilde (~) not recognized in key file path #9

Samyak2 opened this issue Sep 4, 2021 · 2 comments · May be fixed by #10
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@Samyak2
Copy link
Collaborator

Samyak2 commented Sep 4, 2021

The issue

Heiko allows a custom SSH private key to be used for auth, instead of the one generated by heiko. This can be set in the configuration as shown:
https://github.com/psiayn/heiko/blob/fb8b464ec2d4308fde9a4d6cfbcc2762d2851783/examples/sample-config.yml#L9

Generally, these keys are stored in ~/.ssh (which is $HOME/.ssh). Providing the path with the ~ (tilde) in it is not recognized by heiko, it exits with this error:

init: SSH Key ~/.ssh/somekey.pub for node somenode does not exist: stat ~/.ssh/somekey.pub: no such file or directory

The solution

When the paths are read on this line:
https://github.com/psiayn/heiko/blob/fb8b464ec2d4308fde9a4d6cfbcc2762d2851783/internal/config/sshSetup.go#L110-L112

If it starts with ~/, it must be expanded appropriately. Possible approaches for this are here and here.

@Samyak2 Samyak2 added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Sep 4, 2021
@u5surf
Copy link

u5surf commented Sep 5, 2021

@Samyak2
How about like this?

diff --git a/internal/config/sshSetup.go b/internal/config/sshSetup.go
index 2845b9d..83c2106 100644
--- a/internal/config/sshSetup.go
+++ b/internal/config/sshSetup.go
@@ -107,6 +107,9 @@ func SetAuth(configuration *Config) error {

                default:
                        // Set custom key if specified
+                        if strings.Contains(node.Auth.Keys.Path, "~") {
+                           strings.ReplaceAll(node.Auth.Keys.Path, "~", homePath)
+                        }
                        if node.Auth.Keys.Path != "" {
                                publicKeyPath = node.Auth.Keys.Path + ".pub"
                                privateKeyPath = node.Auth.Keys.Path

@Samyak2
Copy link
Collaborator Author

Samyak2 commented Sep 5, 2021

How about like this?

diff --git a/internal/config/sshSetup.go b/internal/config/sshSetup.go
index 2845b9d..83c2106 100644
--- a/internal/config/sshSetup.go
+++ b/internal/config/sshSetup.go
@@ -107,6 +107,9 @@ func SetAuth(configuration *Config) error {

                default:
                        // Set custom key if specified
+                        if strings.Contains(node.Auth.Keys.Path, "~") {
+                           strings.ReplaceAll(node.Auth.Keys.Path, "~", homePath)
+                        }
                        if node.Auth.Keys.Path != "" {
                                publicKeyPath = node.Auth.Keys.Path + ".pub"
                                privateKeyPath = node.Auth.Keys.Path

@u5surf I'm not sure if that will be valid in all cases. The tilde should only be recognized at the beginning of the path, as in ~/.ssh/key should become /home/user/.ssh/key. A tilde anywhere else in the path must not be replaced. /~somedir is a valid path and must not become //home/usersomedir.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants