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

add https redirect to deck #6081

Merged
merged 2 commits into from
Jan 2, 2018

Conversation

BenTheElder
Copy link
Member

@BenTheElder BenTheElder commented Dec 23, 2017

/area prow
fixes #5282

  • move all HTTP handling to a non-default mux
  • add a flag (disabled by default) to enable injecting an https redirect handler mux over the "real" mux

@k8s-ci-robot k8s-ci-robot added area/prow Issues or PRs related to prow approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 23, 2017
@BenTheElder
Copy link
Member Author

once this looks OK I'll bump deck and then we can merge / deploy

@BenTheElder BenTheElder requested a review from spxtr December 23, 2017 00:13
@BenTheElder
Copy link
Member Author

We could also muck with the ingress or something, but all we need here is to optionally dissallow non-https in deck (by always redirecting anything else), which gives some nicer guarantees hopefully and isn't much code.

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a test?

r.URL.Scheme = "https"
http.Redirect(w, r, r.URL.String(), http.StatusMovedPermanently)
} else {
mux.ServeHTTP(w, r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/mux/oldMux/
This would create an infinite recursion loop as is because this mux reference is actually captured so after line 127 mux==redirectMux 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, yeah originally I wasn't capturing, and then I realized I couldn't swap them, will fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@BenTheElder
Copy link
Member Author

Does this need a test?

I don't think so, there's not much useful to assert here, and it's not a critical behavior.

@0xmichalis
Copy link
Contributor

This should be an option in Ingress and not something codified in prow. In Openshift, we use Openshift Routes (predecessor to k8s Ingress) for all external traffic to prow and the redirects happen automatically by the router.

buildCluster = flag.String("build-cluster", "", "Path to file containing a YAML-marshalled kube.Cluster object. If empty, uses the local cluster.")
tideURL = flag.String("tide-url", "", "Path to tide. If empty, do not serve tide data.")
hookURL = flag.String("hook-url", "", "Path to hook plugin help endpoint.")
redirectToHTTPS = flag.Bool("redirect-to-https", false, "Enable http to https redirect.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer a config option for this, but I'm not 100% sure.

@BenTheElder
Copy link
Member Author

BenTheElder commented Dec 23, 2017 via email

@BenTheElder
Copy link
Member Author

/hold
I actually probably need to do x-forwarded-for instead of the scheme 🤦‍♂️
I would still prefer that our single user facing web server in prow be able to require https without an extra router just for this. It's not much code and will be cheaper to run and maintain.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 23, 2017
@spxtr
Copy link
Contributor

spxtr commented Dec 25, 2017

I think it's pretty standard to use something like nginx or openshift routes or whatever your cloud supports for HTTPS redirection. On GCE it seems like nginx is the norm.

I don't want to add another server to our deployment just for such a trivial redirect

I hear you, but I actually prefer it to writing our own code. Because this is a pretty common pattern for k8s/GKE users, we should show how simple it is to do with kubernetes :)

@BenTheElder
Copy link
Member Author

I hear you, but I actually prefer it to writing our own code. Because this is a pretty common pattern for k8s/GKE users, we should show how simple it is to do with kubernetes :)

Writing an NGINX rule is code :-) Optionally handling x-forwarded-proto doesn't really justify more latency and operational complexity imho. It's actually going to be more LOC to add an NGINX rule in the middle (including the nginx deployment etc.) ...

GCE-Ingress / Load Balancer -> kube-proxy / iptables -> nginx -> kube-proxy -> kube-proxy (if on another node) -> deck and back again is pretty overkill just to gain a single redirect. If we were using an ingress-nginx it would be simple.

Really the GCE ingress / load balancer should support this :(

@BenTheElder BenTheElder removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 27, 2017
buildCluster = flag.String("build-cluster", "", "Path to file containing a YAML-marshalled kube.Cluster object. If empty, uses the local cluster.")
tideURL = flag.String("tide-url", "", "Path to tide. If empty, do not serve tide data.")
hookURL = flag.String("hook-url", "", "Path to hook plugin help endpoint.")
redirectToHTTPS = flag.Bool("redirect-to-https", false, "Enable x-forwarded-for http to https redirect.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x-forwarded-for != x-forwarded-proto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks.

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 2, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, cjwagner

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 43b0134 into kubernetes:master Jan 2, 2018
@BenTheElder BenTheElder deleted the secure-the-deck branch January 2, 2018 20:24
@BenTheElder
Copy link
Member Author

This has a key (and rather stupid) mistake: it needs to redirect to the external domain, not the one in the forwarded in the request. This is an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prow should redirect HTTP to HTTPS
6 participants