-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible: cannot connect to the LXD server (due to python version) #79473 #5616
Comments
This comment was marked as outdated.
This comment was marked as outdated.
unfortunately, it's been months I debugged this. otherwise I would smash you guys with code blocks and the solution to this. I know this is a poor bug report. anyway, iirc it had something to do with the change of the ssl context in python 3.10. and you had to use ssl._create_default_https_context = ssl._create_unverified_context to make it work or something related to that. cant remember anymore. but it was a really easy fix for me back then. basically, python 3.10 wants to sslverify the remote LXD's cert, and can't (since it is a self-signed cert), then gives up and throws an exception. anyway, Im using alpine/3.15 for my ansible environments since then and have no problem with this bug anymore. but since I didnt see anyone mention this bug that it is actually due to python 3.10, I thought I should mention it for future people coming from google etc. so, you have any "cannot connect to LXD server", no matter if you're using the lxd inventory plugin or molecule with the molecule_lxd module? just get rid of python 3.10 and install python 3.9.15 and that will fix the problem. |
!component =plugins/inventory/lxd.py |
Files identified in the description: If these files are incorrect, please update the |
I don't see any code that disables certificate validation in the existing code. So why do you need to disable certificate validation (which is something really dangerous!) to get this working? It sounds to me like there's another underlying problem you are working around by simply disabling certificate validation. |
because - like I said - it is a private cert. especially when working with LXD. lxd generates a self-signed cert. and the python lib (whatever is used, Im not into python really), I guess it is the ssl lib, doesnt like self-signed certs. I disabled the ssl_verify back then, because of the self-signed cert. not because I didnt want to verify a cert in general. it is the very special case of a self-signed cert verification that fails. I didnt know any other way around back then, so I just disabled it completely. |
I don't see why this should change between Python 3.9 and Python 3.10. Self-signed certificates should never have been accepted. |
I dont know. see this bug for example: https://bugs.gentoo.org/show_bug.cgi?id=835498 and see the commit that fixed that issue. it has something to do with |
he discovered the same thing like me. |
here is another example, with a similar solution: the web is full with questions regarding this. and all relates to python 3.10. everything < 3.10 works just fine. |
Hello @ALL, first thanks to: @omani for sharing that informations. I took a look and I used code/utils at the inventory Plugin, which probably goes back to the early days of lxd implementations. If I see it correctly these functions are used in a lot of modules:
So i will go deeper to fix that problem but i have to build a testlab first. Thanks Frank |
The default location of the client certificate implies the authentication flow described in lxd docu . IMHO a lot better than explaining users, that lxd default authentication just is not secure and they should acknowledge that by setting validate_certs=false and feel guilty about it. This approach to fixing the bug suggests the enhancement server_cert (in a 2nd PR perhaps?).
@heino You probably invested significant effort in the pyLXD / validate_certs=false route. Do You see a place for that approach in Your work ? From a first sight on read-the-docs it looks like manageable effort: client = Client(
endpoint='http://10.0.0.1:8443',
cert=('/path/to/client.crt', '/path/to/client.key'),
verify='/path/to/server.crt') |
I just ran into a connection issue with a LXD using a SSL certificate issued by letsencrypt. Got the same output as reported in this issue:
When i looked at the actual error it was:
After some digging i found python/cpython#96972 and this line. After changing
to
My connection is working just fine. I'm using |
Yes, it sounds like |
Hello! What's the future of this? LXD uses self-signed server certificates by default and trusts them via password or token, this plugin must support by-pass certificate validation or work with And even better - ability to connect to LXD just by specifying its remote name from local LXC, often it already has all required information (url, certificate, the server also already know our certs). |
I don't think anyone so far worked on adding support for a |
Summary
the lxd inventory plugin (and also molecule with lxd but that is another topic) does not work with python > 3.9.
python 3.10 breaks the LXD module due to SSL verification errors.
Issue Type
Bug Report
Component Name
lxd inventory plugin (and also molecule_lxd, but that is another topic).
Ansible Version
Community.general Version
Configuration
OS / Environment
any OS with python 3.10
Steps to Reproduce
start a new LXD container with alpine 3.16.
install python3 (will install python 3.10):
run a simple lxd inventory plugin or molecule, or anything that uses lxd connection plugin and it will throw an error that it cannot connect to the remote LXD server.
but now do the above steps with alpine 3.15 (which only has python 3.9.15) and everything will work.
the inventory plugin can be used like this. create a lxd.yml in your inventory folder:
Expected Results
no error
Actual Results
LXDRaiseException("cannot connect to LXD server").
Code of Conduct
The text was updated successfully, but these errors were encountered: