Repository navigation
Implement credential prompting using GIT_ASKPASS - #190
Conversation
Signed-off-by: Katrina Uychaco <[email protected]>
Signed-off-by: Katrina Uychaco <[email protected]>
Signed-off-by: Katrina Uychaco <[email protected]>
Signed-off-by: Katrina Uychaco <[email protected]>
|
👍 Great explanation. Seems like a pretty reasonable solution to me! |
|
It makes me sad this is still necessary but otherwise seems pretty reasonable 👍
I'm curious why we'd do this, vs. bundling the helper in the Atom package. |
Amen, sister. But presumably this is the kind of (lesser?) evil we're choosing by shelling out to Git. I don't have any suggestions, merely a vague wishing this could be simpler. |
Yeah, that's the ticket. |
|
One thought... remember how we're thinking about adding a registry for URL handlers? I wonder if we could also add some kind of registry for command line flag handlers. Imagine if you could run something like this: atom --package-handler='git.credential-collector'That would just call Atom, which would forward the CLI arguments to a handler defined by your package. There is the pesky question of which window to run it in. Perhaps it could default to the focused window? Anyway, this is just an idea for another approach. |
I prefer this but wasn't sure how to make it work. There are a couple things I ran into:
That's why I had to create a simple launcher file that's run with the shell, which calls out to Electron to run the actual helper (which has the socket path hard coded in it). I guess the launcher script that gets written could pass the path to the socket file as the first argument and the question Git sends as the second, but we're still writing scripts to a temp folder.
Yeah the main thing here is |
Ugh, yeah, I forgot that 😢 Nice work finding a way 👍 |
@simurai for thoughts on UX polish :) |
@BinaryMuse I think that the git-shell-out-strategy.js: if (useCredentialManager) {
env.GIT_ASKPASS = '/path/to/bundled/ask-pass.sh'
env.ATOM_HELPER_PATH = this.getAtomHelperPath()
env.ATOM_CREDENTIAL_SOCKET_PATH = await this.listenForCredentials()
}ask-pass.sh (bundled somewhere): #!/bin/sh
ELECTRON_RUN_AS_NODE=1 \
ELECTRON_NO_ATTACH_CONSOLE=1 \
$ATOM_HELPER_PATH ./ask-pass.jsask-pass.js (bundled somewhere): const net = require('net')
const sockPath = process.env.ATOM_CREDENTIAL_SOCKET_PATH
const socket = net.connect(sockPath, () => {
// ...
}) |
|
@maxbrunsfeld I love that idea, and implemented it, but realized: will it work when the app is packaged in an asar? Will Git be able to access the launcher script? |
|
Yeah, we'll need to keep the launcher script outside of the asar archive. There are already some other files that are explicitly excluded from asar bundling. They are listed here. |
|
@BinaryMuse Adjusted the spacing, but haven't tested it. How do I get the modal to show up? I guess removing the git credentials from my keychain? |
| @@ -0,0 +1,2 @@ | |||
| #!/bin/sh | |||
| ELECTRON_RUN_AS_NODE=1 ELECTRON_NO_ATTACH_CONSOLE=1 "$ATOM_GITHUB_ELECTRON_PATH" "$ATOM_GITHUB_CREDENTIAL_HELPER_SCRIPT_PATH" "$ATOM_GITHUB_CREDENTIAL_HELPER_SOCK_PATH" "$@" | |||
There was a problem hiding this comment.
Since this script is just wrapping the electron call, it might be worth doing exec $ATOM_GITHUB_ELECTRON_PATH here, just to avoid unnecessarily forking and preserving the sh process.
Ignore failing credential helper test
|
@simurai Sorry, I just saw your comment! Yeah, if you remove the GH.com credentials from your keychain it'll prompt when you pull an HTTPS repo. |
git fetch with credential prompting in Atom98a3f09 to
6acd398
Compare
4905262 to
179f5af
Compare
| @@ -0,0 +1,2 @@ | |||
| #!/bin/sh | |||
| ELECTRON_RUN_AS_NODE=1 ELECTRON_NO_ATTACH_CONSOLE=1 "$ATOM_GITHUB_ELECTRON_PATH" "$ATOM_GITHUB_CREDENTIAL_HELPER_SCRIPT_PATH" "$ATOM_GITHUB_CREDENTIAL_HELPER_SOCK_PATH" "$@" | |||
There was a problem hiding this comment.
@damieng surprisingly this seems to be working on Windows. Any thoughts as to why/how? Should we write a Windows version or do you think it's okay to just merge this as is since it seems to be working?
There was a problem hiding this comment.
Are you sure Windows is even running this .sh file? If it is it must be via the Git Shell that's included in the package we download.
Have you tried this with private repos over https rather than ssh/git?
There was a problem hiding this comment.
Yup, it must be running the file in order for the prompt to be working within Atom. Just verified that it works with private repos as well as public over https.
Fixes #290
Fixes #191
Fixes #208
This PR implements
CredentialHelper(0f18c33) to facilitate prompting the user for Git credentials via the Atom UI.It still needs a considerable amount of UX polish, but the PR as-is demonstrates the idea well enough, and I'd like to get some 👀 on it early to determine if I'm completely off my rocker or not.
From a high level, here's how it works:
CredentialHelperCredentialHelper...Atom Helper) to the same folderGIT_ASKPASSenvironment variable pointing to the Node.js script in the temporary folder; Git launches this program, passing in an input prompt as the first argument, if it needs input from the userIt seems convoluted, but I can't think of another way to go about getting input interactively. Also maybe worth noting that this class could also potentially be used as a general purpose get-input-from-outside-Atom mechanism:
Perhaps not useful now, but maybe one day.
Another new class,
AsyncQueue(e6be1d4), facilitated a refactoring (5161217) to clean things up./cc @kuychaco, @atom/core for 💭, and @joshaber in case there's anything here you think I could be doing differently.