mirror of https://github.com/kubernetes/kops.git
Merge pull request #10161 from rifelpet/nlb-cidr
Move NLB's VPC CIDR security group rule logic into model
This commit is contained in:
commit
235133d0f5
|
|
@ -357,8 +357,19 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||||
Protocol: fi.String("tcp"),
|
Protocol: fi.String("tcp"),
|
||||||
SecurityGroup: masterGroup.Task,
|
SecurityGroup: masterGroup.Task,
|
||||||
ToPort: fi.Int64(443),
|
ToPort: fi.Int64(443),
|
||||||
VPC: b.LinkToVPC(),
|
CIDR: fi.String(b.Cluster.Spec.NetworkCIDR),
|
||||||
})
|
})
|
||||||
|
for _, cidr := range b.Cluster.Spec.AdditionalNetworkCIDRs {
|
||||||
|
c.AddTask(&awstasks.SecurityGroupRule{
|
||||||
|
Name: fi.String(fmt.Sprintf("https-lb-to-master%s-%s", suffix, cidr)),
|
||||||
|
Lifecycle: b.SecurityLifecycle,
|
||||||
|
FromPort: fi.Int64(443),
|
||||||
|
Protocol: fi.String("tcp"),
|
||||||
|
SecurityGroup: masterGroup.Task,
|
||||||
|
ToPort: fi.Int64(443),
|
||||||
|
CIDR: fi.String(cidr),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -643,7 +643,32 @@
|
||||||
},
|
},
|
||||||
"FromPort": 443,
|
"FromPort": 443,
|
||||||
"ToPort": 443,
|
"ToPort": 443,
|
||||||
"IpProtocol": "tcp"
|
"IpProtocol": "tcp",
|
||||||
|
"CidrIp": "172.20.0.0/16"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AWSEC2SecurityGroupIngresshttpslbtomaster1010016": {
|
||||||
|
"Type": "AWS::EC2::SecurityGroupIngress",
|
||||||
|
"Properties": {
|
||||||
|
"GroupId": {
|
||||||
|
"Ref": "AWSEC2SecurityGroupmasterscomplexexamplecom"
|
||||||
|
},
|
||||||
|
"FromPort": 443,
|
||||||
|
"ToPort": 443,
|
||||||
|
"IpProtocol": "tcp",
|
||||||
|
"CidrIp": "10.1.0.0/16"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AWSEC2SecurityGroupIngresshttpslbtomaster1020016": {
|
||||||
|
"Type": "AWS::EC2::SecurityGroupIngress",
|
||||||
|
"Properties": {
|
||||||
|
"GroupId": {
|
||||||
|
"Ref": "AWSEC2SecurityGroupmasterscomplexexamplecom"
|
||||||
|
},
|
||||||
|
"FromPort": 443,
|
||||||
|
"ToPort": 443,
|
||||||
|
"IpProtocol": "tcp",
|
||||||
|
"CidrIp": "10.2.0.0/16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AWSEC2SecurityGroupIngressicmppmtuapielb111024": {
|
"AWSEC2SecurityGroupIngressicmppmtuapielb111024": {
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,25 @@ resource "aws_security_group_rule" "https-api-elb-2001_0_8500__--40" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_security_group_rule" "https-elb-to-master" {
|
resource "aws_security_group_rule" "https-elb-to-master" {
|
||||||
|
cidr_blocks = ["172.20.0.0/16"]
|
||||||
|
from_port = 443
|
||||||
|
protocol = "tcp"
|
||||||
|
security_group_id = aws_security_group.masters-complex-example-com.id
|
||||||
|
to_port = 443
|
||||||
|
type = "ingress"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_security_group_rule" "https-lb-to-master-10-1-0-0--16" {
|
||||||
|
cidr_blocks = ["10.1.0.0/16"]
|
||||||
|
from_port = 443
|
||||||
|
protocol = "tcp"
|
||||||
|
security_group_id = aws_security_group.masters-complex-example-com.id
|
||||||
|
to_port = 443
|
||||||
|
type = "ingress"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_security_group_rule" "https-lb-to-master-10-2-0-0--16" {
|
||||||
|
cidr_blocks = ["10.2.0.0/16"]
|
||||||
from_port = 443
|
from_port = 443
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
security_group_id = aws_security_group.masters-complex-example-com.id
|
security_group_id = aws_security_group.masters-complex-example-com.id
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ type SecurityGroupRule struct {
|
||||||
SourceGroup *SecurityGroup
|
SourceGroup *SecurityGroup
|
||||||
|
|
||||||
Egress *bool
|
Egress *bool
|
||||||
VPC *VPC
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SecurityGroupRule) Find(c *fi.Context) (*SecurityGroupRule, error) {
|
func (e *SecurityGroupRule) Find(c *fi.Context) (*SecurityGroupRule, error) {
|
||||||
|
|
@ -105,7 +104,6 @@ func (e *SecurityGroupRule) Find(c *fi.Context) (*SecurityGroupRule, error) {
|
||||||
ToPort: foundRule.ToPort,
|
ToPort: foundRule.ToPort,
|
||||||
Protocol: foundRule.IpProtocol,
|
Protocol: foundRule.IpProtocol,
|
||||||
Egress: e.Egress,
|
Egress: e.Egress,
|
||||||
VPC: e.VPC,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if aws.StringValue(actual.Protocol) == "-1" {
|
if aws.StringValue(actual.Protocol) == "-1" {
|
||||||
|
|
@ -157,19 +155,6 @@ func (e *SecurityGroupRule) matches(rule *ec2.IpPermission) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.VPC != nil && e.VPC.CIDR != nil {
|
|
||||||
match := false
|
|
||||||
for _, ipRange := range rule.IpRanges {
|
|
||||||
if aws.StringValue(ipRange.CidrIp) == *e.VPC.CIDR {
|
|
||||||
match = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !match {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.SourceGroup != nil {
|
if e.SourceGroup != nil {
|
||||||
// TODO: Only if len 1?
|
// TODO: Only if len 1?
|
||||||
match := false
|
match := false
|
||||||
|
|
@ -266,10 +251,6 @@ func (_ *SecurityGroupRule) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Secu
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CIDR := e.CIDR
|
CIDR := e.CIDR
|
||||||
//TODO: Verify NLB is setting vpc CIDR
|
|
||||||
if e.VPC != nil { //ALLOW security group to use vpc cidr for network load balancer.
|
|
||||||
CIDR = e.VPC.CIDR
|
|
||||||
}
|
|
||||||
// Default to 0.0.0.0/0 ?
|
// Default to 0.0.0.0/0 ?
|
||||||
ipPermission.IpRanges = []*ec2.IpRange{
|
ipPermission.IpRanges = []*ec2.IpRange{
|
||||||
{CidrIp: CIDR},
|
{CidrIp: CIDR},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue