Skip to content
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

pylxd/client: guard against cert=None #618

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ essentially meaning that the authentication has not yet occurred.

>>> from pylxd import Client
>>> client = Client(
... endpoint='http://10.0.0.1:8443',
... endpoint='https://10.0.0.1:8443',
... cert=('lxd.crt', 'lxd.key'))
>>> client.trusted
False
Expand Down
4 changes: 2 additions & 2 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ certificate to the `verify` argument:

>>> from pylxd import Client
>>> client = Client(
... endpoint='http://10.0.0.1:8443',
... endpoint='https://10.0.0.1:8443',
... cert=('/path/to/client.crt', '/path/to/client.key'),
... verify='/path/to/server.crt')

Expand All @@ -38,7 +38,7 @@ for TLS verification.

>>> from pylxd import Client
>>> client = Client(
... endpoint='http://10.0.0.1:8443',
... endpoint='https://10.0.0.1:8443',
... cert=('/path/to/client.crt', '/path/to/client.key'),
... verify=False)

Expand Down
10 changes: 9 additions & 1 deletion pylxd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,15 @@ def assert_has_api_extension(self, name):
def authenticate(self, secret, use_token_auth=True):
if self.trusted:
return
cert = open(self.api.session.cert[0]).read().encode("utf-8")

if not isinstance(self.api.session.cert, tuple):
raise exceptions.ClientConnectionFailed("No client certificate specified")

try:
with open(self.api.session.cert[0]) as f:
cert = f.read().encode("utf-8")
except FileNotFoundError:
raise exceptions.ClientConnectionFailed("Client certificate not found")

# Quirk to handle 5.21 that supports explicit trust tokens as well as
# password auth. We need to ascertain if the provided secret is indeed a
Expand Down