Cannot add-model to localhost (lxd) with a controller running on microk8s

Hi there,

I’m hitting an issue trying to add a model on the ‘localhost’ cloud (lxd) given that the controller lives on microk8s.

Given a fresh install:

$ snap list
juju             3.6.6               31166  3/stable            canonical✓     -
lxd              5.21.3-c5ae129      33110  5.21/stable         canonical✓     -
microk8s         v1.31.7             7968   1.31-strict/stable  canonical✓     -

Proceeding with the following setup goes fine:

$ juju clouds
...
Clouds available on the client:
Cloud      Regions  Default    Type  Credentials  Source    Description
localhost  1        localhost  lxd   1            built-in  LXD Container Hypervisor
microk8s   1        localhost  k8s   1            built-in  A Kubernetes Cluster
$
$ juju bootstrap microk8s k8s-ctrl
$ 
$ juju add-cloud -c k8s-ctrl localhost
$
$ juju clouds
...
Clouds available on the controller:
Cloud      Regions  Default    Type
localhost  1        localhost  lxd  
microk8s   1        localhost  k8s
...

However once I try to add a model on ‘localhost’, I get an error:

$ juju add-model --controller k8s-ctrl lxd-model localhost --debug --show-log 
18:28:22 INFO  juju.cmd supercommand.go:56 running juju [3.6.6 48f295cccb79738cc30a3d280da011a027cd4d16 gc go1.24.2]
18:28:22 DEBUG juju.cmd supercommand.go:57   args: []string{"/snap/juju/31166/bin/juju", "add-model", "--controller", "k8s-ctrl", "lxd-model", "localhost", "--debug", "--show-log"}
18:28:22 INFO  juju.juju api.go:90 connecting to API addresses: [10.152.183.120:17070]
18:28:22 INFO  juju.kubernetes.klog klog.go:113 Use tokens from the TokenRequest API or manually created secret-based tokens instead of auto-generated secret-based tokens.%!(EXTRA []interface {}=[])
18:28:22 DEBUG juju.api apiclient.go:537 starting proxier for connection
18:28:22 DEBUG juju.api apiclient.go:541 tunnel proxy in use at localhost on port 41217
18:28:22 DEBUG juju.api apiclient.go:1080 successfully dialed "wss://localhost:41217/api"
18:28:22 INFO  juju.api apiclient.go:601 connection established to "wss://localhost:41217/api"
18:28:22 INFO  cmd authkeys.go:113 Adding contents of "/home/ubuntu/.local/share/juju/ssh/juju_id_rsa.pub" to authorized-keys
18:28:22 DEBUG juju.container.lxd connection.go:180 using LXD socket at path: "/var/snap/lxd/common/lxd/unix.socket"
18:28:22 DEBUG juju.api monitor.go:35 RPC connection died
ERROR failed to open environ: LXD socket not found; is LXD installed & running?

Please install LXD by running:
	$ sudo snap install lxd
and then configure it with:
	$ newgrp lxd
	$ lxd init

18:28:22 DEBUG cmd supercommand.go:571 error stack: 
failed to open environ: LXD socket not found; is LXD installed & running?

Please install LXD by running:
	$ sudo snap install lxd
and then configure it with:
	$ newgrp lxd
	$ lxd init

github.com/juju/juju/rpc.(*Conn).Call:178: 
github.com/juju/juju/api.(*state).APICall:1182: 
github.com/juju/juju/api/client/modelmanager.(*Client).CreateModel:78: 
github.com/juju/juju/cmd/juju/controller.(*addModelCommand).Run:275:

Obviously LXD is installed and initialized. I can successfully juju bootstrap localhost tmp-ctrl and then add a model to make sure of that.

Furthermore, I can also successfully expose LXD on a local port, add-cloud it as a remote cloud with the IP to both the client & microk8s controller and proceed with adding a model and deploying stuff… So this really points toward an integration issue with the snap socket.

Any idea what going on and/or any suggestions as to how to get this setup working?

Thanks.