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

KNOX-2961 - Knox SSO cookie Invalidation - Phase I #797

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

smolnar82
Copy link
Contributor

@smolnar82 smolnar82 commented Sep 29, 2023

What changes were proposed in this pull request?

The KNOXSSO service is modified in a way such that it saves the generated SSO cookie using Knox's token state service capabilities in case token management is enabled in KNOXSSO's configuration (using the well-known knox.token.exp.server-managed=true parameter).
This is only the SSO cookie generation side of the feature. The verification side also needs to be configured the same way: the SSOCookieProvider configuration must have the same parameter to enable this new feature.
In addition to the save/verify changes, the Token Management page is updated:

  • there is only one table
  • the new table contains every token (own tokens, impersonated tokens, SSO cookies)
  • from now on, impersonated tokens can be disabled, enabled, or revoked
  • SSO cookies can only be disabled (=invalidated) once. The token reaper thread cleans disabled SSO cookies even if they are not expired

How was this patch tested?

Manually tested using PAM, LDAP, and PAC4J (SAML2 and OIDC) authentication mechanisms. I flipped the knox.token.exp.server-managed to true in knoxsso, homepage, and manager topologies.
Logged into the Knox home page (contains some valid UI links in the sandbox topology) as well as opened the Token Management and Token Generation pages. I also opened a private window with the Token Management page to mimic a system administrator (a superuser who has the power to disable tokens for other users).

Confirmed that I can proxy some UIs from the Knox Home page and could generate manage tokens as usual.
Then, in the private window, I disabled the previously generated SSO cookie for my session in the non-private window and confirmed that I was redirected to the Knox login page or to my configured global logout redirect in case of Pac4j authentication (for this feature to work with Pac4j, the knox.global.logout.page.url configuration is a must-have parameter in gateway-site.xml).

This is how the Token Management page looks like with my new changes:
Screenshot 2023-10-02 at 10 18 28

Important note: as the commit message suggests, this is only the 1st phase of the job. In the 2nd one, two new improvements are coming:

  • pre-configured superusers can view tokens of others and not only theirs
  • batch operations should be able to be executed using the available actions to make it easier for a superuser to disable one's tokens in a round


private final Set<SessionInvalidator> sessionInvalidators = new HashSet<>();

public void registerSessionInvalidator(SessionInvalidator sessionInvalidator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens after a topology undeployent? Do we need to unregister the previously registered invalidator?

Copy link
Contributor Author

@smolnar82 smolnar82 Oct 2, 2023

Choose a reason for hiding this comment

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

Hmm...that's a good question. I'd believe the previously registered one will be destroyed by Jetty, but it's worth a try to see if this really happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

SessionInvalidators.KNOX_SSO_INVALIDATOR.getSessionInvalidators().forEach(sessionInvalidator -> {
sessionInvalidator.onAuthenticationError(request, response);
});
final boolean doGlobalLogout = request.getAttribute("doGlobalLogout") == null ? false
Copy link
Contributor

Choose a reason for hiding this comment

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

doGlobalLogout should be a constant, it is used in Pac4jDispatcherFilter too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

if (!disabledKnoxSsoCookies.isEmpty()) {
log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
for (String tokenId : disabledKnoxSsoCookies) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How many tokens do we expect to have normally? If it's a lot then maybe having a dedicated sql delete statement would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good argument. I also had the same idea but I wanted to have the PR out ASAP so that you guys can review it. Let me submit a new PS with the updated DELETE statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@pzampino pzampino left a comment

Choose a reason for hiding this comment

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

LGTM

@smolnar82 smolnar82 merged commit c49302a into apache:master Oct 6, 2023
2 checks passed
@smolnar82 smolnar82 deleted the KNOX-2961 branch October 6, 2023 07:23
stoty pushed a commit to stoty/knox that referenced this pull request May 14, 2024
…#797)

Change-Id: I67a65224dfac4178e5aedd187a3a1cdafb162727
stoty pushed a commit to stoty/knox that referenced this pull request May 14, 2024
…into cdpd-master

* changes:
  CDPD-62588, KNOX-2972: Session resource can generate application logout URL with profile/topologies query parameters (apache#808)
  CDPD-62595, KNOX-2970: Removing KnoxSSO cookie from the token state service upon logout (apache#806)
  CDPD-62598, KNOX-2971: Applying word wrapping in the comment and metadata columns on the Token Management UI (apache#807)
  CDPD-62592, KNOX-2969: KnoxSSO Cookies should be ignored while calculating token limit per user (apache#805)
  CDPD-62585, KNOX-2968: Batch token enable action should succeed even if enabled KnoxSSO cookies are selected (apache#804)
  CDPD-61809, KNOX-2961: Knox SSO cookie Invalidation - Phase II (apache#799)
  CDPD-61184, KNOX-2961: Knox SSO cookie Invalidation - Phase I (apache#797)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants