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

Open etcd port only when Calico uses "etcd" datastore #10032

Merged
merged 2 commits into from
Oct 9, 2020
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
2 changes: 1 addition & 1 deletion nodeup/pkg/model/networking/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *CalicoBuilder) Build(c *fi.ModelBuilderContext) error {
}

// @check if tls is enabled and if so, we need to download the client certificates
if !b.UseEtcdManager() && b.UseEtcdTLS() {
if b.IsKubernetesLT("1.12") && !b.UseEtcdManager() && b.UseEtcdTLS() {
name := "calico-client"
dirname := "calico"
ca := filepath.Join(dirname, "ca.pem")
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ func (c *Cluster) IsKubernetesGTE(version string) bool {
return clusterVersion.GTE(*parsedVersion)
}

// IsKubernetesLT checks if the version is < the specified version.
// It panics if the kubernetes version in the cluster is invalid, or if the version is invalid.
func (c *Cluster) IsKubernetesLT(version string) bool {
return !c.IsKubernetesGTE(version)
}

// EnvVar represents an environment variable present in a Container.
type EnvVar struct {
// Name of the environment variable. Must be a C_IDENTIFIER.
Expand Down
10 changes: 6 additions & 4 deletions pkg/model/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ func (b *FirewallModelBuilder) applyNodeToMasterBlockSpecificPorts(c *fi.ModelBu
}

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/iam/iam_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func ReadableStatePaths(cluster *kops.Cluster, role Subject) ([]string, error) {
}

// @check if calico is enabled as the CNI provider and permit access to the client TLS certificate by default
if networkingSpec.Calico != nil {
if cluster.IsKubernetesLT("1.12") && networkingSpec.Calico != nil {
calicoClientCert := false
for _, x := range cluster.Spec.EtcdClusters {
if x.Provider == kops.EtcdProviderTypeManager {
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (b *PKIModelBuilder) Build(c *fi.ModelBuilderContext) error {
})

// @check if calico is enabled as the CNI provider
if b.KopsModelContext.Cluster.Spec.Networking.Calico != nil {
if b.IsKubernetesLT("1.12") && b.KopsModelContext.Cluster.Spec.Networking.Calico != nil {
c.AddTask(&fitasks.Keypair{
Name: fi.String("calico-client"),
Lifecycle: b.Lifecycle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,12 @@ resource "aws_security_group_rule" "node-to-master-tcp-1-2379" {
type = "ingress"
}

resource "aws_security_group_rule" "node-to-master-tcp-2382-4001" {
resource "aws_security_group_rule" "node-to-master-tcp-2382-4000" {
from_port = 2382
protocol = "tcp"
security_group_id = aws_security_group.masters-bastionuserdata-example-com.id
source_security_group_id = aws_security_group.nodes-bastionuserdata-example-com.id
to_port = 4001
to_port = 4000
type = "ingress"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
"IpProtocol": "tcp"
}
},
"AWSEC2SecurityGroupIngressnodetomastertcp23824001": {
"AWSEC2SecurityGroupIngressnodetomastertcp23824000": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
Expand All @@ -857,7 +857,7 @@
"Ref": "AWSEC2SecurityGroupnodesprivatecalicoexamplecom"
},
"FromPort": 2382,
"ToPort": 4001,
"ToPort": 4000,
"IpProtocol": "tcp"
}
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/update_cluster/privatecalico/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,12 @@ resource "aws_security_group_rule" "node-to-master-tcp-1-2379" {
type = "ingress"
}

resource "aws_security_group_rule" "node-to-master-tcp-2382-4001" {
resource "aws_security_group_rule" "node-to-master-tcp-2382-4000" {
from_port = 2382
protocol = "tcp"
security_group_id = aws_security_group.masters-privatecalico-example-com.id
source_security_group_id = aws_security_group.nodes-privatecalico-example-com.id
to_port = 4001
to_port = 4000
type = "ingress"
}

Expand Down