-
Notifications
You must be signed in to change notification settings - Fork 16
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
adding in some proxyification adjustments #13
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,10 @@ type conf struct { | |
// A special group, `*`, may be specified which allows any authenticated | ||
// user. | ||
AllowedGroups []string `json:"allowed-groups"` | ||
|
||
// Fix the host header on the requst to the backend proxied service to match | ||
// what came in through the front door. | ||
FixHost bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the property here should be a little more descriptive. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like retain host header .. updating now. |
||
} | ||
} | ||
|
||
|
@@ -219,6 +223,9 @@ type disp struct { | |
|
||
// The groups which may access this backend. | ||
groups []string | ||
|
||
// if the host header is to be fixed for this dispatcher or not | ||
fixhost bool | ||
} | ||
|
||
// Construct a URL to the oauth provider that with carry the provided URL as state | ||
|
@@ -319,6 +326,10 @@ func serveHttpProxy(d *disp, w http.ResponseWriter, r *http.Request) { | |
br.Header.Add("Underpants-Email", url.QueryEscape(u.Email)) | ||
br.Header.Add("Underpants-Name", url.QueryEscape(u.Name)) | ||
|
||
if d.fixhost { | ||
br.Host = d.host | ||
} | ||
|
||
bp, err := http.DefaultTransport.RoundTrip(br) | ||
if err != nil { | ||
panic(err) | ||
|
@@ -432,8 +443,14 @@ func hostOf(name string, port int) string { | |
func addSecurityHeaders(c *conf, next http.Handler) http.Handler { | ||
if c.AddSecurityHeaders { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
var proto = "http" | ||
if c.HasCerts() { | ||
w.Header().Add("Strict-Transport-Security", "max-age=16070400; includeSubDomains") | ||
proto = "https" | ||
} | ||
|
||
if r.Header.Get("X-Forwarded-Proto") != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is backwards, should be |
||
r.Header.Add("X-Forwarded-Proto", proto) | ||
} | ||
|
||
w.Header().Add("X-Frame-Options", "SAMEORIGIN") | ||
|
@@ -470,12 +487,13 @@ func setup(c *conf, port int) (*http.ServeMux, error) { | |
} | ||
|
||
m.Handle(fmt.Sprintf("%s/", host), addSecurityHeaders(c, &disp{ | ||
config: c, | ||
route: &route{host: uri.Host, scheme: uri.Scheme}, | ||
host: host, | ||
key: key, | ||
oauth: oc, | ||
groups: r.AllowedGroups, | ||
config: c, | ||
route: &route{host: uri.Host, scheme: uri.Scheme}, | ||
host: host, | ||
key: key, | ||
oauth: oc, | ||
groups: r.AllowedGroups, | ||
fixhost: r.FixHost, | ||
})) | ||
} | ||
|
||
|
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.
s/requst/request (found by @jhump)