"Access Denied" when testing connection to search server in Bitbucket Data Center
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
During the installation of Bitbucket, Bitbucket will hash a random password, which will be used between Bitbucket and bundled OpenSearch for authentication. This password will be stored in the Bitbucket database and OpenSearch security index.
Due to the nature of the provisioning, the password is unknown. If this goes out of sync between Bitbucket and bundled OpenSearch, we will need to set the password for bundled OpenSearch manually.
Environment
- Bitbucket 8 with bundled OpenSearch v1
- Bitbucket 9 with bundled OpenSearch v2
Diagnosis
- Navigate to Administration > Server Settings.
- Click on the Test button under the Search.
- The result would be "Access to the search server was denied. Check your settings.".
- During startup, Bitbucket application log;
$BITBUCKET_HOME/log/atlassian-bitbucket.log
, shows the following error messages:2025-03-04 03:14:16,621 INFO [Caesium-1-1] c.a.b.i.s.i.jobs.StartupChecksJob Running startup jobs for search 2025-03-04 03:14:17,793 ERROR [Caesium-1-1] c.a.b.i.s.i.IndexingSynchronizationService Failed to create indexes: ''[Unsuccessful search response: 401. Bitbucket did not have authorization to request data from the search server.]'' 2025-03-04 03:14:17,793 ERROR [Caesium-1-1] c.a.b.i.s.i.IndexingSynchronizationService Unable to synchronize the mapping in the search server 2025-03-04 03:14:17,794 WARN [Caesium-1-1] c.a.b.i.s.c.cluster.ClusterJobRunner Job execution failed. Rescheduling. Job key: com.atlassian.bitbucket.internal.search.indexing.jobs.StartupChecksJob Job id: c2ffe4a6-5d69-4e4e-8d6b-fda3afd54010 ...
- Bundled OpenSearch log;
$BITBUCKET_HOME/log/search/bitbucket_search.log
, show authentication warnings:[2025-03-04T03:14:17,384][WARN ][o.o.s.a.BackendRegistry ] [bitbucket_bundled] Authentication finally failed for bitbucket from 127.0.0.1:57880 [2025-03-04T03:14:17,774][WARN ][o.o.s.a.BackendRegistry ] [bitbucket_bundled] Authentication finally failed for bitbucket from 127.0.0.1:57880
Cause
The password expected by the Search server is out of sync with the one that Bitbucket uses to authenticate.
Solution
INFO
- Please make sure to have a backup of the
$BITBUCKET_HOME/shared/search
before proceeding. - Please replace the
$BITBUCKET_INSTALL
and$BITBUCKET_INSTALL
accordingly. - For Bitbucket 8 (bundled with OpenSearch v1), the path is
$BITBUCKET_INSTALL/opensearch/plugins/opensearch-security/securityconfig/internal_users.yml
$BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml
- Log in to the Bitbucket machine (SSH and any remote connection).
- Stop Bitbucket.
- Hash a new password by running the following command:
# /bin/bash +x $BITBUCKET_INSTALL/opensearch/plugins/opensearch-security/tools/hash.sh WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use /usr/bin/java [Password:] <qwerty> $2y$12$xLj36E5N.Sgpymk7Ut1FvOeZYh6n9fwr.zBUbHieTA7oK12QWFdNC
- Update the hash value in
$BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml
.# vi $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml # cat $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml _meta: type: "internalusers" config_version: 2 bitbucket: # Default "bitbucket-changeit" password which will be updated by automatic provisioning hash: "$2y$12$xLj36E5N.Sgpymk7Ut1FvOeZYh6n9fwr.zBUbHieTA7oK12QWFdNC" backend_roles: - "admin" description: "Admin user"
- Update
$BITBUCKET_HOME/shared/search/config/opensearch.yml
(Skip this step for Bitbucket 8).# vi $BITBUCKET_HOME/shared/search/config/opensearch.yml # cat $BITBUCKET_HOME/shared/search/config/opensearch.yml <existing content> plugins.security.ssl.http.enabled: true plugins.security.ssl.http.pemcert_filepath: bitbucket.pem plugins.security.ssl.http.pemkey_filepath: bitbucket-key.pem plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem plugins.security.allow_unsafe_democertificates: false
Start Bitbucket.
- Run
securityadmin.sh
.# /bin/bash +x $BITBUCKET_INSTALL/opensearch/plugins/opensearch-security/tools/securityadmin.sh --port 7992 \ -i .bitbucket_security_index_1 \ -f $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml \ -t internalusers \ -icl \ -nhnv \ -cacert $BITBUCKET_HOME/shared/search/config/root-ca.pem \ -cert $BITBUCKET_HOME/shared/search/config/bitbucket.pem \ -key $BITBUCKET_HOME/shared/search/config/bitbucket-key.pem WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use /usr/bin/java Security Admin v7 Will connect to localhost:7992 ... done Connected as "CN=BITBUCKET" OpenSearch Version: 2.18.0 Contacting opensearch cluster 'opensearch' and wait for YELLOW clusterstate ... Clustername: bitbucket_search Clusterstate: YELLOW Number of nodes: 1 Number of data nodes: 1 .bitbucket_security_index_1 index already exists, so we do not need to create one. Populate config from /root Force type: internalusers Will update '/internalusers' with $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml SUCC: Configuration for 'internalusers' created or updated SUCC: Expected 1 config types for node {"updated_config_types":["internalusers"],"updated_config_size":1,"message":null} is 1 (["internalusers"]) due to: null Done with success
For Bitbucket 8, please use
--port 7993
instead. - For Bitbucket 8, test and update the search password in the Server Settings page. For Bitbucket 9, please proceed to the next step.
- Stop Bitbucket.
- Revert the changes on the
$BITBUCKET_HOME/shared/search/config/opensearch.yml
. - Start Bitbucket.
- Test and update the search password in the Server Settings page.
Workaround (with data loss)
WARNING
- The following step involves deleting all the bundled OpenSearch dat,a which means you will lose all the index and search will be unavailable in Bitbucket while bundled OpenSearch is reindexing.
- There is no definitive estimation for the reindexing duration.
- Log in to the Bitbucket machine (SSH and any remote connection).
- Stop Bitbucket.
- Hash a new password by running the following command:
# /bin/bash +x $BITBUCKET_INSTALL/opensearch/plugins/opensearch-security/tools/hash.sh WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use /usr/bin/java [Password:] <qwerty> $2y$12$xLj36E5N.Sgpymk7Ut1FvOeZYh6n9fwr.zBUbHieTA7oK12QWFdNC
- Update the hash value in
$BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml
.# vi $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml # cat $BITBUCKET_HOME/shared/search/config/opensearch-security/internal_users.yml _meta: type: "internalusers" config_version: 2 bitbucket: # Default "bitbucket-changeit" password which will be updated by automatic provisioning hash: "$2y$12$xLj36E5N.Sgpymk7Ut1FvOeZYh6n9fwr.zBUbHieTA7oK12QWFdNC" backend_roles: - "admin" description: "Admin user"
- Delete all the contents of
$BITBUCKET_HOME/shared/search
.# rm -rf $BITBUCKET_HOME/shared/search
- Start Bitbucket.
- Test and update the search password in the Server Settings page.