send-email: Defines smtpPassCmd config option
PATCH 1/1 send-email: Defines smtpPassCmd config option
Defines smtpPassCmd config option, to allow the user to pass a command that is used to output the password.
Its useful for users that store the password encrypted on disk, and want a easy way to send-email without typing it again.
--- Documentation/config/sendemail.txt | 1 + Documentation/git-send-email.txt | 5 +++-- git-send-email.perl | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)
Documentation/config/sendemail.txt +1 -0
@@ -34,6 +34,7 @@ sendemail.from:: sendemail.multiEdit:: sendemail.signedoffbycc:: sendemail.smtpPass:: +sendemail.smtpPassCmd:: sendemail.suppresscc:: sendemail.suppressFrom:: sendemail.to::
Documentation/git-send-email.txt +3 -2
@@ -203,8 +203,9 @@ independently of `--smtp-user` Furthermore, passwords need not be specified in configuration files or on the command line. If a username has been specified (with `--smtp-user` or a `sendemail.smtpUser`), but no password has been -specified (with `--smtp-pass` or `sendemail.smtpPass`), then -a password is obtained using 'git-credential'. +specified (with `--smtp-pass` or `sendemail.smtpPass`, or as an output +of `sendemail.smtpPassCmd`), then a password is obtained using +'git-credential'. --no-smtp-auth:: Disable SMTP authentication. Short hand for `--smtp-auth=none`
git-send-email.perl +11 -0
@@ -170,6 +170,7 @@ sub format_2822_time { my $smtp; my $auth; my $num_sent = 0; +my $smtp_authpass_cmd; # Regexes for RFC 2047 productions. my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -271,6 +272,7 @@ sub do_edit { "smtpserveroption" => \@smtp_server_options, "smtpuser" => \$smtp_authuser, "smtppass" => \$smtp_authpass, + "smtppasscmd" => \$smtp_authpass_cmd, "smtpdomain" => \$smtp_domain, "smtpauth" => \$smtp_auth, "smtpbatchsize" => \$batch_size,
@@ -1303,6 +1305,15 @@ sub smtp_auth_maybe { die "invalid smtp auth: '${smtp_auth}'"; } + # Check password command if password was not provided. + if(!defined $smtp_authpass && defined $smtp_authpass_cmd){ + open my $pass, "$smtp_authpass_cmd |" + or die sprintf(__("Could not execute '%s'"), $smtp_authpass_cmd); + #Cut newline char + $smtp_authpass = substr <$pass>, 0, -1; + close($pass); + } + # TODO: Authentication may fail not because credentials were # invalid but due to other reasons, in which we should not # reject credentials.
Signature · 1 line
2.25.4
Documentation/git-send-email.txt independently of `--smtp-user` · line 208
Quoted 13 lines · Leonardo Bras
Documentation/git-send-email.txt +3
-2@@ -203,8 +203,9 @@ independently of `--smtp-user` Furthermore, passwords need not be specified in configuration files or on the command line. If a username has been specified (with `--smtp-user` or a `sendemail.smtpUser`), but no password has been -specified (with `--smtp-pass` or `sendemail.smtpPass`), then -a password is obtained using 'git-credential'. +specified (with `--smtp-pass` or `sendemail.smtpPass`, or as an output +of `sendemail.smtpPassCmd`), then a password is obtained using +'git-credential'.
this last part on git credential is just undocumented, since it is already doing so since 4d31a44a08 (git-send-email: use git credential to obtain password, 2013-02-12)
and of course, assuming you use a credential helper that keeps the password encrypted you could use that instead of this new feature.
having said that, this looks like a good alternative, but might need to make sure if die makes sense below or would be better to see if you can still get a password through git credential even if that fails.
maybe the rule of what to do might even need some configuration itself.
Carlo
Quoted 9 lines · Carlo Marcelo Arenas Belón
Quoted 2 lines
+of
sendemail.smtpPassCmd), then a password is obtained using +'git-credential'.this last part on git credential is just undocumented, since it is already doing so since
4d31a44a08(git-send-email: use git credential to obtain password, 2013-02-12)and of course, assuming you use a credential helper that keeps the password encrypted you could use that instead of this new feature.
Up to this point I understand your response.
Documenting that "git send-email" can use "git credential" for its password store, if it is not already documented, is of course a good change.
But I am not sure why this is "a good alternative". Having more choices that do not offer anything substantially different is a bad thing. Is this "new mechanism" better in what way? Simpler to use? Faster? Less error prone? Something else?
Thanks.
Quoted 7 lines
having said that, this looks like a good alternative, but might need to make sure if die makes sense below or would be better to see if you can still get a password through git credential even if that fails.
maybe the rule of what to do might even need some configuration itself.
Carlo
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Carlo Marcelo Arenas Belón
Quoted 2 lines
+of
sendemail.smtpPassCmd), then a password is obtained using +'git-credential'.this last part on git credential is just undocumented, since it is already doing so since
4d31a44a08(git-send-email: use git credential to obtain password, 2013-02-12)
Quoted 8 lines
Quoted 2 lines
and of course, assuming you use a credential helper that keeps the password encrypted you could use that instead of this new feature.
Up to this point I understand your response.
Documenting that "git send-email" can use "git credential" for its password store, if it is not already documented, is of course a good change.
I agree completely.
Quoted 4 lines
But I am not sure why this is "a good alternative". Having more choices that do not offer anything substantially different is a bad thing. Is this "new mechanism" better in what way? Simpler to use? Faster? Less error prone? Something else?
Ditto. I don't think that an increased surface-area of possibilities to specify your password to 'git send-email' is useful. Put another way:
why *not* use the in-built credential helper, which is already supported?
Would having it documented eliminate some rationale for invoking a separate program?
Quoted 9 lines
Thanks.
Quoted 7 lines
having said that, this looks like a good alternative, but might need to make sure if die makes sense below or would be better to see if you can still get a password through git credential even if that fails.
maybe the rule of what to do might even need some configuration itself.
Carlo
Thanks,
Taylor
Quoted 6 lines · Taylor Blau
Quoted 3 lines · Junio C Hamano
Documenting that "git send-email" can use "git credential" for its password store, if it is not already documented, is of course a good change.
I agree completely.
I also concur.
Quoted 5 lines
Quoted 4 lines
But I am not sure why this is "a good alternative". Having more choices that do not offer anything substantially different is a bad thing. Is this "new mechanism" better in what way? Simpler to use? Faster? Less error prone? Something else?
Quoted 7 lines
Ditto. I don't think that an increased surface-area of possibilities to specify your password to 'git send-email' is useful. Put another way:
why *not* use the in-built credential helper, which is already supported?Would having it documented eliminate some rationale for invoking a separate program?
I think perhaps many folks aren't aware that you can invoke Git with an arbitrary shell command as "credential.helper", which of course makes life a lot easier. So if you want to invoke a separate command, it's really as easy as this:
git config credential.smtp://smtp.crustytoothpaste.net.helper \
'!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'So I think that documenting the use of the credential helper is step 1, because probably most people _do_ want to use that for their passwords, and then documenting that credential helpers can be arbitrary shell commands that speak the protocol is step 2, so that people who don't can figure out a way to do what they want.
I'll send some patches later which document the latter feature, since I don't think we mention it anywhere outside of the FAQ. I actually didn't know about it until Peff mentioned it to me one time.
Signature · 2 lines
brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204
Quoted 14 lines · brian m. carlson
I think perhaps many folks aren't aware that you can invoke Git with an arbitrary shell command as "credential.helper", which of course makes life a lot easier. So if you want to invoke a separate command, it's really as easy as this:
git config credential.smtp://smtp.crustytoothpaste.net.helper \ '!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'So I think that documenting the use of the credential helper is step 1, because probably most people _do_ want to use that for their passwords, and then documenting that credential helpers can be arbitrary shell commands that speak the protocol is step 2, so that people who don't can figure out a way to do what they want.
Quoted 3 lines
I'll send some patches later which document the latter feature, since I don't think we mention it anywhere outside of the FAQ. I actually didn't know about it until Peff mentioned it to me one time.
This is documented, but only recently did it make it out of Documentation/technical/ and into gitcredentials(7). I don't mind adding more pointers, though.
It's also being discussed in this thread:
https://lore.kernel.org/git/[email protected]/
about how deep into the rabbit-hole we want to go in terms of showing a working example. In particular, in your example above I'd consider checking that "$1" is "get" in the function.
You also could be using credential.*.username. It's twice as many git-config commands to set up on the command-line, but IMHO the resulting config file is a little easier to read.
-Peff
Quoted 16 lines · Jeff King
Quoted 14 lines · brian m. carlson
I think perhaps many folks aren't aware that you can invoke Git with an arbitrary shell command as "credential.helper", which of course makes life a lot easier. So if you want to invoke a separate command, it's really as easy as this:
git config credential.smtp://smtp.crustytoothpaste.net.helper \ '!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'So I think that documenting the use of the credential helper is step 1, because probably most people _do_ want to use that for their passwords, and then documenting that credential helpers can be arbitrary shell commands that speak the protocol is step 2, so that people who don't can figure out a way to do what they want.
Quoted 7 lines
Quoted 3 lines
I'll send some patches later which document the latter feature, since I don't think we mention it anywhere outside of the FAQ. I actually didn't know about it until Peff mentioned it to me one time.
This is documented, but only recently did it make it out of
Documentation/technical/and into gitcredentials(7). I don't mind adding more pointers, though.
Ah, yes, I remembered that series, but forgot that it introduced documentation for that.
I'll just send a patch that updates the config option to mention the other cases, since we already document it in gitcredentials(7).
Signature · 2 lines
brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204
Quoted 21 lines · brian m. carlson
Quoted 20 lines · Jeff King
Quoted 17 lines · brian m. carlson
I think perhaps many folks aren't aware that you can invoke Git with an arbitrary shell command as "credential.helper", which of course makes life a lot easier. So if you want to invoke a separate command, it's really as easy as this:
git config credential.smtp://smtp.crustytoothpaste.net.helper \ '!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'So I think that documenting the use of the credential helper is step 1, because probably most people _do_ want to use that for their passwords, and then documenting that credential helpers can be arbitrary shell commands that speak the protocol is step 2, so that people who don't can figure out a way to do what they want.
I'll send some patches later which document the latter feature, since I don't think we mention it anywhere outside of the FAQ. I actually didn't know about it until Peff mentioned it to me one time.
Quoted 6 lines
Quoted 3 lines
This is documented, but only recently did it make it out of
Documentation/technical/and into gitcredentials(7). I don't mind adding more pointers, though.Ah, yes, I remembered that series, but forgot that it introduced documentation for that.
if we are going to mention an example or a credential helper specially tailored to smtp, then the recently reintroduced syntax by Dscho in 9a121b0d22 (credential: handle credential.<partial-URL>.<key> again, 2020-04-24), might come up handy IMHO.
Carlo
Quoted 3 lines · Carlo Marcelo Arenas Belón
having said that, this looks like a good alternative, but might need to make sure if die makes sense below or would be better to see if you can still get a password through git credential even if that fails.
Thank you.
Quoted 14 lines · Junio C Hamano
Quoted 9 lines · Carlo Marcelo Arenas Belón
Quoted 2 lines
+of
sendemail.smtpPassCmd), then a password is obtained using +'git-credential'.this last part on git credential is just undocumented, since it is already doing so since
4d31a44a08(git-send-email: use git credential to obtain password, 2013-02-12)and of course, assuming you use a credential helper that keeps the password encrypted you could use that instead of this new feature.
Up to this point I understand your response.
Quoted 8 lines
Documenting that "git send-email" can use "git credential" for its password store, if it is not already documented, is of course a good change.
But I am not sure why this is "a good alternative". Having more choices that do not offer anything substantially different is a bad thing. Is this "new mechanism" better in what way? Simpler to use? Faster? Less error prone? Something else?
The main reason would be "simpler to use".
At the point the developer is configuring smtp, adding another line with 'command to get the password' instead of 'password' is way more intuitive than configure a credential.
Best regards,
Leonardo Bras
Quoted 2 lines · brian m. carlson
git config credential.smtp://smtp.crustytoothpaste.net.helper \
'!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'I have tried doing this, with --global, and my config file changed like this:
[credential "smtp://smtp.gmail.com"]
helper = "!f() { echo [email protected]; echo
\"password=$(gpg2 -q --for-your-eyes-only --no-tty -d ~/words/imap)\"; }; f"
While sendemail has:
[sendemail]
smtpServer = smtp.gmail.com
smtpServerPort = 587
smtpEncryption = tls
smtpUser = [email protected]
Yet still, I was asked for password:
Password for 'smtp://[email protected]@smtp.gmail.com:587':
What have I done wrong?
Best regards,
Leonardo Bras
Quoted 19 lines · Leonardo Bras
Quoted 2 lines · brian m. carlson
git config credential.smtp://smtp.crustytoothpaste.net.helper \ '!f() { echo username=my-username; echo "password=$(my-password-command)"; }; f'I have tried doing this, with --global, and my config file changed like this:
[credential "smtp://smtp.gmail.com"]
helper = "!f() { echo [email protected]; echo
\"password=$(gpg2 -q --for-your-eyes-only --no-tty -d ~/words/imap)\"; }; f"While sendemail has:
[sendemail]
smtpServer = smtp.gmail.com
smtpServerPort = 587
smtpEncryption = tls
smtpUser = [email protected]
Quoted 2 lines
Yet still, I was asked for password:
Password for 'smtp://[email protected]@smtp.gmail.com:587':
I think the way the host-matching works, you'd need to put the ":587" into the credential.*.url config section heading for it to match.
-Peff
Quoted 5 lines · Jeff King
Yet still, I was asked for password:
Quoted 1 line
Password for 'smtp://[email protected]@smtp.gmail.com:587':
I think the way the host-matching works, you'd need to put the ":587" into the credential.*.url config section heading for it to match.
Oh, that makes sense.
It works, thanks!