Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Implement credential prompting using GIT_ASKPASS - #190

Merged
kuychaco merged 29 commits into
masterfrom
mkt-credential-helper
Nov 14, 2016
Merged

kuychaco merged 29 commits into
masterfrom
mkt-credential-helper

Conversation

@BinaryMuse

@BinaryMuse BinaryMuse commented Aug 11, 2016 •

Copy link
Copy Markdown
Contributor

Fixes #290
Fixes #191
Fixes #208

  • Move credential info to inherited environment variables
  • Make canceling kill Git process (make like hitting ctrl-C)
  • Refactor submit/cancel to be passed in
  • Add support for Windows (windows versions of scripts, named pipe)
  • mask sensitive inputs (start with masking all inputs?)
  • copy script to temp folder since git can't get it out of the asar file

This PR implements CredentialHelper (0f18c33) to facilitate prompting the user for Git credentials via the Atom UI.

fetch-credentials

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:

  1. If a Git command may request credentials, we create an instance of CredentialHelper
  2. CredentialHelper...
    1. starts a server listening on a socket in a temporary path and
    2. writes a small Node.js application (launched with Atom Helper) to the same folder
  3. Git is then launched with the GIT_ASKPASS environment 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 user
  4. When the Node.js program starts, it writes the question passed to it to the socket
  5. The server receives the question via the socket and prompts the user for input
  6. When the user submits data, the server writes it to the socket
  7. When the Node.js program reads the answer from the socket, it writes it to standard out and exits
  8. When the Git process exits, we clean up the socket server and the temporary folder

It 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:

credential-helper

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.


@maxbrunsfeld

Copy link
Copy Markdown
Contributor

👍 Great explanation. Seems like a pretty reasonable solution to me!

@joshaber

joshaber commented Aug 11, 2016 •

Copy link
Copy Markdown
Contributor

It makes me sad this is still necessary but otherwise seems pretty reasonable 👍

writes a small Node.js application (launched with Atom Helper) to the same folder

I'm curious why we'd do this, vs. bundling the helper in the Atom package.

@iolsen

iolsen commented Aug 11, 2016

Copy link
Copy Markdown

It seems convoluted

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.

@maxbrunsfeld

maxbrunsfeld commented Aug 11, 2016 •

Copy link
Copy Markdown
Contributor

vs. bundling the helper in the Atom package.

Yeah, that's the ticket.

@nathansobo

Copy link
Copy Markdown
Contributor

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.

@BinaryMuse

Copy link
Copy Markdown
Contributor Author

@joshaber @maxbrunsfeld

I'm curious why we'd do this, vs. bundling the helper in the Atom package

I prefer this but wasn't sure how to make it work. There are a couple things I ran into:

  1. GIT_ASKPASS (near as I can tell) only takes an executable; it can't pass arguments or set additional environment variables
  2. The shebang for a script can't contain spaces (so pointing directly to Atom Helper is out)

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.

@nathansobo

atom --package-handler='git.credential-collector'

Yeah the main thing here is GIT_ASKPASS (again, AFAICT) not taking command line arguments. We'd still have to have a script that calls this command. Though maybe not as bad as what we have here. :) Only concern would be speed (we already do communication over a socket when atom is run and another process is already running, right? And it's not always performant for some reason.)

@joshaber

Copy link
Copy Markdown
Contributor

GIT_ASKPASS (near as I can tell) only takes an executable; it can't pass arguments or set additional environment variables

Ugh, yeah, I forgot that 😢

Nice work finding a way 👍

@kuychaco

Copy link
Copy Markdown
Contributor

It still needs a considerable amount of UX polish, but the PR as-is demonstrates the idea well enough

@simurai for thoughts on UX polish :)

@maxbrunsfeld

maxbrunsfeld commented Aug 12, 2016 •

Copy link
Copy Markdown
Contributor

I prefer this but wasn't sure how to make it work. There are a couple things I ran into:

  1. GIT_ASKPASS (near as I can tell) only takes an executable; it can't pass arguments or set additional environment variables

@BinaryMuse I think that the GIT_ASKPASS program will inherit the environment of the parent git command. So it seems like you could do something like this:

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.js

ask-pass.js (bundled somewhere):

const net = require('net')
const sockPath = process.env.ATOM_CREDENTIAL_SOCKET_PATH
const socket = net.connect(sockPath, () => {
  // ...
})

@BinaryMuse

Copy link
Copy Markdown
Contributor Author

@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?

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

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.

@simurai

simurai commented Aug 14, 2016

Copy link
Copy Markdown
Contributor

@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" "$@"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
@kuychaco
kuychaco changed the base branch from ku-git-shell-out to master August 17, 2016 19:30
@BinaryMuse

Copy link
Copy Markdown
Contributor Author

@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.

@kuychaco kuychaco changed the title Add git fetch with credential prompting in Atom Implement credential prompting using GIT_ASKPASS Nov 5, 2016
@kuychaco
kuychaco force-pushed the mkt-credential-helper branch from 98a3f09 to 6acd398 Compare November 7, 2016 21:52
@kuychaco
kuychaco force-pushed the mkt-credential-helper branch from 4905262 to 179f5af Compare November 9, 2016 21:18
@@ -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" "$@"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@kuychaco
kuychaco merged commit d4277be into master Nov 14, 2016
@kuychaco
kuychaco deleted the mkt-credential-helper branch November 14, 2016 17:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants