perf(federation): 連合の署名をEd25519鍵に対応
#14278 のやり直し Fix #14273 Fix of https://github.com/misskey-dev/misskey/pull/13464 Resolve https://github.com/misskey-dev/misskey/issues/11129 Fix https://github.com/misskey-dev/misskey/issues/7506
What
- [x] ローカルユーザーのEd25519鍵を発行する
- 持っていなかったらDeliverManager.executeの時に発行する
- [x] AP Personに
additionalPublicKeysを追加- publicKeyの配列をとる
- Spec: https://github.com/misskey-dev/node-http-message-signatures/tree/0.0.1?tab=readme-ov-file#additionalpublickeys
- [x]
InboxProcessorService.processで複数の公開鍵に対応する - [x] HTTP Signatureの実装ライブラリを自作して根本的に変える:
https://github.com/misskey-dev/node-http-message-signatures
- 今までのライブラリはEd25519の検証がとても遅いため
- Web Crypto APIベースでPromiseになった(並列度が高い状況では高速に?)
- RSA鍵の処理でもパフォーマンスに対してポジティブな効果が得られました
- [x] nodeinfoにHTTP Signatureの対応状況(暗号方式は?RFC 9421に対応しているか?)を掲示
- Spec: https://github.com/misskey-dev/node-http-message-signatures/tree/0.0.1?tab=readme-ov-file#http-message-signatures-implementation-level
- [x] nodeinfoの情報を基にサーバーごとに署名を出し分ける
- [x] ローカルでの連合試験用にhttpリクエストの仕様変更 (fetchInstanceMetadataが作動するように、環境変数名変更)
- [x] ジョブキューの並列度を見直し
- deliverJobConcurrency: 16 (←128)
- deliverJobPerSec: 1024 (←128)
- inboxJobConcurrency: 4 (←16)
- inboxJobPerSec: 64 (←32)
RFC 9421への対応はここでは行わない
- 署名検証で同一名キーが見つからない場合のupdatePersonなどの最短間隔を12分から5分に短縮
- inboxで署名検証が失格になった場合、キューを再試行しないようにしていたがするように
- admin/show-userで公開鍵(リモートユーザー)/秘密鍵公開鍵ペア(ローカルユーザー)を確認できるように
- updatePersonの後に発火するremoteUserUpdatedイベントにより、ApDbResolverServiceのpublicKeyキャッシュ
publicKeyByUserIdCacheをリフレッシュするように(ユーザーごと) - deliverでinboxに投げて401が返ってきた場合、時計が狂っている場合などを考慮しリトライできるように
- signature parseにおいてheaders.dateとサーバー時間のズレは両方向に300sを許容するように (headers.date - サーバー時間 <= 2000しか許容していなかったがこれだと問題が起きた)
Why
Deliverやsigned Getの軽量化
Additional info (optional)
CHANGELOG
-
Feat: 連合に使うHTTP SignaturesがEd25519鍵に対応するように #16250
- Ed25519署名に対応するサーバーが増えると、deliverで要求されるサーバーリソースが削減されます
- ジョブキューのconfig設定のデフォルト値を変更しました。
default.ymlでジョブキューの並列度を設定している場合は、concurrencyの値を下げるとパフォーマンスが改善する可能性があります。- deliverJobConcurrency: 16 (←128)
- deliverJobPerSec: 1024 (←128)
- inboxJobConcurrency: 4 (←16)
- inboxJobPerSec: 64 (←32)
- ジョブキューのconfig設定のデフォルト値を変更しました。
- Ed25519署名に対応するサーバーが増えると、deliverで要求されるサーバーリソースが削減されます
-
[x] Includes and depends on https://github.com/misskey-dev/misskey/pull/16284
-
[ ] Includes and depends on https://github.com/misskey-dev/misskey/pull/16279
-
[ ] Includes and depends on https://github.com/misskey-dev/misskey/pull/16297
-
[ ] Includes and depends on https://github.com/misskey-dev/misskey/pull/16268
diff https://github.com/tamaina/misskey/compare/remote-suspend..re2-ed25519
Checklist
- [x] Read the contribution guide
- [x] Test working in a local environment
- [ ] (If needed) Add story of storybook
- [ ] (If needed) Update CHANGELOG.md
- [ ] (If possible) Add tests
Codecov Report
:x: Patch coverage is 47.72162% with 631 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 63.05%. Comparing base (e98252a) to head (f26f778).
:warning: Report is 1128 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #16250 +/- ##
============================================
+ Coverage 42.56% 63.05% +20.48%
============================================
Files 1685 1151 -534
Lines 170650 115973 -54677
Branches 4223 7992 +3769
============================================
+ Hits 72643 73123 +480
+ Misses 97546 40690 -56856
- Partials 461 2160 +1699
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
このPRによるapi.jsonの差分
差分はこちら
--- base
+++ head
@@ -16624,6 +16624,9 @@
"isSuspended": {
"type": "boolean"
},
+ "isRemoteSuspended": {
+ "type": "boolean"
+ },
"isHibernated": {
"type": "boolean"
},
@@ -16675,6 +16678,67 @@
"roleId"
]
}
+ },
+ "publicKeys": {
+ "type": [
+ "array",
+ "null"
+ ],
+ "items": {
+ "type": "object",
+ "properties": {
+ "userId": {
+ "type": "string"
+ },
+ "keyId": {
+ "type": "string"
+ },
+ "keyPem": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "userId",
+ "keyId",
+ "keyPem"
+ ]
+ }
+ },
+ "keyPairs": {
+ "type": [
+ "object",
+ "null"
+ ],
+ "properties": {
+ "userId": {
+ "type": "string"
+ },
+ "publicKey": {
+ "type": "string"
+ },
+ "privateKey": {
+ "type": "string"
+ },
+ "ed25519PublicKey": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "ed25519PrivateKey": {
+ "type": [
+ "string",
+ "null"
+ ]
+ }
+ },
+ "required": [
+ "userId",
+ "publicKey",
+ "privateKey",
+ "ed25519PublicKey",
+ "ed25519PrivateKey"
+ ]
}
},
"required": [
@@ -16695,13 +16759,16 @@
"isModerator",
"isSilenced",
"isSuspended",
+ "isRemoteSuspended",
"isHibernated",
"lastActiveDate",
"moderationNote",
"signins",
"policies",
"roles",
- "roleAssigns"
+ "roleAssigns",
+ "publicKeys",
+ "keyPairs"
]
}
}
@@ -91774,6 +91841,9 @@
"string",
"null"
]
+ },
+ "httpMessageSignaturesImplementationLevel": {
+ "type": "string"
}
},
"required": [
@@ -91801,7 +91871,8 @@
"faviconUrl",
"themeColor",
"infoUpdatedAt",
- "latestRequestReceivedAt"
+ "latestRequestReceivedAt",
+ "httpMessageSignaturesImplementationLevel"
]
},
"GalleryPost": {
federation test、テストでエラーが出たところでlogのどの位置が該当箇所なのかわからん
なんかユーザーをresolveできてない?
isDeletedがtrueになってた
なんで?
- alice/bobの作成はbeforeAllだからdescribe内でalice/bobは同一
- suspendは外部に対してDeleteである
- unsuspendはUndo DeleteだがそれはMisskeyは処理しない(unsuspendはリモートに伝わらない)
- よって
Alice can follow Bobはaliceをsuspendする処理が走った後そのまま実行される、aliceがisDeletedになっているのは全く理にかなっている
ようはリモートユーザーが削除済/中なのにinboxに何かしらを送りつけてくるパターンなんだけど、受信側がそれをどう解釈するかは結構悩ましいかも
ようわからんけどとりあえず #13256 先にやるか
問題1: ap/showでuriでの参照がすり抜けて、createPersonでalready registeredエラーが出る
動いたんだが
p1.a9z.devに適用した
https://codeberg.org/fediverse/fep/src/branch/main/fep/521a/fep-521a.md に対応すべき?(すべき)
ASN.1←→Multibaseの変換処理が大きくなりそうなのでこのPRはこのままで
https://github.com/misskey-dev/misskey/issues/14244
これか
conflict resolved