Skip to content

Commit 1f3bacc

Browse files
committed
tls fixes
1 parent 7f84ade commit 1f3bacc

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

internal/controller/client/openstackclient_controller.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4444
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
4545
"github.com/openstack-k8s-operators/lib-common/modules/common"
46+
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
4647
"github.com/openstack-k8s-operators/lib-common/modules/common/clusterdns"
4748
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4849
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
@@ -217,7 +218,8 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
217218
}
218219

219220
clientLabels := map[string]string{
220-
common.AppSelector: "openstackclient",
221+
common.AppSelector: "openstackclient",
222+
common.OwnerSelector: instance.Name,
221223
}
222224

223225
configVars := make(map[string]env.Setter)
@@ -359,6 +361,27 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
359361
configVars[mcpTLSSecretName] = env.SetValue(certSecret.ResourceVersion)
360362
}
361363

364+
// Use the internal Keystone endpoint for the MCP sidecar's clouds.yaml
365+
// so it connects directly to the in-cluster service and avoids
366+
// TLS issues with the public OCP route.
367+
internalAuthURL, err := keystoneAPI.GetEndpoint(endpoint.EndpointInternal)
368+
if err != nil {
369+
instance.Status.Conditions.Set(condition.FalseCondition(
370+
clientv1.OpenStackClientReadyCondition,
371+
condition.RequestedReason,
372+
condition.SeverityInfo,
373+
"waiting for internal Keystone endpoint"))
374+
return ctrl.Result{RequeueAfter: time.Duration(5) * time.Second}, nil
375+
}
376+
377+
mcpCloudsYAML := openstackclient.MCPCloudsYAML(
378+
internalAuthURL,
379+
keystoneAPI.Spec.AdminProject,
380+
keystoneAPI.Spec.AdminUser,
381+
keystoneAPI.Spec.Region,
382+
instance.Spec.CaBundleSecretName,
383+
)
384+
362385
mcpConfigCM := &corev1.ConfigMap{
363386
ObjectMeta: metav1.ObjectMeta{
364387
Name: instance.Name + "-mcp-config",
@@ -368,13 +391,14 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
368391
_, err = controllerutil.CreateOrPatch(ctx, r.Client, mcpConfigCM, func() error {
369392
mcpConfigCM.Data = map[string]string{
370393
"config.yaml": openstackclient.MCPConfigYAML(instance.Spec.CaBundleSecretName, mcpTLSEnabled),
394+
"clouds.yaml": mcpCloudsYAML,
371395
}
372396
return controllerutil.SetControllerReference(instance, mcpConfigCM, r.Scheme)
373397
})
374398
if err != nil {
375399
return ctrl.Result{}, fmt.Errorf("error creating MCP config ConfigMap: %w", err)
376400
}
377-
configVars[instance.Name+"-mcp-config"] = env.SetValue(openstackclient.MCPConfigYAML(instance.Spec.CaBundleSecretName, mcpTLSEnabled))
401+
configVars[instance.Name+"-mcp-config"] = env.SetValue(openstackclient.MCPConfigYAML(instance.Spec.CaBundleSecretName, mcpTLSEnabled) + mcpCloudsYAML)
378402

379403
}
380404

@@ -394,7 +418,6 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
394418
mcpServiceHash, err := util.ObjectHash(map[string]interface{}{
395419
"containerImage": instance.Spec.ContainerImage,
396420
"mcpContainerImage": instance.Spec.MCP.ContainerImage,
397-
"mcpConfig": openstackclient.MCPConfigYAML(instance.Spec.CaBundleSecretName, instance.Spec.CaBundleSecretName != ""),
398421
"configVarsHash": configVarsHash,
399422
})
400423
if err != nil {

internal/openstackclient/funcs.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ func ClientPodSpec(
116116
if instance.Spec.MCP != nil && instance.Spec.MCP.Enabled {
117117
mcpVolumeMounts := []corev1.VolumeMount{
118118
{
119-
Name: "openstack-config",
119+
Name: "mcp-config",
120120
MountPath: "/home/cloud-admin/.config/openstack/clouds.yaml",
121121
SubPath: "clouds.yaml",
122+
ReadOnly: true,
122123
},
123124
{
124125
Name: "openstack-config-secret",
@@ -127,7 +128,8 @@ func ClientPodSpec(
127128
},
128129
{
129130
Name: "mcp-config",
130-
MountPath: "/tmp/mcp-config",
131+
MountPath: "/tmp/mcp-config/config.yaml",
132+
SubPath: "config.yaml",
131133
ReadOnly: true,
132134
},
133135
}
@@ -234,6 +236,25 @@ mcp_transport_security:
234236
`, caCert, tlsConfig, allowedOriginScheme)
235237
}
236238

239+
// MCPCloudsYAML returns a clouds.yaml using the given auth URL for the MCP sidecar.
240+
// When caBundleSecretName is set, a cacert path is included for TLS verification.
241+
func MCPCloudsYAML(authURL, projectName, userName, region, caBundleSecretName string) string {
242+
caCert := ""
243+
if caBundleSecretName != "" {
244+
caCert = fmt.Sprintf("\n cacert: %s", tls.DownstreamTLSCABundlePath)
245+
}
246+
return fmt.Sprintf(`clouds:
247+
default:
248+
auth:
249+
auth_url: %s
250+
project_name: %s
251+
username: %s
252+
user_domain_name: Default
253+
project_domain_name: Default
254+
region_name: %s%s
255+
`, authURL, projectName, userName, region, caCert)
256+
}
257+
237258
func clientPodVolumeMounts() []corev1.VolumeMount {
238259
return []corev1.VolumeMount{
239260
{

0 commit comments

Comments
 (0)