Giter Site home page Giter Site logo

opa-sign-verify's Introduction

OPA Bundle Signing

Simple demonstration of bundle signing and verification for Open Policy Agent (OPA).

Create RSA key pair

First of all, we'll need a key pair (a private key for signing and a public key for verification):

openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in private_key.pem -out public_key.pem

Create .signatures.json

Given that we have a policy directory we'll want to create bundle from, we can now create a .signatures.json file, which we'll later use for bundle verification:

opa sign --signing-key private_key.pem --bundle policy/

Once created, move the .signatures.json file into the bundle directory:

mv .signatures.json policy/

Build bundle

We're now ready to build the bundle, providing both the signing key and the verification key:

opa build --bundle --signing-key private_key.pem  --verification-key public_key.pem policy/

Upload bundle to bundle server

Next, move bundle to bundle server. For the purpose of the example, we'll use an nginx server running locally. The below command is on Mac OS with nginx installed via brew โ€” the location of the nginx "www" directory may obviously vary.

mv bundle.tar.gz /opt/homebrew/var/www

Run OPA with bundle verification config

opa-conf.yaml

services:
  nginx:
    url: http://localhost:8080

bundles:
  policy:
    service: nginx
    resource: bundle.tar.gz
    signing:
      keyid: verifier

keys:
  verifier:
    key: changeme

We now have a signed bundle served from our bundle server, so let's start the OPA server with a config file pointing out its location. Note especially the use of --set-file to point out the location of our public key. This is preferable over keeping keys embedded in the configuration:

opa run --server \
        --config-file=opa-conf.yaml \
        --set-file="keys.verifier.key=public_key.pem"

Make sure you see "Bundle loaded and activated successfully." in the logs.

Done!

opa-sign-verify's People

Contributors

anderseknert avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

magnologan

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.