Skip to content

[sqli-ze] sessions: atomic session creation #979

@ellemouton

Description

@ellemouton
  • Today, a session is created as follows:
    1) Lock Lit's sessRegMu mutex to ensure only one thread is trying to create a session at a time
    2) call the session store's db.GetUnusedIDAndKeyPair method to find an unused alias & private key pair.
    3) call the NewSession function to construct a new Sessions object (note: this does not touch the DB yet) .
    4) Finally, call the store's db.CreateSession method to actually go persist the new store.
    5) unlock sessRegMu.
    6) (For linked sessions: we also use the CheckSessionGroupPredicate to ensure any linked sessions are inactive.)

  • How the above flow came about: For Autopilot sessions, we wanted to make sure we could successfully register a session with Autopilot before actually going and persisting it to our DB. But at the time of registration, we already want to know the ID/Local pub key pair we will use for the session. This is why we would do all this in-memory only work before actually persisting the session. This is also why we needed to lock the mutex to ensure only one thread calls db.GetUnusedIDAndKeyPair at a time.

  • For a clean interface though, all the above should really happen atomically under a single database read transaction & we should not need to expose things like db.GetUnusedIDAndKeyPair and db.CheckSessionGroupPredicate.

  • What we will instead do is:
    - Add a new session.State: SessionReserved, which will be the new first state of a session.
    - Then, we will change NewSession to instead be a method on the Store interface. This will
    - take care of finding a unique ID/Local key pair (so we can remove that from the interface).
    - insert the new session but under the Reserved state.
    - if a group is linked, here is where we will check that all other sessions are revoked. So CheckSessionGroupPredicate can also be removed from the interface.
    - CreateSession will then only move a session from Reserved to Created.
    - On DB startup, we make sure to delete all sessions in the Reserved state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions