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

OCPBUGS-42579: Add network policies for konnectivity server and ignition server proxy #4840

Merged
merged 1 commit into from
Oct 7, 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
62 changes: 62 additions & 0 deletions hypershift-operator/controllers/hostedcluster/network_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ func (r *HostedClusterReconciler) reconcileNetworkPolicies(ctx context.Context,
}); err != nil {
return fmt.Errorf("failed to reconcile ignition nodeport network policy: %w", err)
}
// Reconcile nodeport-ignition-proxy Network Policy
policy = networkpolicy.NodePortIgnitionProxyNetworkPolicy(controlPlaneNamespaceName)
if _, err := createOrUpdate(ctx, r.Client, policy, func() error {
return reconcileNodePortIgnitionProxyNetworkPolicy(policy, hcluster)
}); err != nil {
return fmt.Errorf("failed to reconcile ignition proxy nodeport network policy: %w", err)
}
}
case hyperv1.Konnectivity:
if svc.ServicePublishingStrategy.Type == hyperv1.NodePort {
Expand All @@ -161,6 +168,15 @@ func (r *HostedClusterReconciler) reconcileNetworkPolicies(ctx context.Context,
}); err != nil {
return fmt.Errorf("failed to reconcile konnectivity nodeport network policy: %w", err)
}

// Reconcile nodeport-konnectivity Network Policy when konnectivity is hosted in the kas pod
policy = networkpolicy.NodePortKonnectivityKASNetworkPolicy(controlPlaneNamespaceName)
if _, err := createOrUpdate(ctx, r.Client, policy, func() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will create the policy always, we need to identify where is konnectivity and then place the netpol accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to identify where is konnectivity and then place the netpol accordingly.

how? the hypershift operator isn't responsible for laying down the konnectivity agent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right. I had an eye in the security people that maybe they will concern to have that gate opened.

return reconcileNodePortKonnectivityKASNetworkPolicy(policy, hcluster)
}); err != nil {
return fmt.Errorf("failed to reconcile konnectivity nodeport network policy: %w", err)
}

}
}
}
Expand Down Expand Up @@ -357,6 +373,29 @@ func reconcileNodePortOauthNetworkPolicy(policy *networkingv1.NetworkPolicy, hcl
return nil
}

func reconcileNodePortIgnitionProxyNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8443)
protocol := corev1.ProtocolTCP
policy.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{
{
From: []networkingv1.NetworkPolicyPeer{},
Ports: []networkingv1.NetworkPolicyPort{
{
Port: &port,
Protocol: &protocol,
},
},
},
}
policy.Spec.PodSelector = metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "ignition-server-proxy",
},
}
policy.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeIngress}
return nil
}

func reconcileNodePortIgnitionNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(9090)
protocol := corev1.ProtocolTCP
Expand All @@ -380,6 +419,29 @@ func reconcileNodePortIgnitionNetworkPolicy(policy *networkingv1.NetworkPolicy,
return nil
}

func reconcileNodePortKonnectivityKASNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8091)
protocol := corev1.ProtocolTCP
policy.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{
{
From: []networkingv1.NetworkPolicyPeer{},
Ports: []networkingv1.NetworkPolicyPort{
{
Port: &port,
Protocol: &protocol,
},
},
},
}
policy.Spec.PodSelector = metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "kube-apiserver",
},
}
policy.Spec.PolicyTypes = []networkingv1.PolicyType{networkingv1.PolicyTypeIngress}
return nil
}

func reconcileNodePortKonnectivityNetworkPolicy(policy *networkingv1.NetworkPolicy, hcluster *hyperv1.HostedCluster) error {
port := intstr.FromInt(8091)
protocol := corev1.ProtocolTCP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func NodePortIgnitionNetworkPolicy(namespace string) *networkingv1.NetworkPolicy
}
}

func NodePortIgnitionProxyNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "nodeport-ignition-proxy",
},
}
}

func NodePortKonnectivityNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -104,6 +113,15 @@ func NodePortKonnectivityNetworkPolicy(namespace string) *networkingv1.NetworkPo
}
}

func NodePortKonnectivityKASNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "nodeport-konnectivity-kas",
},
}
}

func VirtLauncherNetworkPolicy(namespace string) *networkingv1.NetworkPolicy {
return &networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand Down