-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix hsts support when not using SSL #632
Conversation
@bilby91 thanks for the PR! we will review it shortly. |
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 PR fixes the issue at first glance but there appears to be some issues.
If hsts
, hsts-behind-proxy
and redirect-to-https
are set in the annotations. The following warning appears:
*84 using uninitialized "hsts_header_val" variable
This occurs because it hits the redirect in server.SSLRedirect
before the headers are added. Some some additional handling needs to be done here.
@Dean-Coakley Good catch, I totally missed that. Do you think that moving the block of code on top of BTW, do you have a cheap way of testing this ? The way I tested this took me some time to get stuff setup. |
@bilby91 I think this issue is more complex than we initially expected. I'd recommend waiting until we can provide you with some guidance on how to meet all edge cases. But feel free to share commits/comments in the meantime if you feel so inclined. There is no way to test without a cluster - if that's what you're hoping for. However you don't need to test with a cloud loadbalancer. I'm testing against a minikube cluster with the complete-example deployed. And then use curl You can also run the binary locally against a running cluster. You'd set this up by
This will help you debug template compilation. However please note this will not substitute testing in a cluster. There is no nginx running here. You can use this for dev purposes before testing in a cluster. |
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.
@bilby91
we reviewed the PR more thoroughly. Please see the suggestions. Thanks!
{{- end}} | ||
{{end}} | ||
{{- end}} | ||
|
||
{{- if $server.HSTS}} |
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.
with this suggestion HSTS will only be enabled when TLS termination is enabled and hsts-behind-proxy
annotation/configmapkey is true.
{{- if $server.HSTS}} | |
{{- if and $server.HSTS (or $server.SSL $server.HSTSBehindProxy)}} |
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.
Additionally, please move lines 66-78 (the {{- if and $server.HSTS (or $server.SSL $server.HSTSBehindProxy)}} ... {{end}}
block) above line 56 ({{if $server.SSL}})
. This will fix the warning message like this *84 using uninitialized "hsts_header_val" variable
.
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.
@pleshakov Thanks for taking the time to review the change! The suggested changes would apply for nginx-plus and regular nginx right ? Just making sure!
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.
yep. for both templates! thanks for double checking.
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.
Pushed suggested changes!
41e40c9
to
ed0bd9f
Compare
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.
👍
Thanks a lot @bilby91 ! |
Closes #627
Proposed changes
This change will fix the HSTS support when not handling SSL at the ingress layer. Previously, the templating code would only render the HSTS related directives if the
SSL
was true which is never the case when a load balancer that sits in front of the ingress handle the TLS.Fixes the following issue: #627
Checklist
Before creating a PR, run through this checklist and mark each as complete.