Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-20106

Invalid SSH Keys in Bitbucket Database Cause 500 Internal Error on SSH Keys Page

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • 8.19.0
    • SSH
    • None

      Issue Summary

      When the Bitbucket database contains an invalid SSH key, the SSH keys page for the user, project, or repository (whichever has the invalid SSH key) fails to load and results in a 500 Internal Error.

      There is UI validation in Bitbucket to block the submission of invalid SSH keys, but Bitbucket still reports some keys as corrupted. It is unclear when exactly this occurs.

      Steps to Reproduce

      1. We couldn't replicate the issue consistently, but it is reproducible by manually inserting an invalid SSH key into the Bitbucket database and then attempting to load the SSH key page.

      Expected Results

      SSH keys should load properly. If there are invalid SSH keys, an option to remove them manually should be provided.

      Actual Results

      The following exception is thrown in the atlassian-bitbucket.log file:

      2025-05-29 12:57:55,121 ERROR [http-nio-7990-exec-191 url: /mvc/error500; user: sam] *1AZHG51x777x17826238x9 17mjje9 10.24.102.247,10.160.60.8 "GET /mvc/error500 HTTP/1.1" c.a.s.i.web.ErrorPageController There was an unhandled exception loading [/plugins/servlet/ssh/account/keys]
      java.lang.reflect.UndeclaredThrowableException: null
      	at jdk.proxy16/jdk.proxy16.$Proxy2450.toPublicKey(Unknown Source)
      	at com.atlassian.bitbucket.internal.ssh.rest.RestSshKey.<init>(RestSshKey.java:40)
      	at com.google.common.collect.Iterators$6.transform(Iterators.java:829)
      	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)
      	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:278)
      	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:239)
      	at com.atlassian.bitbucket.rest.util.RestPage.<init>(RestPage.java:40)
      	at com.atlassian.bitbucket.rest.util.RestPage.<init>(RestPage.java:48)
      	at com.atlassian.bitbucket.rest.util.RestPage.<init>(RestPage.java:33)
      	at com.atlassian.bitbucket.internal.ssh.fragments.SshKeysContextProvider.createSshKeysContext(SshKeysContextProvider.java:208)
      	at com.atlassian.bitbucket.internal.ssh.fragments.SshKeysContextProvider.createKeyTableContext(SshKeysContextProvider.java:164)
      	at com.atlassian.bitbucket.internal.ssh.fragments.SshKeysContextProvider.createKeyTableContext(SshKeysContextProvider.java:83)
      	at com.atlassian.bitbucket.internal.ssh.servlet.ViewKeysRequestHandler.get(ViewKeysRequestHandler.java:53)
      .........
      	at com.atlassian.stash.internal.web.auth.BeforeLoginPluginAuthenticationFilter.doFilter(BeforeLoginPluginAuthenticationFilter.java:73)
      	at com.atlassian.stash.internal.request.DefaultRequestManager.doAsRequest(DefaultRequestManager.java:84)
      	at com.atlassian.stash.internal.hazelcast.ConfigurableWebFilter.doFilter(ConfigurableWebFilter.java:38)
      	at java.base/java.lang.Thread.run(Thread.java:840)
      	... 271 frames trimmed
      Caused by: java.lang.reflect.InvocationTargetException: null
      	at jdk.internal.reflect.GeneratedMethodAccessor879.invoke(Unknown Source)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at net.java.ao.EntityProxy.invoke(EntityProxy.java:107)
      	... 54 common frames omitted
      Caused by: java.lang.IllegalArgumentException: Failed to decode public key: AAAAB3NzaC1yc2EAAAABJQAAAIBebZQemWig5PYaH+jzScOkvP9iiabdmY9CBj9g
      4G8FWh2tuNz4BS8PVjHpofXjlBQaBzluu1G0mWmJYSb/dH4sPxo3Ma6QCEZbJKxj
      	at com.atlassian.bitbucket.internal.ssh.utils.KeyUtils.decodeKeyAndLabel(KeyUtils.java:195)
      	at com.atlassian.bitbucket.internal.ssh.utils.KeyUtils.getPublicKey(KeyUtils.java:156)
      	at com.atlassian.bitbucket.internal.key.ssh.dao.PartialSshKey.toPublicKey(PartialSshKey.java:43)
      	... 57 common frames omitted
      Caused by: java.lang.IllegalArgumentException: Unable to decode public key
      	at com.atlassian.bitbucket.internal.ssh.utils.KeyUtils.getPublicKey(KeyUtils.java:151)
      	at com.atlassian.bitbucket.internal.ssh.utils.KeyUtils.decodeKeyAndLabel(KeyUtils.java:192)
      	... 59 common frames omitted
      Caused by: java.io.EOFException: Premature EOF - expected=128, actual=76
      	at org.apache.sshd.common.util.io.IoUtils.readFully(IoUtils.java:498)
      	at org.apache.sshd.common.util.io.IoUtils.readFully(IoUtils.java:480)
      	at org.apache.sshd.common.config.keys.KeyEntryResolver.readRLEBytes(KeyEntryResolver.java:197)
      	at org.apache.sshd.common.config.keys.KeyEntryResolver.decodeBigInt(KeyEntryResolver.java:183)
      	at org.apache.sshd.common.config.keys.impl.RSAPublicKeyDecoder.decodePublicKey(RSAPublicKeyDecoder.java:73)
      	at org.apache.sshd.common.config.keys.impl.RSAPublicKeyDecoder.decodePublicKey(RSAPublicKeyDecoder.java:50)
      	at org.apache.sshd.common.config.keys.PublicKeyEntryDecoder.decodePublicKeyByType(PublicKeyEntryDecoder.java:76)
      	at org.apache.sshd.common.config.keys.PublicKeyRawDataDecoder.decodePublicKey(PublicKeyRawDataDecoder.java:62)
      	at org.apache.sshd.common.config.keys.PublicKeyRawDataDecoder.decodePublicKey(PublicKeyRawDataDecoder.java:51)
      	at com.atlassian.bitbucket.internal.ssh.utils.KeyUtils.getPublicKey(KeyUtils.java:149)
      	... 60 common frames omitted
      

      Workaround

      Use the DB queries mentioned in this KB article to find the SSH ID and remove them using the DELETE SSH API endpoint.

              cf36c85a7bd3 Charlie Wang
              5338c0aa34f9 Danny Samuel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: