Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Add config for k8s-keystone-auth webhook
Browse files Browse the repository at this point in the history
* Make keystone auth webhook configurable
* Add unittests for k8s-keystone-auth config
  • Loading branch information
Travis Holton committed Dec 7, 2023
1 parent 66e7806 commit 0892205
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
11 changes: 11 additions & 0 deletions magnum_capi_helm/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
"A cluster label can override this."
),
),
cfg.BoolOpt(
"k8s_keystone_auth_enabled",
default=False,
help=(
"Enable or disable Keystone authentication webhook."
" If enabled this will run the k8s-keystone-auth subchart"
" to install the webhook pod and add additional configuration"
" to kube-apiserver routing authentication requests through"
" the webhook."
),
),
]

CONF = cfg.CONF
Expand Down
20 changes: 20 additions & 0 deletions magnum_capi_helm/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,26 @@ def _update_helm_release(self, context, cluster, nodegroups=None):
}
values = helm.mergeconcat(values, network_details)

# CatalystCloud: K8s keystone auth webhook
if CONF.capi_helm.k8s_keystone_auth_enabled:
k8s_keystone_auth_config = {
"authWebhook": "k8s-keystone-auth",
"openstack": {
"k8sKeystoneAuth": { # addon subchart configuration
"enabled": True,
"values": {
"openstackAuthUrl": context.auth_url,
"projectId": context.project_id,
},
}
},
}
values = helm.mergeconcat(values, k8s_keystone_auth_config)
LOG.debug(
"Enable K8s keystone auth webhook for"
f" project: {context.project_id} auth url: {context.auth_url}"
)

self._helm_client.install_or_upgrade(
self._get_chart_release_name(cluster),
CONF.capi_helm.helm_chart_name,
Expand Down
73 changes: 72 additions & 1 deletion magnum_capi_helm/tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from magnum_capi_helm import helm
from magnum_capi_helm import kubernetes


CONF = conf.CONF


Expand Down Expand Up @@ -1733,6 +1732,78 @@ def test_delete_nodegroup(self, mock_update):
mock_update.call_args.args[2][0].as_dict(),
)

@mock.patch.object(neutron, "get_network", autospec=True)
@mock.patch.object(
driver.Driver, "_ensure_certificate_secrets", autospec=True
)
@mock.patch.object(driver.Driver, "_create_appcred_secret", autospec=True)
@mock.patch.object(kubernetes.Client, "load", autospec=True)
@mock.patch.object(driver.Driver, "_get_image_details", autospec=True)
@mock.patch.object(helm.Client, "install_or_upgrade", autospec=True)
def test_k8s_keystone_auth_not_enabled(
self,
mock_install,
mock_image,
mock_load,
mock_appcred,
mock_certs,
mock_get_net,
):
CONF.capi_helm.k8s_keystone_auth_enabled = False
mock_image.return_value = (
"imageid1",
"1.27.4",
"ubuntu",
)
mock_client = mock.MagicMock(spec=kubernetes.Client)
mock_load.return_value = mock_client
mock_get_net.side_effect = (
lambda c, net, source, target, external: f"{net}-{external}"
)
self.driver._update_helm_release(self.context, self.cluster_obj)
mock_install.assert_called()
values = mock_install.call_args.args[3]
# self.assertIn("kubernetesVersion", values)
# print("values: %s" % values["kubernetesVersion"])
self.assertNotIn("authWebhook", values)

@mock.patch.object(neutron, "get_network", autospec=True)
@mock.patch.object(
driver.Driver, "_ensure_certificate_secrets", autospec=True
)
@mock.patch.object(driver.Driver, "_create_appcred_secret", autospec=True)
@mock.patch.object(kubernetes.Client, "load", autospec=True)
@mock.patch.object(driver.Driver, "_get_image_details", autospec=True)
@mock.patch.object(helm.Client, "install_or_upgrade", autospec=True)
def test_k8s_keystone_auth_enabled(
self,
mock_install,
mock_image,
mock_load,
mock_appcred,
mock_certs,
mock_get_net,
):
CONF.capi_helm.k8s_keystone_auth_enabled = True
mock_image.return_value = (
"imageid1",
"1.27.4",
"ubuntu",
)
mock_client = mock.MagicMock(spec=kubernetes.Client)
mock_load.return_value = mock_client
mock_get_net.side_effect = (
lambda c, net, source, target, external: f"{net}-{external}"
)
self.driver._update_helm_release(self.context, self.cluster_obj)
mock_install.assert_called()
values = mock_install.call_args.args[3]
# self.assertIn("kubernetesVersion", values)
# print("values: %s" % values["kubernetesVersion"])
self.assertIn("authWebhook", values)
k8s_keystone_auth_conf = values["openstack"]["k8sKeystoneAuth"]
self.assertEqual(k8s_keystone_auth_conf["enabled"], True)

def test_create_federation(self):
self.assertRaises(
NotImplementedError,
Expand Down

0 comments on commit 0892205

Please sign in to comment.