Repository navigation
Log the client address when a request is rejected - #476
Merged
Merged
Conversation
Token and capacity rejections were logged without the peer address, so repeated attempts could not be traced or banned from the server log. Rejections on /asr, /v1/listen and /v1/audio/transcriptions now end with (client=ADDRESS), and capacity rejections are logged as well. The token is never logged. The Nginx example forwards X-Forwarded-For so the logged address is the real client when the proxy is trusted.
The Nginx example now overwrites X-Forwarded-For with the address Nginx saw instead of appending to a client-supplied value, and shows a per-address connection limit, since the session cap is shared by all clients of a worker.
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.
Rejected requests were logged without the peer address, and capacity rejections and REST token failures were not logged at all. An operator could not trace repeated attempts or feed them to fail2ban or a proxy rule. This follows the remarks in discussion #463.
Changes:
/asr,/v1/listenand/v1/audio/transcriptionslog a warning ending with(client=ADDRESS). The REST route did not log before.docs/deployment.mddescribes the log lines. The Nginx example now setsX-Forwarded-Forto$remote_addr, so a client cannot choose the logged address, and shows a per-addresslimit_conn, since the session cap is shared by all clients of a worker.The address is the direct peer. Behind a proxy it is the forwarded address only when
--forwarded-allow-ipstrusts that proxy, which is Uvicorn's existing behaviour.Validation:
tests/test_session_limits.pyandtests/test_server.pynow assert the logged address and that a wrong token does not appear in the log. They fail without the change (6 failures) and pass with it.X-Forwarded-For: 203.0.113.7logsclient=203.0.113.7. With proxy headers off it logsclient=127.0.0.1.Not validated: the Nginx directives were not run against an Nginx instance.
This does not add a per-client session cap inside WLK. Behind a shared proxy address that would need its own design.