cerbos webassebly 集成简单说明

cerbos 包含了一个lite 包,可以方便不依赖backend server 进行认证,内部基于了webassebly 进行policy 的存储

参考使用

  • policies.wasm 文件

此文件来自官方的测试,实际上目前官方文档暂时没有说明此文件如何生成,但是通过官方测试文件可以看到一些东西,后边我会说
以下内容

  • app.js
 
const { Lite } = require("@cerbos/lite")
 
const {readFileSync} = require("fs")
 
const  { resolve } = require("path")
 
const client = new Lite(
    readFileSync(resolve(__dirname, "./policies.wasm"))
);
 
 
async function isAllowed() {
    const allowed = await client.isAllowed({
        principal: {
            id: "me@example.com",
            policyVersion: "1",
            scope: "test",
            roles: ["USER"],
            attr: {
                country: {
                    alpha2: "",
                    alpha3: "NZL",
                },
            },
        },
        resource: {
            kind: "document",
            id: "mine",
            policyVersion: "1",
            scope: "test",
            attr: {
                owner: "me@example.com",
            },
        },
        action: "edit",
        includeMetadata: true,
        requestId: "42",
    });
    console.log(allowed);
}
 
isAllowed();
  • 效果

说明

目前webassembly 文件的生成暂时没有资料介绍的(应该是官方hub 中通过ci/cd 生成的)同时测试webassembly 文件可以看出应该是基于自己开发的一些rust cli 工具生成的,其中deallocate,set_globals,allocate,check 是几个比较重要的方法

参考资料

https://docs.cerbos.dev/cerbos-hub/decision-points-embedded.html
https://github.com/cerbos/cerbos-sdk-javascript/blob/main/docs/lite.lite.md
https://github.com/cerbos/cerbos-sdk-javascript/tree/main/packages/lite

posted on   荣锋亮  阅读(13)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-12-02 johnfercher/maroto fork 版本几个bug 的修复
2020-12-02 johnfercher/maroto 不错的pdf golang pdf 生成工具包
2020-12-02 jung-kurt/gofpdf pdf 生成操作
2020-12-02 griddb 4.5 体验
2020-12-02 griddb 4.5 社区版新特性
2019-12-02 testcontainers 基本使用
2019-12-02 sqler 2.2 发布了,支持定时任务以及触发器

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示