However it seems that the pylxd call to get all instances has stopped working. I have written a simple Python script to attempt to access the remote server’s instances:
from pylxd import Client
client = Client(endpoint='https://192.168.6.10:8443', verify=False)
client.instances.all()
Running the script gives me the following error which I hadn’t encountered previously:
Traceback (most recent call last):
File "test.py", line 4, in <module>
print(client.instances.all())
File "/usr/local/lib/python3.8/dist-packages/pylxd-2.2.11-py3.8.egg/pylxd/models/instance.py", line 252, in all
response = client.api[cls._endpoint].get()
File "/usr/local/lib/python3.8/dist-packages/pylxd-2.2.11-py3.8.egg/pylxd/client.py", line 159, in get
self._assert_response(response,
File "/usr/local/lib/python3.8/dist-packages/pylxd-2.2.11-py3.8.egg/pylxd/client.py", line 117, in _assert_response
raise exceptions.LXDAPIException(response)
pylxd.exceptions.LXDAPIException: not authorized
Would this be due to changes in LXD’s API or pylxd itself? Any tips are appreciated.
That would make sense, thank you. I previously left the verify option as false since the container was isolated and it simplified the deployment process.
Would this be due to updates in LXD’s API? I am questioning since I had previsously worked with remote servers with pylxd without certificates successfully.
You might have worked with them by using the local socket without a cert (pylxd might do it behind the scenes), but you haven’t worked with them over HTTP without a cert.
to skip the certificate verification using pylxd 2.2.11 and it has worked without issues on LXD 4.13 .
I’ll have to retest it using an older version of LXD to confirm. I am unsure about the inner workings of pylxd but since it worked before without the need to setup certificates I left it as is. I’ll report back with updates as soon as I finish testing
verify has nothing todo with authenticating you. Could you image if LXD had 1 parameter to skip all authentication? Hacker news / Reddit would have a field day.
It appears looking at pylxd if you pass this configuration;
client = Client(verify=False)
// or
client = Client()
Then pylxd will try to use socket to connect, which may have adverse side effects i’m not aware of yet aware of - abusing the socket is not a solution, default to HTTP then work backwards.
Previous versions of LXD seem to create the cert files at : $HOME/snap/lxd/current/.config/lxc
pylxd (at least on version 2.2.11) automatically detects this path and uses it to fetch the certificate and key files.
Newer versions of LXD, including LTS 4.0.7, seem to create the certs at $HOME/snap/lxd/common/config/ which makes pylxd unable to find the files automatically if the paths are not provided.
Pylxd currently looks for ~/snap/lxd/current/.config/lxc/client.crt and then ~/.config/lxc/client.crt.
I wonder if we shouldn’t just replace the former with /snap/lxd/common/config/client.crt given it seems to have been the default for quite a long time, or add it as a first option.