diff --git a/src/middlewared/middlewared/api/v25_04_0/virt_instance.py b/src/middlewared/middlewared/api/v25_04_0/virt_instance.py index 02840ac1b886..f161cc341887 100644 --- a/src/middlewared/middlewared/api/v25_04_0/virt_instance.py +++ b/src/middlewared/middlewared/api/v25_04_0/virt_instance.py @@ -37,6 +37,17 @@ class Image(BaseModel): variant: str | None +class IdmapUserNsEntry(BaseModel): + hostid: int + maprange: int + nsid: int + + +class UserNsIdmap(BaseModel): + uid: IdmapUserNsEntry + gid: IdmapUserNsEntry + + class VirtInstanceEntry(BaseModel): id: str name: Annotated[NonEmptyString, StringConstraints(max_length=200)] @@ -48,6 +59,7 @@ class VirtInstanceEntry(BaseModel): environment: dict[str, str] aliases: list[VirtInstanceAlias] image: Image + userns_idmap: UserNsIdmap | None raw: dict | None vnc_enabled: bool vnc_port: int | None diff --git a/src/middlewared/middlewared/plugins/virt/instance.py b/src/middlewared/middlewared/plugins/virt/instance.py index fc7cf81f8531..d21c124d6f87 100644 --- a/src/middlewared/middlewared/plugins/virt/instance.py +++ b/src/middlewared/middlewared/plugins/virt/instance.py @@ -80,6 +80,29 @@ async def query(self, filters, options): 'raw': None, # Default required by pydantic } + idmap = None + if idmap_current := i['config'].get('volatile.idmap.current'): + idmap_current = json.loads(idmap_current) + uid = list(filter(lambda x: x.get('Isuid'), idmap_current)) or None + if uid: + uid = { + 'hostid': uid[0]['Hostid'], + 'maprange': uid[0]['Maprange'], + 'nsid': uid[0]['Nsid'], + } + gid = list(filter(lambda x: x.get('Isgid'), idmap_current)) or None + if gid: + gid = { + 'hostid': gid[0]['Hostid'], + 'maprange': gid[0]['Maprange'], + 'nsid': gid[0]['Nsid'], + } + idmap = { + 'uid': uid, + 'gid': gid, + } + entry['userns_idmap'] = idmap + if options['extra'].get('raw'): entry['raw'] = i