Skip to content

Commit 0c2aa47

Browse files
KPostOfficeastefanutti
authored andcommitted
add cfg check for mtls before enabling access to client
Signed-off-by: Kevin <[email protected]>
1 parent 1c8a64d commit 0c2aa47

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Diff for: pkg/controllers/raycluster_controller.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
262262
kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace}
263263
}
264264

265-
_, err = r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredNetworkPolicy(cluster, kubeRayNamespaces), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
265+
_, err = r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredNetworkPolicy(cluster, r.Config, kubeRayNamespaces), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
266266
if err != nil {
267267
logger.Error(err, "Failed to update NetworkPolicy")
268268
}
@@ -460,7 +460,13 @@ func generateCACertificate() ([]byte, []byte, error) {
460460
return privateKeyPem, certPem, nil
461461
}
462462

463-
func desiredNetworkPolicy(cluster *rayv1.RayCluster, kubeRayNamespaces []string) *networkingv1ac.NetworkPolicyApplyConfiguration {
463+
func desiredNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConfiguration, kubeRayNamespaces []string) *networkingv1ac.NetworkPolicyApplyConfiguration {
464+
allSecuredPorts := []*networkingv1ac.NetworkPolicyPortApplyConfiguration{
465+
networkingv1ac.NetworkPolicyPort().WithProtocol(corev1.ProtocolTCP).WithPort(intstr.FromInt(8443)),
466+
}
467+
if ptr.Deref(cfg.MTLSEnabled, true) {
468+
allSecuredPorts = append(allSecuredPorts, networkingv1ac.NetworkPolicyPort().WithProtocol(corev1.ProtocolTCP).WithPort(intstr.FromInt(10001)))
469+
}
464470
return networkingv1ac.NetworkPolicy(cluster.Name, cluster.Namespace).
465471
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
466472
WithSpec(networkingv1ac.NetworkPolicySpec().
@@ -501,8 +507,7 @@ func desiredNetworkPolicy(cluster *rayv1.RayCluster, kubeRayNamespaces []string)
501507
),
502508
networkingv1ac.NetworkPolicyIngressRule().
503509
WithPorts(
504-
networkingv1ac.NetworkPolicyPort().WithProtocol(corev1.ProtocolTCP).WithPort(intstr.FromInt(8443)),
505-
networkingv1ac.NetworkPolicyPort().WithProtocol(corev1.ProtocolTCP).WithPort(intstr.FromInt(10001)),
510+
allSecuredPorts...,
506511
),
507512
),
508513
).

0 commit comments

Comments
 (0)