SSL を使用して Tomcat で Bitbucket Server を保護する
Bitbucket Server のプロキシ設定および保護
このページの内容
関連コンテンツ
- 関連コンテンツがありません
このページでは、Bitbucket Server に付属しているアプリケーション サーバーである Apache Tomcat への HTTPS (HTTP over SSL) アクセスを有効化する方法について説明します。
SSL を使用して Bitbucket を保護する理由
Bitbucket Server がインターネットに接続されている場合、ユーザー名、パスワード、およびその他の独自データがリスクに晒される可能性があります。SSL で保護し、セキュアなアクセスを必須にすることを検討することをおすすめします。
Bitbucket Server の実行には、リバース プロキシの背後での Bitbucket Server の実行などの他のネットワーク トポロジ オプションがあります。いくつかの一般的なオプションの概要については、「Bitbucket Server のプロキシと保護」を参照してください。
これらの手順を使用して Bitbucket Server をセットアップした場合、Bitbucket Server へのアクセスは直接アクセスになり、ユーザーのブラウザと Bitbucket Server の間のすべての通信は SSL を使用して保護されます。
はじめる前に
ここで記載している構成を使用すると、次のようになります。
- Bitbucket Server would listen for requests on port
8443
; the port can be changed, if required. - Bitbucket Server would be available at
https://<computer name>:8443
; the base URL can be changed, if required. - その結果、Bitbucket Server のこの新しい URL を使用して、他のアプリケーションとの既存のリンクを再構成する必要があります。
- Bitbucket Server と同じホスト名およびコンテキスト パスで、別のアトラシアン アプリケーション、または Java Web アプリケーションを実行している場合は、Bitbucket Server にコンテキスト パスを設定することができます。
- ユーザーのコンピューターと Bitbucket Server との間の Git 操作の保護は別途検討する必要があります。「Git への SSH アクセスを有効にする」を参照してください。
これらの手順は参考として提供されます
アトラシアン アプリケーションでは製品内の SSL の使用が許可されます。ただし、アトラシアンのサポートはその設定に対する支援は行いません。したがって、アトラシアンではこのためのサポートの提供を保証できません 。
証明書の変換で支援が必要な場合、証明書の提供元のベンダーにご相談ください。アトラシアン サポートは、SSL 関連のサポート依頼は証明書の発行機関に転送します。
また、これらの手順は、管理者が小規模なチーム用に Bitbucket Server をセットアップすることを意図しています。
自己署名証明書の生成
暗号化が必要だが web サイトのリクエストの身元を確認する必要がない場合、自己署名証明書が役立ちます。一般的に、自己署名証明書はテスト環境や社内ネットワーク(イントラネット)で使用します。
証明書が認証局 (CA) によって署名されていないため、ユーザーはサイトが信頼されていない旨のメッセージを受け取り、証明書を承認する複数のステップをサイトにアクセスする前に実行する必要があります。これは通常、サイトに初めてアクセスする際に発生します。
ここで紹介している証明書の作成手順では Java の keytool を使用します。証明書を生成するツールはほかにも提供されています。
Bitbucket Server の本番環境インスタンスをセットアップする場合は、自己署名証明書ではなく CA 証明書 (後述) を使用することをおすすめします。
To generate a self-signed certificate using Java's keytool
utility
Create a new
.keystore
file in the Bitbucket Server home directory.Bitbucket ホーム ディレクトリへのアクセス権を持つユーザー アカウントでログイン (または sudo を使用) します。
次のコマンドを実行します。
Windows "%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA -sigalg SHA256withRSA -keystore <Bitbucket home>\shared\config\ssl-keystore
Linux、macOS $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -sigalg SHA256withRSA -keystore <Bitbucket home>/shared/config/ssl-keystore
The default keystore Bitbucket uses is
<Bitbucket server home directory>/shared/config/ssl-keystore
. You can specify different keystore location using thekeystore
parameter. But, in this case, you will have to include it in thebitbucket.properties
file as described in the configuration section.
パスワードを要求された場合 (設定する 2 つのパスワードのうちの 1 つ目。同一のパスワードを使用する必要があります)、次の手順に従います。
- 証明書に使用するパスワード (秘密鍵) を指定します。
- The default password Tomcat expects is '
changeit
'. If you use any other value you must specify it in the<Bitbucket home directory>/shared/bitbucket.properties
file. - 次のステップで必要になるので、パスワードを記録しておきます。
- プロンプトに従い、名前、組織、場所を指定します。この情報は、エンティティの X.500 識別名(DN)を構成するのに使用されます。
CN ("What is your first and last name?") は、Bitbucket を実行しているサーバーの完全修飾ホスト名と一致している必要があります。異なる場合、Tomcat はSSL の証明書を使用できません。これは、Bitbucket Server インストールにアクセスするために、web ブラウザで「http://」(ポート番号なし) に続けて入力する名前です。 - When asked for the password for '
tomcat
' (the alias you entered in the keytool command above), press the 'Enter' key. This specifies that your keystore entry will have the same password as your private key. If needed, you can specify different key password.
Configure HTTPS in bitbucket.properties
Bitbucket Server の既定接続は、保護されていない HTTP 接続を使用します。必要なアクセスのタイプに応じ、自身のインスタンスに HTTPS のアクセスのみを許可するように Bitbucket の既定コネクタを変更 (またはコネクタを追加) する必要があります。
- HTTPS アクセスのみを許可するよう構成するには、HTTPS のみのアクセスを要求するように既定コネクタを置き換える必要があります。
- HTTP リクエストを安全な HTTPS 接続にリダイレクトするには、追加の安全なコネクタにリダイレクトするよう既定のコネクタを構成します。
There are a number of ways to configure secure connections depending on your requirements. These instructions describe how to replace Bitbucket's default connector with a secure, HTTPS-only connection by adding configuration properties to the bitbucket.properties
file.
Bitbucket Server を HTTPS アクセスのみを許可するように構成する方法
Bitbucket Server ホーム ディレクトリに移動します。
Open the
shared/bitbucket.properties
file and add these properties:server.port=8443 server.ssl.enabled=true server.ssl.key-store=/path/to/keystore/bitbucket.jks server.ssl.key-store-password=<password value> server.ssl.key-password=<password value>
これらのプロパティについて...By adding these properties to your
bitbucket.properties
file you override the default connector values.プロパティ 動作 server.port=8443
ポート 8443 で SSL アクセスを有効化します (HTTPS の初期設定は 443 ですが、競合を避けるために 443 の代わりに 8443 が使用されます) server.scheme=https
要求された URL スキームを指定します server.ssl.enabled=true
Specifies whether SSL enabled (true) or not (false). Setting this to true
automatically defaultsserver.scheme=https
andserver.secure=true
; they do not need to be set explicitly.server.ssl.client-auth=need
Specifies whether client authentication is wanted (" want
") or needed ("need
"). Requires a trust store.server.ssl.protocol=TLSv1.2
We recommend requiring TLS 1.2. If you have clients that don't support TLS 1.2, don't include this property. The default is "TLS
".server.ssl.key-alias=<alias>
SSH キーの値を指定します。既定ではないエイリアスを指定した場合にのみ必要です (既定値は "tomcat")。 server.ssl.key-store=/path/to/keystore/bitbucket.jks
ファイルシステム上のどこにキーストアがあるかを指定します。既定以外の場所 (<Bitbucket Server ホーム ディレクトリ>/shared/config/ssl-keystore 以外) でキーストアを作成した場合にのみ必要です。
Windows の場合...Windows の場合、パスではスラッシュを使用します。例:
server.ssl.key-store=c:/Atlassian/ApplicationData/Bitbucket/bitbucket.jks
バックスラッシュを使用する場合、2 回連続して使用する必要があります (例: "C:\\Atlassian\\...")
server.ssl.key-store-password=<password value>
Specifies your keystore password. Only required if your keystore password is anything other than the default (" changeit
").server.ssl.key-password=<password value>
Specifies your key password. Only required if your key password is anything other than the default (" changeit
").server.ssl.key-store-type=jks
キーストア タイプを指定します。キーストアでが既定 ("jks") 以外を使用している場合にのみ必要です。CA が提供する証明書の場合は "pkcs12" などにすることができます。 If you created the keystore somewhere else on the filesystem, add the
keystoreFile
attribute to the connector tag as well. If your keystore password is anything other than "changeit
", addkeystorePass="<password value>"
to thebitbucket.properties
file.
ファイルを保存します。
Bitbucket Server を起動 (または再起動) します。「Bitbucket Server の開始および終了」をご参照ください。
Access Bitbucket Server at
https://localhost:8443/
in your browser.
自己署名証明書のエクスポート
キーストアから証明書をエクスポートする必要がある場合 (別のキーストアにインポートできるようにする場合など)、次のコマンドを使用します。
自己署名証明書をエクスポートするコマンド
Windows | "%JAVA_HOME%\bin\keytool" -export -alias tomcat -file file.cer -keystore <Bitbucket Server home directory>\shared\config\ssl-keystore |
---|---|
Linux、macOS | $JAVA_HOME/bin/keytool -export -alias tomcat -file file.cer -keystore <Bitbucket Server home directory>/shared/config/ssl-keystore |
CA 証明書のリクエスト
デジタル証明書は認証局 (CA) によって、Web サイトが会社を表していることを証明するために発行されます。本番環境で Bitbucket Server を実行する場合、VeriSign、DigiCert またはr Thawte などの CA が発行した証明書が必要となります。以下の手順は Tomcat のドキュメントのものです。
まず、ローカル証明書を作成し、その証明書に基づいて証明書署名依頼 (CSR) を作成します。次に、選択した認証局に CSR を登録します。CA はその CSR を使用して証明書を生成します。
- Use Java's
keytool
utility to generate a local self-signed certificate, as described in the section above. Use the
keytool
utility to generate a CSR. If needed, replace the keystore file name with the path to and filename of the.keystore
file you generated for your local certificate:Windows "%JAVA_HOME%\bin\keytool" -certreq -keyalg RSA -alias tomcat -file certreq.csr -keystore <Bitbucket home>\shared\config\ssl-keystore
Linux、macOS $JAVA_HOME/bin/keytool -certreq -keyalg RSA -alias tomcat -file certreq.csr -keystore <Bitbucket home>/shared/config/ssl-keystore
- Submit the generated file called
certreq.csr
to your chosen certificate authority. Refer to the documentation on the CA's website to find out how to do this. - CA が証明書を送信します。
Import the new certificate into your local keystore. Assuming your certificate is called
file.cer,
run this command to add the certificate to the keystore:Windows "%JAVA_HOME%\bin\keytool" -import -alias tomcat -file file.cer -keystore <Bitbucket home>\shared\config\ssl-keystore
Linux、macOS $JAVA_HOME/bin/keytool -import -alias tomcat -file file.cer -keystore <Bitbucket home>/shared/config/ssl-keystore
トラブルシューティング
前述の説明に従って keytool で作成した自己署名証明書、または CA 証明書を使用する場合の、トラブルシューティングのヒントをいくつか紹介します。
When you enter "https://localhost:8443/" in your browser, if you get a message such as "Cannot establish a connection to the server at localhost:8443," look for error messages in your <Bitbucket home>/shared/logs/atlassian-bitbucket.log
file. Here are some possible errors with explanations.
SSL + Apache + IE の問題
Internet Explorer を使用して SSL 経由で添付ファイルをアップロードした場合にエラーが発生する問題が報告されています。これは IE のバグが原因で、Apache で次の設定を行うことで解決できます。
BrowserMatch ".MSIE." \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
Google 検索を行うとこれに関する多くの情報が得られます。
キーストアが見つからない
java.io.FileNotFoundException: /var/atlassian/application-data/bitbucket/shared/config/ssl-keystore (No such file or directory)
This indicates that Tomcat cannot find the keystore. By default Bitbucket server expects keystore to be available in the file <Bitbucket Server home directory>/shared/config/ssl-keystore. If you use non-default location, you will need to specify where the keystore file is in <Bitbucket Server home directory>/shared/bitbucket.properties
. Add the following attribute to the connector tag you uncommented:
server.ssl.key-store=${bitbucket.shared.home}/config/ssl-keystore
また、キーストア ファイルの読み取り権限を持つユーザーとして Bitbucket Server を実行していることを確認します。
パスワードが間違っている、またはパスワードが一致しない
java.io.IOException: Keystore was tampered with, or password was incorrect
You likely used a different password for your keystore file than the default, which is "changeit
", or specified incorrect key password in the bitbucket.properties file.
java.io.IOException: Cannot recover key
changeit
", or specified incorrect key password in the bitbucket.properties file.To check if either of these problems is the case, locate the <Bitbucket Server home directory>/shared/bitbucket.properties
file, and verify these two properties have matching values.
server.ssl.key-store-password=<password value>
server.ssl.key-password=<password value>
不正な証明書
javax.net.ssl.SSLException: No available certificate corresponds to the SSL cipher suites which are enabled.
既定では、keytool は DSA のパブリック キーを使用する証明書を作成します。証明書を生成する際には、-keyalg RSA オプション を使用するようにします。
If the Keystore has more than one certificate, Tomcat will use the "tomcat" certificate unless otherwise specified in the <Bitbucket home directory>/shared/bitbucket.properties
file.
Verify this attribute is set in the bitbucket.properties
file.
server.ssl.key-alias=tomcat
Apache Portable Runtime (APR) の使用
現時点では、Bitbucket サーバーは APR をサポートしていません。
クライアント認証の有効化
To enable client authentication in Tomcat, ensure that the value of the server.ssl.client-auth
attribute in your bitbucket.properties
file is set to "need
".
server.ssl.client-auth=need
不正な証明書タイプ
If the certificate from the CA is in PKSC12 format, add the server.ssl.key-store-type
attribute in your bitbucket.properties
file with the "PKCS12"
value.
server.ssl.key-store=${bitbucket.shared.home}/config/ssl-keystore
server.ssl.key-store-password=changeit
server.ssl.key-store-type=pkcs12
次のコマンドを使用して、pkcs12 証明書を既定の JCS キーストアにインポートすることもできます。
keytool -importkeystore -srckeystore <Bitbucket server home>/shared/config/certificate.pfx -srcstoretype pkcs12 -srcstorepass exportpass -srcalias <Source keystore alias> -destkeystore <Bitbucket server home>/shared/config/ssl-keystore -deststoretype jks -deststorepass changeit -destalias tomcat
証明書チェーンが不完全
キーストアでエンティティ / ドメイン証明書よりも手前にルート証明書と中間証明書がインポートされていない場合、次のエラーが表示されます。
[root@dev atlas]# $JAVA_HOME/bin/keytool -import -alias tomcat -file my_entity_cert.crt
Enter keystore password:
keytool error: java.lang.Exception: Failed to establish chain from reply
ほとんどの場合、CA は複数の証明書を含む圧縮ファイルを送信します。インポート順序が重要になるため、最初にルート証明書、次に中間証明書 (1 つまたは複数)、最後にエンティティ / ドメイン証明書の順でインポートする必要があります。keytool を使用した Tomcat (Java ベース) Web サーバーでの証明書のインストール向けのガイダンスを提供する多数のオンライン リソースがあります。
関連コンテンツ
- 関連コンテンツがありません