Code Monkey home page Code Monkey logo

git-signed's Introduction

Logo

GitHub tag npm npm

Why?

Signing your commits ensure:

  1. That your commits cannot be re-edited by someone else (using git commit --amend)
  2. That no one cant impersonate you and try to add commits to a codebase

However, getting started with commit signing is often a tedious process. Many developers still do not sign their commits despite both GitHub and GitLab promoting its use.

Also, without having imported the public key of collaborators on the project, you will not be able to confirm that their commits are indeed signed. This means that locally (either during development or on a CI server), you will likely not have a straightforward way to verify and ensure that all commits in your repository are indeed signed.

git-signed solves both problems by providing a workflow for creating, publishing, and locally syncing GPG keys. It also configures the local repository to automatically sign all commits with the selected key.

Requirements

You will need gpgme installed locally on your machine.

  • Arch Linux: pacman -S gpgme or yaourt -S gpgme
  • Ubuntu: apt-get install gpgme
  • macOS: brew install gpgme

Windows users do not need to install gpgme, we will be using the copy of gnupg that is installed alongside git.

Installation

npm install --save-dev git-signed

Usage

Tutorial

Click here to see our tutorial

In package.json:

{
  "scripts": {
    "collaborator:join": "git-signed --join",
    "collaborator:export-key": "git-signed --export",
    "collaborator:sync-keys": "git-signed --sync",
    "test:commit-signatures": "git-signed"
  }
}

Then, add yourself as a collaborator. This will add a collaborators entry in you package.json file that will be augmented with information about how to fetch your key.

npm run collaborator:join

On GitHub and GitLab PRs, signed commit will have a "verified" badge attached to them.

verified badge

To add your GPG key to GitHub, GitLab, or other systems, export your key.

npm run collaborator:export-key

As collaborators join the project, more collaborators entries will be added to your package.json. You will need to fetch their keys so to see their commits as properly signed.

npm run collaborator:sync-keys

Once you have synced the keys to your localk keyring, you can now test that all commits are indeed signed.

test:commit-signatures

In some cases, you will want to start checking for signed commits only from a certain point in history (for instance, if all previous commits on the project were not signed until this point). Adding a commit short hash to the git-signed command will ignore all previous commits in your commit tree.

{
  "scripts": {
    "test:commit-signatures": "git-signed 86ce8bc"
  }
}

Finally, note that git-signed will only scan commits in the current branch. To scan another branch, simply switch to it, and run git-signed again.

Integrating with Husky

Husky allows for the automated setup of commit hooks. One common use of git-signed is to add a post-commit test to let developers know that they need to sign their work.

{
  "scripts": {
    "precommit": "npm run test",
    "postcommit": "npm run test:commit-signatures",
    "postmerge": "npm install && npm run collaborator:sync-keys",
    "update": "npm install && npm run collaborator:sync-keys"
  }
}

You may find a more complete example in the package.json file of this project.

Repository configuration

repo settings

If you are using GitHub or GitLab, you will need to disable Allow squash commit and Allow rebase commit; this is due to the fact that signed commits would eithet be squashed into an unsigned one, or simply get unsigned.

License

MIT.

Acknowledgements

Git graphic by tnp_sergey_novosyolov from TheNounProject is licensed under CC BY 3.0. Check out the new logo that I created on LogoMaker.com https://logomakr.com/1D6HDT

git-signed's People

Contributors

stelcheck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

git-signed's Issues

Error exit when joining

  • gpg version: 2.1.18
  • git version: 2.19.0
  • node version: 8.12.0
  • machine: debian stretch

When I try to add myself as a collaborator, the command seems to fail.
Is this from versioning error or something else?

xun@debian:/tmp/doo.2dox3mQspY (master #)$ npm run collaborator:join

> [email protected] collaborator:join /tmp/doo.2dox3mQspY
> git-signed --join

? Enter your name Shunsuke Tamiya
? Enter your email [email protected]
? Select the GPG key you wish to use for signing your commits Key fingerprint = B603 407C 78A1 8965 7BA8  4214 4E53 D51F 715D AA9D (rsa4096/0x4E53D51F715DAA9D) [Created 2018-09-01 | Expires 2019-09-01]
    - [ unknown] Shunsuke Tamiya <[email protected]>
? Enter the server where you would like to export your public key hkp://keys.gnupg.net
Sending your public key to hkp://keys.gnupg.net...
gpg: "Key" not a key ID: skipping
gpg: "fingerprint" not a key ID: skipping
gpg: "=" not a key ID: skipping
gpg: "B603" not a key ID: skipping
gpg: "407C" not a key ID: skipping
gpg: "78A1" not a key ID: skipping
gpg: "8965" not a key ID: skipping
gpg: "7BA8" not a key ID: skipping
gpg: "4214" not a key ID: skipping
gpg: "4E53" not a key ID: skipping
gpg: "D51F" not a key ID: skipping
gpg: "715D" not a key ID: skipping
gpg: "AA9D" not a key ID: skipping
  Error: Command failed: gpg --keyserver hkp://keys.gnupg.net --send-key Key fingerprint = B603 407C 78A1 8965 7BA8  4214 4E53 D51F 715D AA9D
  gpg: "Key" not a key ID: skipping
  gpg: "fingerprint" not a key ID: skipping
  gpg: "=" not a key ID: skipping
  gpg: "B603" not a key ID: skipping
  gpg: "407C" not a key ID: skipping
  gpg: "78A1" not a key ID: skipping
  gpg: "8965" not a key ID: skipping
  gpg: "7BA8" not a key ID: skipping
  gpg: "4214" not a key ID: skipping
  gpg: "4E53" not a key ID: skipping
  gpg: "D51F" not a key ID: skipping
  gpg: "715D" not a key ID: skipping
  gpg: "AA9D" not a key ID: skipping

  - child_process.js:602 checkExecSyncError
    child_process.js:602:13

  - child_process.js:642 Object.execSync
    child_process.js:642:13

  - join.js:231 pushToPublicServer
    [doo.2dox3mQspY]/[git-signed]/commands/join.js:231:6

  - join.js:153 retrieveInfo
    [doo.2dox3mQspY]/[git-signed]/commands/join.js:153:9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.