Giter Club home page Giter Club logo

polai's Introduction

polai

Warning This project is experimental and is not recommended for use

Foreword

This project was an experimental project to understand the complexity of the Cedar policy language. The project is incomplete and doesn't feature the automated reasoning guarantees that the official engine has. For use in a production context, consume the official engine directly or via one of the bindings.


GoDoc

A Cedar policy language lexer, parser & evaluator.

Installation

go get github.com/iann0036/polai

Please add -u flag to update in the future.

Usage

Basic Usage

package main

import (
    "fmt"
    "strings"

    "github.com/iann0036/polai"
)

func main() {
    e := polai.NewEvaluator(strings.NewReader(`
    permit (
        principal,
        action,
        resource == Folder::"My Folder"
    ) when {
        context.ssl == true
    };`))

    result, _ := e.Evaluate(`User::"alice"`, `Action::"listFiles"`, `Folder::"My Folder"`, `{
        "ssl": true
    }`)

    if result {
        fmt.Println("Authorized")
    } else {
        fmt.Println("Not Authorized")
    }
}

Advanced Options

package main

import (
    "fmt"
    "strings"

    "github.com/iann0036/polai"
)

func main() {
    e := polai.NewEvaluator(strings.NewReader(`
    permit (
        principal,
        action,
        resource == Folder::"My Folder"
    ) when {
        if context.ssl == true && principal.hasTraining
        then true
        else principal.invalidproperty
    };`))

    e.AllowShortCircuiting = true // evaluation will fail when set to false

    e.SetEntities(strings.NewReader(`
    [
        {
            "uid": "User::\"alice\"",
            "attrs": {
                "hasTraining": true
            }
        },
        {
            "uid": "User::\"kate\"",
            "attrs": {
                "hasTraining": false
            }
        }
    ]`))

    result, _ := e.Evaluate(`User::"alice"`, `Action::"listFiles"`, `Folder::"My Folder"`, `{
        "ssl": true
    }`)

    if result {
        fmt.Println("Authorized")
    } else {
        fmt.Println("Not Authorized")
    }
}

Features

  • Policy language interpreter
  • Basic permit and forbid evaluation logic
  • Equality / inequality operator within principal, action, and resource within the scope block
  • Inheritance (in) within scope block
  • Basic set (in) for action within scope block
  • Basic when and unless evaluation logic
  • Logical operators for basic types (string, long, boolean) within condition block
  • Entity store interpreter
  • Inheritance (in) within condition block
  • Entity attributes evaluation
  • IP and Decimal extensions
  • Context object
  • Set operations
  • has operation
  • Logical not ! operation
  • like operator
  • if-then-else ternary
  • Enforce Action:: namespace for actions
  • && and || short-circuiting
  • if-then-else short-circuiting
  • Embedded if-then-else
  • 4x limit on unary
  • Syntactic constraint on multiply operator
  • Anonymous records / sets
  • __entity / __extn syntax in context / entities
  • Policy templates

License

This project is under MIT license. See the LICENSE file for the full license text.

polai's People

Contributors

iann0036 avatar

Stargazers

Liam Woodleigh-Hardinge avatar Phil Hassey avatar  avatar Rúben Silva avatar RT avatar vignesh avatar Vlad Ionescu avatar Majed Traboulsi avatar Mark Wolfe avatar Lam Tran avatar Mathis Joffre avatar Eduardo Rabelo avatar rowan avatar Roman avatar

Watchers

Zikani Nyirenda Mwase avatar  avatar  avatar

Forkers

samtimur

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.