Skip to content

feat: Expose per-host permissions from the vfolder host list#12333

Open
rapsealk wants to merge 5 commits into
mainfrom
feat/list-hosts-allowed-permissions
Open

feat: Expose per-host permissions from the vfolder host list#12333
rapsealk wants to merge 5 commits into
mainfrom
feat/list-hosts-allowed-permissions

Conversation

@rapsealk

Copy link
Copy Markdown
Member

Summary

GET /folders/_/hosts returned only allowed — the list of host names a user may use — while discarding the per-host permission sets that list_hosts already computes internally as a VFolderHostPermissionMap. As a result, a client cannot tell apart hosts where the user may create a vfolder (create-vfolder) from hosts where they only hold read/mount permissions (mount-in-session, download-file, …). The host list therefore advertises hosts that fail later when a create is attempted against them.

This adds an allowed_permissions mapping (host → permission names) to the response, sourced from the permission map the service already builds — so clients can mark or hide non-writable hosts up front.

Changes

  • ListHostsActionResult (services/vfolder/actions/storage_ops.py): add allowed_permissions: dict[str, list[str]].
  • VFolderService.list_hosts (services/vfolder/services/vfolder.py): populate it from allowed_hosts.to_json() (the same filtered VFolderHostPermissionMap used for allowed).
  • ListHostsResponse (common/dto/manager/vfolder/response.py): add allowed_permissions, defaulting to {} so existing clients parse unchanged.
  • VFolderHandler.list_hosts (api/rest/vfolder/handler.py): pass the field through.
  • Tests: service-level assertion that a create-capable host and a read-only host are distinguished; DTO round-trip + backward-compat (absent field → {}).

Compatibility

Additive and backward-compatible: allowed is unchanged and allowed_permissions is optional with an empty-mapping default. Its keys mirror allowed exactly. The per-host permission data was already exposed via the V2 GraphQL storage-host-permissions query; this closes the gap for the REST host-list endpoint.

The `GET /folders/_/hosts` response only returned `allowed` — the host
names a user may use — discarding the per-host permission sets that
`list_hosts` already computes. Clients therefore could not tell apart
hosts the user may create vfolders on from read-only hosts, and would
fail late when a create was attempted against a non-writable host.

Carry the existing `VFolderHostPermissionMap` through
`ListHostsActionResult` into `ListHostsResponse` as `allowed_permissions`
(host -> permission names, e.g. `create-vfolder`). The field defaults to
an empty mapping so existing clients keep parsing unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 22, 2026 01:16
@rapsealk rapsealk requested a review from a team as a code owner June 22, 2026 01:16
@github-actions github-actions Bot added the size:M 30~100 LoC label Jun 22, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added comp:manager Related to Manager component comp:common Related to Common component labels Jun 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the vfolder REST host-list endpoint by exposing per-host permission sets alongside the existing allowed host list, enabling clients to distinguish create-capable hosts from read-only hosts before attempting vfolder creation.

Changes:

  • Adds an allowed_permissions mapping (host → permission values) to the list_hosts service result and REST response DTO.
  • Populates the new mapping in VFolderService.list_hosts() using the existing VFolderHostPermissionMap computed during host filtering.
  • Adds unit tests covering service behavior and DTO backward-compatibility (missing field defaults to {}).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/manager/services/vfolder/test_vfolder_storage_service.py Adds a service-level test ensuring create-capable and read-only hosts are distinguished via allowed_permissions.
tests/unit/common/dto/manager/vfolder/test_response.py Adds DTO tests for the new field and for default-empty backward compatibility.
src/ai/backend/manager/services/vfolder/services/vfolder.py Includes allowed_permissions in the service action result returned by list_hosts().
src/ai/backend/manager/services/vfolder/actions/storage_ops.py Extends ListHostsActionResult with the new allowed_permissions field.
src/ai/backend/manager/api/rest/vfolder/handler.py Passes allowed_permissions through into the REST response model.
src/ai/backend/common/dto/manager/vfolder/response.py Adds allowed_permissions to ListHostsResponse with a {} default for compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

default=default_host,
allowed=sorted(allowed_hosts),
volume_info=volume_info,
allowed_permissions=allowed_hosts.to_json(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in c34ff84. allowed_permissions is now built with sorted hosts and sorted permission names instead of to_json()'s set ordering, so the REST response is deterministic. Added a test asserting each permission list is sorted.

`VFolderHostPermissionMap.to_json()` iterates over a set, so the per-host
permission lists were emitted in nondeterministic order — unstable JSON
once exposed in the REST response. Build `allowed_permissions` with sorted
hosts and sorted permission names instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
"by host name (e.g. `create-vfolder`, `mount-in-session`). Lets "
"clients distinguish hosts the user may create folders on from "
"read-only hosts, since `allowed` carries only host names. "
"Added in 26.4.4."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be 26.4.5

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — corrected to 26.4.5 (since 26.4.4 is already in RC). Updated in the latest push.

26.4.4 is already cutting RCs; a feature landing on main now ships in
26.4.5. Per reviewer feedback.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rapsealk rapsealk requested a review from fregataa June 22, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component comp:manager Related to Manager component size:M 30~100 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants