feat(acl): 增加资源 ACL、用户组授权与向量权限过滤#3213
Draft
qin-ctx wants to merge 11 commits into
Draft
Conversation
Persist direct and inherited ACL fields in context records so filesystem operations and vector retrieval enforce the same permissions.
确保 ACL 更新结果与锁内状态一致,移动失败可恢复向量 URI,并让后台解析沿用发起请求的用户组身份。精简重复实现和低价值测试。
个人资源保持 owner 私有,分享通过移动到共享区完成;跨区移动按目标 scope 继承或清空 ACL,并将向量权限过滤限制在共享区。
恢复 telemetry 空上下文和 import 的基线写法,仅保留 ACL 用户组身份传递。
ACL 元数据读取失败时终止权限判断,并确保 grep 的 node_limit 作用于权限过滤后的可见结果。
删除重复、时序绑定和实现细节测试,并撤销非必要的 grep 循环扩容。保留用例只覆盖独立的安全、一致性和兼容性故障。
# Conflicts: # openviking/storage/viking_fs.py # tests/storage/test_semantic_processor_mv_vector_store.py
将 write、delete 和 reindex 收敛到 read/write/manage 能力检查,并修复 add target 权限校验未等待的问题。
用 AclAction 和 AclLevel 约束内部权限分支,拒绝裸字符串 action,并保持 API 与存储字符串格式兼容。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
为 OpenViking 的
viking://resources/...共享区增加协作文档式 ACL,并让文件操作、维护操作和向量检索使用同一套权限语义。个人区
viking://user/{user_id}/resources/...保持 owner 私有;需要共享时将资源移动到共享区。共享区支持用户、用户组和user:*,目录授权向所有后代累加继承,子节点只能增加授权,不覆盖祖先授权。ACL 不创建独立 collection,也不写入 JSON/tags。direct 和 inherited 权限保存在 context collection 的原生
list<string>标量字段中,find/search可直接在向量查询阶段过滤。本轮同时把历史上的 write、delete 和新加入的 reindex 特判收敛到
VikingFS的统一能力检查,避免继续维护多套近似但不一致的 access 逻辑。Human Involvement
Related Issue
无。
Type of Change
Changes Made
1. ACL 模型与存储
user:{user_id}、group:{group_id}、user:*。viewer -> read、editor -> read + write、manager -> read + write + manage。AclLevel和AclAction两个str + Enum;HTTP/CLI 与 context 标量仍使用相同字符串值,协议和存储格式不变。ADMIN是共享区隐式 manager;个人区不接受 ACL。acl_direct_{read,write,manage}_principal_ids、acl_inherited_{read,write,manage}_principal_ids和派生字段acl_enabled。acl_enabled=false,继续使用升级前 URI 规则,不要求全量回填。2. 统一鉴权入口
单节点强制鉴权统一为
_ensure_access(uri, ctx, *, action=AclAction.READ),批量操作统一为_ensure_access_many(uris, ctx, *, action);_can_access/_can_access_many只负责过滤和布尔判断。write/manage 调用必须显式传枚举,运行时拒绝裸字符串 action,避免拼写错误或错误分支。每次强制鉴权按固定顺序执行:
原
_ensure_mutable_access、_ensure_delete_access和 reindex 路由_authorize_reindex_uri已删除。原 URI access 规则只保留为不可绕过的 namespace 边界,以及未启用 ACL 时的兼容回退,不再维护第二套操作权限。操作映射:
readwritemanagewritemanage首次在共享节点建立 ACL 是唯一 bootstrap:ACL 尚未启用时仅共享区隐式 manager 可设置;启用后按有效
manage判断。3. 写入、删除、移动与 reindex
write;递归操作先批量校验,避免部分成功。manage;递归删除完整扫描并校验子树后才产生副作用。manage、目标write。共享区内部保留 direct ACL 并按新祖先重算 inherited;个人区与共享区之间移动时按目标 scope 清理或继承 ACL。write鉴权。USER、ADMIN、ROOT 不再各自维护 reindex scope 特判。write鉴权,修复原同步包装调用 async helper、实际未执行权限检查的问题。viking://account 根只允许管理员执行 write 类维护;删除仍由 namespace 防护禁止。4. 检索与用户组
检索身份由服务端从请求上下文生成:
共享区向量查询对 direct/inherited read principal 字段执行原生
contains-any过滤。target URI 只限制检索范围,不要求中间目录可读,因此深层文件被直接授权后仍可召回。用户组按 account 持久化稳定
group_id。增删成员只改变后续请求的RequestContext.group_ids,不展开用户列表,也不重写资源 context;退出组后下一次请求立即失去对应授权。5. 最小 CLI 示例
直接授权并验证读取、检索和 reindex:
组授权无需逐个维护资源 ACL:
ov --sudo admin create-group acme Engineering ov --sudo admin add-group-member acme grp_0123 bob ov acl grant viking://resources/project-a --principal group:grp_0123 --level viewer # 移出组后,下一次请求立即撤权,不重写资源记录 ov --sudo admin remove-group-member acme grp_0123 bobTesting
本轮合并与鉴权重构验证:
60 passed。ruff check、compileall、git diff --check通过,旧鉴权 helper 引用为 0。cargo test -p ov_cli为390 passed;Go SDKgo test ./...通过。Build Docs、plugin-tests、check-deps及 Rust 多平台构建。Checklist
Screenshots (if applicable)
不适用,改动为服务端、存储、SDK 和 CLI 能力。
Additional Notes
main(a0e822a0)并处理冲突:保留 main 的 canonical URI 行为,同时保留 ACL 分支的批量向量 URI 更新与失败回滚;冲突测试只保留两个可发现真实回归的用例。docs/zh/concepts/15-acl.md、docs/zh/api/12-acl.md、docs/zh/api/07-system.md,并同步维护英文版本。