git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv2 0/13] credential helpers

From
Jeff King <peff@peff.net>
Date
Dec 9, 2011, 23:18 UTC
Message-ID
<20111209231800.GA14376@sigill.intra.peff.net>
In-Reply-To
<7vzkf1fwvn.fsf@alter.siamese.dyndns.org>
On Fri, Dec 09, 2011 at 10:00:44AM -0800, Junio C Hamano wrote:
Show 15 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > It works, and it detects truncated output both ways properly (I know
> > because I had to update every test, since the old output was missing the
> > end-of-credential marker).
> >
> > It makes me a little sad, because the original format (relying on EOF)
> > was so Unix-y.
> 
> It saddens me, too.  A reasonable middle ground would be to stop treating
> an empty input as "no restriction" but "never matches".
> 
> I suspect that it is far more likely for a helper to fail (due to
> configuration errors, for example) before it produces any output than
> after it gives some but not all output lines.

Yeah, I think that's a reasonable compromise. Instead of the patch I posted earlier, how about this:

diff --git a/credential-store.c b/credential-store.c
index a2c2cd0..26f7589 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -96,7 +96,16 @@ static void store_credential(const char *fn, struct credential *c)
 
 static void remove_credential(const char *fn, struct credential *c)
 {
-	rewrite_credential_file(fn, c, NULL);
+	/*
+	 * Sanity check that we actually have something to match
+	 * against. The input we get is a restrictive pattern,
+	 * so technically a blank credential means "erase everything".
+	 * But it is too easy to accidentally send this, since it is equivalent
+	 * to empty input. So explicitly disallow it, and require that the
+	 * pattern have some actual content to match.
+	 */
+	if (c->protocol || c->host || c->path || c->username)
+		rewrite_credential_file(fn, c, NULL);
 }
 
 static int lookup_credential(const char *fn, struct credential *c)


We _could_ modify credential_match() to automatically reject such a
pattern at that level, but it does actually have a use on the lookup
side. In config, a context like "https://example.com/foo.git" would
match each of:

  [credential "https://example.com/foo.git"]
          helper = ...
  [credential "https://example.com"]
          helper = ...
  [credential "https://"]
          helper = ...
  [credential]
          helper = ...

The final one is an just an extension of the others to the empty pattern
(you could also spell it [credential ""], and it would have the same
effect).

So the "empty pattern" does actually have a use, from the end-users's
point of view. It's just that with removal, it's a little more dangerous
and a little less likely to be useful (as compared to lookup).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 27 of 30 in “[PATCHv2 0/13] credential helpers”
  1. Jeff KingDec 6, 2011
  2. 01/13 test-lib: add test_config_global variantJeff King, Dec 6, 2011
  3. 02/13 t5550: fix typoJeff King, Dec 6, 2011
  4. 03/13 introduce credentials APIJeff King, Dec 6, 2011
  5. 04/13 credential: add function for parsing url componentsJeff King, Dec 6, 2011
  6. 05/13 http: use credential API to get passwordsJeff King, Dec 6, 2011
  7. 06/13 credential: apply helper configJeff King, Dec 6, 2011
  8. Junio C HamanoDec 6, 2011
  9. Jeff KingDec 7, 2011
  10. Jeff KingDec 7, 2011
  11. 07/13 credential: add credential.*.usernameJeff King, Dec 6, 2011
  12. 08/13 credential: make relevance of http path configurableJeff King, Dec 6, 2011
  13. 09/13 docs: end-user documentation for the credential subsystemJeff King, Dec 6, 2011
  14. 10/13 credentials: add "cache" helperJeff King, Dec 6, 2011
  15. 11/13 strbuf: add strbuf_add*_urlencodeJeff King, Dec 6, 2011
  16. 12/13 credentials: add "store" helperJeff King, Dec 6, 2011
  17. Junio C HamanoDec 6, 2011
  18. Jeff KingDec 9, 2011
  19. 13/13 t: add test harness for external credential helpersJeff King, Dec 6, 2011
  20. Junio C HamanoDec 6, 2011
  21. Jeff KingDec 6, 2011
  22. Junio C HamanoDec 6, 2011
  23. Jeff KingDec 7, 2011
  24. Junio C HamanoDec 8, 2011
  25. Jeff KingDec 9, 2011
  26. Junio C HamanoDec 9, 2011
  27. Jeff KingDec 9, 2011
  28. Junio C HamanoDec 9, 2011
  29. Jeff KingDec 9, 2011
  30. Junio C HamanoDec 9, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.