Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-21167

OpenSSH keys are not supported when creating Bitbucket Server repositories in RSS mode

    XMLWordPrintable

Details

    Description

      Issue Summary

      Creating a Bitbucket Server repository in RSS mode using OpenSSH keys doesn't work. Bamboo throws the following error message:

      Specs logs
      26-Nov-2020 14:08:16	com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16	java.lang.IllegalArgumentException: com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$validateAndCreateRepositoryObjects$21(PlanConfigImportServiceImpl.java:1259)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:129)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.validateAndCreateRepositoryObjects(PlanConfigImportServiceImpl.java:1235)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$modifyTopLevelPlanFunction$2(PlanConfigImportServiceImpl.java:560)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.core.ScopedExclusionServiceImpl.tryWithLock(ScopedExclusionServiceImpl.java:74)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.modifyExistingTopLevelPlan(PlanConfigImportServiceImpl.java:461)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$importPlan$0(PlanConfigImportServiceImpl.java:426)
      26-Nov-2020 14:08:16		at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.persistence.BambooTransactionHibernateTemplate.execute(BambooTransactionHibernateTemplate.java:28)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.importPlan(PlanConfigImportServiceImpl.java:405)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.DefaultSpecsConsumer.importPlanProperties(DefaultSpecsConsumer.java:120)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.importers.PlanImporterProvider.lambda$getEntityProvider$1(PlanImporterProvider.java:38)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsWithImporter(AllTypesSpecsImporter.java:88)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsOfAllTypes(AllTypesSpecsImporter.java:52)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.lambda$processSpecs$2(JavaSpecsImportServiceImpl.java:77)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.SpecsOptimizeProcessor.processSpecs(SpecsOptimizeProcessor.java:42)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.processSpecs(JavaSpecsImportServiceImpl.java:63)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.RepositoryStoredSpecsServiceImpl.runBambooSpecs(RepositoryStoredSpecsServiceImpl.java:175)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.RssDetectionServiceImpl.runRssDetection(RssDetectionServiceImpl.java:330)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.detection.RssDetectionRunnable.run(RssDetectionRunnable.java:42)
      26-Nov-2020 14:08:16		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      26-Nov-2020 14:08:16		at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      26-Nov-2020 14:08:16		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      26-Nov-2020 14:08:16		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41)
      26-Nov-2020 14:08:16		at java.lang.Thread.run(Thread.java:748)
      26-Nov-2020 14:08:16	Caused by: com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.validateOrGenerateSshKeys(BitbucketServerExporter.java:325)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:290)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:71)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.exporters.RepositoryExporterImpl.importRepository(RepositoryExporterImpl.java:275)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$validateAndCreateRepositoryObjects$21(PlanConfigImportServiceImpl.java:1241)
      26-Nov-2020 14:08:16		... 28 more
      

      Steps to Reproduce

      1. Create an application link to Bitbucket Server if you haven't one already.
      2. Create/ add a Bitbucket Server repository to your plan using Java Specs:
        Java Specs
        .planRepositories(new BitbucketServerRepository()
                                .name("myRepository")
                                .repositoryViewer(new BitbucketServerRepositoryViewer())
                                .server(new ApplicationLink()
                                        .name("<applicationName>"))
                                .projectKey("<projectKey>")
                                .repositorySlug("<repositorySlug>")
                                .sshPublicKey("<sshPublicKey>")
                                .sshPrivateKey("<sshPrivateKey>")
                                .sshCloneUrl("<sshCloneUrl>")
                                .branch("master"))
        
        Example
        .planRepositories(new BitbucketServerRepository()
                                .name("BbS")
                                .repositoryViewer(new BitbucketServerRepositoryViewer())
                                .server(new ApplicationLink()
                                        .name("Bitbucket 7.6.0")
                                        .id("1dc14b2e-02aa-38c3-89f4-a2d782eb18dc"))
                                .projectKey("SPECS")
                                .repositorySlug("godzilla")
                                .sshPublicKey("ssh-rsa AAAAB3N...")
                                .sshPrivateKey("BAMSCRT@0@0@2e8329V...")
                                .sshCloneUrl("ssh://git@bitbucket760:7999/specs/godzilla.git")
                                .branch("master"))
        
      3. Create an SSH key pair using the following commands (the authentication is supposed to work whether you choose a password or not):
        ssh-keygen -t rsa -C "your_email@example.com"
        

        According to man ssh-keygen when the -m option is not used OpenSSH will write newly-generated private keys in its own format.

      4. Copy the public key to your Java Specs code.
      5. Take the private key and access Bamboo to encrypt it using the following steps:
      6. Use the encrypted private key in your Java Specs code.
      7. Go to Bitbucket Server and add the public key to the repository you're trying to add to your plan in the Java Specs code.
        • Taking the example above I should be adding my public key to the repository named godzilla.
      8. Push the changes made to your Java Specs code to your repository.
      9. Access the Bamboo admin > Linked repositories page and find your repository.
      10. Go to the Specs status tab.
      11. Try to Scan your repository.

      Expected Results

      Bamboo will add a repository to your plan managed via Java Specs and you'll see a "Specs execution successful" message.

      Actual Results

      The scan process fails with "Error in Bamboo Specs" and the below exception is thrown in the Specs logs:

      Specs logs
      26-Nov-2020 14:08:16	com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16	java.lang.IllegalArgumentException: com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$validateAndCreateRepositoryObjects$21(PlanConfigImportServiceImpl.java:1259)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:129)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.validateAndCreateRepositoryObjects(PlanConfigImportServiceImpl.java:1235)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$modifyTopLevelPlanFunction$2(PlanConfigImportServiceImpl.java:560)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.core.ScopedExclusionServiceImpl.tryWithLock(ScopedExclusionServiceImpl.java:74)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.modifyExistingTopLevelPlan(PlanConfigImportServiceImpl.java:461)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$importPlan$0(PlanConfigImportServiceImpl.java:426)
      26-Nov-2020 14:08:16		at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.persistence.BambooTransactionHibernateTemplate.execute(BambooTransactionHibernateTemplate.java:28)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.importPlan(PlanConfigImportServiceImpl.java:405)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.DefaultSpecsConsumer.importPlanProperties(DefaultSpecsConsumer.java:120)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.importers.PlanImporterProvider.lambda$getEntityProvider$1(PlanImporterProvider.java:38)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsWithImporter(AllTypesSpecsImporter.java:88)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.AllTypesSpecsImporter.importBambooYamlsOfAllTypes(AllTypesSpecsImporter.java:52)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.lambda$processSpecs$2(JavaSpecsImportServiceImpl.java:77)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.SpecsOptimizeProcessor.processSpecs(SpecsOptimizeProcessor.java:42)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.rss.JavaSpecsImportServiceImpl.processSpecs(JavaSpecsImportServiceImpl.java:63)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.RepositoryStoredSpecsServiceImpl.runBambooSpecs(RepositoryStoredSpecsServiceImpl.java:175)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.RssDetectionServiceImpl.runRssDetection(RssDetectionServiceImpl.java:330)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.detection.RssDetectionRunnable.run(RssDetectionRunnable.java:42)
      26-Nov-2020 14:08:16		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      26-Nov-2020 14:08:16		at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      26-Nov-2020 14:08:16		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      26-Nov-2020 14:08:16		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41)
      26-Nov-2020 14:08:16		at java.lang.Thread.run(Thread.java:748)
      26-Nov-2020 14:08:16	Caused by: com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException: Clone url or ssh key pair is not valid
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.validateOrGenerateSshKeys(BitbucketServerExporter.java:325)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:290)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.plugins.stash.v2.exporter.BitbucketServerExporter.importLocationData(BitbucketServerExporter.java:71)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.exporters.RepositoryExporterImpl.importRepository(RepositoryExporterImpl.java:275)
      26-Nov-2020 14:08:16		at com.atlassian.bamboo.configuration.external.PlanConfigImportServiceImpl.lambda$validateAndCreateRepositoryObjects$21(PlanConfigImportServiceImpl.java:1241)
      26-Nov-2020 14:08:16		... 28 more
      

      Workaround

      Check the content of your private key:

      -----BEGIN OPENSSH PRIVATE KEY-----
      

      If it starts with the message above you'll need to convert it to RSA format following these instructions:

      1. Backup your private key.
      2. Run the following command to convert the key:
        ssh-keygen -p -N "" -m pem -f /path/to/private/key
        
      3. Check the content again and you should now see the following line:
        -----BEGIN RSA PRIVATE KEY-----
        

      Attachments

        Issue Links

          Activity

            People

              mgardias Marcin Gardias
              brosa Bruno Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: