Skip to content

Commit 28aae17

Browse files
authored
Merge pull request #2784 from nikParasyr/port-security
🐛 Allow setting disablePortSecurity on OSM port
2 parents 871fb07 + 0c84d39 commit 28aae17

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

controllers/openstackmachine_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ func openStackMachineSpecToOpenStackServerSpec(openStackMachineSpec *infrav1.Ope
556556
}
557557
serverPort.FixedIPs = clusterSubnets
558558
}
559-
if len(serverPort.SecurityGroups) == 0 && defaultSecGroup != nil {
559+
// Only inject the default SG when portSecurity is not disabled,
560+
// there are no SGs passed by user and defaultSecGroup is set
561+
portSecurityDisabled := serverPort.DisablePortSecurity != nil && *serverPort.DisablePortSecurity
562+
if !portSecurityDisabled && len(serverPort.SecurityGroups) == 0 && defaultSecGroup != nil {
560563
serverPort.SecurityGroups = []infrav1.SecurityGroupParam{
561564
{
562565
ID: defaultSecGroup,

controllers/openstackmachine_controller_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,34 @@ func TestOpenStackMachineSpecToOpenStackServerSpec(t *testing.T) {
346346
UserDataRef: userData,
347347
},
348348
},
349+
{
350+
name: "Explicit port with disablePortSecurity",
351+
spec: &infrav1.OpenStackMachineSpec{
352+
Flavor: ptr.To(flavorName),
353+
Image: image,
354+
Ports: []infrav1.PortOpts{{
355+
Network: &infrav1.NetworkParam{ID: ptr.To(networkUUID)},
356+
ResolvedPortSpecFields: infrav1.ResolvedPortSpecFields{
357+
DisablePortSecurity: ptr.To(true),
358+
},
359+
}},
360+
},
361+
cluster: openStackClusterNetworkWithoutID,
362+
want: &infrav1alpha1.OpenStackServerSpec{
363+
Flavor: ptr.To(flavorName),
364+
IdentityRef: identityRef,
365+
Image: image,
366+
Ports: []infrav1.PortOpts{{
367+
Network: &infrav1.NetworkParam{ID: ptr.To(networkUUID)},
368+
SecurityGroups: nil,
369+
ResolvedPortSpecFields: infrav1.ResolvedPortSpecFields{
370+
DisablePortSecurity: ptr.To(true),
371+
},
372+
}},
373+
Tags: tags,
374+
UserDataRef: userData,
375+
},
376+
},
349377
}
350378
for i := range tests {
351379
tt := tests[i]

0 commit comments

Comments
 (0)