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

Add Ledger key rotation tutorial #367

Merged
merged 22 commits into from
Sep 13, 2024
Merged

Conversation

alnoki
Copy link
Contributor

@alnoki alnoki commented May 28, 2024

Background

@davidiw @gedigi @hariria @hardsetting @xbtmatt

Per in-person discussions re: authentication key rotation and Ledger.

This relies on the new features from the aptos-core PR aptos-labs/aptos-core#11151 which was subsequently broken into 3 smaller PRs:

Changes

  1. Add a tutorial on rotating the authentication key for a wallet from hot private key to Ledger and back, using localnet to demonstrate new Framework code.
  2. Change a fenced code block with lots of escape characters from bash to text to avoid syntax highlighting issues in IDE.
  3. Update existing authentication key rotation documentation as necessary with important caveats.
  4. Crosslink Ledger and standard key rotation documents.
  5. Fix header hierarchy where it resulted in unintuitive navigation.

Testing

From in apps/nextra:

npx -p [email protected] pnpm dev
  1. Install the aptos-core CLI from source using [Framework] Safe onchain key rotation address mapping for standard accounts aptos-core#14309 (or main, once it merges)
  2. Follow http://localhost:3030/en/build/guides/key-rotation
  3. Follow http://localhost:3030/en/build/cli/trying-things-on-chain/ledger#authentication-key-rotation

Checklist

  • Do all Lints pass?
    • Have you ran pnpm spellcheck? (This is failing due to issues with content I have not modified)
    • Have you ran pnpm fmt?
    • Have you ran pnpm lint? (This is failing due to issues with content I have not modified)

Copy link

vercel bot commented May 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
developer-docs-nextra ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2024 7:14pm

Copy link

netlify bot commented May 28, 2024

Deploy Preview for aptos-developer-docs ready!

Name Link
🔨 Latest commit 543aaa6
🔍 Latest deploy log https://app.netlify.com/sites/aptos-developer-docs/deploys/6687052621664a000836bcbe
😎 Deploy Preview https://deploy-preview-367--aptos-developer-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@alnoki

This comment was marked as resolved.

Copy link
Collaborator

@gregnazario gregnazario left a comment

Choose a reason for hiding this comment

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

@movekevin can you take a look at this? Seems like encouraging people to rotate back and forth between different keys is not a good idea.


This tutorial will walk you through both scenarios.

<Callout type="warning" emoji="💀">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use a red exclamation, instead of skulls.

We should also add, this is really only something that should be done if you know what you're doing or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 543aaa6

Note that the callout additionally specifies not to do it until finishing the base ledger guide, which includes a power user warning

Comment on lines 171 to 172
If you are on a UNIX-like system, the following command can be used to start a
fresh localnet as a background process:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can go over people's heads sometimes.

Let's say macOS or Linux (I know there's BSD and other things, but it should be good enough).

I also, generally try not to suggest people to launch background processes unless they know what they're doing. Pretty easy to do things wrong there, especially since the local testnet will print output from 0x1::debug::print

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 543aaa6 with MacOS/Linux distinction and power user callout

Comment on lines +192 to +200
Create a private key corresponding to an authentication key, and thus initial
account address, that starts with the vanity prefix `0xaaa`:

```sh filename="Terminal"
aptos key generate \
--assume-yes \
--output-file private-key-a \
--vanity-prefix 0xaaa
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Vanity prefixes are nice, but let's keep it to a randomly generated one, so people aren't waiting for a while to churn through prefixes to get to the rest of the tutorial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can actually be kinda hard to follow along if luck of the draw two accounts start with similar hex chars

Vanity address with only 3 chars is negligible time to generate, and the labelling make the tutorial flow way easier

Comment on lines 255 to 261
<Callout type="info" emoji="🧠">
As a best practice, this command uses a [BIP44 account index] offset of 1000 to
indicate that the account is secured by a rotated authentication key on a
Ledger.

This practice aids in profile recovery, as shown below.
</Callout>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what that means.

Maybe it's better to say that it's best practice to choose a common large number, such as 1000 to ensure it doesn't conflict with already existing ledger accounts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 543aaa6

```sh filename="Terminal"
aptos account rotate-key \
--assume-yes \
--new-derivation-index 1000 \
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is in the CLI yet?

At least not 3.4.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in the PR description

Install the CLI from source, as described in aptos-labs/aptos-core#11151

This PR pairs simply because I had to split docs and source into two separate repos aptos-labs/aptos-core#11151

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noting that I've updated the PR description per the recent set of aptos-core PRs that have merged, to stipulate installing the latest Framework updates

Comment on lines 330 to 336
<Callout type="info" emoji="🧠">
If you are using a UNIX-like machine:

```shell filename="Terminal"
rm private-key-*
```
</Callout>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really dangerous, please remove it.

Someone who copies and pastes this could wipe out other private keys. Ideally should not be having a rm ...* command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 543aaa6

If you are using a UNIX-like machine:

```shell filename="Terminal"
aptos config delete-profile --profile ledger-wallet-1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also not a command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in the PR description

Install the CLI from source, as described in aptos-labs/aptos-core#11151

This PR pairs simply because I had to split docs and source into two separate repos aptos-labs/aptos-core#11151

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noting that I've updated the PR description per the recent set of aptos-core PRs that have merged, to stipulate installing the latest Framework updates

@alnoki
Copy link
Contributor Author

alnoki commented Jul 4, 2024

@gregnazario thanks for the above comments. I believe I've addressed all where applicable

Just flagging here again that this PR requires aptos-labs/aptos-core#11151, without which there is no support for ledger auth key rotation

I'd try and do everything in one PR (docs and CLI source updates), but alas there is no longer a monorepo

Seems like encouraging people to rotate back and forth between different keys is not a good idea.

Before ledger support became available, plenty of projects launched under hot keys (and many still do, unfortunately, due to the >20kb issue on ledger), and without the CLI updates proposed in the linked PR, there is no way to secure an upgradeable package with anything other than a hot key

I agree that key rotation is advanced and should be reserved for specific use cases, but securing Move packages with accounts that don't use hot keys is important for ecosystem OpSec

Comment on lines 59 to 61
not rotate an account's authentication key to a key that is already in the
table, as this attack that would prevent lookup of the valid originating address
that the holder of an authentication key had previously approved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
not rotate an account's authentication key to a key that is already in the
table, as this attack that would prevent lookup of the valid originating address
that the holder of an authentication key had previously approved.
not rotate an account's authentication key to a key that is already in the
table, as this attack would prevent lookup of the valid originating address
that the holder of an authentication key had previously approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 806a984

Comment on lines 86 to 87
mapped to in the table (since the table is only updated upon during rotation,
not upon standard account generation).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
mapped to in the table (since the table is only updated upon during rotation,
not upon standard account generation).
mapped to in the table (since the table is only updated during rotation,
not upon standard account generation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 806a984


<Callout type="info" emoji="🧠">
The [`account::rotate_authentication_key_call`] was introduced to support
non-standard key algorith, like passkeys, which cannot produce proofs of
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
non-standard key algorith, like passkeys, which cannot produce proofs of
non-standard key algorithms, like passkeys, which cannot produce proofs of

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 806a984

if so, verifies that the rotating account's address is the one mapped to in the
table.

This means that if an arbitary account's authentication key is rotated to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
This means that if an arbitary account's authentication key is rotated to
This means that if an arbitrary account's authentication key is rotated to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 806a984

Copy link
Collaborator

@hariria hariria left a comment

Choose a reason for hiding this comment

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

Some nits and otherwise it looks good to me. Will let @gregnazario take a final pass


<Callout type="warning" emoji="❗">
Before you start this tutorial make sure you have completed the
[key rotation guide](../../advanced-guides/key-rotation.mdx).
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of the relative links to the key rotation guide do not work for me when testing it in the preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like advanced-guides was renamed to guides

Resolved in c32f593

@alnoki
Copy link
Contributor Author

alnoki commented Aug 18, 2024

@hariria I believe I've addressed all your recent comments and that I had previously addressed all comments from @gregnazario

I've updated the PR description for more clarity on the associated aptos-core PRs

@igor-p
Copy link
Contributor

igor-p commented Sep 13, 2024

Discussed with @gregnazario, ok to merge.

@igor-p igor-p merged commit a63a255 into aptos-labs:main Sep 13, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants