Git Product home page Git Product logo

vault-jwt-sign's Introduction

Signing a JWT with HashiCorp Vault Transit Secrets Engine - Advanced

Transit Engine for Sign and Verify

To complete this example you need to have a Vault instance available and unsealed. You will also need the following environment variables set.

export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=x.abcdefghijk1234567
  1. Enable transit engine

    vault secrets enable transit
  2. Create our signing key

    vault write -f transit/keys/jwt type=rsa-4096 exportable=true

Python Example

This python example uses the HVAC client for Vault and the JWCrypto libraries for generating a JWT.

  1. Install python dependancies

    pip install jwcrypto hvac

Using Vault to read signing key

  1. Generate token with gen-jwt.py

    ./gen-jwt.py

    This will output the JWT and write it to the file token.jwt

  2. Verify token with check-jwt.py

    ./check-jwt.py

    This reads the token from the file (token.jwt) from the previous step and outputs the info claim.

    # Example
    $ ./check-jwt.py
    {"info":"Token signed at: 18/05/2021 15:36:22"}

Providing signing Key

  1. Create a priv.pem file with your private key in PEM format.

  2. Generate token with gen-jwt.py

    ./gen-jwt.py

    This will output the JWT and write it to the file token.jwt

  3. Verify token with check-jwt.py

    ./check-jwt.py

    Since the provided private key doesn't come from Vault, the JWT verification will fail.

    # Example
    $ ./check-jwt.py
    Not signed by key version: 1
    Not signed by key version: 2
    Not signed by key version: 3
    Not signed by key version: 4
    Not signed by key version: 5
    Token not signed by any key

Rotating the signing key

The private key for signing can be rotated with the rotate-key.py script.

$ ./rotate-key.py

Specifying Key version

By default the script uses the latest version of the signing key. This can be adjusted by setting the KEY_VER environment variable.

export KEY_VER=5

vault-jwt-sign's People

Contributors

methridge avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

gitrgoliveira

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.