Skip to main content

Simple Grant Language

Project description


SGL (Simple Grant Language)

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 python code. (Compare the JavaScript/Node.js equivalent):

from sgl.api import satisfies

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

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

for person in people:
    name = person['id']
    if satisfies(person, my_rule):
        print(f"Welcome backstage, {name}.")
        print(f"Sorry, this area is restricted, {name}.")

If you ran this code, you'd see:

$ python
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, XML, 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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgl-0.9.17.tar.gz (8.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page