Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Correctly set port and scheme when behind proxy. #116

Merged
merged 9 commits into from
Sep 26, 2014
Merged

Conversation

kkellyy
Copy link
Contributor

@kkellyy kkellyy commented Sep 15, 2014

Pushmanager now forms its URLs with information from any proxy it might be behind.

For pushmanager to do this, the proxy must forward its port and scheme via HTTP headers. Pushmanager uses the X-Forwarded-Port and X-Forwarded-Proto headers for this.

  • If the X-Forwarded-Port is set, then it will override the default of Settings['main-app']['port'].
  • If the X-Forwarded-Proto is set, then it will override the default of https.

For nginx, add these to http, server, or location blocks:

proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;

For apache2, can add these (or write logic to determine port & protocol):

RequestHeader set X-Forwarded-Port 443
Requestheader set X-Forwarded-Proto "http"

@kkellyy kkellyy changed the title Pushspam remove port Correctly set port and scheme when behind proxy. Sep 15, 2014
@@ -1195,7 +1194,7 @@ def verify_branch_successful(cls, updated_request):
<p>
<strong>%(user)s - %(title)s</strong><br />
<em>%(repo)s/%(branch)s</em><br />
<a href="https://%(pushmanager_servername)s%(pushmanager_port)s/request?id=%(id)s">https://%(pushmanager_servername)s%(pushmanager_port)s/request?id=%(id)s</a>
<a href="%(pushmanager_url)s/request?id=%(id)s">%(pushmanager_url)srequest?id=%(id)s</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

does this one need the slash?

@asottile
Copy link
Contributor

Seems fine, how are we going to set the X-blahblahblah headers? Are there plans to produce useful error messages / fallbacks if those are absent?

@kkellyy
Copy link
Contributor Author

kkellyy commented Sep 16, 2014

I left some comments about how to set apache2 or nginx proxies to forward those headers. The fallback for port is the value in the config.yaml and the protocol used in the request. Those should always be valid, but the user will be bypassing the proxy that way. I'm not sure if a warning is useful there or not, though.

'conflicts_with': (
"master"
if 'conflict-master' in updated_request['tags']
else "another pickme"
),
'pickme_name': updated_request['branch'],
'pickme_id': updated_request['id'],
Copy link
Member

Choose a reason for hiding this comment

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

pickme_id is still used in msg. Is there a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There aren't any tests for these things, I believe because they require a valid git repo. We're about to test these cases manually for things like this. Thanks for the catch.

… git.py of pickme_id being removed in URL generation
@@ -1105,14 +1106,13 @@ def pickme_conflict_detected(cls, updated_request, send_notifications):
else "another pickme"
),
'conflicts': updated_request['conflicts'].replace('\n', '<br/>'),
'pushmanager_servername': Settings['main_app']['servername'],
'reviewboard_servername': Settings['reviewboard']['servername'],
'pushmanager_url' : pushmanager_url,
'pushmanager_port': (
Copy link
Member

Choose a reason for hiding this comment

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

we don't need pushmanager_port anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's being used by the reviewboard link here. Is that incorrect?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed it is. It does look wrong since reviewboard doesn't need pushmanager's port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See other comment on same issue.

ymilki added a commit that referenced this pull request Sep 26, 2014
Correctly set port and scheme when behind proxy.

Given a correctly configured web server, the pushmanager url builder is now proxy aware.
Needs: X-Forwarded-Proto and X-Forwarded-Port headers
@ymilki ymilki merged commit 56cfea0 into master Sep 26, 2014
ymilki added a commit to ymilki/pushmanager that referenced this pull request Sep 26, 2014
 IMPROVEMENTS

 * tags can contain the string 'conflict' again (asottile, Yelp#119)
 * 'git-ok' tag now links to gitweb (kkellyy, Yelp#117)
 * pushmanager is now proxy aware (kkellyy, Yelp#116)

 BUG FIXES

 * reviewboard links no longer contains the pushmanager port (kkellyy, Yelp#121)

 DEPRECATED

 * 'hoods' tag no longer has post-stage checklist steps (kkellyy, Yelp#120)
@asottile asottile deleted the pushspam_remove_port branch September 27, 2014 23:52
ymilki added a commit to ymilki/pushmanager that referenced this pull request Sep 29, 2014
 IMPROVEMENTS

 * tags can contain the string 'conflict' again (asottile, Yelp#119)
 * 'git-ok' tag now links to gitweb (kkellyy, Yelp#117)
 * pushmanager is now proxy aware (kkellyy, Yelp#116)

 BUG FIXES

 * reviewboard links no longer contains the pushmanager port (kkellyy, Yelp#121)

 DEPRECATED

 * 'hoods' tag no longer has post-stage checklist steps (kkellyy, Yelp#120)
@ymilki ymilki mentioned this pull request Sep 29, 2014
ymilki added a commit that referenced this pull request Sep 29, 2014
 IMPROVEMENTS

 * tags can contain the string 'conflict' again (asottile, #119)
 * 'git-ok' tag now links to gitweb (kkellyy, #117)
 * pushmanager is now proxy aware (kkellyy, #116)

 BUG FIXES

 * reviewboard links no longer contains the pushmanager port (kkellyy, #121)

 DEPRECATED

 * 'hoods' tag no longer has post-stage checklist steps (kkellyy, #120)
ymilki added a commit that referenced this pull request Sep 29, 2014
 IMPROVEMENTS

 * tags can contain the string 'conflict' again (asottile, #119)
 * 'git-ok' tag now links to gitweb (kkellyy, #117)
 * pushmanager is now proxy aware (kkellyy, #116)
 * 'After certifying' checklist now says 'Before certifying' (kkellyy, #122)

 BUG FIXES

 * reviewboard links no longer contains the pushmanager port (kkellyy, #121)

 DEPRECATED

 * 'hoods' tag no longer has post-stage checklist steps (kkellyy, #120)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants