Repository navigation
fix(http): read the client address from trusted proxies - #22
Merged
Merged
Conversation
Behind the load balancer every request arrived from the balancer's address, so all clients shared one rate-limit bucket per balancer node: ten sign-ins a minute for everyone together. Seen on qa, where the remaining count on /v1/catalog was separate per balancer address and did not change with the caller. Proxies in the private and loopback ranges are trusted by default (TRUSTED_PROXIES overrides), for the address, scheme and port only. X-Forwarded-Host is not read. Also: the runbook and the README say to seed the categories, which a fresh deployment does not have.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while checking the qa deployment.
The fault
The service never told Laravel to trust the load balancer, so
$request->ip()was the balancer's address for every request. Every rate limit that counts per address was shared by all clients on a balancer node:auth: 10 sign-ins, registrations or password resets a minute, for everyone togetherinstance-register: 10 a minutecatalog: 300 a minute, across all anonymous trafficpackages: anonymous npm and Composer readsOn qa,
X-RateLimit-Remainingon/v1/catalogcounted down separately for each of the three balancer addresses and was unaffected by who called.The change
config/trustedproxy.php: proxies in the private and loopback ranges are trusted by default;TRUSTED_PROXIESoverrides (addresses, CIDR ranges, or*). An ECS task behind an ALB needs no configuration.X-Forwarded-Hostis not: an ALB passes a client's own value through, and the public host isREGISTRY_PUBLIC_URL.X-Forwarded-For.tests/Feature/TrustedProxiesTest.phpcovers each of these.Docs
TRUSTED_PROXIESin the configuration table and the deployment list.php artisan registry:seed --force). A fresh deployment has none: qa's/v1/catalog/categoriesis[], and the Studio's category list is empty with it.After merging
Push to
deploy/qa. To check: the remaining count on/v1/catalog/extensions/xshould continue across the balancer's addresses instead of starting again on each.