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

walletunlocker+lnd: add command line flag to allow passing admin macaroon after wallet creation #1288

Merged
merged 12 commits into from
Nov 7, 2020

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented May 26, 2018

Fixes #1236.

The new flag --stateless_init of the startup commands create, unlock and changepassword instructs the daemon to not create any macaroon files in its file system but instead return the admin macaroon in the response.
The lncli then prints the macaroon to the standard output (binary serialized in hex format) or writes it to the file specified with the --save_to parameter.

Some of the integration test code is also contained in PR #1152. If either of these two PRs get merge, I'll rebase/fix the other one.

@guggero guggero force-pushed the stateless-init branch 3 times, most recently from 8a457dd to d88e737 Compare June 5, 2018 08:27
@guggero guggero force-pushed the stateless-init branch 3 times, most recently from 7e87918 to b48f6f0 Compare June 14, 2018 06:23
@meshcollider meshcollider added macaroons cli Related to the command line interface labels Jun 15, 2018
@guggero guggero force-pushed the stateless-init branch 2 times, most recently from 9a4e4c6 to d570156 Compare July 1, 2018 10:31
@Roasbeef Roasbeef added P2 should be fixed if one has time P3 might get fixed, nice to have needs review PR needs review by regular contributors needs testing PR hasn't yet been actively tested on testnet/mainnet labels Jul 10, 2018
@guggero guggero force-pushed the stateless-init branch 9 times, most recently from 3391512 to 0580880 Compare July 29, 2018 16:03
@guggero
Copy link
Collaborator Author

guggero commented Jul 29, 2018

This PR has gotten a lot more complicated than initially thought...
The reason is that in #618 it was implemented that when the wallet password was changed, the macaroon DB was just deleted and then re-created, resulting in all macaroons to be invalidated.

According to @Roasbeef (#1236 (comment)), this was a mistake.
So I also implemented the re-encryption of the macaroon DB and an optional flag --new_mac_root_key in the changepassword command that replaces the existing macaroon root key with a new one in case the user really wants it that way.

@neogeno is helping me with the testing, thanks a lot for that!

@guggero guggero force-pushed the stateless-init branch 3 times, most recently from f697e5c to 1e6e526 Compare July 30, 2018 06:31
lnd.go Outdated Show resolved Hide resolved
walletunlocker/service.go Outdated Show resolved Hide resolved
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

alright, tremendous effort with this PR! I think it is time to welcome it to 2020 😎

LGTM 💯

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Looking pretty good! Has been a while since I looked at this PR, so first just a few clarifying questions w.r.t the intended behavior.

cmd/lncli/cmd_walletunlocker.go Show resolved Hide resolved
macaroons/store.go Show resolved Hide resolved
lnd.go Outdated Show resolved Hide resolved
lnd.go Show resolved Hide resolved
lnd.go Show resolved Hide resolved
walletunlocker/service.go Show resolved Hide resolved
// to delete them here and they will be recreated during normal startup
// later. If they are missing, this is only an error if the
// stateless_init flag was not set.
if in.NewMacaroonRootKey || in.StatelessInit {
Copy link
Member

Choose a reason for hiding this comment

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

Don't we always need to do this for any change password request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, not anymore. Before, we just deleted the whole macaroon DB, effectively invalidating all macaroons. Therefore it did make sense to delete the macaroon files themselves as well. But now, we only re-generate the root key if specifically requested. So we only need to remove the macaroon files on disk if the root key is changed or if the user tries to switch to stateless.

}
return nil, err
}
err = macaroonService.ChangePassword(privatePw, in.NewPassword)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to now explicitly perform this new password change at the macaroon service level? If we crash at this point, but the above succeeds, then the user may end up in a situation where they can't start up (?) or just aren't able to use their macaroons. I guess in either case, then they can just remove their on-disk macaroons, then have things just "work".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Before we just deleted the whole macaroon DB. But since we now want to support only changing the password, without invalidating all macaroons, we have to perform the actual password change on the DB level.

Indeed, if something goes wrong here, it could result in the wallet DB password being changed but the macaroon DB password not. The user then still has the option to completely remove the macaroon DB and all macaroon files to resolve this. Not sure if we need to address this in this PR?

lntest/itest/lnd_macaroons_test.go Show resolved Hide resolved
@guggero guggero force-pushed the stateless-init branch 3 times, most recently from 827ca50 to 2cf4f20 Compare October 9, 2020 08:15
@guggero guggero requested a review from Roasbeef October 9, 2020 08:16
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🕺

guggero and others added 12 commits November 7, 2020 11:18
…locker

This commit adds the --stateless_init flag to all three wallet unlocker
operations. Once you initialize a wallet stateless, you need to set
this flag for every further wallet unlocker operation. Otherwise you
risk non-encrypted macaroon information to leak to the underlying
system.
To make sure no macaroons are created anywhere if the stateless
initialization was requested, we keep the requested initialization mode
in the memory of the macaroon service.
As a preparation for the next commit where we add proper wallet unlocker
shutdown handling, we move the calls that require cleanup down after the
creation of the wallet unlocker service itself.
Because we'll need to return the macaroon through the wallet unlocker
we cannot shut down its service before we have done so, otherwise
we'll end up in a deadlock. That's why we collect all shutdown
tasks and return them as a function that can be called after we've
initialized the macaroon service.
To prepare for new tests to be added, we first rewrite the existing
tests to use the require library and get rid of some smaller linter
issues.
This will prevent the subservers from writing macaroons to disk
when the stateless_init flag is set to true. It accomplishes
this by storing the StatelessInit value in the Macaroon Service.
@guggero guggero merged commit 72cacb9 into lightningnetwork:master Nov 7, 2020
@guggero guggero deleted the stateless-init branch November 7, 2020 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface macaroons needs review PR needs review by regular contributors needs testing PR hasn't yet been actively tested on testnet/mainnet P2 should be fixed if one has time v0.12
Projects
None yet
Development

Successfully merging this pull request may close these issues.

walletunlocker+lnd: add command line flag to allow passing macaroons after wallet creation
8 participants