Lxc config device add or remove returns an error

I’m getting an odd error message when running lxc config device add or remove commands. This is the error I get on the host

Error: Invalid devices: Not an IP address: localhost

And here are the commands that generate them…

lxc config device remove c1 myport80

lxc config device add c1 myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:localhost:80

None of the containers are reachable via the web and I just ran a kernel upgrade on Debian 9 earlier today…

Does anyone have any ideas? lxc and lxd are 3.13, installed via snap…

You need to try instead with

lxc config device add c1 myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80

It is likely that it was allowed in older versions of LXD to put localhost there.
Also, in /snap/core/current/etc/hosts it shows that the snap knows about localhost.

1 Like

That still returns Error: Invalid devices: Not an IP address: localhost

I’ve been working through this thread but I can’t see anything too dramatic… Running on Debian stretch container networking not working

You cannot get the message Error: Invalid devices: Not an IP address: localhost if you have not specified localhost in the command line.

Can you check again that you have replaced localhost with 127.0.0.1 in the command?

Yeah… this is what I ran…

lxc config device add haproxy myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801

This error message is something I’ve tracked down as I can’t load any sites in various containers… everything seems to run fine but this is the only error message I’ve been able to find so far…

Also, I can run wget successfully, so outbound stuff is fine but the sites themselves can’t be reached…

Containers all have IP addresses and so on, so I’m at a bit of a loss…

When rebooting having installed the new kernel, I had to re-install zfs to get the containers to start, but this ran fine…

sudo apt -y install linux-headers-$(uname -r)
sudo apt -y install zfsutils-linux zfs-zed
sudo apt -y install spl-dkms
sudo apt -y install zfs-dkms

I’m using the default bridge… lxc network info lxdbr0 shows

Name: lxdbr0
MAC address: fe:19:f7:0d:17:34
MTU: 1500
State: up

Ips:
  inet	10.114.60.1
  inet6	fd42:8037:c8ed:bf9a::1
  inet6	fe80::1856:5cff:feac:c112

Network usage:
  Bytes received: 1.47MB
  Bytes sent: 96.56MB
  Packets received: 18982
  Packets sent: 18882

When you add a device with lxc config device add ..., you give an instruction to LXD to perform this device addition whenever you restart that container.
Therefore, if previously you could run specify localhost in the proxy device, now you cannot.
If since you cannot now, you need to first remove the old proxy device and add a new one.

$ lxc config device list mycontainer
myport80
$ lxc config device remove mycontainer myport80
Device myport80 removed from mycontainer
$ lxc config device add mycontainer myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801
Device myport801 added to mycontainer
$ lxc config device list mycontainer
myport801
$ 

If you get some error, please paste verbatim the commands and their responses. 

Here are the commands and corresponding errors…

debian@br-lxd:~$ lxc config device list haproxy
myport443
myport80
myport8000
debian@br-lxd:~$ lxc config device remove haproxy myport80
Error: Invalid devices: Not an IP address: localhost
debian@br-lxd:~$ lxc config device add haproxy myport801 proxy listen=tcp:0.0.0.0:801 connect=tcp:127.0.0.1:801
Error: Invalid devices: Not an IP address: localhost

Ok, this is so straightforward.

What happened is that with older versions of LXD, you could specify localhost but now you can’t.
But what happens if you have some lingering old proxy devices that still mention localhost?
In that case, you are stuck because you cannot perform any other configuration on this container!
LXD will not accept any change to the configuration of the container because after any change, the configuration will still be invalid due to the localhost.

But why can’t you just remove the offending proxy device (with localhost)?
Because it looks like you have two offending proxy devices, and with lxc config device remove ... you can remove only one device at a time. But you cannot remove any of the two, because the other will still be in there.

What you need, is a workaround to sort this issue.
Can you run

debian@br-lxd:~$ lxc config edit haproxy

and edit out both the localhost references in your proxy devices?
Does that command work for you or does LXD complain even with lxc config edit haproxy?

1 Like

Ok, thank you… I just edited this line connect: tcp:localhost:80 to now read connect: tcp:0.0.0.0:80… there were 3 lines in the config with localhost entries… Everything seems to be working now!

Hi!

You probably have two instances of proxy devices that mention the localhost.
You need to replace both localhosts with 127.0.0.1. Then, save.

devices:
  compartilhado:
    path: /compartilhado
    source: /compartilhado
    type: disk
  glassfish4848:
    connect: tcp:localhost:4848
    listen: tcp:0.0.0.0:4848
    type: proxy
  temp:
    path: /temp
    source: /temp
    type: disk

lxc config device remove appserv-desativado glassfish4848

Error: Invalid value for device option connect: Not an IP address: localhost

lxc delete appserv-desativado

Error: Invalid value for device option connect: Not an IP address: localhost

lxc config edit appserv-desativado

Config parsing error: Invalid devices: Invalid value for device option connect: Not an IP address: localhost
Press enter to start the editor again

(after try to save)

# lxc version
Client version: 3.16
Server version: 3.16

Can you show lxc config show --expanded appserv-desativado?

Nevermind, there is a bug in LXD 3.16 which is preventing you from fixing this…

@tomp the fact that we’re validating the devices on instantiation makes it impossible to fix such a scenario by removing or editing the device as its current state prevents LXD from loading it. We need to change that so it’s possible to fix broken configuration.

As a workaround, you can run:

lxd sql global "UPDATE containers_devices_config SET value='tcp:127.0.0.1:4848' WHERE value='tcp:localhost:4848';"

That will replace the value directly in the database and should fix your container.

Obviously the real fix is to allow us to fix/remove broken device configuration which shouldn’t be too difficult for @tomp to sort out.

@stgraber

Sorry about this, although that configuration (using “localhost” for the connect option) has been invalid since 3.15, the new device framework’s validation in 3.16 is rather over zealous in preventing use of devices that have invalid config. So much so that you are unable to edit or remove it to fix the problem.

This issue is fixed with this pull request: https://github.com/lxc/lxd/pull/6086

it worked, thanks