moonpolicykit

    A backend-neutral, explainable relationship-based authorization toolkit for MoonBit.

    authorization
    policy
    rbac
    rebac
    access-control
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    18

    #MoonPolicyKit API

    MoonPolicyKit provides explainable relationship-based authorization primitives for MoonBit applications.

    #Core API

    • ObjectRef::new
    • SubjectRef::direct
    • SubjectRef::userset
    • RelationTuple::new
    • PolicyRule::direct_allow
    • PolicyRule::direct_deny
    • PolicyRule::traverse_allow
    • PolicyRule::traverse_deny
    • PolicyEngine::check
    • PolicyEngine::check_many
    • PolicyEngine::filter_allowed
    • PolicyEngine::validate
    • PolicyEngine::stats
    • PolicyEngine::to_json

    CheckResult includes the final decision, reason, traversal depth, cycle flag, and proof steps used to reach the decision.

    CheckRequest

    pub(all) struct CheckRequest {
    object : ObjectRef
    permission : String
    principal : SubjectRef
    } derive(Eq,
    Debug
    )

    CheckRequest::new

    fn CheckRequest::new(object : ObjectRef, permission : String, principal : SubjectRef) -> CheckRequest

    CheckResult

    pub(all) struct CheckResult {
    allowed : Bool
    denied : Bool
    reason : String
    steps : Array[String]
    max_depth_seen : Int
    cycle_detected : Bool
    } derive(
    Debug
    )

    CheckResult::to_json

    fn CheckResult::to_json(self : CheckResult) -> String

    DecisionChange

    pub(all) struct DecisionChange {
    request : CheckRequest
    kind : DecisionChangeKind
    before : CheckResult
    after : CheckResult
    } derive(
    Debug
    )

    DecisionChangeKind

    pub(all) enum DecisionChangeKind {
    NewlyAllowed
    NewlyDenied
    Unchanged
    } derive(Eq,
    Debug
    )

    ObjectRef

    pub(all) struct ObjectRef {
    kind : String
    id : String
    } derive(Eq,
    Debug
    )

    ObjectRef::key

    fn ObjectRef::key(self : ObjectRef) -> String

    ObjectRef::new

    fn ObjectRef::new(kind : String, id : String) -> ObjectRef

    PolicyEngine

    pub(all) struct PolicyEngine {
    tuples : Array[RelationTuple]
    rules : Array[PolicyRule]
    max_depth : Int
    } derive(
    Debug
    )

    PolicyEngine::add_rule

    fn PolicyEngine::add_rule(self : PolicyEngine, rule : PolicyRule) -> Bool

    PolicyEngine::add_tuple

    fn PolicyEngine::add_tuple(self : PolicyEngine, tuple : RelationTuple) -> Bool

    PolicyEngine::check

    fn PolicyEngine::check(self : PolicyEngine, object : ObjectRef, permission : String, principal : SubjectRef) -> CheckResult

    PolicyEngine::check_many

    fn PolicyEngine::check_many(self : PolicyEngine, requests : Array[CheckRequest]) -> Array[CheckResult]

    PolicyEngine::filter_allowed

    fn PolicyEngine::filter_allowed(self : PolicyEngine, objects : Array[ObjectRef], permission : String, principal : SubjectRef) -> Array[ObjectRef]

    PolicyEngine::new

    fn PolicyEngine::new(max_depth? : Int) -> PolicyEngine

    PolicyEngine::remove_tuple

    fn PolicyEngine::remove_tuple(self : PolicyEngine, tuple : RelationTuple) -> Bool

    PolicyEngine::rule_count

    fn PolicyEngine::rule_count(self : PolicyEngine) -> Int

    PolicyEngine::stats

    PolicyEngine::to_json

    fn PolicyEngine::to_json(self : PolicyEngine) -> String

    PolicyEngine::tuple_count

    fn PolicyEngine::tuple_count(self : PolicyEngine) -> Int

    PolicyEngine::validate

    PolicyImpactReport

    pub(all) struct PolicyImpactReport {
    changes : Array[DecisionChange]
    newly_allowed : Int
    newly_denied : Int
    unchanged : Int
    } derive(
    Debug
    )

    PolicyImpactReport::has_privilege_expansion

    fn PolicyImpactReport::has_privilege_expansion(self : PolicyImpactReport) -> Bool

    PolicyImpactReport::to_json

    fn PolicyImpactReport::to_json(self : PolicyImpactReport) -> String

    PolicyRule

    pub(all) struct PolicyRule {
    object_namespace : String
    permission : String
    source_relation : String
    target_permission : String
    effect : Int
    } derive(Eq,
    Debug
    )

    PolicyRule::direct_allow

    fn PolicyRule::direct_allow(object_namespace : String, permission : String, source_relation : String) -> PolicyRule

    PolicyRule::direct_deny

    fn PolicyRule::direct_deny(object_namespace : String, permission : String, source_relation : String) -> PolicyRule

    PolicyRule::traverse_allow

    fn PolicyRule::traverse_allow(object_namespace : String, permission : String, source_relation : String, target_permission : String) -> PolicyRule

    PolicyRule::traverse_deny

    fn PolicyRule::traverse_deny(object_namespace : String, permission : String, source_relation : String, target_permission : String) -> PolicyRule

    PolicyStats

    pub(all) struct PolicyStats {
    tuples : Int
    rules : Int
    object_kinds : Int
    relations : Int
    permissions : Int
    } derive(Eq,
    Debug
    )

    PolicyStats::to_json

    fn PolicyStats::to_json(self : PolicyStats) -> String

    RelationTuple

    pub(all) struct RelationTuple {
    object : ObjectRef
    relation : String
    subject : SubjectRef
    } derive(Eq,
    Debug
    )

    RelationTuple::key

    fn RelationTuple::key(self : RelationTuple) -> String

    RelationTuple::new

    fn RelationTuple::new(object : ObjectRef, relation : String, subject : SubjectRef) -> RelationTuple

    SubjectRef

    pub(all) struct SubjectRef {
    kind : String
    id : String
    relation : String
    } derive(Eq,
    Debug
    )

    SubjectRef::direct

    fn SubjectRef::direct(kind : String, id : String) -> SubjectRef

    SubjectRef::key

    fn SubjectRef::key(self : SubjectRef) -> String

    SubjectRef::object

    fn SubjectRef::object(self : SubjectRef) -> ObjectRef

    SubjectRef::userset

    fn SubjectRef::userset(kind : String, id : String, relation : String) -> SubjectRef

    ValidationIssue

    pub(all) struct ValidationIssue {
    code : String
    message : String
    } derive(Eq,
    Debug
    )

    analyze_policy_impact

    fn analyze_policy_impact(before : PolicyEngine, after : PolicyEngine, requests : Array[CheckRequest]) -> PolicyImpactReport

    Compares two policy engines over an explicit, deterministic request set.

    Newly allowed decisions represent privilege expansion and should normally receive security review before deployment.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io