Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iad-os/jorah-policy-middleware

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iad-os/jorah-policy-middleware

Open Policy Agent Middleware

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

JORAH Policy Middleware

Add dependency to project

npm i @iad-os/jorah-policy-middleware

Configure

import jorah from '@iad-os/jorah-policy-middleware';

//...

const config = {
  url: 'http://opa:8181/v1/data',
  dryRun: {
    enabled: true,
    header: 'x-authorizer',
  },
};

const default = {
    doPost: async (req, url, data, options) => {
        return await axios.create().post(url, data, options);
    },
    onDecision: (req, res, next) => {
        if (req.policyEvaluation.decision?.result?.allow) {
            res.json(req.policyEvaluation);
            next();
            return;
        }
        next(new Error(`OPA-POLICY - FORBIDDEN`));
    },
    decisionPath: req => {
        return `/${req.path.split('/')[1]}`;
    },
    toPolicyEvaluationRequest: (req, required) => ({
        input: {
            ...required,
            req: {
            method: req.method,
            params: req.params,
            },
        },
    }),
};

export default jorah(config, default);

Usage

On express router middleware:

import express from 'express';
import jorah from './jorah';

const router = express.Router();

router.route('/').all(
    // other middleware ...
    jorah({
        onDecision: (req, res, next) => {
            res.json(req.policyEvaluation);
        },
        decisionPath: req =>
            `${req.baseUrl}${reduce(req.params, (acc, param, name) => `${acc}/${name.replace('_id', '')}`, '')}`,
        required: {
            id: req => req.params.id
        },
    })
    // other middleware ...
);

As express middleware:

import express from 'express';
import jorah from './jorah';

const expressApp = express()
  // other middleware ...
  .use(jorah({})); // in this way the middleware use a default configurations

Keywords

FAQs

Package last updated on 18 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc