-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add sslPolicy for NLB to change listener's security policy #9666
Add sslPolicy for NLB to change listener's security policy #9666
Conversation
Hi @FrankYang0529. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
dc6a2ce
to
46ef91c
Compare
46ef91c
to
7d62a2a
Compare
/ok-to-test Thanks for adding this! I haven't looked at the ELB API behavior closely but we should make sure that when someone removes listenerPolicies from their ClusterSpec that the API ELB is updated to use AWS' default listener policy. We'll also want to add terraform and cloudformation support but that can happen in followup PRs. |
@rifelpet Thanks for reviewing! I have two questions about generating terraform and cloudformation.
|
Also we'll want to add this to an integration test which will test both the terraform and cloudformation outputs. Add the new field to the ClusterSpec in the two |
Small one from me: Add a line about this in the cluster spec docs ( |
7d62a2a
to
eb4756a
Compare
9cf770e
to
89d5d9f
Compare
Updated it. Thank you! |
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tested this out and ran into some trouble. I tried to add this policy to my API ELB: ELBSecurityPolicy-TLS-1-2-2017-01
but received this error during update cluster --yes
:
W0826 15:49:52.508545 63215 executor.go:128] error running task "LoadBalancer/api.foo.k8s.local" (8m0s remaining to succeed): error updating load balancer listener's security policy: PolicyNotFound: There is no policy with name ELBSecurityPolicy-TLS-1-2-2017-01 for load balancer api-ho-dev-a-us-west-2-k8-a656uf
status code: 400, request id: 0814b82c-2e84-4f08-a67e-b8f0cd5fd979
even though that is a valid policy name according to aws elb describe-load-balancer-policies
.
Reading these docs it seems I would need to "create" the policy for the load balancer from the predefined policies, and then I can assign it to the listener.
aws elb create-load-balancer-policy --load-balancer-name my-loadbalancer
--policy-name my-SSLNegotiation-policy --policy-type-name SSLNegotiationPolicyType
--policy-attributes AttributeName=Reference-Security-Policy,AttributeValue=ELBSecurityPolicy-2016-08
I'm wondering if Kops should try to reconcile this as well, creating the load-balancer-policy if it does not already exist, based on the API Field being used as the Rerence-Security-Policy. Once it is ensured to exist for the API ELB then Kops can SetLoadBalancerPoliciesOfListener
. Thoughts?
I also think we will want to add API validation that makes sure this field is only set if the sslCertificate
field is also set. We could add the validation here:
kops/pkg/apis/kops/validation/aws.go
Lines 33 to 37 in ffaf75f
if c.Spec.API != nil { | |
if c.Spec.API.LoadBalancer != nil { | |
allErrs = append(allErrs, awsValidateAdditionalSecurityGroups(field.NewPath("spec", "api", "loadBalancer", "additionalSecurityGroups"), c.Spec.API.LoadBalancer.AdditionalSecurityGroups)...) | |
} | |
} |
and I think field.Forbidden() might be the most appropriate validation error for this.
@@ -529,6 +536,24 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan | |||
return fmt.Errorf("Unable to find newly created ELB %q", loadBalancerName) | |||
} | |||
e.HostedZoneId = lb.CanonicalHostedZoneNameID | |||
|
|||
// Set ELB listener's Security Policy | |||
if l, ok := e.Listeners["443"]; ok && len(l.PolicyNames) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than looking for the listener on port 443 perhaps it would be more flexible to perform this logic on any listener that has a Protocol of SSL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only apply security policies when specifying an ACM certificate. However, we set the listener on port 443 when the ACM certificate is existent. So I only set security policies for the listener on port 443 here.
kops/pkg/model/awsmodel/api_loadbalancer.go
Lines 112 to 114 in d90c90c
if lbSpec.SSLCertificate != "" { | |
listeners["443"] = &awstasks.LoadBalancerListener{InstancePort: 443, SSLCertificateID: lbSpec.SSLCertificate} | |
} |
Sounds good! Let's wait for #9011 to land and only add support for setting policies on NLBs. |
@FrankYang0529 The NLB PR has been merged, are you still willing to update this to support NLB Listener SSLPolicies? |
@rifelpet Yes, I will update it this week. |
678e542
to
06ba4bb
Compare
06ba4bb
to
1ef09fd
Compare
@rifelpet , I have updated it. We can support NLB Listener SSL Policy now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much simpler now that it supports NLBs rather than classic load balancers :) nice work!
We'll want to add terraform and cloudformation support for this too. It should just be a matter of adding the new field here and setting its value below:
kops/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go
Lines 645 to 651 in ecea477
type terraformNetworkLoadBalancerListener struct { | |
LoadBalancer *terraform.Literal `json:"load_balancer_arn" cty:"load_balancer_arn"` | |
Port int64 `json:"port" cty:"port"` | |
Protocol string `json:"protocol" cty:"protocol"` | |
CertificateARN *string `json:"certificate_arn,omitempty" cty:"certificate_arn"` | |
DefaultAction []terraformNetworkLoadBalancerListenerAction `json:"default_action" cty:"default_action"` | |
} |
and cloudformation has its own struct later in the file too. (docs for terraform and cloudformation)
If you want I can do that in a followup PR.
1ef09fd
to
9201046
Compare
@rifelpet Thanks for reviewing. I updated the code and added |
looks good, one last suggestion: Can you add an example |
@rifelpet, I have added |
The verify-cloudformation failure is unrelated and was fixed by #10256. This PR's next invocation of that job should pass. The TestLifecycleComplex failures are because the network load balancer task isn't recognizing the new field when describing the existing listeners in AWS. Reading the test failure output:
This can be interpreted as "after applying the changes, Kops' interpretation of the NLB listener state doesn't match what it had just sent to AWS. Therefore there's either a bug in the Fixing it should just be a matter of setting the kops/upup/pkg/fi/cloudup/awstasks/network_load_balancer.go Lines 360 to 372 in a0c8925
|
073ce65
to
93dcadd
Compare
@rifelpet Thank you for your elaboration. I know how it works now! Also, I have updated the code and I can run tests successfully. |
looks great, thanks for sticking with this! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FrankYang0529, rifelpet The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
closes #9633