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

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server, Data Center, and Cloud By Request - This article was written for the Atlassian server and data center platforms but may also be useful for Atlassian Cloud customers. If completing instructions in this article would help you, please contact Atlassian Support and mention it.

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

Problem

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.

Cause

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

Resolution

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

For 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

For 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. Go to <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

Last modified on Mar 30, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.