Skip to content

Commit c9c5377

Browse files
authored
Impl. securityLists conf opt and management modes (#180)
Adds loadbalancer.securityListManagementMode config option that configures how the CCM should manage security lists. Depreciates loadbalancer.disableSecurityListManagement in favour of loadbalancer.securityListManagementMode: None. Additionally adds loadbalancer.securityLists config option to allow explicit configuration of the security lists managed by the CCM on a per subnet basis.
1 parent 563024f commit c9c5377

File tree

6 files changed

+225
-82
lines changed

6 files changed

+225
-82
lines changed

manifests/cloud-provider-example.yaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ compartment: ocid1.compartment.oc1..aaaaaaaa3um2atybwhder4qttfhgon4j3hcxgmsvnyvx
1717
vcn: ocid1.vcn.oc1..aaaaaaaask7mpk4mij3pnm6yvnntte25ffadxiivpokxevfxgtsu6ftkqhrq
1818

1919
loadBalancer:
20-
# disableSecurityListManagement disables the automatic creation of ingress
21-
# rules for the node subnets and egress rules for the load balancers to the
22-
# node subnets.
23-
#
24-
# If security list management is disabled, then it requires that the user
25-
# has setup a rule that allows inbound traffic to the appropriate ports
26-
# for kube proxy health port, node port ranges, and health check port ranges.
27-
# E.g. 10.82.0.0/16 30000-32000
28-
disableSecurityListManagement: false
29-
3020
# subnet1 configures one of two subnets to which load balancers will be added.
3121
# OCI load balancers require two subnets to ensure high availability.
3222
subnet1: ocid1.subnet.oc1.phx.aaaaaaaasa53hlkzk6nzksqfccegk2qnkxmphkblst3riclzs4rhwg7rg57q
3323

34-
# subnet2 configures the second of two subnets to which load balancers will
35-
# be added. OCI load balancers require two subnets to ensure high
36-
# availability.
24+
# subnet2 configures the second of two subnets to which load balancers will be
25+
# added. OCI load balancers require two subnets to ensure high availability.
3726
subnet2: ocid1.subnet.oc1.phx.aaaaaaaahuxrgvs65iwdz7ekwgg3l5gyah7ww5klkwjcso74u3e4i64hvtvq
27+
28+
# SecurityListManagementMode configures how security lists are managed by the CCM.
29+
# "All" (default): Manage all required security list rules for load balancer services.
30+
# "Frontend": Manage only security list rules for ingress to the load
31+
# balancer. Requires that the user has setup a rule that
32+
# allows inbound traffic to the appropriate ports for kube
33+
# proxy health port, node port ranges, and health check port ranges.
34+
# E.g. 10.82.0.0/16 30000-32000.
35+
# "None": Disables all security list management. Requires that the
36+
# user has setup a rule that allows inbound traffic to the
37+
# appropriate ports for kube proxy health port, node port
38+
# ranges, and health check port ranges. E.g. 10.82.0.0/16 30000-32000.
39+
# Additionally requires the user to mange rules to allow
40+
# inbound traffic to load balancers.
41+
securityListManagementMode: All

pkg/oci/ccm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3131
wait "k8s.io/apimachinery/pkg/util/wait"
3232
informers "k8s.io/client-go/informers"
33+
informersv1 "k8s.io/client-go/informers/core/v1"
3334
clientset "k8s.io/client-go/kubernetes"
3435
listersv1 "k8s.io/client-go/listers/core/v1"
3536
cache "k8s.io/client-go/tools/cache"
@@ -137,18 +138,17 @@ func (cp *CloudProvider) Initialize(clientBuilder controller.ControllerClientBui
137138
}
138139
cp.NodeLister = nodeInformer.Lister()
139140

140-
if cp.config.LoadBalancer.DisableSecurityListManagement {
141-
cp.securityListManager = newSecurityListManagerNOOP()
142-
143-
} else {
144-
serviceInformer := factory.Core().V1().Services()
141+
var serviceInformer informersv1.ServiceInformer
142+
if cp.config.LoadBalancer.SecurityListManagementMode != ManagementModeNone {
143+
serviceInformer = factory.Core().V1().Services()
145144
go serviceInformer.Informer().Run(wait.NeverStop)
146145
glog.Info("Waiting for service informer cache to sync")
147146
if !cache.WaitForCacheSync(wait.NeverStop, serviceInformer.Informer().HasSynced) {
148147
utilruntime.HandleError(fmt.Errorf("Timed out waiting for service informer to sync"))
149148
}
150-
cp.securityListManager = newSecurityListManager(cp.client, serviceInformer.Lister())
149+
151150
}
151+
cp.securityListManager = newSecurityListManager(cp.client, serviceInformer.Lister(), cp.config.LoadBalancer.SecurityLists, cp.config.LoadBalancer.SecurityListManagementMode)
152152
}
153153

154154
// ProviderName returns the cloud-provider ID.

pkg/oci/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,17 @@ type LoadBalancerConfig struct {
5050
// E.g. 10.82.0.0/16 30000-32000
5151
DisableSecurityListManagement bool `yaml:"disableSecurityListManagement"`
5252

53+
// SecurityListManagementMode defines how the CCM manages security lists
54+
// when provisioning load balancers. Available modes are All, Frontend,
55+
// and None.
56+
SecurityListManagementMode string `yaml:"securityListManagementMode"`
57+
5358
Subnet1 string `yaml:"subnet1"`
5459
Subnet2 string `yaml:"subnet2"`
60+
61+
// SecurityLists defines the Security List to mutate for each Subnet (
62+
// both load balancer and worker).
63+
SecurityLists map[string]string `yaml:"securityLists"`
5564
}
5665

5766
// Config holds the OCI cloud-provider config passed to Kubernetes compontents
@@ -70,6 +79,13 @@ type Config struct {
7079

7180
// Complete the config applying defaults / overrides.
7281
func (c *Config) Complete() {
82+
if c.LoadBalancer.SecurityListManagementMode == "" {
83+
c.LoadBalancer.SecurityListManagementMode = ManagementModeAll // default
84+
if c.LoadBalancer.DisableSecurityListManagement {
85+
glog.Warningf("cloud-provider config: \"loadBalancer.disableSecurityListManagement\" is DEPRECIATED and will be removed in a later release. Please set \"loadBalancer.SecurityListManagementMode: %s\".", ManagementModeNone)
86+
c.LoadBalancer.SecurityListManagementMode = ManagementModeNone
87+
}
88+
}
7389
if c.CompartmentID == "" && c.Auth.CompartmentID != "" {
7490
glog.Warning("cloud-provider config: \"auth.compartment\" is DEPRECIATED and will be removed in a later release. Please set \"compartment\".")
7591
c.CompartmentID = c.Auth.CompartmentID

pkg/oci/config_validate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func validateLoadBalancerConfig(c *LoadBalancerConfig, fldPath *field.Path) fiel
5555
if c.Subnet2 == "" {
5656
allErrs = append(allErrs, field.Required(fldPath.Child("subnet2"), ""))
5757
}
58+
if !IsValidSecurityListManagementMode(c.SecurityListManagementMode) {
59+
allErrs = append(allErrs, field.Invalid(fldPath.Child("securityListManagementMode"), c.SecurityListManagementMode, "invalid security list management mode"))
60+
}
5861
return allErrs
5962
}
6063

pkg/oci/config_validate_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ func TestValidateConfig(t *testing.T) {
4444
},
4545
},
4646
errs: field.ErrorList{},
47+
}, {
48+
name: "valid_with_non_default_security_list_management_mode",
49+
in: &Config{
50+
Auth: AuthConfig{
51+
Region: "us-phoenix-1",
52+
TenancyID: "ocid1.tenancy.oc1..aaaaaaaatyn7scrtwtqedvgrxgr2xunzeo6uanvyhzxqblctwkrpisvke4kq",
53+
CompartmentID: "ocid1.compartment.oc1..aaaaaaaa3um2atybwhder4qttfhgon4j3hcxgmsvnyvx4flfjyewkkwfzwnq",
54+
UserID: "ocid1.user.oc1..aaaaaaaai77mql2xerv7cn6wu3nhxang3y4jk56vo5bn5l5lysl34avnui3q",
55+
PrivateKey: "-----BEGIN RSA PRIVATE KEY----- (etc)",
56+
Fingerprint: "8c:bf:17:7b:5f:e0:7d:13:75:11:d6:39:0d:e2:84:74",
57+
},
58+
LoadBalancer: LoadBalancerConfig{
59+
Subnet1: "ocid1.tenancy.oc1..aaaaaaaatyn7scrtwtqedvgrxgr2xunzeo6uanvyhzxqblctwkrpisvke4kq",
60+
Subnet2: "ocid1.subnet.oc1.phx.aaaaaaaahuxrgvs65iwdz7ekwgg3l5gyah7ww5klkwjcso74u3e4i64hvtvq",
61+
SecurityListManagementMode: ManagementModeFrontend,
62+
},
63+
},
64+
errs: field.ErrorList{},
4765
}, {
4866
name: "missing_region",
4967
in: &Config{
@@ -186,14 +204,40 @@ func TestValidateConfig(t *testing.T) {
186204
errs: field.ErrorList{
187205
&field.Error{Type: field.ErrorTypeRequired, Field: "loadBalancer.subnet2", BadValue: ""},
188206
},
207+
}, {
208+
name: "invalid_security_list_management_mode",
209+
in: &Config{
210+
Auth: AuthConfig{
211+
Region: "us-phoenix-1",
212+
TenancyID: "ocid1.tenancy.oc1..aaaaaaaatyn7scrtwtqedvgrxgr2xunzeo6uanvyhzxqblctwkrpisvke4kq",
213+
CompartmentID: "ocid1.compartment.oc1..aaaaaaaa3um2atybwhder4qttfhgon4j3hcxgmsvnyvx4flfjyewkkwfzwnq",
214+
UserID: "ocid1.user.oc1..aaaaaaaai77mql2xerv7cn6wu3nhxang3y4jk56vo5bn5l5lysl34avnui3q",
215+
PrivateKey: "-----BEGIN RSA PRIVATE KEY----- (etc)",
216+
Fingerprint: "8c:bf:17:7b:5f:e0:7d:13:75:11:d6:39:0d:e2:84:74",
217+
},
218+
LoadBalancer: LoadBalancerConfig{
219+
Subnet1: "ocid1.tenancy.oc1..aaaaaaaatyn7scrtwtqedvgrxgr2xunzeo6uanvyhzxqblctwkrpisvke4kq",
220+
Subnet2: "ocid1.subnet.oc1.phx.aaaaaaaahuxrgvs65iwdz7ekwgg3l5gyah7ww5klkwjcso74u3e4i64hvtvq",
221+
SecurityListManagementMode: "invalid",
222+
},
223+
},
224+
errs: field.ErrorList{
225+
&field.Error{
226+
Type: field.ErrorTypeInvalid,
227+
Field: "loadBalancer.securityListManagementMode",
228+
BadValue: "invalid",
229+
Detail: "invalid security list management mode",
230+
},
231+
},
189232
},
190233
}
191234

192235
for _, tt := range testCases {
193236
t.Run(tt.name, func(t *testing.T) {
237+
tt.in.Complete()
194238
result := ValidateConfig(tt.in)
195239
if !reflect.DeepEqual(result, tt.errs) {
196-
t.Errorf("ValidateConfig(%#v)\n=> %#v\nExpected: %#v", tt.in, result, tt.errs)
240+
t.Errorf("ValidateConfig(%#v)\n=> %q \nExpected: %q", tt.in, result, tt.errs)
197241
}
198242
})
199243
}

0 commit comments

Comments
 (0)