How to get Client IP Address in Access Logs
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
These statements are assumed true for the purpose of the following article:
- Anonymous access is enabled in Bamboo
- Users are not logged in while running the described below
Purpose
Determine the client IP address from which REST API requests against Bamboo originate since currently neither the <bamboo-install>/logs/access_log
or <bamboo-install>/logs/catalina.out
provide this information.
The following appears in the <bamboo-install>/logs/catalina.out:
# from same box Bamboo is running (192.168.0.12)
2016-01-19 22:18:18,379 INFO [http-bio-8085-exec-1] [AccessLogFilter] 127.0.0.1 GET http://webserver.bamboo/rest/api/latest/plan/PROJ-PLAN/branch.json 140522kb
# from a different box (192.168.0.15)
2016-01-19 22:19:48,878 INFO [http-bio-8085-exec-3] [AccessLogFilter] 127.0.0.1 GET http://webserver.bamboo/rest/api/latest/plan/PROJ-PLAN/branch.json 63411kb
The following appears in the <bamboo-install>/logs/access_log:
# from same box Bamboo is running (192.168.0.12)
127.0.0.1 [19/Jan/2016:22:18:21 -0200] "GET /rest/api/latest/plan/PROJ-PLAN/branch.json HTTP/1.1" 200 441 2928 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"
# from a different box (192.168.0.15)
127.0.0.1 [19/Jan/2016:22:19:48 -0200] "GET /rest/api/latest/plan/PROJ-PLAN/branch.json HTTP/1.1" 200 441 12 "-" "Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0"
Diagnosis
Diagnostic Steps
Install Bamboo and set it up behind Apache
VirtualHost<Virtualhost *:80> ServerName webserver.bamboo ProxyRequests Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:8085/ ProxyPassReverse / http://localhost:8085/ <Location /> Order allow,deny Allow from all </Location> </Virtualhost>
Add
ServerName
to/etc/hosts
orC:\Windows\System32\drivers\etc\hosts
on the Bamboo server, e.g. 192.168.0.12/etc/hosts (Linux/MacOS), C:WindowsSystem32driversetchosts (Windows)127.0.0.1 webserver.bamboo
Add
ServerName
to/etc/hosts
orC:\Windows\System32\drivers\etc\hosts
on a different server, e.g. 192.168.0.15/etc/hosts (Linux/MacOS), C:WindowsSystem32driversetchosts (Windows)192.168.0.12 webserver.bamboo
- Create a new Project / Plan with Repository and add a branch.
- Log out and navigate to the following URL in a web browser:
http://webserver.bamboo/rest/api/latest/plan/PROJ-PLAN/branch.json
from the same server where Bamboo is running, e.g. 192.168.0.12 - Log out and navigate to the following URL in a web browser:
http://webserver.bamboo/rest/api/latest/plan/PROJ-PLAN/branch.json
from the other server, e.g. 192.168.0.15 - Both requests are presented in the Bamboo logs as 127.0.0.1 where we would expect the individual client IPs 192.168.0.12 (same server) or 192.168.0.15 (different server)
Cause
In the <bamboo-install>/conf/server.xml
you can find the following entry that describes what Bamboo will capture and write to the logs:
<Valve className="org.apache.catalina.valves.AccessLogValve" resolveHosts="false"
pattern="%a %t "%m %U%q %H" %s %b %D "%{Referer}i" "%{User-Agent}i""/>
There is a value missing: %{X-Forwarded-For}i
Refer to http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for further information.
Solution
In order to have Bamboo log the client IP Address:
- Stop Bamboo.
Prepend the missing value to
<bamboo-install>/conf/server.xml
to the front of the existing value of the "pattern" attribute within the "Valve" tag:<bamboo-install>/conf/server.xml<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="access_client_ip." suffix=".log" pattern=""%{X-Forwarded-For}i" %l %u %t %r %s %b "%{User-Agent}i" "%{Referer}i"" resolveHosts="false"/>
Start Bamboo
Test
Redo steps 5 & 6 from the Diagnostic Steps above and note the difference in the logs:
# from same box Bamboo is running (192.168.0.12)
"127.0.0.1" - - [20/Jan/2016:12:02:48 -0200] GET /rest/api/latest/plan/PROJ-PLAN/branch.json HTTP/1.1 200 460 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" "-"
# from a different box (192.168.0.15)
"192.168.0.15" - - [20/Jan/2016:12:01:54 -0200] GET /rest/api/latest/plan/PROJ-PLAN/branch.json HTTP/1.1 200 460 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-"