Test button in Search server for Bitbucket server results in the access denied

お困りですか?

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

コミュニティに質問

プラットフォームについて: Server、Data Center、および Cloud (状況に応じる) - この記事はアトラシアンのサーバーおよびデータセンター プラットフォーム向けに記載されていますが、Atlassian Cloud のお客様も記事の内容を利用できる可能性があります。この記事で説明されている手順の実施が役立つと考えられる場合、アトラシアン サポートにお問い合わせのうえ、この記事を紹介してください。

For Bitbucket 7.20 and below, Elasticsearch was bundled. Starting with 7.21, OpenSearch is the bundled search server

問題

The information that is in the Search section of the Admin cog Icon >> Server Settings page when sent after pressing the "Test" button results in the "Access denied" when using the Embedded Search server.

原因

The password expected by the Search server is out of sync with the one that Bitbucket Server is using to authenticate.

ソリューション

We need to reset the password on the Search server.

For Elasticsearch

Updating the credentials on the buckler.yml and restarting the Elasticsearch service should fix this issue.

  • Shutdown Elasticsearch and Bitbucket Server

    # service atlbitbucket stop
  • Edit the buckler.yml file. Back it up first

    # vi /var/atlassian/application-data/bitbucket/shared/search/buckler/buckler.yml
  • Right after the text "auth.basic.password:" remove the current default password and replace with any password of your choice.
  • Next, start up Bitbucket Server and ensure first that you're able to access http://localhost:7992 on the browser. You could also perform an initial test and entering the credentials on the pop-up dialog with the updated credentials to see if you're able to login.

    # service atlbitbucket start
  • If you're able to login, attempt to test with the same credentials from the Bitbucket Server Administration area

For Opensearch

Linux の場合

Step 1: Create a new password hash

Passwords are stored in a hash format in a file named internal_users.yml file. As the name suggests this file stores user credentials including the admin user. Therefore, the first step is to create the hash. Opensearch provides a script to create a password hash.

  1. Run the below shell script for Linux:
% cd /opt/atlassian/bitbucket/7.21.0/opensearch/plugins/opensearch-security/tools/
tools % sh +x hash.sh
[Password:]
$2y$12$xJFIfgehXFcZ3Rn6iOwW3O8ckusMTv9iTDXxJmWD3FZUVSynB5quy

You will be prompted to enter a password and outputs its hash. You can use bitbucket-changeit for example. Copy the output as we are going to store it in internal_users.yml

Here /opt/atlassian/bitbucket/7.21.0 is our installation directory for Bitbucket 7.21.0.

Step 2: Update internal_users.yml
  1. Open the internal_users.yml file in <Bitbucket-installation-directory>/opensearch/plugins/opensearch-security/securityconfig:
vi /opt/atlassian/bitbucket/7.21.0/opensearch/plugins/opensearch-security/securityconfig/internal_users.yml

      2. Find the “admin” user section and update the hash value with what you got in the previous step:

admin:
hash: "$2y$12$xJFIfgehXFcZ3Rn6iOwW3O8ckusMTv9iTDXxJmWD3FZUVSynB5quy"
reserved: true
backend_roles:
- "admin"
description: "Demo admin user"
Step 3: Apply security changes

Run the below command with your custom paths for Bitbucket home and installation directory. 

  1. In the below command, the Bitbucket home path is /var/atlassian/application-data/bitbucket and the Bitbucket installation directory path is /opt/atlassian/bitbucket/7.21.0.
/opt/atlassian/bitbucket/7.21.0/opensearch/plugins/opensearch-security/tools/securityadmin.sh --port 7993 \
-f ../securityconfig/internal_users.yml \
-t internalusers \
-icl \
-nhnv \
-cacert /var/atlassian/application-data/bitbucket/shared/search/config/root-ca.pem \
-cert /var/atlassian/application-data/bitbucket/shared/search/config/bitbucket.pem \
-key /var/atlassian/application-data/bitbucket/shared/search/config/bitbucket-key.pem

        2. This is the output you'll see if it is successful and you've supplied the correct paths:

Security Admin v7
WARNING: Seems you want connect to the OpenSearch HTTP port.
         securityadmin connects on the transport port which is normally 9300.
Will connect to localhost:7993 ... done
Connected as CN=BITBUCKET
OpenSearch Version: 1.2.4
OpenSearch Security Version: 1.2.4.0
Contacting opensearch cluster 'opensearch' and wait for YELLOW clusterstate ...
Clustername: bitbucket_search
Clusterstate: YELLOW
Number of nodes: 1
Number of data nodes: 1
.opendistro_security index already exists, so we do not need to create one.
Populate config from /opt/atlassian/bitbucket/7.21.0/opensearch/plugins/opensearch-security/tools
Force type: internalusers
Will update '_doc/internalusers' with ../securityconfig/internal_users.yml 
   SUCC: Configuration for 'internalusers' created or updated
Done with success

Lastly, attempt to test with the same credentials from the Bitbucket Server Administration area under Search

In case if this doesn't work, try the following steps. (This works only on Linux, for now)

  1. Shut down your bitbucket instance.
  2. Delete the all contents of this folder $BITBUCKET_HOME/shared/search
  3. Start up Bitbucket and wait for some time for the initial search index creation.
  4. After that, run Step 3: Apply security changes from above.
  5. Once it's successful, try to click on the Test button on Bitbucket UI → Administration → Server settings → Under search, with the password you had used in  Step 1: Create a new password hash. You can see that the test is successful and the password has been reset.

Windows の場合

Step 1: Create a new password hash

Passwords are stored in a hash format in a file named internal_users.yml file. As the name suggests this file stores user credentials including the admin user. Therefore, the first step is to create the hash. Opensearch provides a script to create a password hash.

  1. For Windows, you have to enter into the <Bitbucket-installation-directory>\opensearch\plugins\opensearch-security\tools> and run the hash.bat file
cd C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\tools>
C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\tools> .\hash.bat
[Password:]
$2y$12$zjrg.uQxhyOAbpZ1WPBCyeCjPB60K5k3U/p9PmxlllfI8vBgahhga

You will be prompted to enter a password and outputs its hash. You can use bitbucket-changeit for example. Copy the output as we are going to store it in internal_users.yml

Here C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0 is our installation directory for Bitbucket 7.21.0.

Step 2: Update internal_users.yml
  1. <Bitbucket-installation-directory>\opensearch\plugins\opensearch-security\securityconfig に移動します。
  2. Open the internal_users.yml file in a text editor
  3. Find the “admin” user section and update the hash value with what you got in the previous step:
_meta:
  type: "internalusers"
  config_version: 2

bitbucket:
  # Default "bitbucket-changeit" password which will be updated by automatic provisioning
  hash: "$2y$12$zjrg.uQxhyOAbpZ1WPBCyeCjPB60K5k3U/p9PmxlllfI8vBgahhga"
  backend_roles:
    - "admin"
  description: "Admin user"
Step 3: Apply security changes
  1. Run the below command with your custom paths for Bitbucket home and installation directory. In the below command, the home path is D:\bitbucket-home\ and the installation directory path is C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0.
  2. Open a Powershell Window or Command Prompt in the C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\tools and run the below command:
.\securityadmin.bat --port 7993 -f C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\securityconfig\internal_users.yml -t internalusers -icl -nhnv -cacert D:\bitbucket-home\shared\search\config\root-ca.pem -cert D:\bitbucket-home\shared\search\config\bitbucket.pem -key D:\bitbucket-home\shared\search\config\bitbucket-key.pem

       3. This is the output you will get:

Security Admin v7
WARNING: Seems you want connect to the OpenSearch HTTP port.
         securityadmin connects on the transport port which is normally 9300.
Will connect to localhost:7993 ... done
Connected as CN=BITBUCKET
OpenSearch Version: 1.2.4
OpenSearch Security Version: 1.2.4.0
Contacting opensearch cluster 'opensearch' and wait for YELLOW clusterstate ...
Clustername: bitbucket_search
Clusterstate: YELLOW
Number of nodes: 1
Number of data nodes: 1
.opendistro_security index already exists, so we do not need to create one.
Populate config from C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\tools
Force type: internalusers
Will update '_doc/internalusers' with C:\Atlassian\Bitbucket\atlassian-bitbucket-7.21.0\opensearch\plugins\opensearch-security\securityconfig\internal_users.yml
   SUCC: Configuration for 'internalusers' created or updated
Done with success

 Lastly, attempt to test with the same credentials from the Bitbucket Server Administration area under Search

最終更新日 2022 年 6 月 20 日

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

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