Copied ZFS Storage Volumes loose original uid/gid mappings

The problem

When copying a storage volume to another LXD server you loose the volatile.idmap.last and volatile.idmap.next config variables! This is very bad if the destination LXD server has different uid/gid mappings. For example when copying storage volumes between an LXD v3 PPA server (security.idmap.base=165536, secutity.idmap.size=65536) to an LXD v3 Snap server (security.idmap.base=1000000
, secutity.idmap.size=1000000000) files on copied storage volumes will have the wrong uid/gids!

Sample run

lxd603% lxc storage volume show ${PREFIX}pool ${PREFIX}vol
config:
volatile.idmap.last: ‘[{“Isuid”:true,“Isgid”:false,“Hostid”:165536,“Nsid”:0,“Maprange”:65536},{“Isuid”:false,“Isgid”:true,“Hostid”:165536,“Nsid”:0,“Maprange”:65536}]’
volatile.idmap.next: ‘[{“Isuid”:true,“Isgid”:false,“Hostid”:165536,“Nsid”:0,“Maprange”:65536},{“Isuid”:false,“Isgid”:true,“Hostid”:165536,“Nsid”:0,“Maprange”:65536}]’
description: “”
name: temp424-vol
type: custom
used_by:
- /1.0/containers/temp424-vm
location: none

lxd603% lxc storage volume copy ${PREFIX}pool/${PREFIX}vol ${REMOTE_LXD_SERVER}:${PREFIX}pool/${PREFIX}vol
Storage volume copied successfully!

lxd603% lxc storage volume show ${REMOTE_LXD_SERVER}:${PREFIX}pool ${PREFIX}vol
config: {}
description: “”
name: temp424-vol
type: custom
used_by:
location: none

As you can see the “volatile.idmap” values do not show on the destination server! Is there a way to keep the “volatile.idmap” settings with the “lxc storage volume copy” command? My environment is Ubuntu 18.04, LXD Snap v3.11.

Commands to reproduce the problem:

  1. On origin LXD Server 1 create profile, storage, volume and container
PREFIX=temp422-

lxc profile create ${PREFIX}lxd3_ppa_idmap
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.base 165536
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.size 65536
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.isolated true
lxc launch ubuntu:18.04 ${PREFIX}vm --profile ${PREFIX}lxd3_ppa_idmap --profile default
lxc exec ${PREFIX}vm -- exec "mkdir /${PREFIX}mp"
lxc storage create ${PREFIX}pool zfs source=rpool/${PREFIX}lxd
lxc storage volume create ${PREFIX}pool ${PREFIX}vol
lxc storage volume attach ${PREFIX}pool ${PREFIX}vol ${PREFIX}vm /${PREFIX}mp
  1. Prepare ZFS storage on destination LXD server 2
REMOTE_LXD_SERVER=lxd614

lxc storage create ${REMOTE_LXD_SERVER}:${PREFIX}pool zfs source=rpool/${PREFIX}lxd
  1. Copy storage volume and verify different settings
lxc storage volume show ${PREFIX}pool ${PREFIX}vol
lxc storage volume copy ${PREFIX}pool/${PREFIX}vol ${REMOTE_LXD_SERVER}:${PREFIX}pool/${PREFIX}vol
lxc storage volume show ${REMOTE_LXD_SERVER}:${PREFIX}pool ${PREFIX}vol
  1. To cleanup the test items
lxc stop ${PREFIX}vm
lxc delete ${PREFIX}vm 
lxc storage volume delete ${PREFIX}pool ${PREFIX}vol
lxc storage delete ${PREFIX}pool
lxc profile delete ${PREFIX}lxd3_ppa_idmap
lxc storage volume delete ${REMOTE_LXD_SERVER}:${PREFIX}pool ${PREFIX}vol
lxc storage delete ${REMOTE_LXD_SERVER}:${PREFIX}pool

BTW, I’m using the following workaround on the destination server. This works but this is a very complicated way to fix an easy thing…

  1. Create profile with uid/gid mappings of origin lxd server

PREFIX=temp422-

lxc profile create ${PREFIX}lxd3_ppa_idmap
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.base 165536
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.size 65536
lxc profile set ${PREFIX}lxd3_ppa_idmap security.idmap.isolated true

  1. Create a temporary container using this profile

lxc launch ubuntu:18.04 ${PREFIX}tmpvm --profile ${PREFIX}lxd3_ppa_idmap --profile default

  1. Attach the copied storage volume to have the “volatile” vars set:

lxc storage volume show ${PREFIX}pool ${PREFIX}vol
lxc exec ${PREFIX}tmpvm – exec “mkdir /tmpmount”
lxc storage volume attach ${PREFIX}pool ${PREFIX}vol ${PREFIX}tmpvm /tmpmount
lxc storage volume detach ${PREFIX}pool ${PREFIX}vol ${PREFIX}tmpvm
lxc storage volume show ${PREFIX}pool ${PREFIX}vol

  1. To cleanup the workaround items

lxc stop ${PREFIX}tmpvm
lxc delete ${PREFIX}tmpvm
lxc profile delete ${PREFIX}lxd3_ppa_idmap

Can you file this as an issue at https://github.com/lxc/lxd/issues?

@stgraber: Ok, here you go:
https://github.com/lxc/lxd/issues/5640