How to get Client IP Address in Access Logs

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server と Data Center のみ - この記事は、サーバーおよびデータセンター プラットフォームのアトラシアン製品にのみ適用されます。

 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.

<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

<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"

診断

診断ステップ

  1. 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>
    
  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)
    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)
    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)

原因

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

ソリューション

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

テスト

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

<bamboo-install/logs/access_client_ip>
# 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" "-"

最終更新日 2016 年 11 月 24 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.