Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133159 / 25.04 / Expose idmap #15234

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/virt_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/middlewared/middlewared/plugins/virt/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading