How to get Client IP Address in Access Logs

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

Summary

 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

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:

1 2 3 4 5 # 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:

1 2 3 4 5 # 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

  1. Install Bamboo and set it up behind Apache

    VirtualHost

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <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>
  2. Add ServerName to /etc/hosts or C:\Windows\System32\drivers\etc\hosts on the Bamboo server, e.g. 192.168.0.12

    /etc/hosts (Linux/MacOS), C:WindowsSystem32driversetchosts (Windows)

    1 127.0.0.1 webserver.bamboo
  3. Add ServerName to /etc/hosts or C:\Windows\System32\drivers\etc\hosts on a different server, e.g. 192.168.0.15

    /etc/hosts (Linux/MacOS), C:WindowsSystem32driversetchosts (Windows)

    1 192.168.0.12 webserver.bamboo
  4. Create a new Project / Plan with Repository and add a branch.

  5. 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

  6. 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

  7. 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:

<bamboo-install>/conf/server.xml

1 2 <Valve className="org.apache.catalina.valves.AccessLogValve" resolveHosts="false" pattern="%a %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;"/>

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:

  1. Stop Bamboo.

  2. 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

    1 2 3 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="access_client_ip." suffix=".log" pattern="&quot;%{X-Forwarded-For}i&quot; %l %u %t %r %s %b &quot;%{User-Agent}i&quot; &quot;%{Referer}i&quot;" resolveHosts="false"/>
  3. Start Bamboo

Test

Redo steps 5 & 6 from the Diagnostic Steps above and note the difference in the logs:

<bamboo-install/logs/access_client_ip>

1 2 3 4 5 # 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" "-"

Updated on April 15, 2025

Still need help?

The Atlassian Community is here for you.