|
| 1 | +--- |
| 2 | +title: "Keyless Git Signing with Sigstore" |
| 3 | +date: 2022-12-02 |
| 4 | +author: Daniel Bevenius |
| 5 | +--- |
| 6 | + |
| 7 | +This post contains the steps for setting up |
| 8 | +[gitsign](https://github.com/sigstore/gitsign) to sign your git |
| 9 | +commits using [sigstore](https://www.sigstore.dev/). |
| 10 | + |
| 11 | +### Install gitsign |
| 12 | +```console |
| 13 | +$ go install github.com/sigstore/gitsign@latest |
| 14 | +``` |
| 15 | +Or using brew: |
| 16 | +```console |
| 17 | +$ brew install sigstore/tap/gitsign |
| 18 | +``` |
| 19 | + |
| 20 | +### Configure git |
| 21 | +The collowing will configure signing for the current project: |
| 22 | +```console |
| 23 | +#!/bin/bash |
| 24 | + |
| 25 | +# Sign all commits |
| 26 | +git config --local commit.gpgsign true |
| 27 | + |
| 28 | +# Sign all tags |
| 29 | +git config --local tag.gpgsign true |
| 30 | + |
| 31 | +# Use gitsign for signing |
| 32 | +git config --local gpg.x509.program gitsign |
| 33 | + |
| 34 | +# gitsign expects x509 args |
| 35 | +git config --local gpg.format x509 |
| 36 | +``` |
| 37 | +To configure for all projects, use: |
| 38 | +```console |
| 39 | +#!/bin/bash |
| 40 | + |
| 41 | +# Sign all commits |
| 42 | +git config --global commit.gpgsign true |
| 43 | + |
| 44 | +# Sign all tags |
| 45 | +git config --global tag.gpgsign true |
| 46 | + |
| 47 | +# Use gitsign for signing |
| 48 | +git config --global gpg.x509.program gitsign |
| 49 | + |
| 50 | +# gitsign expects x509 args |
| 51 | +git config --global gpg.format x509 |
| 52 | +``` |
| 53 | + |
| 54 | +### Commit |
| 55 | +Now when you commit, `gitsign` will be used to start an Open ID |
| 56 | +Connect (OIDC) flow. This will allow you to choose an OIDC provider: |
| 57 | + |
| 58 | +```console |
| 59 | +$ git commit -v |
| 60 | +Your browser will now be opened to: |
| 61 | +https://oauth2.sigstore.dev/auth/auth?access_type=online&client_id=sigstore&code_challenge=eQvdw56pTgXnkj76Cab-4ZWaKk8XFM6UFFBdayKQX1Y&code_challenge_method=S256&nonce=2GmBDq86TMNuz8VhMUixMxiPSe2&redirect_uri=http%3A%2F%2Flocalhost%3A39617%2Fauth%2Fcallback&response_type=code&scope=openid+email&state=2GmBDlYDps5Ywd8dX4Ebwo4VnQL |
| 62 | +[master 4292869] Add initial Oniro notes |
| 63 | + 1 file changed, 10 insertions(+) |
| 64 | + create mode 100644 notes/oniro.md |
| 65 | +``` |
| 66 | + |
| 67 | +Note that on github this commit will be marked as `Unverified` because |
| 68 | +the sigstore Certificate Authority root is not part of Github's trust |
| 69 | +root. Further, validation needs to be done using Rekor to verify that |
| 70 | +the certificate was valid at the time this commit was signed. |
| 71 | + |
| 72 | +To avoid having to choose an auth provider each time, set the following environment variable. For example: |
| 73 | +```console |
| 74 | +$ export GITSIGN_CONNECTOR_ID=https://github.com/login/oauth |
| 75 | +``` |
| 76 | + |
| 77 | +### Verifying a commit |
| 78 | +```console |
| 79 | +$ git verify-commit HEAD |
| 80 | +``` |
| 81 | +If verified, you'll see output similar to this: |
| 82 | +```console |
| 83 | +tlog index: 6058402 |
| 84 | +gitsign: Signature made using certificate ID 0xb073e00bfabd4fb9988b9e1e0896dcfc1527fcdb | CN=sigstore-intermediate,O=sigstore.dev |
| 85 | +gitsign: Good signature from [daniel.bevenius@gmail.com] |
| 86 | +Validated Git signature: true |
| 87 | +Validated Rekor entry: true |
| 88 | +``` |
| 89 | + |
| 90 | +### Inspect commit signature |
| 91 | +```console |
| 92 | +$ git cat-file commit HEAD \ |
| 93 | + | sed -n '/BEGIN/, /END/p' \ |
| 94 | + | sed 's/^ //g' \ |
| 95 | + | sed 's/gpgsig //g' \ |
| 96 | + | sed 's/SIGNED MESSAGE/PKCS7/g' \ |
| 97 | + | openssl pkcs7 -print -print_certs -text |
| 98 | +``` |
0 commit comments