Skip to content

Commit 4c96d28

Browse files
Fix inbound rule to allow only APIServerPort (#1166)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 9b67037 commit 4c96d28

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

cloud/scope/cluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ func (s *ClusterScope) updateDefaultSG(sgID string) error {
186186
options.SetSecurityGroupID(sgID)
187187
options.SetSecurityGroupRulePrototype(&vpcv1.SecurityGroupRulePrototype{
188188
Direction: core.StringPtr("inbound"),
189-
Protocol: core.StringPtr("all"),
189+
Protocol: core.StringPtr("tcp"),
190190
IPVersion: core.StringPtr("ipv4"),
191+
PortMin: core.Int64Ptr(int64(s.APIServerPort())),
192+
PortMax: core.Int64Ptr(int64(s.APIServerPort())),
191193
})
192194
_, _, err := s.IBMVPCClient.CreateSecurityGroupRule(options)
193195
if err != nil {

cloud/scope/machine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,11 @@ func (m *MachineScope) SetProviderID(id *string) error {
522522
}
523523
return nil
524524
}
525+
526+
// APIServerPort returns the APIServerPort.
527+
func (m *MachineScope) APIServerPort() int32 {
528+
if m.Cluster.Spec.ClusterNetwork != nil && m.Cluster.Spec.ClusterNetwork.APIServerPort != nil {
529+
return *m.Cluster.Spec.ClusterNetwork.APIServerPort
530+
}
531+
return 6443
532+
}

controllers/ibmvpcmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (r *IBMVPCMachineReconciler) reconcileNormal(machineScope *scope.MachineSco
190190
return ctrl.Result{}, fmt.Errorf("invalid primary ip address")
191191
}
192192
internalIP := instance.PrimaryNetworkInterface.PrimaryIP.Address
193-
port := int64(6443)
193+
port := int64(machineScope.APIServerPort())
194194
poolMember, err := machineScope.CreateVPCLoadBalancerPoolMember(internalIP, port)
195195
if err != nil {
196196
return ctrl.Result{}, errors.Wrapf(err, "failed to bind port %d to control plane %s/%s", port, machineScope.IBMVPCMachine.Namespace, machineScope.IBMVPCMachine.Name)

controllers/ibmvpcmachine_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func TestIBMVPCMachineLBReconciler_reconcile(t *testing.T) {
356356
},
357357
},
358358
},
359+
Cluster: &capiv1beta1.Cluster{},
359360
IBMVPCClient: mockvpc,
360361
}
361362
return gomock.NewController(t), mockvpc, machineScope, reconciler

0 commit comments

Comments
 (0)