Skip to content

Commit f819dce

Browse files
authored
Merge pull request #10032 from hakman/calico-firewall
Open etcd port only when Calico uses "etcd" datastore
2 parents f49b194 + 9c888bc commit f819dce

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

nodeup/pkg/model/networking/calico.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (b *CalicoBuilder) Build(c *fi.ModelBuilderContext) error {
3939
}
4040

4141
// @check if tls is enabled and if so, we need to download the client certificates
42-
if !b.UseEtcdManager() && b.UseEtcdTLS() {
42+
if b.IsKubernetesLT("1.12") && !b.UseEtcdManager() && b.UseEtcdTLS() {
4343
name := "calico-client"
4444
dirname := "calico"
4545
ca := filepath.Join(dirname, "ca.pem")

pkg/apis/kops/cluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ func (c *Cluster) IsKubernetesGTE(version string) bool {
674674
return clusterVersion.GTE(*parsedVersion)
675675
}
676676

677+
// IsKubernetesLT checks if the version is < the specified version.
678+
// It panics if the kubernetes version in the cluster is invalid, or if the version is invalid.
679+
func (c *Cluster) IsKubernetesLT(version string) bool {
680+
return !c.IsKubernetesGTE(version)
681+
}
682+
677683
// EnvVar represents an environment variable present in a Container.
678684
type EnvVar struct {
679685
// Name of the environment variable. Must be a C_IDENTIFIER.

pkg/model/firewall.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ func (b *FirewallModelBuilder) applyNodeToMasterBlockSpecificPorts(c *fi.ModelBu
250250
}
251251

252252
if b.Cluster.Spec.Networking.Calico != nil {
253-
// Calico needs to access etcd
254-
// TODO: Remove, replace with etcd in calico manifest
255-
klog.Warningf("Opening etcd port on masters for access from the nodes, for calico. This is unsafe in untrusted environments.")
256-
tcpBlocked[4001] = false
253+
if b.IsKubernetesLT("1.12") {
254+
// Calico needs to access etcd
255+
// TODO: Remove, replace with etcd in calico manifest
256+
klog.Warningf("Opening etcd port on masters for access from the nodes, for calico. This is unsafe in untrusted environments.")
257+
tcpBlocked[4001] = false
258+
}
257259
protocols = append(protocols, ProtocolIPIP)
258260
}
259261

pkg/model/iam/iam_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ func ReadableStatePaths(cluster *kops.Cluster, role Subject) ([]string, error) {
570570
}
571571

572572
// @check if calico is enabled as the CNI provider and permit access to the client TLS certificate by default
573-
if networkingSpec.Calico != nil {
573+
if cluster.IsKubernetesLT("1.12") && networkingSpec.Calico != nil {
574574
calicoClientCert := false
575575
for _, x := range cluster.Spec.EtcdClusters {
576576
if x.Provider == kops.EtcdProviderTypeManager {

pkg/model/pki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (b *PKIModelBuilder) Build(c *fi.ModelBuilderContext) error {
129129
})
130130

131131
// @check if calico is enabled as the CNI provider
132-
if b.KopsModelContext.Cluster.Spec.Networking.Calico != nil {
132+
if b.IsKubernetesLT("1.12") && b.KopsModelContext.Cluster.Spec.Networking.Calico != nil {
133133
c.AddTask(&fitasks.Keypair{
134134
Name: fi.String("calico-client"),
135135
Lifecycle: b.Lifecycle,

tests/integration/update_cluster/bastionadditional_user-data/kubernetes.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,12 @@ resource "aws_security_group_rule" "node-to-master-tcp-1-2379" {
753753
type = "ingress"
754754
}
755755

756-
resource "aws_security_group_rule" "node-to-master-tcp-2382-4001" {
756+
resource "aws_security_group_rule" "node-to-master-tcp-2382-4000" {
757757
from_port = 2382
758758
protocol = "tcp"
759759
security_group_id = aws_security_group.masters-bastionuserdata-example-com.id
760760
source_security_group_id = aws_security_group.nodes-bastionuserdata-example-com.id
761-
to_port = 4001
761+
to_port = 4000
762762
type = "ingress"
763763
}
764764

tests/integration/update_cluster/privatecalico/cloudformation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@
847847
"IpProtocol": "tcp"
848848
}
849849
},
850-
"AWSEC2SecurityGroupIngressnodetomastertcp23824001": {
850+
"AWSEC2SecurityGroupIngressnodetomastertcp23824000": {
851851
"Type": "AWS::EC2::SecurityGroupIngress",
852852
"Properties": {
853853
"GroupId": {
@@ -857,7 +857,7 @@
857857
"Ref": "AWSEC2SecurityGroupnodesprivatecalicoexamplecom"
858858
},
859859
"FromPort": 2382,
860-
"ToPort": 4001,
860+
"ToPort": 4000,
861861
"IpProtocol": "tcp"
862862
}
863863
},

tests/integration/update_cluster/privatecalico/kubernetes.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,12 @@ resource "aws_security_group_rule" "node-to-master-tcp-1-2379" {
752752
type = "ingress"
753753
}
754754

755-
resource "aws_security_group_rule" "node-to-master-tcp-2382-4001" {
755+
resource "aws_security_group_rule" "node-to-master-tcp-2382-4000" {
756756
from_port = 2382
757757
protocol = "tcp"
758758
security_group_id = aws_security_group.masters-privatecalico-example-com.id
759759
source_security_group_id = aws_security_group.nodes-privatecalico-example-com.id
760-
to_port = 4001
760+
to_port = 4000
761761
type = "ingress"
762762
}
763763

0 commit comments

Comments
 (0)