SSL を使用して HAProxy の内側にある Bitbucket Server を保護する
このページでは、HAProxy サーバーが Bitbucket Server のリバース プロキシとして動作するネットワーク トポロジを確立する方法を説明します。一般に、このような構成は次のような場合に使用されます。
- Bitbucket Server が "ファイアウォールの背後" の保護された領域にインストールされていて、ファイアウォール外部のユーザーが Bitbucket Server にアクセスするためのゲートウェイを HAProxy が提供する場合。
- Bitbucket Server を、保護されたポート (例: Linux では 1024 よりも大きいポート) で提供する必要がある場合。Bitbucket Server を権限を持つユーザー (例: root) で実行することはできないため、Bitbucket Server でこれらのポートに直接アクセスすることはできません。このような場合、HAProxy はこれらのポートをバインドしてリクエストを Bitbucket Server に転送できます。
On this page:
このページに記載されている構成は、次のシナリオの結果を示しています。
- HAProxy と外部クライアントとの接続が SSL で保護されている。HAProxy と Bitbucket Server との間の接続が保護されていない。
- Bitbucket Server と HAProxy が同じマシン上で実行されている。
- Bitbucket Server is currently available at
http://mycompany.com:7990/
. - Bitbucket Server is to be made available at
https://mycompany.com/bitbucket
.
重要な考慮事項
- すでに実行中の HAProxy インスタンスが存在することを想定しています。
- サーバー マシンに SSL 証明書がインストールされている必要があります。
- 他のアプリケーションとの既存のリンクは、Bitbucket Server の新しい URL を使用して再構成する必要があります。
- ユーザーのコンピューターと Bitbucket Server との間の Git 操作の保護は別途検討する必要があります。「Git への SSH アクセスを有効にする」を参照してください。
- 「SSL を使用して Tomcat で Bitbucket Server を保護する」にあるように、プロキシを使用することなく SSL を直接使用するように Bitbucket Server を構成することも可能です。
アトラシアンのサポート提供範囲に、 HAProxy 連携は含まれません。HAProxy の利用で支援が必要な場合、answers.atlassian.com のアトラシアン コミュニティや、アトラシアン パートナーから支援を得ることができます。
ステップ 1: Bitbucket Server のコンテキスト パスを設定する
Bitbucket Server and HAProxy need to be serving from the same context. Bitbucket Server is currently accessed at http://mycompany.com:7990. It needs to be changed to serve from http://mycompany.com:7990/bitbucket
to match context https://mycompany.com/bitbucket
.
- Locate the
bitbucket.properties
file in the shared directory of your<Bitbucket Server home directory>.
次の内容を追加して、Bitbucket Server のコンテキスト パスを変更します。
server.context-path=/bitbucket
- ファイルを保存します。
考慮事項
- コンテキスト パスを使用する場合、同じパスを Bitbucket Server のベース URL のコンテキスト パスにも適用することが重要です (ステップ 2)。
- The context path for serving from the root context is
path=""
(i.e notpath="/")
.
ステップ 2: Bitbucket Server のベース URL の変更
- ブラウザ ウィンドウを開き、管理者アカウントで Bitbucket Server にログインします。
- Go to the Bitbucket Server administration area and click Server settings (under 'Settings'), and change Base URL to match the URL HAProxy will be serving. For this example, use
https://mycompany.com/bitbucket.
ステップ 3: Tomcat コネクタを設定する
この例では続けて、HAProxy で Bitbucket Server を提供する方法を Tomcat に示す次の属性を構成し、Tomcat が適切な URL を生成できるようにする必要があります。
Locate the <Bitbucket Server home directory>/shared/bitbucket.properties
file, and add the following:
server.secure=true
server.scheme=https
server.proxy-port=443
server.redirect-port=443
server.proxy-name=mycompany.com
これらの属性の役割
proxyPort
is set to 443 to indicate that HAProxy is accepting connections over on the standard HTTPS port 443.
proxyName
andscheme
are are set to the values that HAProxy is serving Bitbucket Server over.secure
attribute is also set totrue
to tell Bitbucket Server that the connection between the client and HAProxy is considered secure.redirectPort
is set to 443 so that Tomcat knows how to send a user to a secure location when necessary (this is not really necessary in this example because this connector is alreadysecure
).
Tomcat Connector の設定の詳細については、Apache Tomcat 7.0 の HTTP Connector リファレンスを参照してください。
ステップ 4: HAProxy の構成
Merge the example below into your HAProxy configuration (e.g /etc/haproxy/haproxy.cfg
). This is a complete HAProxy 1.5.x configuration. Note that HAProxy 1.5.x or greater is required for SSL support. You can just take the bits that fit your needs. The important configuration is in the bitbucket_http_frontend
and bitbucket_http_backend
.
global
log /dev/log local0
log /dev/log local1 notice
user haproxy
group haproxy
daemon
ssl-default-bind-options no-sslv3
maxconn 1000
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
# Tells HAProxy to start listening for HTTPS requests. It uses the SSL key
# and certificate found within certAndKey.pem. All requests will be routed
# to the bitbucket_http_backend.
frontend bitbucket_http_frontend
bind *:443 ssl crt /etc/haproxy/certAndKey.pem ciphers HIGH:!aNULL:!MD5
default_backend bitbucket_http_backend
# This is an optional rule that will redirect all requests to https://mycompany.com
# to https://mycompany.com/bitbucket.
redirect location /bitbucket if { path -i / }
# The bitbucket_http_backend simply forwards all requests onto http://mycompany.com:7990/.
# It will only allow 50 concurrent connections to the server at once.
backend bitbucket_http_backend
mode http
option httplog
option forwardfor
option http-server-close
option httpchk
server bitbucket01 mycompany.com:7990 maxconn 50
(オプション) ステップ 4: SSH 接続のリダイレクト
HAProxy は、すべての Bitbucket Server SSH トラフィックをプロキシする機能を提供しています。詳細については「SSH ポート フォワーディングのセットアップ」をご確認ください。