Check for already configured ssh keys before using automatic key#5958
Check for already configured ssh keys before using automatic key#5958
Conversation
|
I haven't updated the tests yet because I wanted to get a general 👍 on this approach before diving into them. Will update them accordingly once things are decided. |
mislav
left a comment
There was a problem hiding this comment.
I think this is a worthwhile exploration! I would have some suggestions how to simplify the approach before this ships, but it's a bit premature at this stage to start reorganizing code around. Thanks for the code spike 🙇
|
@mislav I've updated the logic to just check for existing Does the approach look good? If so, I'll start putting actual polish on it. |
…cli/cli into cmbrose/no-auto-key-if-uploaded
josebalius
left a comment
There was a problem hiding this comment.
I'm a bit worried about the performance implications of this change. We tried to keep the SSH command as fast as possible, and this PR adds more cycles to this process. I wonder if we have alternatives?
@josebalius there are a couple ways that the api call to fetch known keys can be short circuited:
The issue is the case where there IS a matching public key locally and in dotcom. In that case there's not much we can do to cache that result (at least not that I'm aware of) and so the cli would always make the api check every time. It may be enough to just encourage users to stay out of this group - use the auto keys as the preferred option if they can and use One slight alternative is to create a new RPC call to the codespace to fetch authorized_keys directly instead of via the dotcom api. That may be slightly faster since codespaces are geo-located with the user (generally). However, it's still an api call and I'm not too convinced just looking at the theory though that the latency savings would warrant the engineering effort. @josebalius what do you think? |
My concern with one, is that in order to get the fast experience the user has to do something extra that they have not been doing until now, so we are changing the default experience. Granted perhaps this should have been the default experience and avoid some of the friction users often run into. If we find a |
@josebalius thats not really correct. With the proposal to skip the api check if the codespaces.auto key exists, then only the very first run of the ssh command would be slower. All subsequent runs would be fast as the key would have be generated in the first run. This change is explicitly to better support users who have policies on their machines that flag ssh keys without passphrases. Currently they are required to always use the -i flag in order to work around the automatic key generation. This change will remove the pain in the command line at the cost of the api call latency. That said, we could even recommend that those users manually create the codespaces.auto key themselves, just one time and they would also then skip the api latency. |
It is guaranteed that the connection authentication will work. It is however still possible that something else could be broken in the ssh connection, e.g. the code spec doesn't have ssh installed. |
Fair In that case, short circuiting if it exists:
sounds like a good idea. Only thing is what happens if for some reason user needs to re-gen, should we provide some way of "resetting" or regenerating the key? |
Is there a scenario where the user would need to do that? The That said, if they need to reset it, they can just delete it manually and either just run |
|
@josebalius thanks for all the feedback/discussion here! I've added the short circuit existence check, does this look OK now? |
josebalius
left a comment
There was a problem hiding this comment.
This is looking good, there's still a lot of code 🙈 that I'd probably want to take more time with and test some different things, but I trust you've got this working, and it works well ❤️
|
@josebalius I've outlined the validations I've run for this at the top, if there's anything you think I'm missing let me know! I did run into one issue I was hoping you could help with though, regarding The issue is that If you then use Losing the I'm not really sure how to move forward with this because I don't have enough context on how |
|
The resolution to the issue about |
Fixes: https://github.com/github/codespaces/issues/8154 (again)
An additional follow up to #5752 where users had issues with the password-less
codespaces.autokey being generated forgh cs ssh, even though they already had valid ssh keys configured.This PR will now check the ssh configuration to see which private keys ssh (or scp) will use and check if the user has a matching public key uploaded to GitHub. If so, it will skip creating the automatic key.
The configuration check is done using
ssh -G localhostwhich gives the effective configuration for the reallocalhostconnection the command will attempt to make later. It parses this configuration foridentityfilelines and uses these as the target private keys to search for in the public key set.Additionally, the PR improves the handling of
--profileand-- -Fparameters, where before we cautiously bailed out and did not generate keys, we now can use those parameters in thessh -Gcall to check if we should still generate auto keys with those parameters. This is useful for users ofgh ssh cs --configto ensure that they still get proper automatic keys. If the-- -iflag is provided, the command will continue to not generate automatic keys, this provides an escape hatch from the behavior if needed.Note: the
-Gflag is added inOpenSSH 6.8which released in 2015, so hopefully that is long enough ago to rely on 😄Verified cases:
codespaces.auto:codespaces.autoalready existscodespaces.autoalready exists and has a passphrase--configflow as documented in--helpcodespaces.autoexists-- -i <key>for key with/without passphrase--profilewhich specifies a custom key