camunda / camunda-bpm-platform

Flexible framework for workflow and decision automation with BPMN and DMN. Integration with Quarkus, Spring, Spring Boot, CDI.
https://camunda.com/
Apache License 2.0
4.12k stars 1.56k forks source link

OAuth2 session is not revalidated #4585

Closed tasso94 closed 1 month ago

tasso94 commented 2 months ago

Environment (Required on creation)

Camunda Run with OAuth2.

Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket)

When logging out from Cognito:

https://camunda-run.auth.us-east-1.amazoncognito.com/logout?response_type=code&client_id=$CLIENT_ID&scope=openid&redirect_uri=http://localhost:8080/

Replace $CLIENT_ID with what you can find in spring.security.oauth2.client.registration.

... the user is still logged in to the web apps.

Steps to reproduce (Required on creation)

Observed Behavior (Required on creation)

User is still logged in.

Expected behavior (Required on creation)

User should be logged out.

Root Cause (Required on prioritization)

Not clear. I guess the authentication is cached forever. Maybe we need to implement something like https://github.com/camunda/camunda-bpm-platform/issues/3146 here as well.

Solution Ideas

  1. Implement something similar to #3146.
  2. Configure session cookie max age 5 minutes (might be problematic when running multiple webapps within one Spring Boot application or when the user changes it again).
  3. Maybe there is some Spring Security built-in mechanism to solve this which ensures the authentications are revalidated periodically.

Hints

It only works when logging out from Cognito first and using the OAuth2 Spring Security Logout URL second: http://localhost:8080/logout

Like this, the session cookie is cleared.

However, this is not acceptable because it requires another User action. When the identity provider forces a logout or removes the user, Camunda should check regularly if the user is still valid.

Links

Breakdown

### Pull Requests
- [ ] https://github.com/camunda/camunda-bpm-platform/pull/4603

Dev2QA handover

danielkelemen commented 1 month ago

Notes

OAuth2 works with tokens for authentication and Spring Security is fully supporting this. Tokens have a lifetime until they are valid, this is the exp claim, for instance: exp=2024-09-09T16:13:05Z. This lifetime is configurable in the identity providers, including the usage of refresh tokens. Cognito & OKTA default is 1h.

General security recommendation is to use short-lived access tokens combined with long-lived refresh tokens. With refresh tokens applications can renew access tokens but they can be revoked and the refresh mechanism won't work when the user is not logged in anymore in SSO.

Articles:

OIDC Back Channel Logout

Details

OpenID Connect Session Management 1.0 allows the ability to log out the end user at the Client by having the Provider make an API call to the Client. This is referred to as - Spring Security feature: https://github.com/spring-projects/spring-security/issues/7845 - Spring Security docs: https://docs.spring.io/spring-security/reference/reactive/oauth2/login/logout.html#configure-provider-initiated-oidc-logout

Outcome:

Spring Security & Okta Configurations

Resources:

Outcome:

danielkelemen commented 1 month ago

Dev2QA

Make sure no expired access token is used in the application. Our filter logs the expiration, you can activate debug log in application.yaml with:

logging:
  level:
    org.camunda.bpm.spring.boot.starter.security.oauth2: DEBUG

Notes:

gbetances089 commented 1 month ago

Verified on camunda-bpm-run-ee-7.22.0-20240919.175253-98