Skip to content

[JENKINS-73427] With 'Accept first connection' host key verification, and JGit, newly added known_hosts entries are malformed #1686

@jenkins-infra-bot

Description

@jenkins-infra-bot

I had noticed a lot of errors in our logs surrounding bad known_hosts entries. After some investigation, I was able to reproduce the errors with a minimal example.

  • Start with the jenkins 2.466 container image, and install just the suggested plugins.
  • Change Host Key Verification Configuration to 'Accept First Connection'
  • Under tools, change the git installation to JGit
  • Create a small pipeline, I used:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        git(url: 'git@​github.com:jglick/simple-maven-project-with-tests.git')
      }
    }
  }
} 
  • Run once, this example will fail because I'm not using credentials, but simply attempting to connect was enough to populate the known_hosts file.
  • Check the known hosts, for me it had one entry
|1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= 

Noticing the first part has |1||,|1|| ecdsa-sha2-nistp256

  • On a second run, it will cause an error because it can't read the entry, and since it can't find an entry that matches, it creates another invalid entry.

It doesn't seem to have a great impact, however it does start to fill up the known_hosts file, and as it grows, the errors in the log grow as well since there is an error for each entry it fails to read:

Known hosts file /var/jenkins_home/.ssh/known_hosts contains invalid line |1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
java.lang.IllegalArgumentException: Invalid hash pattern (insufficient data): |1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= 

Originally reported by mbrunton27, imported from: With 'Accept first connection' host key verification, and JGit, newly added known_hosts entries are malformed
  • assignee: markewaite
  • status: Open
  • priority: Minor
  • component(s): git-client-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 2
  • imported: 20251211-071809
Raw content of original issue

I had noticed a lot of errors in our logs surrounding bad known_hosts entries. After some investigation, I was able to reproduce the errors with a minimal example.

  • Start with the jenkins 2.466 container image, and install just the suggested plugins.
  • Change Host Key Verification Configuration to 'Accept First Connection'
  • Under tools, change the git installation to JGit
  • Create a small pipeline, I used:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        git(url: '[email protected]:jglick/simple-maven-project-with-tests.git')
      }
    }
  }
} 
  • Run once, this example will fail because I'm not using credentials, but simply attempting to connect was enough to populate the known_hosts file.
  • Check the known hosts, for me it had one entry
|1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= 

Noticing the first part has |1|<blah>|<blah>,|1|<blah>|<blah> ecdsa-sha2-nistp256

  • On a second run, it will cause an error because it can't read the entry, and since it can't find an entry that matches, it creates another invalid entry.

It doesn't seem to have a great impact, however it does start to fill up the known_hosts file, and as it grows, the errors in the log grow as well since there is an error for each entry it fails to read:

Known hosts file /var/jenkins_home/.ssh/known_hosts contains invalid line |1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
java.lang.IllegalArgumentException: Invalid hash pattern (insufficient data): |1|vHQTSjzHfpTcSNCbqMC6wEt7Mdc=|DtAq017Mv0pQZgijf9OBKbFiXV0=,|1|Y3N48nfiSHdw0U8ks35rVAUT7EM=|x9574xf5oQLevrHV4yulGkk9LOQ= 
  • environment: Docker image jenkins/jenkins:2.466 with suggested plugins installed. Git client plugin version 5.0.0

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions