Skip to content

Commit

Permalink
Expose idmap
Browse files Browse the repository at this point in the history
These might be important for users to know which uid/gid to use when
sharing data between host and container.
  • Loading branch information
william-gr committed Dec 19, 2024
1 parent d754ffb commit fd038b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit fd038b5

Please sign in to comment.