Skip to content

feat(api): list authorized datasets for scoped knowledge API keys - #45247

Open
XiaoBa-Yu wants to merge 1 commit into
langgenius:mainfrom
XiaoBa-Yu:codex/scoped-dataset-list
Open

XiaoBa-Yu wants to merge 1 commit into
langgenius:mainfrom
XiaoBa-Yu:codex/scoped-dataset-list

Conversation

@XiaoBa-Yu

@XiaoBa-Yu XiaoBa-Yu commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #45246

Summary

Integrations holding a knowledge API key scoped to Classic datasets cannot discover their authorized dataset IDs: GET /v1/datasets returns 403. This change lets a key with Classic bindings list only those datasets, reusing the DatasetServiceApiGrant query boundary introduced by #44840.

  • Workspace-wide keys retain upstream tenant-scoped visibility, independent of the Owner's personal ACL.
  • Legacy-only and mixed Classic/KnowledgeFS keys can list only their bound Classic datasets. Scope filtering precedes search, tags, pagination and counting; RBAC, maintainer fallback and include_all cannot widen it.
  • KnowledgeFS-only keys keep the existing 403 on this legacy collection. A mixed key whose last Classic binding is removed also returns 403, rather than becoming unrestricted. An admitted key whose search matches no datasets still gets a normal empty list.
  • Dataset creation, other collection operations, direct resource checks and resource-access-token resolution retain their existing admission rules. This does not add KnowledgeFS discovery or migrate key bindings.

This intentionally revises collection rejection for keys with Classic dataset bindings from #37569. No migration, frontend behavior change or response-schema change is required. The API description and scope documentation are updated.

Validation

  • 368 targeted tests passed across Service API dataset routes/authentication, dataset services, resource-access-token services and key binding repositories.
  • New rejection cases failed before the change (200 instead of 403) and passed afterward. Real-route SQLite coverage includes KnowledgeFS-only GET/HEAD, mixed-key projection and revocation of its last Classic binding, RBAC on/off, include_all, member-private authorized datasets, unbound Owner datasets, cross-tenant isolation, search and pagination.
  • Full make type-check-core, make lint, staged test-double guard and git diff --check passed.

Tests use temporary SQLite resources, real tag queries and response serialization. Token identity lookup and external model configuration are replaced at test boundaries; scope resolution and query filtering are real. Production databases and running services were not used. Container integration tests are CI-owned; the latest revision's remote CI result must be checked separately.

Screenshots

N/A — backend authorization behavior only; the existing response shape is preserved.

Checklist

  • This change requires a documentation update, included: Dify Document — API source/generated descriptions are updated; separate dify-docs handoff is pending.
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. — Repository API/scope documentation is updated; separate dify-docs handoff remains pending.
  • I ran backend lint and full type checks (make lint and make type-check-core). Frontend checks are N/A for this backend-only behavior change.

From Codex

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-27 07:17:50.135148611 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-27 07:17:38.826994926 +0000
@@ -2441,27 +2441,27 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/unit_tests/controllers/service_api/test___init__.py:775:12
 ERROR Argument `() -> Session` is not assignable to parameter `session_factory` with type `sessionmaker[@_]` in function `sqlalchemy.orm.scoping.scoped_session.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:121:27
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:123:27
 ERROR Missing argument `app_model` in function `protected_view` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:291:36
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:293:36
 ERROR Missing argument `app_model` in function `protected_view` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:366:61
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:368:61
 ERROR Missing argument `end_user` in function `protected_view` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:366:61
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:368:61
 ERROR Missing argument `app_model` in function `protected_view` [missing-argument]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:523:36
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:525:36
 ERROR Object of class `NoneType` has no attribute `last_used_at` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:527:16
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:529:16
 ERROR Argument `Literal['abnormal']` is not assignable to parameter `value` with type `AppStatus | SQLCoreOperations[AppStatus]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:562:28
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:564:28
 ERROR Object of class `NoneType` has no attribute `tenant_id` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:995:16
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:997:16
 ERROR Object of class `NoneType` has no attribute `dataset_ids` [missing-attribute]
-   --> tests/unit_tests/controllers/service_api/test_wraps.py:996:16
+   --> tests/unit_tests/controllers/service_api/test_wraps.py:998:16
 ERROR Object of class `NoneType` has no attribute `dataset_ids` [missing-attribute]
-    --> tests/unit_tests/controllers/service_api/test_wraps.py:1099:16
+    --> tests/unit_tests/controllers/service_api/test_wraps.py:1105:16
 ERROR Object of class `NoneType` has no attribute `last_used_at` [missing-attribute]
-    --> tests/unit_tests/controllers/service_api/test_wraps.py:1101:16
+    --> tests/unit_tests/controllers/service_api/test_wraps.py:1107:16
 ERROR Argument `list[Unknown]` is not assignable to parameter `llm_response` with type `Generator[LLMResultChunk]` in function `core.agent.output_parser.cot_output_parser.CotAgentOutputParser.handle_react_stream_output` [bad-argument-type]
   --> tests/unit_tests/core/agent/output_parser/test_cot_output_parser.py:56:71
 ERROR No matching overload found for function `str.join` called with arguments: (list[AgentScratchpadUnit.Action | str]) [no-matching-overload]

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 88.02% 88.02% +0.00%
Strict coverage 87.65% 87.66% +0.01%
Typed symbols 98,532 98,578 +46
Untyped symbols 13,470 13,470 0
Modules 4708 4708 0

@github-actions github-actions Bot added the web This relates to changes on the web. label Nov 1, 2026
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.60%. Comparing base (15384ac) to head (47ce11b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #45247      +/-   ##
==========================================
+ Coverage   90.55%   90.60%   +0.04%     
==========================================
  Files        6615     6635      +20     
  Lines      411627   413534    +1907     
  Branches    82518    82674     +156     
==========================================
+ Hits       372759   374678    +1919     
+ Misses      32473    32463      -10     
+ Partials     6395     6393       -2     
Flag Coverage Δ
api 90.31% <100.00%> (+0.07%) ⬆️
cli 94.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 1, 2026
@XiaoBa-Yu
XiaoBa-Yu force-pushed the codex/scoped-dataset-list branch 2 times, most recently from 93a2ae7 to 06699bf Compare November 1, 2026 10:54
@XiaoBa-Yu
XiaoBa-Yu marked this pull request as ready for review November 1, 2026 11:05
@XiaoBa-Yu
XiaoBa-Yu force-pushed the codex/scoped-dataset-list branch 3 times, most recently from a3f71d8 to 2e60f77 Compare November 5, 2026 03:22
@XiaoBa-Yu
XiaoBa-Yu force-pushed the codex/scoped-dataset-list branch from 2e60f77 to a5022e4 Compare November 17, 2026 06:22
Allow legacy-only and mixed knowledge API keys to discover their authorized
Classic dataset IDs through the collection read endpoint. Reuse the upstream
DatasetServiceApiGrant query boundary before search, pagination and counting.

Keep KnowledgeFS-only keys forbidden on the legacy collection, including
mixed keys whose last Classic binding has been removed. Preserve workspace
key visibility and all other operation/resource-token admission rules.

Cover the registered route with SQLite regressions for tenant and resource
isolation, member-private datasets, RBAC/include_all, mixed scopes, revoked
bindings and empty search results. Update API and scope documentation.
@XiaoBa-Yu
XiaoBa-Yu force-pushed the codex/scoped-dataset-list branch from a5022e4 to 47ce11b Compare November 27, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow scoped knowledge API keys to discover authorized dataset IDs

1 participant