Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Implement standard keystore API #2736

Closed
wants to merge 18 commits into from

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Oct 20, 2021

Issue Addressed

Implements the standard key manager API from https://ethereum.github.io/keymanager-APIs/, formerly ethereum/beacon-APIs#151
Related to #2557

Proposed Changes

  • Add all of the new endpoints from the standard API: GET, POST and DELETE.
  • Add a validators.enabled column to the slashing protection database to support atomic disable + export.
  • Add tests for all the common sequential accesses of the API
  • Add tests for interactions with remote signer validators
  • Add end-to-end tests for migration of validators from one VC to another
  • Implement the authentication scheme from the standard (token bearer auth)

Additional Info

The enabled column in the validators SQL database is necessary to prevent a race condition when exporting slashing protection data. Without the slashing protection database having a way of knowing that a key has been disabled, a concurrent request to sign a message could insert a new record into the database. The delete_concurrent_with_signing test exercises this code path, and was indeed failing before the enabled column was added.

The validator client authentication has been modified from basic auth to bearer auth, with basic auth preserved for backwards compatibility.

@michaelsproul michaelsproul added the work-in-progress PR is a work-in-progress label Oct 20, 2021
@michaelsproul michaelsproul force-pushed the std-keymanager-api branch 3 times, most recently from 33d8645 to 3a1b030 Compare October 20, 2021 06:06
@michaelsproul
Copy link
Member Author

I've added a draft implementation of the auth scheme described here: ethereum/beacon-APIs#151 (comment)

There's a lot of discussion around the standard, so I'm going to step back from the impl until the dust settles a bit

@michaelsproul
Copy link
Member Author

This is almost ready for review!

There's one FIXME remaining about returning the correct error status for the import/delete of web3signer validators.

Other than that I'll be working on getting the API spec into the new repo: https://github.com/ethereum/keymanager-APIs, although I think we could merge something to unstable before that is completely finalised.

We are currently divergent on the eth/v1/auth endpoint, so I'll also move that to a lighthouse prefix.

@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Nov 12, 2021
@michaelsproul
Copy link
Member Author

This is finally ready for review! 🎉

CI should pass now that a Windows-specific issue has been addressed in 21037cf.

@paulhauner
Copy link
Member

paulhauner commented Nov 22, 2021

I'm starting to review this! There's a conflict, FYI 🙂

@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Dec 16, 2021
@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Jan 14, 2022
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

This is great, really neat and well tested 👌 I don't have anything substantial to say, I just had a few comments whilst reading it.

It's great to see the standard API progressing 🎉

}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[serde(rename_all = "kebab-case")]

I'm not sure, but it seems like we don't need this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, this was just intended to lowercase the variants, so I've switched to rename_all = "lowercase" in 294d44b

.find(|def| def.voting_public_key == pubkey)
{
if !def.signing_definition.is_local_keystore() {
return Err("cannot import duplicate of existing remote signer validator".into());
Copy link
Member

Choose a reason for hiding this comment

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

I notice that an enabled = false validator might not appear in /list but they'll trigger this duplicate warning here. I don't see this as a significant issue and I assume there's going to be some edge-cases when meshing the standard API with our validator management.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point. I'm OK with the current behaviour, but yeah, might make sense to re-assess in future.

let mut definitions_map = HashMap::new();
for def in self.definitions.as_slice() {
for def in self.definitions.as_slice().iter().filter(|def| def.enabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, it's interesting that we didn't previously filter enabled = false 🤔 I think it's definitely the right thing to do.

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Jan 28, 2022
@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Jan 28, 2022
@michaelsproul
Copy link
Member Author

Thanks for the review @paulhauner! Will be great to get this out into a release

I think I've addressed the review comments so this should be good to go 🤞

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

🚀

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Jan 30, 2022
@michaelsproul
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Jan 30, 2022
## Issue Addressed

Implements the standard key manager API from https://ethereum.github.io/keymanager-APIs/, formerly ethereum/beacon-APIs#151
Related to #2557

## Proposed Changes

- [x] Add all of the new endpoints from the standard API: GET, POST and DELETE.
- [x] Add a `validators.enabled` column to the slashing protection database to support atomic disable + export.
- [x] Add tests for all the common sequential accesses of the API
- [x] Add tests for interactions with remote signer validators
- [x] Add end-to-end tests for migration of validators from one VC to another
- [x] Implement the authentication scheme from the standard (token bearer auth)

## Additional Info

The `enabled` column in the validators SQL database is necessary to prevent a race condition when exporting slashing protection data. Without the slashing protection database having a way of knowing that a key has been disabled, a concurrent request to sign a message could insert a new record into the database. The `delete_concurrent_with_signing` test exercises this code path, and was indeed failing before the `enabled` column was added.

The validator client authentication has been modified from basic auth to bearer auth, with basic auth preserved for backwards compatibility.
@bors bors bot changed the title Implement standard keystore API [Merged by Bors] - Implement standard keystore API Jan 31, 2022
@bors bors bot closed this Jan 31, 2022
@michaelsproul michaelsproul deleted the std-keymanager-api branch January 31, 2022 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants