Giter VIP home page Giter VIP logo

simple-grant-lang's Introduction

SGL (Simple Grant Language)

This is the JavaScript implementation of SGL. It is usable in both node.js and browser environments. There is also a python implementation.

SGL is a simple but flexible DSL for matching people against criteria (typically, authorization). It is like XACML but simpler and JSON-oriented. You can use it to write rules about who should be able to do what, and then to compare circumstances to the rules to enforce custom logic. This lets you create your own Role-Based Access Control mechanisms, as well as authorizations based on other criteria.

For example, here's an SGL rule that says only members of the press should be allowed backstage at a concert:

{"grant": ["backstage"], "when": { "roles": "press" }}

And here's how you might use that rule in JavaScript/Node.JS code (Compare the python equivalent):

var sgl = require('simple-grant-lang')

my_rule = {grant: ["backstage"], when: { "roles": "press" }};

people = [
    {id: "Alex", roles: ["ticket-holder"]},
    {id: "Sofia", roles: ["ticket-holder", "press"]}
];

for (var i = 0; i < people.length; ++i) {
    name = people[i].id;
    if (sgl.satisfies(person, my_rule)) {
        console.print("Welcome backstage, " + name);
    } else {
        console.print("Sorry, this area is restricted, " + name);
    }
}

If you ran this code, you'd see:

$ node sampleCode.js
Sorry, this area is restricted, Alex.
Welcome backstage, Sofia.

SGL supports arbitrarily complex rules with boolean operators, as well as rules that require multiple people to jointly exercise a privilege. However, it's simple enough that you should be able to learn it in just a few minutes. See the tutorial.

Note: SGL can be rendered in various styles. The example above uses the recommended JSON rendering, since JSON is familiar, broadly supported, and easy to read. Other possibilities include ProtoBuf, MsgPack, CBOR, and human-friendly text.

SGL is not integrated with any particular enforcement mechanism, because it's designed for problems where you have to do your own enforcement. Hooking it up to enforcement mechanisms is trivial, though.

See also

simple-grant-lang's People

Contributors

dependabot[bot] avatar dhh1128 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simple-grant-lang's Issues

Support for custom properties?

The SGL documentation states that custom properties can be used to describe rules for granting privileges based on attributes different than, e.g. the role of a principal.

Looking at the current implementation it seems like the JS package does not support this use case. I have forked and extended this library to support arbitrary custom properties (in a fairly naive way I believe).

I was generally curious if support for this feature will be added to this library, as well as what things need to be taken into consideration to do so robustly.

Thank you!

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.