[go: up one dir, main page]

Page MenuHomePhabricator

Gerrit replication to codfw (gerrit-replica.wikimedia.org) stopped working after Gerrit 3.4.5 upgrade
Closed, ResolvedPublicBUG REPORT

Description

Diffusion mirrors of Gerrit repos not showing commits made since August 17

This is probably a known issue, but Diffusion doesn't seem to be showing changes made to the code since some time on August 17 - for core MediaWiki or any of the extensions or skins. You can see this for core MediaWiki here:

https://phabricator.wikimedia.org/source/mediawiki/history/master/

Is this an issue with Jenkins, maybe? Or maybe just a sign that Diffusion is on its way out?


Upstream issue https://bugs.chromium.org/p/gerrit/issues/detail?id=16215

The issue is due to Gerrit 3.4.4 to 3.4.5 upgrade (T315408). When trying to ssh on port 22 on the gerrit2002.wikimedia.org host (which serves gerrit-replica.wikimedia.org), the ssh connection can not be established:

Caused by: org.apache.sshd.common.SshException: KeyExchange signature verification failed for key type=ssh-rsa

Fix got to rollback to 3.4.4.

It is apparently a bug in Apache Mina SSH (which is upgrade from 2.6.0 to 2.7.0 by that Gerrit version). The Apache Mina SSH versions for Gerrit are:

$ git grep "SSHD_VERS =" v3.4.4 v3.4.5 v3.5.2 v3.6.1
v3.4.4:tools/nongoogle.bzl:    SSHD_VERS = "2.6.0"
v3.4.5:tools/nongoogle.bzl:    SSHD_VERS = "2.7.0"
v3.5.2:tools/nongoogle.bzl:    SSHD_VERS = "2.7.0"
v3.6.1:tools/nongoogle.bzl:    SSHD_VERS = "2.8.0"

It is apparently solved by 2.8.0 and thus Gerrit 3.6.

It might be possible to workaround the issue by regenerating the ssh key pair used for replication (and used by the gerrit2 user).

Event Timeline

bd808 subscribed.

My first thought was that T313250: Bring up gerrit2002 may have been involved in this, but it looks like that was completed prior to the mirror breaking.

The configured origin URL for the MediaWiki core mirror is https://gerrit-replica.wikimedia.org/r/mediawiki/core. That value has not changed since 2019-08-05. It is currently a 404 however (and the same on https://gerrit.wikimedia.org) which makes me wonder if there has been a Gerrit upgrade that changed the URL structure?

bd808 renamed this task from Diffusion not showing commits made since August 17 to Diffusion mirros of Gerrit repos not showing commits made since August 17.Aug 23 2022, 12:27 AM
bd808 renamed this task from Diffusion mirros of Gerrit repos not showing commits made since August 17 to Diffusion mirrors of Gerrit repos not showing commits made since August 17.

I cloned core from gerrit-replica and git log ends on August 17th.

Then I cloned core from gerrit and git log is already at August 23rd.

So what failed here is the sync between gerrit and gerrit-replica. They are at a different state.

I will look more at the reasons for this which will be related to rsync and UID and the fact that we want to use a correct new UID on newer phab hosts.

Meanwhile the origin URL could be changed from gerrit-replica to gerrit and it should work again.

Dzahn triaged this task as High priority.Aug 23 2022, 1:20 AM

gerrit replication between gerrit servers is broken due to:

Caused by: org.apache.sshd.common.SshException: KeyExchange signature verification failed for key type=ssh-rsa

It's possibly an upstream bug in mina, the ssh daemon used by Gerrit.

https://issues.apache.org/jira/browse/SSHD-1163

or another issue with the replication key

I double checked the key is in place, identical between gerrit1001 and gerrit2002.

Then I manually became user gerrit2 and connected with ssh from gerrit1001 to gerrit2002, adding the gerrit2002 to /var/lib/gerrit2/.ssh/known_hosts (!).

I just could not reload the replication config because remote plugin administration is disabled.

Also confirmed I can ssh between hosts with ssh -i id_rsa gerrit2002.wikimedia.org explicitly as the gerrit2 user and telling it to use the key in gerrit2's homedir.

Gerrit was upgraded on August 17th (T315408).

I will try adding the "sshd.enableDeprecatedKexAlgorithms = true" and restarting gerrit tomorrow morning unless someone beats me to it.

Mentioned in SAL (#wikimedia-operations) [2022-08-23T15:06:16Z] <mutante> gerrit - service restart - T315942 - added sshd.enableDeprecatedKexAlgorithms = true

Tried that, both the new host has been added to known_hosts and the above config option has been added which was made in reaction to the upstream bug.

Unfortunately the issue for us still persists.

I downloaded the Gerrit 3.4.5 .war file from the download site, unpacked it and could confirm the mina version:

 ./WEB-INF/lib/sshd-mina-2.7.0.jar
./WEB-INF/lib/mina-core-2.0.21.jar

This matches the upstream bug which says it affects 2.7.0.

So: https://issues.apache.org/jira/browse/SSHD-1163 and the fix is supposed to be https://github.com/apache/mina-sshd/pull/195 but we don't have that yet.

One user said:

//ssh client config like this, can connect to server
KexAlgorithms = ecdh-sha2-nistp256
HostKeyAlgorithms = rsa-sha2-256

Change 825845 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.4] Revert "Gerrit v3.4.5 and rebuild plugins"

https://gerrit.wikimedia.org/r/825845

Change 825845 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.4] Revert "Gerrit v3.4.5 and rebuild plugins"

https://gerrit.wikimedia.org/r/825845

Mentioned in SAL (#wikimedia-operations) [2022-08-23T17:39:13Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@e11e6a7]: Revert Gerrit from 3.4.5 to 3.4.4 # T315942

Mentioned in SAL (#wikimedia-operations) [2022-08-23T17:39:17Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@e11e6a7]: Revert Gerrit from 3.4.5 to 3.4.4 # T315942 (duration: 00m 04s)

Mentioned in SAL (#wikimedia-operations) [2022-08-23T17:39:47Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@cb7edfb]: Revert Gerrit from 3.4.5 to 3.4.4 # T315942

Mentioned in SAL (#wikimedia-operations) [2022-08-23T17:39:55Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@cb7edfb]: Revert Gerrit from 3.4.5 to 3.4.4 # T315942 (duration: 00m 08s)

replication works again after gerrit was reverted to 3.4.4

Replication to gerrit2@gerrit2002.wikimedia.org:/srv/gerrit/git/mediawiki/extensions/WikimediaEvents.git completed in 42579ms

hashar renamed this task from Diffusion mirrors of Gerrit repos not showing commits made since August 17 to Gerrit replication to codfw (gerrit-replica.wikimedia.org) stopped working after Gerrit 3.4.5 upgrade.Aug 23 2022, 5:55 PM
hashar updated the task description. (Show Details)

To summarize from my side again:

There is an upstream bug in mina sshd. It causes the exact error message we got. (KeyExchange signature verification failed for key type=ssh-rsa).

But it's an actual bug where it picks the wrong algo, it's not about the fact it's an RSA key.

https://issues.apache.org/jira/browse/SSHD-1163
https://issues.apache.org/jira/plugins/servlet/mobile#issue/SSHD-1163

The fix is supposed to be: but that has not landed in our version yet.

https://github.com/apache/mina-sshd/pull/195

The upstream bug says it affects *2.7.0* and our upgrade from Gerrit 3.4.4 to Gerrit 3.4.5 meant exactly this, that we upgraded mina from 2.6.0 to 2.7.0.

as confirmed by:

17:51 <+hashar> $ git grep "SSHD_VERS =" v3.4.4 v3.4.5 v3.5.2 v3.6.1
17:51 <+hashar> v3.4.4:tools/nongoogle.bzl:    SSHD_VERS = "2.6.0"
17:51 <+hashar> v3.4.5:tools/nongoogle.bzl:    SSHD_VERS = "2.7.0"

This is expected to work again per:

[2022-08-23 17:44:49,216] Replication to gerrit2@gerrit2002.wikimedia.org:/srv/gerrit/git/mediawiki/core.git completed in 86808ms, 10759ms delay, 0 retries [CONTEXT pushOneId="69aa9ddf" ]

This is where Phabricator gets it from.

Just don't see it yet on https://phabricator.wikimedia.org/source/mediawiki/history/master/

Told Phabricator to reschedule updating the repo, via web UI diffusion -> .. -> manage repo,..-> update now (schedules it for the daemons to do it 'asap'). But no change yet.

Told Phabricator to reschedule updating the repo, via web UI diffusion -> .. -> manage repo,..-> update now (schedules it for the daemons to do it 'asap'). But no change yet.

That is because Gerrit is still replication and that takes a while. The queue items can be listed via ssh -p 29418 gerrit.wikimedia.org gerrit show-queue -w:

$ gerrit show-queue -w|grep mediawiki/core
+ ssh -p 29418 hashar@gerrit.wikimedia.org gerrit show-queue -w
ae8ad240              18:51:57.464      git-upload-pack /mediawiki/core (jenkins-bot)
aa6f4cf2 waiting .... 17:43:22.490      [aa88acd7] push gerrit2@gerrit2002.wikimedia.org:/srv/gerrit/git/mediawiki/core.git [..all..]

There are 1900 entries pending (all repositories) and there are four threads processing them.

Alright, thanks. That seemed to be at odds with the "mediawiki/core.git completed in 86808ms" but will just check again later.

Great debugging @Dzahn!

As there was talk about mitigating the MINA upstream KEX bug by either trying to switch to different ssh keys or waiting for the 3.6 upgrade ... my experience is that Gerrit's SSH server is always a bit painful. As Gerrit upstream fixes the problem by asking to upgrade to 3.6, I'd also follow that route.

(Changing keys while staying on Gerrit 3.4.5/3.5 might solve the most visible KEX issue, but it still leaves you with a broken MINA 2.7 release, which also is affected for example by SSHD-1197 (Race condition in KEX))

I kept digging into it last night and this morning.

Based on https://github.com/apache/mina-sshd/pull/195#issuecomment-851009117 I have used:

.ssh/config
HostKeyAlgorithms rsa-sha2-256
KexAlgorithms diffie-hellman-group-exchange-sha256

I wanted to "easily" reproduce the issue and my idea is to use the jgit CLI interface. The repository is https://gerrit.googlesource.com/jgit the sha1 to use can be found in Gerrit via modules/jgit submodule:

Gerrit versionjgit sha1
v3.4.41e59cabc0
v3.4.578c9b9260

Compile with mvn -DskipTests clean package and then one can run it the cli with ./org.eclipse.jgit.pgm/target/jgit. I picked ls-remote as a subcommand.

It works on v3.4.4

jgit((1e59cabc0...))$ ./org.eclipse.jgit.pgm/target/jgit --version
jgit version 5.12.1-SNAPSHOT

jgit((1e59cabc0...))$ ./org.eclipse.jgit.pgm/target/jgit ls-remote ssh://localhost/test/foo.git
fatal: ssh://localhost/test/foo.git: fatal: '/test/foo.git' does not appear to be a git repository

Fails on v3.4.5:

jgit((78c9b9260...))$ ./org.eclipse.jgit.pgm/target/jgit --version
jgit version 5.13.1-SNAPSHOT
jgit((78c9b9260...))$ ./org.eclipse.jgit.pgm/target/jgit ls-remote ssh://localhost/test/foo.git
2022-08-24 11:13:36 [sshd-JGitSshClient[543788f3]-nio2-thread-3] WARN org.eclipse.jgit.internal.transport.sshd.JGitClientSession - exceptionCaught(JGitClientSession[localhost/127.0.0.1:22])[state=Opened] SshException: KeyExchange signature verification failed for key type=ssh-rsa
fatal: ssh://localhost/test/foo.git: KeyExchange signature verification failed for key type=ssh-rsa

Setting environment variable java_args=-Dorg.slf4j.simpleLogger.defaultLogLevel=debug gives a lot more details.

The one that has the above ssh config and dies at org.apache.sshd.client.kex.DHGEXClient.next(DHGEXClient.java:241) has:

HostKeyAlgorithms [rsa-sha2-256]
KexAlgorithms diffie-hellman-group-exchange-sha256,ext-info-c
proposing HostKeyAlgorithms [rsa-sha2-256, ext-info-c]

Without settings in .ssh/config:

HostKeyAlgorithms [rsa-sha2-512, rsa-sha2-256, ssh-rsa, ecdsa-sha2-nistp256-cert-v01@openssh.com, ecdsa-sha2-nistp384-cert-v01@openssh.com, ecdsa-sha2-nistp521-cert-v01@openssh.com, ssh-ed25519-cert-v01@openssh.com, rsa-sha2-512-cert-v01@openssh.com, rsa-sha2-256-cert-v01@openssh.com, ssh-rsa-cert-v01@openssh.com, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com, ssh-dss-cert-v01@openssh.com, ssh-dss]
KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256,diffie-hellman-group18-sha512,diffie-hellman-group17-sha512,diffie-hellman-group16-sha512,diffie-hellman-group15-sha512,diffie-hellman-group14-sha256,ext-info-c
proposing HostKeyAlgorithms [rsa-sha2-512, rsa-sha2-256, ssh-rsa, ecdsa-sha2-nistp256-cert-v01@openssh.com, ecdsa-sha2-nistp384-cert-v01@openssh.com, ecdsa-sha2-nistp521-cert-v01@openssh.com, ssh-ed25519-cert-v01@openssh.com, rsa-sha2-512-cert-v01@openssh.com, rsa-sha2-256-cert-v01@openssh.com, ssh-rsa-cert-v01@openssh.com, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com, ssh-dss-cert-v01@openssh.com, ssh-dss, ext-info-c]

Kex: kex algorithms = ecdh-sha2-nistp521
Kex: server host key algorithms = rsa-sha2-512
# good

And on gerrit1001 as gerrit2 user:

HostKeyAlgorithms [rsa-sha2-512, rsa-sha2-256, ssh-rsa, ecdsa-sha2-nistp256-cert-v01@openssh.com, ecdsa-sha2-nistp384-cert-v01@openssh.com, ecdsa-sha2-nistp521-cert-v01@openssh.com, ssh-ed25519-cert-v01@openssh.com, rsa-sha2-512-cert-v01@openssh.com, rsa-sha2-256-cert-v01@openssh.com, ssh-rsa-cert-v01@openssh.com, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ecdsa-sha2-nistp256@openssh.com, sk-ssh-ed25519@openssh.com, ssh-dss-cert-v01@openssh.com, ssh-dss]
KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256,diffie-hellman-group18-sha512,diffie-hellman-group17-sha512,diffie-hellman-group16-sha512,diffie-hellman-group15-sha512,diffie-hellman-group14-sha256,ext-info-c

Kex: kex algorithms = diffie-hellman-group-exchange-sha256
Kex: server host key algorithms = rsa-sha2-512
# fails

So for some reason on my machine it picks the ecdh-sha2-nistp521 kex algorithm and that works.

On gerrit1001 diffie-hellman-group-exchange-sha256 is picked which erroneously use DHGEXClient and leads to the bug.

If I try to set KexAlgorithms ecdh-sha2-nistp256 that fails with Unable to negotiate key exchange for kex algorithms:

clientecdh-sha2-nistp256,ext-info-c
servercurve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256

Our ssh servers have:

/etc/ssh/sshd_config
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256

Then curve25519-sha256@libssh.org is unknown to jgit since it was added by Mina sshd 2.8.0 via https://issues.apache.org/jira/browse/SSHD-704:

ignoring unknown algorithm 'curve25519-sha256@libssh.org' in KexAlgorithms curve25519-sha256@libssh.org

The negotiation is thus made with diffie-hellman-group-exchange-sha256 and that triggers the build.

I will check with SRE to add another kex algorithm, at least until we upgrade to Gerrit 3.6.

Change 826237 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/puppet@production] gerrit: allow nist kex algorithms on OpenSsh server

https://gerrit.wikimedia.org/r/826237

hashar updated the task description. (Show Details)

Filed as https://bugs.chromium.org/p/gerrit/issues/detail?id=16215 . An ideal fix would be to upgrade Gerrit 3.4 series to Mina 2.8.0 but that might not be trivial. We should get the workaround applied and then do the Gerrit upgrades 3.4.53.5.x3.6.x.

Change 826237 merged by Dzahn:

[operations/puppet@production] gerrit: allow nist kex algorithms on OpenSsh server

https://gerrit.wikimedia.org/r/826237

SSHd and ssh client settings have been adjusted to use ecdh-sha2-nistp521 as kex algo after Hashar's change above has been deployed.

puppet refreshed the daemon and replication.log still looked normal and showed completed replications afterwards.

The ssh connection works now:

gerrit2@gerrit1001$ /home/hashar/jgit-g78c9b9260 ls-remote ssh://gerrit2002.wikimedia.org/test/gerrit-ping.git
fatal: ssh://gerrit2002.wikimedia.org/test/gerrit-ping.git: fatal: '/test/gerrit-ping.git' does not appear to be a git repository

It negotiates Kex: kex algorithms = ecdh-sha2-nistp521

I will upgrade Gerrit to 3.4.5 on Monday European morning.

Change 827163 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.4] Gerrit v3.4.5 and rebuild plugins [2]

https://gerrit.wikimedia.org/r/827163

Change 827163 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.4] Gerrit v3.4.5 and rebuild plugins [2]

https://gerrit.wikimedia.org/r/827163

I have updated both Gerrit to 3.4.5 and I have confirmed the replication to gerrit-replica.wikimedia.org works. That would let Phabricator get up to date :]

Change #1064413 had a related patch set uploaded (by Dzahn; author: Dzahn):

[operations/puppet@production] gerrit: fix todo from 2022, remove nist key setting

https://gerrit.wikimedia.org/r/1064413

Change #1082846 had a related patch set uploaded (by Dzahn; author: Dzahn):

[operations/puppet@production] gerrit2003: set SSH disable_nist_kex to true on new bookwork host

https://gerrit.wikimedia.org/r/1082846

Change #1082846 merged by Dzahn:

[operations/puppet@production] gerrit2003: set SSH disable_nist_kex to true on new bookwork host

https://gerrit.wikimedia.org/r/1082846