Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Authentication of PeerIds in authority discovery records #10317

Merged
merged 17 commits into from
Dec 5, 2021

Conversation

wigy-opensource-developer
Copy link
Contributor

@wigy-opensource-developer wigy-opensource-developer commented Nov 19, 2021

This PR adds a proof that the authority controls the key behind the PeerId it advertises to be reachable at.

Closes #8833

  • Reexport libp2p::identity::PublicKey and libp2p::identity::error::SigningError from sc-network and use it in sc-authority-discovery.
  • Add a test that decodes SignedAuthorityRecord from the old format.

skip check-dependent-cumulus

@wigy-opensource-developer wigy-opensource-developer added A3-in_progress Pull request is in progress. No review needed at this stage. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Nov 19, 2021
@github-actions github-actions bot added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Nov 19, 2021
@bkchr
Copy link
Member

bkchr commented Nov 29, 2021

Is this ready for review?

@wigy-opensource-developer
Copy link
Contributor Author

Now it is code complete in my view, especially if the CI passes. Where do I need to document the new command-line option?

@wigy-opensource-developer wigy-opensource-developer changed the title [WIP] Authentication of PeerIds in audi records Authentication of PeerIds in audi records Nov 29, 2021
@wigy-opensource-developer wigy-opensource-developer changed the title Authentication of PeerIds in audi records Authentication of PeerIds in authority discovery records Nov 29, 2021
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a test would be nice

client/cli/src/commands/run_cmd.rs Outdated Show resolved Hide resolved
Comment on lines +430 to +431
serde_json::to_writer(&file, data)?;
file.flush()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. Forgot it in this changeset. Was thinking about if this reduces the race-condition that another process opens the file before the permissions are applied. It is a very thin chance, and did not want to push it 😟

client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that the old dht entry is still decodable?

bin/node/cli/src/service.rs Outdated Show resolved Hide resolved

/// Reject authority discovery records that are not signed by their network identity (PeerId)
///
/// Defaults to `false` to provide compatibility with old versions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should default to true to have new networks enabled this by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would cause silent breaking for existing networks, which use Default::default() in their sc-authority-discovery::Worker instantiation. I would be more conservative here and reduce gotchas in the ecosystem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no one uses this, but fine.

Then we should document this in the docs of the crate?

client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Show resolved Hide resolved
client/authority-discovery/src/worker.rs Show resolved Hide resolved
client/authority-discovery/src/worker/tests.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker/tests.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker/tests.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker/tests.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
@wigy-opensource-developer
Copy link
Contributor Author

wigy-opensource-developer commented Dec 1, 2021

Can we add a test that the old dht entry is still decodable?

At the moment I have added tests that do not sign the record. The wire format should be the same as the old records. Should I record an encoded record from a test on master and try to decode it with the current proto definition in a test?

@bkchr
Copy link
Member

bkchr commented Dec 1, 2021

Should I record an encoded record from a test on master and try to decode it with the current proto definition in a test?

Yes that was my idea, but if you are sure that the format is compatible. I'm also okay without any test.

client/network/src/service/signature.rs Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Outdated Show resolved Hide resolved
client/authority-discovery/src/worker.rs Show resolved Hide resolved
client/network/src/lib.rs Outdated Show resolved Hide resolved
@wigy-opensource-developer
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot
Copy link

Merge cancelled due to error. Error: Checks failed for cb009e0

@bkchr bkchr merged commit 76d34c4 into master Dec 5, 2021
@bkchr bkchr deleted the wigy-auth-auth-disco branch December 5, 2021 19:17
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
…10317)

* Consolidating test and production code

* Signing/verifying authority discovery records with PeerId

Unsigned records cannot be rejected yet, they just produce
a warning in the log.

* Upgrading to libp2p 0.40

* libp2p::identity and sp_core::crypto Ed25519 are compatible

* Rejecting authority records unsigned by peer id can be configured

* Fixes based on review comments

* No command-line argument needed

* info was still too much spam in the logs

* Added tests for both strict and loose validation

* Fixing based on review comments

* Pierre preferred a signing method

* Ooops, I need to slow down

* Update bin/node/cli/src/service.rs

* Reexport libp2p crypto used in sc-network

* Added proto3 compatibility tests. And import noise.

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…10317)

* Consolidating test and production code

* Signing/verifying authority discovery records with PeerId

Unsigned records cannot be rejected yet, they just produce
a warning in the log.

* Upgrading to libp2p 0.40

* libp2p::identity and sp_core::crypto Ed25519 are compatible

* Rejecting authority records unsigned by peer id can be configured

* Fixes based on review comments

* No command-line argument needed

* info was still too much spam in the logs

* Added tests for both strict and loose validation

* Fixing based on review comments

* Pierre preferred a signing method

* Ooops, I need to slow down

* Update bin/node/cli/src/service.rs

* Reexport libp2p crypto used in sc-network

* Added proto3 compatibility tests. And import noise.

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authority-discovery should sign its validator key with its PeerIds
3 participants