Support X-Forwarded-For in logging when behind a proxy
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- go
- Domain
- backend, networking
Research direction
Start in mux.go, reading NewHandler and the existing debugHandler and logHandler middleware, then inspect how gorilla/handlers is used for logging. Verify the middleware ordering and confirm that logs show the external client IP from X-Forwarded-For when the server is behind a proxy.
Written by the indexing model from the issue text.
Description
Hi,
By default, the logging in rest-server will always log the IP address of the connection, which in many cases will be the nearest proxy.
Adding support for the X-Forwarded-For headers will allow the logging to display the correct external IP.
Currently 'gorilla/handlers' is used for logging. 'gorilla/handlers' fully supports decoding the X-Forwarded-For headers if
you add the proxyHeaders middleware before the logging middleware.
I'm currently using the following patch (against master) to implemented the additional middleware:
diff --git mux.go mux.go
index 77fcdb4..294708e 100644
--- mux.go
+++ mux.go
@@ -21,6 +21,10 @@ func (s *Server) debugHandler(next http.Handler) http.Handler {
})
}
+func (s *Server) proxyHandler(next http.Handler) http.Handler {
+ return handlers.ProxyHeaders(next)
+}
+
func (s *Server) logHandler(next http.Handler) http.Handler {
var accessLog io.Writer
@@ -104,6 +108,9 @@ func NewHandler(server *Server) (http.Handler, error) {
if server.Debug {
handler = server.debugHandler(handler)
}
+
+ handler = server.proxyHandler(handler)
+
if server.Log != "" {
handler = server.logHandler(handler)
}
As a result, my logs now show the correct external IP, instead of the IP address of my proxy.
Any thoughts?
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 179
- Avg merge
- 15d 9h
- Merged PRs (30d)
- 2
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from restic/rest-server
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
restic/rest-server#389 ·
-
state: need feedback
Difficulty 3/5 1-2 days Newbie friendliness 55/100
restic/rest-server#391 · 5 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
restic/rest-server#390 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
restic/rest-server#384 · 2 comments ·
-
Exit after configurable idle period for servers with limited RAM or are off/suspended when unusedOpen
Difficulty 4/5 3-5 days Newbie friendliness 50/100
restic/rest-server#383 · 2 comments ·
All issues in restic/rest-server
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
rossoctl/context-guru#346 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
prime-radiant-inc/evener#2883 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
gravitational/teleport#69805 ·
Maintainers usually reply within 11 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Under Poisson sampling, the `PLDAccountant` composes the inner event both before and after samplingOpen
Difficulty 2/5 Half a day Newbie friendliness 78/100
google/differential-privacy#496 ·