Skip to content

[sql-18] sessions: tightly couple sessions & accounts #989

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
merged 4 commits into from
Mar 4, 2025

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Feb 27, 2025

In this commit, we more tightly & explicitly link a session to an
account. At a persitance layer, we have always only linked a session to
an account by encoding the AccountID within the macaroon caveat that we
store with the session. We still keep this persistence the same but now
we first ensure that the account exists and we also add an AccountID
field to the Session struct.

This is in preparation for adding a SQL implementation of the session Store
where this link will be done at a relational DB level.

part of #966

@ellemouton ellemouton self-assigned this Feb 27, 2025
@ellemouton ellemouton added the no-changelog This PR is does not require a release notes entry label Feb 27, 2025
@ellemouton ellemouton force-pushed the sql18Sessions10 branch 2 times, most recently from d1b0cf8 to 66b8330 Compare February 28, 2025 07:55
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Generally looks great 🚀 !

I'd like to get some clarifications on the first commit thought, before ACKing :).

The last to comments are optional and non-blocking.

@ellemouton ellemouton force-pushed the sql18Sessions10 branch 2 times, most recently from 638c03c to 021daae Compare February 28, 2025 12:18
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

uTACK LGTM 🚀🎉

Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM 🎉, have only a few nits

string(caveatPrefix),
2,
)
if len(caveatSplit) == 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

strings.Cut could maybe be a nicer alternative here. Is it problematic if the macaroon has two account caveats?

Copy link
Member Author

Choose a reason for hiding this comment

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

strings.Cut could maybe be a nicer alternative here.

nice!

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it problematic if the macaroon has two account caveats?

Yeah - but that would already be a problem today.
This commit is just a refactor of how the extraction logic already works.
Today, the interceptor would just match on the first account.

When we link a session to an account, we want to be able to validate
that the account actually does exist. So in preparation for that, we
first give the session store access to the accounts store.
And use that from the existing accountFromMacaroon helper (which will
then test the new helper by proxy).

We add this helper so that we can use it later on from the sessions
package where we want to extract an account ID from a caveat (we wont
have a full macaroon available).
In this commit, we more tightly & explicitly link a session to an
account. At a persitance layer, we have always only linked a session to
an account by encoding the AccountID within the macaroon caveat that we
store with the session. We still keep this persistence the same but now
we first ensure that the account exists and we also add an AccountID
field to the Session struct.
@ellemouton ellemouton merged commit b65e703 into lightninglabs:master Mar 4, 2025
20 of 21 checks passed
@ellemouton ellemouton deleted the sql18Sessions10 branch March 4, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This PR is does not require a release notes entry sql-ize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants