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

Add support for ssh-agent #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

yuguorui
Copy link

@yuguorui yuguorui commented Dec 2, 2023

Add support for ssh-agent, which can simplify the use of encrypted private keys. As you can load encrypted private keys to ssh-agent to facilitate the sshtunnel.

@dsnet
Copy link
Owner

dsnet commented Dec 4, 2023

Hi, thanks for the PR. I'm open to the change, but using environment variables is a distinct change from the fact that everything else is configured through a JSON configuration file. We should be consistent in specifying agent information in the configuration file as well.

@yuguorui
Copy link
Author

yuguorui commented Dec 5, 2023

Hi~ I re-adjusted the code logic to respect the user's configuration in json. When the user does not configure it, the environment variables are read by default and the actual effective values are printed in the log.

2023/12/05 20:13:44 main.go:179: loaded config:
{
        "SshAgentSocket": "/run/user/1000/keyring/ssh",
        "KeyFiles": null,
        "KnownHostFiles": [
                "/home/yuguorui/.ssh/known_hosts"
        ],
        "KeepAlive": {
                "Interval": 30,
                "CountMax": 2
        },
        "Tunnels": [
                {
                        "Tunnel": "127.0.0.1:8899 -> 127.0.0.1:8899",
                        "Server": "[email protected]:22"
                }
        ],
        "BinarySHA256": "f9554279606e0177ea88ce836a373025dfb8e19b478b25c578a6199b10c71356"
}
2023/12/05 20:13:44 main.go:314: sshtunnel starting

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated
@@ -137,6 +155,10 @@ func loadConfig(conf string) (tunns []tunnel, logger *log.Logger, closer func()
if err := json.Unmarshal(c, &config); err != nil {
logger.Fatalf("unable to decode config: %v", err)
}
if config.SshAgentSocket == "" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not comfortable adding environment variable support and unless we're going to do it for all the configuration parameters. Consistency is a property I find valuable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is the only point I'd like to discuss.

Consistency is indeed crucial, but the Unix socket file provided by ssh-agent typically resides in a temporary directory, which makes it challenging to hardcode in a json file. As part of usability, I would like to update the README.md to make it more informative.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@yuguorui yuguorui force-pushed the master branch 3 times, most recently from c1e9af1 to d5dff8d Compare December 7, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants