- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 224
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
[WIP] Restrict project access by IP address #36044
base: master
Are you sure you want to change the base?
Conversation
@minhaminha here's a branch with the basic model for the IP access work - figure we can PR our respective changes into this and hopefully avoid too much conflict |
90630cf
to
6dc15fe
Compare
Add middlware class to check IP access
), | ||
), | ||
( | ||
"ip_denylist", |
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.
is there any need for a country_denylist
?
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.
I left it out for now since we don't need it and it makes the logic a bit harder to reason about. Though thinking about it again I think we could make it work by saying specificity wins (ie an IP rule beats a country rule), something like:
def is_allowed(ip):
if ip in ip_denylist:
return False
if ip in ip_allowlist:
return True
if country_denylist and is_in_country(ip, country_denylist):
return False
return not country_allowlist or is_in_country(ip, country_allowlist):
That is, allowlisted IPs are always allowed even from denylisted countries.
Still, I think it's okay to hold off for now - we could always add it later if needed
@esoergel I noticed that currently, a user that's not in an allowed country according to the domain's config can trigger multiple requests if they repeatedly try to access the domain. I'm thinking we should also add a session blocklist, so that when a user fails |
@minhaminha yeah that's a good thought - I had the same idea but was uncertain whether it'd be worth it. It certainly makes sense to cache the lookups we allow, since we expect users to make a bunch of requests in sequence. However, if their request is blocked, presumably they won't try again and again unless it's like a DOS attack, which this isn't intended to mitigate against. Still though, I guess we wouldn't actually stick anything in the session for blocked IPs unless we do encounter one, so the cost should be trivial. I'd be on board with that. |
@esoergel blocking by the IP's origin country is now working properly on staging 🎉 . Is there anything else to be done on this PR before releasing it from the drafts? I created an IP Access monitoring dashboard on datadog here, and I'll add the requests-per-day counter on their too/setup the 1000 request threshold alert after this gets merged.
|
Product Description
Technical Summary
https://dimagi.atlassian.net/browse/USH-5818
https://dimagi.atlassian.net/browse/USH-5817
Design document
Feature Flag
Safety Assurance
Safety story
Automated test coverage
QA Plan
Rollback instructions
Labels & Review