All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shikher Verma <root@shikherverma.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, root@shikherverma.com, santiago@nyu.edu,
	sbeller@google.com
Subject: [PATCH] Add a sample hook which saves push certs as notes
Date: Sat,  2 Dec 2017 14:42:48 +0530	[thread overview]
Message-ID: <20171202091248.6037-1-root@shikherverma.com> (raw)
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



  reply	other threads:[~2017-12-02  9:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170906093913.21485-1-root@shikherverma.com>
2017-09-06 21:31 ` [RFC PATCH 0/2] Add named reference to latest push cert Stefan Beller
2017-09-07  0:55   ` Junio C Hamano
2017-09-07  8:55     ` Shikher Verma
2017-09-07  9:11   ` Shikher Verma
2017-09-07 17:43     ` Stefan Beller
2017-09-16  7:21       ` Shikher Verma
2017-09-17  1:40         ` Junio C Hamano
2017-09-18 14:22           ` Santiago Torres
2017-09-18 17:43             ` Stefan Beller
2017-09-19  1:04             ` Junio C Hamano
2017-09-19  3:11               ` Junio C Hamano
2017-12-02  9:12                 ` Shikher Verma [this message]
2017-12-03  0:45                   ` [PATCH] Add a sample hook which saves push certs as notes Todd Zullinger
2017-12-03  6:05                     ` Junio C Hamano
2017-09-07  7:08 ` [RFC PATCH 0/2] Add named reference to latest push cert Shikher Verma
2017-09-07 17:21   ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171202091248.6037-1-root@shikherverma.com \
    --to=root@shikherverma.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=santiago@nyu.edu \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.