Skip to content
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

feat: Add session renew capabilities, #615 #2146

Merged
merged 23 commits into from
Mar 28, 2022

Conversation

abador
Copy link
Contributor

@abador abador commented Jan 14, 2022

Add session renew to kratos:

  • whoami
  • renew by session id
  • renew by current session

Related issue(s)

#615

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    security@ory.sh) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

It's a follow-up after this pr on our repo: Wikia#48

@abador abador changed the title Add session renew capabilities, issue-615 feat: Add session renew capabilities, issue-615 Jan 14, 2022
@abador abador changed the title feat: Add session renew capabilities, issue-615 feat: Add session renew capabilities, #615 Jan 14, 2022
@abador abador force-pushed the issue-615-session-renew branch from 647d112 to 9aa0d49 Compare January 14, 2022 14:20
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Great job! Just a few notes :) Could you please also add a guide to the docs how to use this feature?

driver/config/config.go Outdated Show resolved Hide resolved
driver/config/config.go Outdated Show resolved Hide resolved
internal/testhelpers/handler_mock.go Outdated Show resolved Hide resolved
driver/config/config.go Outdated Show resolved Hide resolved
session/session.go Outdated Show resolved Hide resolved
@abador
Copy link
Contributor Author

abador commented Jan 18, 2022

@aeneasr tests are failing, but this doesn't seem to be caused by my changes(except for prettier). More docs added in here

@aeneasr
Copy link
Member

aeneasr commented Jan 21, 2022

session/handler_test.go Outdated Show resolved Hide resolved
session/handler.go Outdated Show resolved Hide resolved
abador and others added 2 commits January 25, 2022 09:34
Co-authored-by: hackerman <3372410+aeneasr@users.noreply.github.com>
session/handler.go Outdated Show resolved Hide resolved
@aeneasr aeneasr force-pushed the issue-615-session-renew branch from 919f315 to d535f97 Compare February 3, 2022 16:21
Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Thank you! This is looking grand! I just have two minor things regarding the API route structure :)

ID string `json:"id"`
}

// swagger:route PATCH /sessions/refresh/{id} v0alpha2 adminSessionRefresh
Copy link
Member

Choose a reason for hiding this comment

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

We try to have structure with REST resource model, so this would be:

Suggested change
// swagger:route PATCH /sessions/refresh/{id} v0alpha2 adminSessionRefresh
// swagger:route PATCH /sessions/{id}/refresh v0alpha2 adminRefreshSession

or

Suggested change
// swagger:route PATCH /sessions/refresh/{id} v0alpha2 adminSessionRefresh
// swagger:route PATCH /sessions/{id}?refresh=true v0alpha2 adminRefreshSession

Comment on lines 500 to 501
// Calling this endpoint refreshes a given session.
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Calling this endpoint refreshes a given session.
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.
// Calling this endpoint refreshes the given session ID.
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.

Comment on lines 503 to 505
// This endpoint is useful for:
//
// - Session refresh
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// This endpoint is useful for:
//
// - Session refresh

Comment on lines 538 to 552
// swagger:route PATCH /sessions/refresh v0alpha2 adminCurrentSessionRefresh
//
// Calling this endpoint refreshes a given session.
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.
//
// This endpoint is useful for:
//
// - Session refresh
//
// Schemes: http, https
//
// Security:
// oryAccessToken:
//
// Responses:
Copy link
Member

Choose a reason for hiding this comment

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

I think this route would currently cause a conflict with the other session routes? I would suggest:

Suggested change
// swagger:route PATCH /sessions/refresh v0alpha2 adminCurrentSessionRefresh
//
// Calling this endpoint refreshes a given session.
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.
//
// This endpoint is useful for:
//
// - Session refresh
//
// Schemes: http, https
//
// Security:
// oryAccessToken:
//
// Responses:
// swagger:route PATCH /sessions?refresh=true v0alpha2 adminRefreshSessionFromCredentials
//
// Calling this endpoint you can refresh an Ory Session Cookie or Ory Session Token. You must
// include the Ory Session Token in the `Cookie` header or the Ory Session Token in the `X-Session-Token`
// header.
//
// If `session.earliest_refresh` is set it will only refresh the session after this time has passed.
//
// Schemes: http, https
//
// Security:
// oryAccessToken:
//
// Responses:

Please also add these keys (x-session-token, cookie) to the argument this method can receive (see the whoami endpoint for an example) :)

@hero101
Copy link

hero101 commented Feb 18, 2022

What is the status of this PR - is it stale? We are also investigating this and are interested in it.

@aeneasr
Copy link
Member

aeneasr commented Feb 18, 2022

If you want to pick this up please feel free to do so! :)

@codecov
Copy link

codecov bot commented Mar 28, 2022

Codecov Report

Merging #2146 (890765b) into master (b5b1361) will decrease coverage by 0.02%.
The diff coverage is 91.89%.

❗ Current head 890765b differs from pull request most recent head 60fab42. Consider uploading reports for the commit 60fab42 to get more accurate results

@@            Coverage Diff             @@
##           master    #2146      +/-   ##
==========================================
- Coverage   76.62%   76.59%   -0.03%     
==========================================
  Files         318      318              
  Lines       17190    17217      +27     
==========================================
+ Hits        13171    13187      +16     
- Misses       3087     3097      +10     
- Partials      932      933       +1     
Impacted Files Coverage Δ
session/handler.go 71.34% <87.50%> (+1.27%) ⬆️
driver/config/config.go 81.75% <100.00%> (+0.06%) ⬆️
internal/testhelpers/handler_mock.go 91.01% <100.00%> (+0.31%) ⬆️
session/session.go 71.11% <100.00%> (-10.07%) ⬇️
persistence/sql/persister_courier.go 88.33% <0.00%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5b1361...60fab42. Read the comment docs.

@aeneasr
Copy link
Member

aeneasr commented Mar 28, 2022

I don't think that we can add the refresh functionality as it is right now to /session/whoami. It is basically vulnerable to CSRF attacks where an attacker could trick a user into indefinitely refreshing a session. I will probably merge the possibility to refresh a session given the session ID using the admin API only.

identity/handler.go Outdated Show resolved Hide resolved
@hero101
Copy link

hero101 commented Mar 28, 2022

I don't think that we can add the refresh functionality as it is right now to /session/whoami. It is basically vulnerable to CSRF attacks where an attacker could trick a user into indefinitely refreshing a session. I will probably merge the possibility to refresh a session given the session ID using the admin API only.

Great to see this is making progress. I believe that the admin API refresh capabilities will cover most of the use cases.
Any ideas when will this be released in order for us to push it down our pipelines as well?

@aeneasr
Copy link
Member

aeneasr commented Mar 28, 2022

Great to see this is making progress. I believe that the admin API refresh capabilities will cover most of the use cases.
Any ideas when will this be released in order for us to push it down our pipelines as well?

I'll try to get this merged before my vacation

@aeneasr aeneasr merged commit 4348b86 into ory:master Mar 28, 2022
harnash pushed a commit to Wikia/kratos that referenced this pull request Mar 28, 2022
Closes ory#615 

Co-authored-by: hackerman <3372410+aeneasr@users.noreply.github.com>
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
Closes ory#615 

Co-authored-by: hackerman <3372410+aeneasr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants