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

[PATCH] Add a sample hook which saves push certs as notes

From
SVShikher Verma <root@shikherverma.com>
Date
Dec 2, 2017, 09:12 UTC
Message-ID
<20171202091248.6037-1-root@shikherverma.com>
In-Reply-To
<xmqqtvzzqt5u.fsf@gitster.mtv.corp.google.com>

hooks--post-receive.sample: If push cert is present, add it as a git note to the top most commit of the updated ref.

Signed-off-by: Shikher Verma <root@shikherverma.com>
---
 templates/hooks--post-receive.sample | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100755 templates/hooks--post-receive.sample
diff --git a/templates/hooks--post-receive.sample b/templates/hooks--post-receive.sample
new file mode 100755
index 000000000..b4366e43f
--- /dev/null
+++ b/templates/hooks--post-receive.sample
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# An example hook script to store push certificates as notes.
+#
+# To enable this hook, rename this file to "post-receive".
+#
+# The stdin of the hook will be one line for each updated ref:
+# <old-id> <new-id> <refname>
+#
+# For each updated ref this script will :
+# 1. Verify that the ref update matches that in push certificate.
+# 2. add the push cert as note (namespace pushcerts) to <new-id>.
+#
+# If this hook is enabled on the server then clients can prevent
+# git metadata tampering, by using signed pushes and 
+# doing the following while fetching :
+# 1. fetch the git notes (of namespace pushcerts) from server.
+#     $ git fetch origin refs/notes/pushcerts:refs/notes/pushcerts
+# 2. Check that the fetched ref's top most commit has a note
+#     containing a push certificate.
+# 3. Verify the validity of the push certificate in the note and 
+#     check that the ref update matches that in push certificate.
+#
+
+if test -z GIT_PUSH_CERT ; then
+    exit 0
+fi
+
+push_cert=$(git cat-file -p  $GIT_PUSH_CERT)
+
+while read oval nval ref
+do
+	# Verify that the ref update matches that in push certificate.
+	if [[ $push_cert == *$oval" "$nval" "$ref* ]]; then
+		# add the push cert as note (namespaced pushcerts) to nval.
+		git notes --ref=pushcerts add -m "$push_cert" $nval -f
+	fi
+done
-- 
2.15.0
Previous: Junio C HamanoNext: Todd Zullinger
Message 12 of 16 in “Re: [RFC PATCH 0/2] Add named reference to latest push cert”
  1. Stefan BellerSep 6, 2017
  2. Junio C HamanoSep 7, 2017
  3. Shikher VermaSep 7, 2017
  4. Shikher VermaSep 7, 2017
  5. Stefan BellerSep 7, 2017
  6. Shikher VermaSep 16, 2017
  7. Junio C HamanoSep 17, 2017
  8. Santiago TorresSep 18, 2017
  9. Stefan BellerSep 18, 2017
  10. Junio C HamanoSep 19, 2017
  11. Junio C HamanoSep 19, 2017
  12. Add a sample hook which saves push certs as notesShikher Verma, Dec 2, 2017
  13. Todd ZullingerDec 3, 2017
  14. Junio C HamanoDec 3, 2017
  15. Shikher VermaSep 7, 2017
  16. Stefan BellerSep 7, 2017

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.