Skip to content

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

Merged
ellemouton merged 4 commits into
lightninglabs:masterfrom
ellemouton:sql18Sessions10
Mar 4, 2025
Merged

ellemouton merged 4 commits into
lightninglabs:masterfrom
ellemouton:sql18Sessions10

Conversation

@ellemouton

@ellemouton ellemouton commented Feb 27, 2025 •

Copy link
Copy Markdown
Contributor

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

@ViktorT-11 ViktorT-11 left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread session/kvdb_store.go
Comment thread session/test_kvdb.go Outdated
Comment thread accounts/interceptor.go
@ellemouton
ellemouton force-pushed the sql18Sessions10 branch 2 times, most recently from 638c03c to 021daae Compare February 28, 2025 12:18

@ViktorT-11 ViktorT-11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uTACK LGTM 🚀🎉

@bitromortac bitromortac left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread accounts/interceptor.go Outdated
string(caveatPrefix),
2,
)
if len(caveatSplit) == 2 {

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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.

Comment thread accounts/interceptor_test.go
Comment thread session/kvdb_store.go Outdated
Comment thread session/store_test.go Outdated
Comment thread session_rpcserver.go
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
@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.

4 participants