-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: adding device information to the session #2715
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
Conversation
7271b90
to
20cfdc7
Compare
66e9f0f
to
e60b3c9
Compare
d9595f0
to
097e9b0
Compare
Codecov Report
@@ Coverage Diff @@
## master #2715 +/- ##
==========================================
+ Coverage 75.56% 75.65% +0.09%
==========================================
Files 293 294 +1
Lines 17059 17160 +101
==========================================
+ Hits 12891 12983 +92
- Misses 3181 3187 +6
- Partials 987 990 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
...stence/sql/migrations/sql/20220907132836000000_sessions_add_client_fields.cockroach.down.sql
Outdated
Show resolved
Hide resolved
8f3d315
to
a02f67f
Compare
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.
Thank you, it's an improvement to the previous iteration! Unfortunately I still have doubts that the data model will work at scale / long-term. Can you please take a look at the comments?
Before doing any additional coding work, please post a comment with the proposed data layout (feel free to ping me in Slack) that you want to implement so that we can get it right before spending a lot of coding time. Thanks! :)
In the future, we should also stick to our design document process ( https://github.com/ory/kratos/issues/new?assignees=&labels=rfc&template=DESIGN-DOC.yml ) when foundational API and data design is being done.
persistence/sql/migratest/fixtures/session/7458af86-c1d8-401c-978a-8da89133f98b.json
Outdated
Show resolved
Hide resolved
persistence/sql/migratest/fixtures/session/7458af86-c1d8-401c-978a-8da89133f98b.json
Outdated
Show resolved
Hide resolved
persistence/sql/migratest/fixtures/session/7458af86-c1d8-401c-978a-8da89133f98b.json
Show resolved
Hide resolved
@aeneasr First the minor stuff,
I'll rename the metadata struct to Client. The initial idea was to call it a Log and the DB table session_logs (5bb40d8). This however could cause confusion in terms of how people interpreted it and I renamed it after discussion with @zepatrik.
The core idea is that it's a 1-X relationship. One session can have multiple Client/logs based on IP address assuming its a machine that is probably switching between a VPN or direct connection or perhaps different locations like coffee shops/home. The unique index for records would be SessionID + IP. (The User Agent is an unreliable piece of information to uniquely identify a device since it changes when the browser is updated for example.)
The last seen field field could be updated only if it exceeds a previous duration threshold. This could be done to save on the number of writes to the database. For example, Github doesn't give you the exact timestamp, rather that the token was used within the last week or two weeks. The current model helps represent all the IP's the session has been active at. An example below is what could be represented using the current model -
A cascade delete would help keep the records clean with history being removed along with an expired session record. Thoughts? |
8fb9728
to
8f6cfe1
Compare
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.
Perfect, just two things that could be improved in the SQL logic!
It's exiting seeing this PR progress so close to finish! |
a095cd2
to
8250495
Compare
ed1071a
to
6ee8b34
Compare
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.
minor changes to match Ory's code architecture, then it's good to go
persistence/sql/migrations/sql/20220913091948000000_sessions_devices_add_index.postgres.up.sql
Outdated
Show resolved
Hide resolved
70813fc
to
bed0602
Compare
Co-authored-by: Patrik <[email protected]>
bf10771
to
1d6d74e
Compare
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.
Awesome! If we move https://github.com/ory/kratos/pull/2715/files#diff-b496b7e4f89db676e41b419d69c98c5b1336cf9b6029e0d819e07be0a79cea28R124 to a separate function (can be private for now!) we can merge this :)
Closes ory#2091 See https://github.com/ory-corp/cloud/issues/3011 Co-authored-by: hackerman <[email protected]> Co-authored-by: Patrik <[email protected]>
This PR introduces saving device information where the session is in use - IP Address, UA, Location (if available)
The priority sequence for Client IP derivation is -
Related issue(s)
Checklist
If this pull request addresses a security. vulnerability,
I confirm that I got green light (please contact [email protected]) from the maintainers to push the changes.