-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Medium
-
Affects Version/s: 7.2.4, 8.1.3
-
Component/s: Bamboo Specs
-
None
-
2
-
Severity 3 - Minor
-
1
Issue Summary
Bamboo Specs scanning will fail if it contains repository creation and a user exists in Bamboo called SYSTEM as it gets a 401 response from Bitbucket:
Request to Stash failed. Returned with 401. Response body is empty.
This is reproducible on Data Center: yes
Steps to Reproduce
- Create a user in Bamboo called SYSTEM
- Rather simple Repository Stored Spec that has both a linked repository and a plan level repository E.g.
.linkedRepositories("stored-spec") .planRepositories(new BitbucketServerRepository() .name("test") .repositoryViewer(new BitbucketServerRepositoryViewer()) .server(new ApplicationLink() .name("Bitbucket") .id("2a8d2a22-fe36-3a83-805c-b8a28660f3e4")) .projectKey("MIR") .repositorySlug("git-hw") .sshPublicKey("...") .sshPrivateKey("...") .sshCloneUrl("ssh://git@bitbucket:7999/mir/git-hw.git") .sshKeyAppliesToSubmodules(true) .changeDetection(new VcsChangeDetection())) - Update local repository name and commit between reproduction attempts to ensure we trigger the path to create/update a repository
Expected Results
The Repository Stored Spec update succeeds.
Actual Results
The below exception is thrown in the atlassian-bamboo.log file:
2022-03-14 10:08:38,565 WARN [17-BAM::SpecsDetection:pool-25-thread-4] [AllTypesSpecsImporter] com.atlassian.stash.rest.client.api.StashUnauthorizedRestException: Request to Stash failed. Returned with 401. Response body is empty. at com.atlassian.stash.rest.client.core.StashClientImpl.createStashRestException(StashClientImpl.java:888) at com.atlassian.stash.rest.client.core.StashClientImpl.lambda$doRestCall$16(StashClientImpl.java:874) at com.atlassian.stash.rest.client.applinks.ApplinkHttpExecutor$StashApplinkResponseHandler.handle(ApplinkHttpExecutor.java:93) at com.atlassian.applinks.core.auth.ApplicationLinkAnalyticsRequest$ApplicationLinkAnalyticsResponseHandler.handle(ApplicationLinkAnalyticsRequest.java:244) at com.atlassian.applinks.oauth.auth.OAuthApplinksResponseHandler$1.handle(OAuthApplinksResponseHandler.java:122) at com.atlassian.applinks.oauth.auth.OAuthApplinksResponseHandler.handle(OAuthApplinksResponseHandler.java:78) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:61) at com.atlassian.applinks.oauth.auth.OAuthRequest.execute(OAuthRequest.java:58) at com.atlassian.applinks.core.auth.ApplicationLinkAnalyticsRequest.execute(ApplicationLinkAnalyticsRequest.java:56) at com.atlassian.stash.rest.client.applinks.ApplinkHttpExecutor.execute(ApplinkHttpExecutor.java:60) at com.atlassian.stash.rest.client.core.StashClientImpl.doRestCall(StashClientImpl.java:838) at com.atlassian.stash.rest.client.core.StashClientImpl.doRestCall(StashClientImpl.java:825) at com.atlassian.stash.rest.client.core.StashClientImpl.lambda$getRepository$8(StashClientImpl.java:199) at com.atlassian.stash.rest.client.core.StashClientImpl.expectingRestError(StashClientImpl.java:900) at com.atlassian.stash.rest.client.core.StashClientImpl.getRepository(StashClientImpl.java:195) at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:281) at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:84) at com.atlassian.bamboo.configuration.external.exporters.RepositoryExporterImpl.lambda$importRepository$4(RepositoryExporterImpl.java:315) at com.atlassian.bamboo.utils.BambooCallables.callUnchecked(BambooCallables.java:33) at com.atlassian.bamboo.plugin.BambooPluginUtils.callChangedApi(BambooPluginUtils.java:240) at com.atlassian.bamboo.configuration.external.exporters.RepositoryExporterImpl.importRepository(RepositoryExporterImpl.java:315) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$validateAndCreateRepositoryObjects$21(PlanConfigImportServiceImpl.java:1244) at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:129) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.validateAndCreateRepositoryObjects(PlanConfigImportServiceImpl.java:1237) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$modifyTopLevelPlanFunction$2(PlanConfigImportServiceImpl.java:551) at com.atlassian.bamboo.core.ScopedExclusionServiceImpl.tryWithLock(ScopedExclusionServiceImpl.java:74) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.modifyExistingTopLevelPlan(PlanConfigImportServiceImpl.java:453) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$importPlan$0(PlanConfigImportServiceImpl.java:418) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at com.atlassian.bamboo.persistence.BambooTransactionHibernateTemplate.execute(BambooTransactionHibernateTemplate.java:28) at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.importPlan(PlanConfigImportServiceImpl.java:397) at com.atlassian.bamboo.configuration.external.rss.DefaultSpecsConsumer.importPlanProperties(DefaultSpecsConsumer.java:135) at com.atlassian.bamboo.configuration.external.rss.importers.PlanImporterProvider.lambda$getEntityProvider$1(PlanImporterProvider.java:38) at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsWithImporter(AllTypesSpecsImporter.java:130) at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsOfAllTypes(AllTypesSpecsImporter.java:69) at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.lambda$processSpecs$2(JavaSpecsImportServiceImpl.java:80) at com.atlassian.bamboo.configuration.external.rss.SpecsOptimizeProcessor.processSpecs(SpecsOptimizeProcessor.java:43) at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.processSpecs(JavaSpecsImportServiceImpl.java:93) at com.atlassian.bamboo.configuration.external.RepositoryStoredSpecsServiceImpl.runBambooSpecs(RepositoryStoredSpecsServiceImpl.java:204) at com.atlassian.bamboo.configuration.external.RssDetectionServiceImpl.runRssDetection(RssDetectionServiceImpl.java:374) at com.atlassian.bamboo.configuration.external.detection.RssDetectionRunnable.run(RssDetectionRunnable.java:42) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48) at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26) at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17) at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41) at java.lang.Thread.run(Thread.java:748)
Workaround
Workaround 1
Remove the user called SYSTEM from Bamboo
Workaround 2
Create a user called SYSTEM in Bitbucket with administrative permissions.