Wrong redirects on elections.fedoraproject.org #12997
Labels
No labels
announcement
anubis
authentication
aws
backlog
blocked
bodhi
ci
cloud
communishift
copr
database
day-to-day
dc-move
deprecated
dev
discourse
dns
downloads
easyfix
epel
firmitas
forgejo_migration
Gain
High
Gain
Low
Gain
Medium
gitlab
greenwave
hardware
help wanted
high-trouble
koji
koschei
lists
low-trouble
medium-trouble
mirrorlists
monitoring
Needs investigation
odcs
OpenShift
ops
outage
packager_workflow_blocker
pagure
permissions
Priority
Needs Review
Priority
Next Meeting
Priority
🔥 URGENT 🔥
Priority
Waiting on Assignee
Priority
Waiting on External
Priority
Waiting on Reporter
rabbitmq
release-monitoring
releng
request-for-resources
s390x
security
SMTP
sprint-0
sprint-1
src.fp.o
staging
unfreeze
waiverdb
websites-general
wiki
Backlog Status
Needs Review
Backlog Status
Ready
chore
documentation
points
01
points
02
points
03
points
05
points
08
points
13
Priority
High
Priority
Low
Priority
Medium
Sprint Status
Blocked
Sprint Status
Done
Sprint Status
In Progress
Sprint Status
Review
Sprint Status
To Do
Technical Debt
Work Item
Bug
Work Item
Epic
Work Item
Spike
Work Item
Task
Work Item
User Story
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
infra/tickets#12997
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When logging in or out of elections.fedoraproject.org , you get redirected to
https://elections.fedoraproject.org,elections.fedoraproject.org/, which is obviously wrong. It's the same on staging.I've been poking into this and it's quite weird. One thing I noticed is that if you log out and go to https://elections.stg.fedoraproject.org/vote/32 , you get redirected to
https://elections.stg.fedoraproject.org/login?next=https://elections.stg.fedoraproject.org,elections.stg.fedoraproject.org/vote/32. This redirect is, I'm pretty sure, produced by the login_required decorator, and all that does is:so the wrong
nextparameter in the URL is coming fromflask.request.url. I've no idea howflask.request.urlis coming up wrong, but it seems like it's as likely to be a deployment issue as it is a bug in the elections code, so I'm filing it here.I'll keep poking at it for a bit, but I'm rather baffled right now, can't see any reason it would be like this.
Initially reported by @stefw , thanks.
@kevin , who is definitely enjoying his PTO, immediately knew (of course) what this was - it's openshift header forwarding behavior. Setting the
haproxy.router.openshift.io/set-forwarded-headersannotation toreplace(instead of the defaultappend) seems to fix this.If that's all there was to it, though, you'd think more stuff would be broken - using
flask.request.urlor similar is hardly unusual. I do wonder if elections' built-in reverse proxy thing is somehow related here. The openshift doc does specifically mention the "X-Forwarded-For" header, and the elections reverse proxy thingy seems to specifically care about that header, so it kinda adds up. I wonder if this might fix it:or maybe
server.split(",")[0], not sure if it's better to take the first value or the last.Hmm, or maybe...it looks like the
ReverseProxiedthing in elections is basically trying to do the same as werkzeug X-Forwarded-For Proxy Fix, which is documented by flask upstream. Maybe we should switch elections to use that, with appropriate configuration?Filed https://pagure.io/elections/issue/106 to propose replacing
ReverseProxied.From what I can remember, this looks a bit like a problem we had in fedocal that got fixed by...
github.com/fedora-infra/fedocal@3e00d4a425...not sure if that helps you.
Metadata Update from @james:
Yeah, that's pretty much exactly what I was suggesting. The tricky points to me are just:
x_proto=1, x_host=1as the correct ones?@abompard Ping on the above questions wrt using werkzeug.middleware.proxy_fix
Yeah we should switch to Werkzeug's implementation instead of our own (manually copied blob from one project to another).
The argument values we set depend on what we know our proxy will set in the headers. I think it sets
X-Forwarded-Hostsox_host=1seems correct.Here's the reference docs.
Yeah, I read the doc, but I didn't know which headers the proxy sets or how many levels of proxying to consider.
Metadata Update from @phsmoura:
Hey! Sorry I forgot to respond to this one.
Trusting only one level of proxying is a safer bet for something that goes in the code, so I went with that. But I also think this proxy-handling stuff should go into a deployment-specific WSGI file that would do the wrapping, because only the deployers know how many proxies to trust. But that's a little more work and I was in a rush to fix it.
For example, Noggin uses this WSGI file in Ansible: https://pagure.io/fedora-infra/ansible/blob/main/f/roles/openshift-apps/noggin/templates/wsgi.py
So where are we here?
Do you want to take it, @abompard , or should I?
This is also affecting resultsdb. it's probably been the case for a while but didn't cause any obvious effects. but the latest resultsdb container now has werkzeug 3.1.7, which backported this hostname validity check, so now we're choking on it:
note that werkzeug is seeing the hostname as literally
resultsdb.stg.fedoraproject.org, resultsdb.stg.fedoraproject.organd (not surprisingly) considering it invalid.Since this is affecting resultsdb, I particularly think the "this shouldn't be in code" thing is significant. We have no idea how many proxies the Red Hat internal resultsdb instance wants to / needs to trust.
ReverseProxiedwith werkzeug/middleware/proxy_fix.py #112