Secure Bitbucket with Tomcat using SSL

このページの内容

お困りですか?

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

コミュニティに質問

This page describes how to enable HTTPS (HTTP over SSL) access for Apache Tomcat, the application server shipped with Bitbucket Data Center and Server.

Why should I secure Bitbucket using SSL?

You should consider doing this, and making secure access mandatory, if Bitbucket will be internet-facing, which could potentially put usernames, passwords and other proprietary data at risk.

There are other network topology options for running Bitbucket, including running Bitbucket behind a reverse proxy. For an overview of some common options, see Proxy and secure Bitbucket.

When Bitbucket is set up using these instructions, access to Bitbucket is direct, and all communication between a user's browser and Bitbucket will be secured using SSL.

はじめる前に

ここで記載している構成を使用すると、次のようになります。

  • Bitbucket would listen for requests on port 8443; the port can be changed, if required.
  • Bitbucket would be available at https://<computer name>:8443; the base URL can be changed, if required.
  • As a result, any existing links with other applications would need to be reconfigured using this new URL for Bitbucket.
  • You can set the context path for Bitbucket if you are running another Atlassian application, or Java web application, at the same hostname and context path as Bitbucket.
  • Securing Git operations between the user's computer and Bitbucket is a separate consideration - see Enabling SSH access to Git.


これらの手順は参考として提供されます

アトラシアン アプリケーションでは製品内の SSL の使用が許可されます。ただし、アトラシアンのサポートはその設定に対する支援は行いません。したがって、アトラシアンではこのためのサポートの提供を保証できません

証明書の変換で支援が必要な場合、証明書の提供元のベンダーにご相談ください。アトラシアン サポートは、SSL 関連のサポート依頼は証明書の発行機関に転送します。

Also, these instructions are intended for administrators setting up Bitbucket for a small team. 

自己署名証明書の生成

暗号化が必要だが web サイトのリクエストの身元を確認する必要がない場合、自己署名証明書が役立ちます。一般的に、自己署名証明書はテスト環境や社内ネットワーク(イントラネット)で使用します。

証明書が認証局 (CA) によって署名されていないため、ユーザーはサイトが信頼されていない旨のメッセージを受け取り、証明書を承認する複数のステップをサイトにアクセスする前に実行する必要があります。これは通常、サイトに初めてアクセスする際に発生します。

ここで紹介している証明書の作成手順では Java の keytool を使用します。証明書を生成するツールはほかにも提供されています。

If you are setting up a production instance of Bitbucket, we strongly recommend using a CA certificate (described below), rather than using a self-signed certificate.

To generate a self-signed certificate using Java's keytool utility

  1. Create a new .keystore file in the Bitbucket home directory.

    1. Log in with the user account that has access to Bitbucket home directory (or use sudo alternatively).

    2. 次のコマンドを実行します。

      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 home directory>/shared/config/ssl-keystore. You can specify different keystore location using the keystore parameter. But, in this case, you will have to include it in the bitbucket.properties file as described in the configuration section.

  2. パスワードを要求された場合 (設定する 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.
    • 次のステップで必要になるので、パスワードを記録しておきます。

  3. Follow the prompts to specify your name, organization and location. This information is used to construct the X.500 Distinguished Name (DN) of the entity.

    The CN ("What is your first and last name?") must match the fully-qualified hostname of the server running Bitbucket, otherwise Tomcat will not be able to use the certificate for SSL. This is the name you would type in your web browser after 'http://' (no port number) to access your Bitbucket installation.

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

The default connection for Bitbucket uses an unsecured HTTP connection. Depending on the type of access you require, you can change Bitbucket's default connector (or add additional connectors) to require HTTPS-only access to your instance.

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


To configure HTTPS-only access to Bitbucket

  1. Navigate to your home directory.

    1. 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 defaults server.scheme=https and server.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

      Specifies where the keystore is on your filesystem. Only required if you created the keystore in non-default location (other than <Bitbucket home directory>/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", add keystorePass="<password value>" to the bitbucket.properties file.

  2. ファイルを保存します。

  3. Start (or re-start) Bitbucket.

  4. Access Bitbucket at https://localhost:8443/ in your browser.

自己署名証明書のエクスポート

キーストアから証明書をエクスポートする必要がある場合 (別のキーストアにインポートできるようにする場合など)、次のコマンドを使用します。

自己署名証明書をエクスポートするコマンド

Windows
"%JAVA_HOME%\bin\keytool" -export -alias tomcat -file file.cer -keystore <Bitbucket home directory>\shared\config\ssl-keystore
Linux、macOS
$JAVA_HOME/bin/keytool -export -alias tomcat -file file.cer -keystore <Bitbucket home directory>/shared/config/ssl-keystore


CA 証明書のリクエスト

Digital certificates are issued by a Certification Authority (CA) to verify your website represents your company. When running Bitbucket in a production environment, you need a certificate issued by a CA, such as VeriSignDigiCert or Thawte. The instructions below are adapted from the Tomcat documentation.

まず、ローカル証明書を作成し、その証明書に基づいて証明書署名依頼 (CSR) を作成します。次に、選択した認証局に CSR を登録します。CA はその CSR を使用して証明書を生成します。

  1. Use Java's keytool utility to generate a local self-signed certificate, as described in the section above.

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

  4. CA が証明書を送信します。

  5. 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 expects keystore to be available in the file <Bitbucket home directory>/shared/config/ssl-keystore. If you use non-default location, you will need to specify where the keystore file is in <Bitbucket 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

Additionally, please, make sure you are running Bitbucket as the user who has permission to read the keystore file. 

パスワードが間違っている、またはパスワードが一致しない

 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
You likely used a different password for your key than the default, which is "changeit", or specified incorrect key password in the bitbucket.properties file.

To check if either of these problems is the case, locate the <Bitbucket 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

Bitbucket does not support APR at the moment.

クライアント認証の有効化

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 home>/shared/config/certificate.pfx -srcstoretype pkcs12 -srcstorepass exportpass -srcalias <Source keystore alias> -destkeystore <Bitbucket 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 サーバーでの証明書のインストール向けのガイダンスを提供する多数のオンライン リソースがあります。

最終更新日: 2022 年 10 月 4 日

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

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