Skip to content

oidclogout #21718

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 5 commits into from
Mar 18, 2025
Merged

oidclogout #21718

merged 5 commits into from
Mar 18, 2025

Conversation

wy65701436
Copy link
Contributor

enable oidc session logout

1, give the option of logging out user session from OIDC provider. 2, give the option of logging out user offline session from OIDC provider.

Thank you for contributing to Harbor!

Comprehensive Summary of your change

Issue being fixed

Fixes #(issue)

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

@wy65701436 wy65701436 added the target/2.13.0 issues that are targeting v2.13.0 label Mar 11, 2025
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.24%. Comparing base (c8c11b4) to head (7cae7be).
Report is 414 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #21718      +/-   ##
==========================================
+ Coverage   45.36%   46.24%   +0.87%     
==========================================
  Files         244      250       +6     
  Lines       13333    14150     +817     
  Branches     2719     2913     +194     
==========================================
+ Hits         6049     6543     +494     
- Misses       6983     7260     +277     
- Partials      301      347      +46     
Flag Coverage Δ
unittests 46.24% <ø> (+0.87%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 494 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@reasonerjt
Copy link
Contributor

Could you explain the difference between "oidc session" and "oidc offline session"?

securityCtx, ok := security.FromContext(cc.Context())
if !ok {
log.Error("Failed to get security context")
cc.CustomAbort(http.StatusInternalServerError, "Internal error.")
Copy link
Member

Choose a reason for hiding this comment

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

Can we not have a precise error message, explaining what actually went wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the 500 error, we used to only provide more details in the log and not expose them further.

Copy link
Member

Choose a reason for hiding this comment

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

does exposing the error, provide a threat, or might help the user to resolve the issue himself?

@wy65701436
Copy link
Contributor Author

Could you explain the difference between "oidc session" and "oidc offline session"?

According to the OpenID Connect RP-Initiated Logout specification, RP-Initiated Logout should be performed by sending a request to the end_session_endpoint with the ID token. This approach is generally defined in the OpenID specification for all IdPs to properly terminate user sessions.

Based on the Keycloak documentation and what I observed, specifically the section on offline access, an offline session is treated like an active session, created during user authentication with the offline_access scope. To revoke an offline session, a POST request must be made to the revoke endpoint. Since I’ve only tested with Keycloak, I’m uncertain whether other IdPs follow the same flow. As this behavior isn't explicitly defined in the OpenID specification, I’ve included an option (checkbox) for logging out offline sessions.

@wy65701436 wy65701436 force-pushed the oidcbase branch 2 times, most recently from bb9a4e4 to 06dbd3c Compare March 12, 2025 05:58
@reasonerjt
Copy link
Contributor

reasonerjt commented Mar 12, 2025

Based on the Keycloak documentation and what I observed, specifically the section on offline access, an offline session is treated like an active session, created during user authentication with the offline_access scope. To revoke an offline session, a POST request must be made to the revoke endpoint. Since I’ve only tested with Keycloak, I’m uncertain whether other IdPs follow the same flow. As this behavior isn't explicitly defined in the OpenID specification, I’ve included an option (checkbox) for logging out offline sessions.

I need to look into the details of the code for other parts, but IMO in this release we don't need to distinguish "OIDC session" and "offline session". I don't think of a use case where the user wants to end his "OIDC session" but keep the "offline session". I think we should just provide the option for the user to end "OIDC session" when he logs out from Harbor, and we always end the "offline session" when the "OIDC session" is terminated. This seems intuitive enough for me, and we won't need to debug the corner case like user log out without ending the "offline session" and login again which the ID provider may or may not terminate the existing offline session, which may impact the use case for "CLI secret"

@wy65701436
Copy link
Contributor Author

Based on the Keycloak documentation and what I observed, specifically the section on offline access, an offline session is treated like an active session, created during user authentication with the offline_access scope. To revoke an offline session, a POST request must be made to the revoke endpoint. Since I’ve only tested with Keycloak, I’m uncertain whether other IdPs follow the same flow. As this behavior isn't explicitly defined in the OpenID specification, I’ve included an option (checkbox) for logging out offline sessions.

I need to look into the details of the code for other parts, but IMO in this release we don't need to distinguish "OIDC session" and "offline session". I don't think of a use case where the user wants to end his "OIDC session" but keep the "offline session". I think we should just provide the option for the user to end "OIDC session" when he logs out from Harbor, and we always end the "offline session" when the "OIDC session" is terminated. This seems intuitive enough for me, and we won't need to debug the corner case like user log out without ending the "offline session" and login again which the ID provider may or may not terminate the existing offline session, which may impact the use case for "CLI secret"

Sure, I will remove the option for logging out the offline session and treat it as a "nice-to-have" flow.

enable oidc session logout

1, give the option of logging out user session from OIDC provider.
2, give the option of logging out user offline session from OIDC provider.

Signed-off-by: wang yan <[email protected]>
Signed-off-by: wang yan <[email protected]>
Signed-off-by: wang yan <[email protected]>
@wy65701436 wy65701436 force-pushed the oidcbase branch 3 times, most recently from 34a5c0d to e88adfe Compare March 17, 2025 06:27
@wy65701436 wy65701436 force-pushed the oidcbase branch 2 times, most recently from f4af7d2 to 84935bd Compare March 17, 2025 11:34
Signed-off-by: wang yan <[email protected]>
@wy65701436 wy65701436 merged commit 5960bc8 into goharbor:main Mar 18, 2025
12 checks passed
@Nicolfo
Copy link

Nicolfo commented May 21, 2025

I'm following this issue since I want to use Harbor with Keycloak as OIDC provider.
I've a question concerning the use of offline access functionality (to support CLI) in conjunction with OIDC RP-initiated logout.

The first thing I tried was enabling the OIDC Session Logout flag (to complete a correct RP-initiated logout) and requesting an offline_access scope. My expected behaviour is that after a logout from the web portal I can continue to use the CLI secret throught docker cli, but this is valid only for a short amount of time (tokens remaining lifespan).

If I remove the flag from OIDC Session Logout CLI secret continue to work (since I'm not terminate the session/revoking the offline token), but I completely lose the track of my offline sessions (every login create a new session) and the only way to revoke them is manually throught the keycloak console.
I don't think it is accettable to not perform complete logout with OIDC when the user terminate session with Harbor, since offline token exist to solve this specific problem.

Is there a way to setup Harbor to perform somewhere similar to AWS cli, where the two session (docker credential and browser) are generated in two different way (oauth2.0 code flow and cli secret request)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/new-feature New Harbor Feature target/2.13.0 issues that are targeting v2.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants