Skip to content

feat(app): support app resource permission snapshots and runtime authorization - #7559

Merged
c121914yu merged 6 commits into
labring:mainfrom
DigHuang:feat/app-permission
Sep 17, 2026
Merged

c121914yu merged 6 commits into
labring:mainfrom
DigHuang:feat/app-permission

Conversation

@DigHuang

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 41.51% 4394 / 10583
🔵 Statements 41.36% 4655 / 11254
🔵 Functions 34.85% 869 / 2493
🔵 Branches 34.84% 2245 / 6443
File CoverageNo changed files found.
Generated in workflow #3479 for commit 1aab184 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_1aab184bc82b2d12db6a980229168896a359ca47

🕒 Time: 2026-09-17 17:12:32 (UTC+8)

@DigHuang
DigHuang force-pushed the feat/app-permission branch 4 times, most recently from bff8b71 to e7a5d50 Compare August 21, 2026 03:32
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

Build and publish successful - Preview fastgpt Image:

ghcr.io/labring/fastgpt-pr:fastgpt_1aab184bc82b2d12db6a980229168896a359ca47

🕒 Time: 2026-09-17 17:13:50 (UTC+8)

@DigHuang
DigHuang force-pushed the feat/app-permission branch 19 times, most recently from f2f0d5f to f9b9a95 Compare August 26, 2026 06:04
@DigHuang
DigHuang marked this pull request as ready for review August 26, 2026 06:04
@DigHuang
DigHuang force-pushed the feat/app-permission branch 2 times, most recently from d58da43 to b49afa8 Compare August 26, 2026 09:27
@DigHuang
DigHuang force-pushed the feat/app-permission branch 12 times, most recently from 8c0a582 to 6fc5922 Compare September 9, 2026 18:38
@c121914yu c121914yu self-assigned this Sep 10, 2026
@DigHuang
DigHuang force-pushed the feat/app-permission branch 7 times, most recently from ae2357e to 76f1083 Compare September 14, 2026 02:52
@c121914yu

Copy link
Copy Markdown
Collaborator

检查了最新提交 e7b67dc00a,Version 模型回退、普通 child 按节点执行时加载,以及 ToolSet 提前加载这几项已经符合预期。不过迁移侧还有两个阻塞问题:

  1. packages/service/support/permission/app/resource.ts 中,getUnauthorizedAppResources 会把所有鉴权异常都转换成“资源不可访问”,filterAuthorizedAppResources 外层又会捕获所有异常并返回 []。因此 Mongo、权限表或模型目录的临时异常仍会被当成无权限处理,迁移随后可能写入合法的空快照并通过校验,无法进入失败重试。

    这里需要精确区分预期业务错误和基础设施错误:明确的无权限(以及产品语义确定要过滤的资源不存在、成员不存在)可以过滤;Mongo、模型目录等未知异常必须继续抛出,让该 App/Version 迁移失败并记录失败。

  2. backfillAppVersionResourceRecords 当前使用 record.tmbId 鉴权。这个字段是创建/发布该 Version 的成员,可能是协作者,不保证是 App owner。只有补建正式 Version 的路径使用了 currentApp.tmbId。如果迁移要求统一按 App owner 生成快照,已有 Version 的回填也需要根据 appId 取得 App.tmbId 后再鉴权。

另外,即使权限查询异常改为向上抛出,最终 validation 仍会通过 replaceFailures 将原始 Mongo 错误覆盖为 App Version resources are still missing or invalid。迁移状态仍然是失败,但具体失败原因会丢失,建议保留已有的处理阶段错误。

建议补充至少三类测试:明确无权限时过滤资源、Mongo/权限查询异常时不写 resources 且记录失败、Version 创建者不是 App owner 时按 App owner 权限生成快照。

@c121914yu

Copy link
Copy Markdown
Collaborator

基于最新 head e7b67dc,补充 review:

  1. 动态工具运行时鉴权仍使用 runningAppInfo.tmbId(packages/service/core/workflow/dispatch/ai/agent/sub/tool/index.ts:141-148),但调用入口使用的是 runningUserInfo.tmbId。此处应改为 runningUserInfo.tmbId,并同步修改测试,不能把应用创建者身份作为预期。

  2. 旧版 MCP 父子 App 格式需要继续兼容。packages/service/core/app/mcp.ts:435-437 在没有内联 mcpToolSet 时直接返回 [],应恢复查询 parentId 子 App 并保留旧 header 规范化逻辑。当前兼容测试创建了内联 Version,未覆盖旧父 App + 子 App、无内联配置的真实数据。

  3. 关于异常 _id 只校验一个 batch:它不会因此直接标记迁移成功,因为只要发现一条异常记录就会 context.fail。实际问题是异常记录超过一个 batch 时,failedRecords 只展示前一批,管理员需要多轮修复和重试才能看到后续记录,失败诊断不完整。建议完整扫描,或明确记录剩余异常数量并保证错误快照可定位。

  4. getCachedModelHandle 仍被 packages/service/core/app/resources.ts 和 packages/service/core/workflow/utils/resource.ts 直接导入。modelAccess.test.ts 明确禁止业务模块直接访问 handle.ts,因此会触发 private snapshot access。建议通过 getModelHandle 或 core/ai/config/utils.ts 中职责明确的兼容辅助函数访问,不建议简单放宽架构测试白名单。

结论:第 1、2 点需要修复;第 3 点是迁移失败信息完整性问题;第 4 点是当前 CI/架构测试阻塞项。

…orization

feat(app): complete resource permission checks and runtime authorization

feat(app): complete resource permission checks and runtime authorization

feat(app): optimize resource migration batching and support system skill authorization

feat(app): migrate workflow state to versions and enforce resource permissions

fix(app): complete version workflow resource migration

fix(app): align resource lookup id queries

fix(app): align resource lookup id queries

feat(resource): missing workflow resources

feat: resource ACL markers and draft concurrency

Introduce resource-level permission markers and optimistic draft checks.

- Add permissionDenied flag to resource/type schemas (skills, datasets, tools) and propagate through rewriteAppWorkflowToDetail.
- Perform viewer-side permission hints for snapshot-external resources; normalize child tool ids into parent tool snapshot entries.
- Treat invalid stored snapshots as empty to avoid bypassing publish-time ACL checks; resolveStoredAppResources now merges and normalizes legacy ids.
- Publish API accepts draftVersionId for optimistic concurrency and enforces matchedCount checks on updates (autoSave & publish).
- Load draft chatConfig for workflow debug when client omits it.
- Frontend: show permission-denied UI, workflow check supports resource_no_permission.
- Tests updated/added to cover behaviors.

feat(app): replace draftVersionId pointer with latest-version reads

fix: CAS update for published app version

fix(app): tighten resource permission and model extraction

feat(app): enforce model resource permissions and preserve legacy fields

- Integrate AI models into standard app resource ACL permissions and simplify model snapshot format to { type: 'model', id }

- Validate model resources at workflow node dispatch boundary and standalone auxiliary endpoints (createQuestionGuide, getSpeech)

- Align tool runtime with version workflow and restore dataset search model imports

- Align getUnauthorizedAppResources with standard auth helpers (authAppByTmbId, authDatasetByTmbId, authSkillByTmbId)

- Preserve legacy workflow fields (modules, edges, chatConfig, resourceRefs) during 4163 migration for rollback compatibility

- Retain backward-compatible modules field in CreateAppBodySchema and AppDetailType

- Add and update test suites for model permissions, question guide, speech synthesis, and migration
fix(app): align form app resource validation and error prompts

fix(app): preserve workflow entry point schema

refactor(app): consolidate resource error states and extract SkillCard

fix(app): align resource tests with model handles

fix(app): resolve upstream rebase integration

fix(app): resolve upstream rebase integration

fix(app): handle soft-deleted resource auth and align tool error handling

fix(app): support app baseline in model summary and smooth selector reload
fix(workflow): authorize dynamic runtime toolset by running user

fix(app): fallback to cached models when resolving legacy app   resources

chore(app): update Pro resource permission runtime

refactor(workflow): JIT on-demand loading for static resources
…4.17.1

- Move app resource snapshot backfill migration task to 4.17.1
- Aggregate legacy MCP child apps into parent published Version toolSet nodes during migration
- Provide runtime backward compatibility in getMCPChildren for legacy child apps
- Skip scanning and validation on child apps with parentId
- Support delay option on SystemMigration registry protocol and forbid delay on blocking startup migrations
- Add SYSTEM_MIGRATION_DELAY_SECONDS environment variable to configure delay duration in seconds
- Delay execution in Runner with active heartbeat lease renewal and signal abort support
- Configure delay: true on 20260916_backfill_app_resource_snapshots
- Update environment variable documentation, .env.template, and unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants