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

Ensure Kubespawner internal SSL secret is correctly encoded as base64 #828

Merged
merged 4 commits into from
Mar 28, 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
11 changes: 3 additions & 8 deletions kubespawner/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,16 +1014,11 @@ def make_secret(
encoded = base64.b64encode(file.read().encode("utf-8"))
secret.data['ssl.crt'] = encoded.decode("utf-8")

with open(cert_paths['cafile']) as file:
encoded = base64.b64encode(file.read().encode("utf-8"))
with open(cert_paths['cafile']) as ca_file, open(hub_ca) as hub_ca_file:
cas = ca_file.read().strip("\n") + "\n" + hub_ca_file.read()
encoded = base64.b64encode(cas.encode("utf-8"))
secret.data["notebooks-ca_trust.crt"] = encoded.decode("utf-8")

with open(hub_ca) as file:
encoded = base64.b64encode(file.read().encode("utf-8"))
secret.data["notebooks-ca_trust.crt"] = secret.data[
"notebooks-ca_trust.crt"
] + encoded.decode("utf-8")

return secret


Expand Down
7 changes: 7 additions & 0 deletions tests/test_spawner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import base64
import json
import os
from functools import partial
Expand Down Expand Up @@ -391,6 +392,12 @@ async def test_spawn_internal_ssl(

spawner.cert_paths = await spawner.move_certs(hub_paths)

# Validate that certificates are correctly encoded
# https://github.com/jupyterhub/kubespawner/pull/828
manifest = spawner.get_secret_manifest(None)
for _, secret in manifest.data.items():
base64.b64decode(secret, validate=True)

# start the spawner
url = await spawner.start()
pod_name = "jupyter-%s" % spawner.user.name
Expand Down