-
Notifications
You must be signed in to change notification settings - Fork 105
[sql-53] firewalldb: actions migration prep 2 - persist full macaroon root key ID in the SQL actions store #1146
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @ViktorTigerstrom, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request implements a foundational update to the SQL actions store, enabling it to record the complete 8-byte macaroon root key ID. This enhancement is a crucial prerequisite for the larger migration effort to transition the actions store from a KVDB to a SQL backend. By storing the full root key ID, the system gains improved accuracy and future-proofing for macaroon-related actions. The current design ensures backward compatibility by not altering the KVDB implementation, with plans to fully leverage the extended ID once the KVDB is phased out.
Highlights
- Enhanced Macaroon ID Storage: The SQL actions store now persists the full 8-byte macaroon root key ID (uint64) instead of just the last 4 bytes, improving data fidelity for macaroon identification.
- Migration Preparation: This change is a critical preparatory step for the ongoing migration of the actions store from KVDB to SQL, ensuring the SQL store is ready for more complete macaroon data.
- Backward Compatibility: The KVDB implementation remains unchanged and will ignore the full root key ID, maintaining compatibility with existing systems until the KVDB store is fully deprecated.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands on the current page.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request prepares for a database migration by changing the SQL actions store to persist the full 8-byte macaroon root key ID. The changes are mostly correct and well-tested, but I've found a critical issue in the data retrieval logic that would cause a panic. I've also suggested a minor refactoring in the test code to improve maintainability. Please see my detailed comments.
The upcoming commit will update the `AddActionReq` struct to include an extra field which the `kvdb` actions store will ignore. Therefore the `assertEqualActions` for the `kvdb` version will need to be update to ignore this field. In preparation for that change, we also do another optimization of the `assertEqualActions` function under kvdb builds, to not mutate the passed action references.
35ecb9c
to
37fa599
Compare
When migrating the actions store from kvdb to sql, we will update the existing actions to include the full mac root key, instead of just the last 4 bytes (currently called `MacaroonIdentifier`). In order to do so, we change the sql implementation of the `actions` store to persist the full mac root key, instead of just the last 4 bytes. As no production data in the sql actions store exists for users yet, it's fine for us to change this without having to address old sql actions which only stored the last 4 bytes. Note though that we do not update the kvdb implementation, and the full macaroon root key will be ignored by the kvdb store even if set. Therefore, the rest of `litd` will still have to just expect the last 4 bytes of the mac root key when accessing an `Action`'s MacaroonIdentifier. Therefore, we we currently never expose the rest of the mac root key outside of the sql actions store. Once the kvdb store has been fully deprecated and removed, we can then update the rest of `litd` to also use the full mac root key, and change the `Action` struct's field to reflect this.
37fa599
to
87cf67e
Compare
@ViktorTigerstrom - what's the main reasoning around storing the full thing? i guess no harm in doing so, but just checking understanding |
got.AccountID = expected.AccountID | ||
require.Equal(t, expected, got) | ||
|
||
got.AccountID = fn.None[accounts.AccountID]() | ||
got.AccountID = actualAccountID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -7,6 +7,7 @@ import ( | |||
"sync" | |||
|
|||
"github.com/lightninglabs/lightning-terminal/firewalldb" | |||
litd_macaroons "github.com/lightninglabs/lightning-terminal/macaroons" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest litmac
?
MacaroonIdentifier: macaroonID, | ||
MacaroonRootKeyID: rootKeyID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok and we need both cause kvdb still stores old identifier but now sql stores full rootkey id?
// If no macaroon was used for the action, then this will not be set. | ||
MacaroonIdentifier fn.Option[[4]byte] | ||
|
||
// MacaroonRootKeyID is the uint64 / full 8 bytes of the root key ID of | ||
// the macaroon used to perform the action. | ||
// If no macaroon was used for the action, then this will not be set. | ||
MacaroonRootKeyID fn.Option[uint64] | ||
|
||
// SessionID holds the optional session ID of the session that this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related to above question, if one of these is stored in kvdb only and the other in sql only, lets add this warning in the comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or actually, to keep the API intuitive, cant se instead only have the MacRootKeyID field here & remove the MacID field. Then extract the relevant format at the DB layer. ie, in the kvdb layer, take the root key ID and compute the mac ID.
macID = fn.Some([4]byte(dbAction.MacaroonIdentifier)) | ||
if len(dbAction.MacaroonIdentifier) >= 4 { | ||
dbMacID := dbAction.MacaroonIdentifier | ||
macID = fn.Some([4]byte(dbMacID[len(dbMacID)-4:])) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not populating the new field below? (see comment about only needing 1 field potentially anyways)
Thanks for the review @ellemouton. I'm answering this clarification first, as I believe that's the deciding factor regarding wether we want to go ahead of with this PR or not:
So after working through the actions migration, it has become clear that the only real reason we'd need to persist the full macaroon root key id (8 bytes), compared to the short version (just the last 4 bytes), is to make it possible to link which exact macaroon was used to when the action was generated. However, I'm not super firm that this protection is totally needed, and IMO it's worth doing for the the sake of it being more clean than opening up for the collision risk. If we do not care about that collision protection however, I don't think we actually need to determine the full root key ID during the migration time as it's not really needed to link possible linked sessions/actions. If so, we can drop the whole short mac key ID -> full root key mapping in the actions migration. Let me know if you think we should proceed with this, or just not try to solve the collision issue :) |
I've realized one scenario where persisting the full root key ID miiiiight be useful is if the user deletes their Not sure if there are many scenarios where this would be useful though :) |
Thanks for the info @ViktorTigerstrom - i think yes it makes sense to store the full thing 🙏 |
Part of #917
This PR addresses an issue I noticed we need to address prior to #1143:
When migrating the actions store from kvdb to sql, we will need to update the existing actions to include the full mac root key, instead of just the last 4 bytes (currently called
MacaroonIdentifier
). In order to do so, we need to change the sql implementation of theactions
store to persist the full mac root key, instead of just the last 4 bytes. As no production data in the sql actions store exists for users yet, it's fine for us to change this without having to address old sql actions which only stored the last 4 bytes.This PR adds this change.
Note though that this PR doesn't update the kvdb implementation, and the full macaroon root key will be ignored by the kvdb store even if set. Therefore, the rest of
litd
will still have to just expect the last 4 bytes of the mac root key when accessing anAction
's MacaroonIdentifier. Therefore, we we currently never expose the rest of the mac root key outside of the sql actions store.Once the kvdb store has been fully deprecated and removed, we can then update the rest of
litd
to also use the full mac root key, and change theAction
struct's field to reflect this.