You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by "smolnar82 (via GitHub)" <gi...@apache.org> on 2023/09/29 10:04:58 UTC
[GitHub] [knox] smolnar82 opened a new pull request, #797: KNOX-2961 - Knox SSO cookie Invalidation - Phase I
smolnar82 opened a new pull request, #797:
URL: https://github.com/apache/knox/pull/797
## What changes were proposed in this pull request?
TODO
## How was this patch tested?
TODO
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "pzampino (via GitHub)" <gi...@apache.org>.
pzampino commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1343020603
##########
gateway-release/home/conf/topologies/manager.xml:
##########
@@ -51,6 +51,11 @@
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
Should this really be enabled OOTB?
##########
gateway-release/home/conf/topologies/knoxsso.xml:
##########
@@ -114,6 +114,11 @@
<name>knoxsso.token.ttl</name>
<value>86400000</value>
</param>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
Should this really be enabled OOTB?
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,19 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ final int numOfRemovedDisabledKnoxSsoCookies = tokenDatabase.deleteDisabledKnoxSsoCookies();
Review Comment:
Is there a possibility that SSO tokens were disabled between the get and this deletion, such that the log would not accurately reflect the set of deleted tokens?
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateServiceMessages.java:
##########
@@ -202,6 +202,15 @@ public interface TokenStateServiceMessages {
@Message(level = MessageLevel.ERROR, text = "An error occurred while removing expired tokens from the database : {0}")
void errorRemovingTokensFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
+ @Message(level = MessageLevel.INFO, text = "Removing {0} disabled KnoxSSO cookie(s) from the database: {1}")
+ void removingDisabledKnoxSsoCookiesFromDatabase(int size, String disabledKnoxSsoCookieList);
+
+ @Message(level = MessageLevel.DEBUG, text = "{0} disabled KnoxSSO cookies have been removed from the database")
+ void removedDisabledKnoxSsoCookiesFromDatabase(int size);
+
+ @Message(level = MessageLevel.ERROR, text = "An error occurred while removing disabled KnoxSSO cookies from the database : {0}")
+ void errorRemovingDisabledKnoxSsoCookiesFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
Review Comment:
Should this error message be DEBUG level?
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -383,6 +384,23 @@ protected Set<String> getExpiredTokens() {
return expiredTokens;
}
+ protected Set<String> getDisabledKnoxSsoCookies() {
+ final Set<String> disbaledKnoxSsoCookies = new HashSet<>();
Review Comment:
typo: disbaled --> disabled
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -350,11 +350,12 @@ private String getTimestampDisplay(long timestamp) {
}
/**
- * Method that deletes expired tokens based on the token timestamp.
+ * Method that deletes expired tokens based on the token timestamp as well as disabled KnoxSSO cookies.
*/
protected void evictExpiredTokens() {
if (readyForEviction()) {
final Set<String> tokensToEvict = getExpiredTokens();
+ tokensToEvict.addAll(getDisabledKnoxSsoCookies());
Review Comment:
Does this result in an unknown token error if a client tries to use a not-yet-expired token which has been disabled and evicted?
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java:
##########
@@ -58,6 +58,9 @@ public class TokenStateDatabase {
private static final String GET_TOKENS_CREATED_BY_USER_NAME_SQL = "SELECT kt.token_id, kt.issue_time, kt.expiration, kt.max_lifetime, ktm.md_name, ktm.md_value FROM " + TOKENS_TABLE_NAME
+ " kt, " + TOKEN_METADATA_TABLE_NAME + " ktm WHERE kt.token_id = ktm.token_id AND kt.token_id IN (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " WHERE md_name = '" + TokenMetadata.CREATED_BY + "' AND md_value = ? )"
+ " ORDER BY kt.issue_time";
+ private static final String GET_DISABLED_SSO_COOKIE_TOKEN_IDS = "SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta1 WHERE meta1.md_name = 'knoxSSOCookie' AND meta1.md_value = 'true' "
+ + "AND EXISTS (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta2 WHERE meta1.token_id = meta2.token_id AND meta2.md_name = 'enabled' AND meta2.md_value = 'false')";
+ private static final String REMOVE_DISBLED_SSO_COOKIES_SQL = "DELETE FROM " + TOKENS_TABLE_NAME + " WHERE token_id IN (" + GET_DISABLED_SSO_COOKIE_TOKEN_IDS + ")";
Review Comment:
typo? : DISBLED
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidator.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public interface SessionInvalidator {
Review Comment:
I think some javadoc for this interface would be helpful, at least explaining its intended usage and any expectations from implementations.
##########
gateway-release/home/conf/topologies/homepage.xml:
##########
@@ -55,6 +55,11 @@
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
Should this really be enabled OOTB?
Is it possible some may not want (by default) the additional overhead associated with keeping the token state for SSO in deployments where it isn't necessary.
Is the default token state service implementation in-memory? Just wondering if the typical number of SSO tokens could lead to OOM issues OOTB.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1343190787
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -350,11 +350,12 @@ private String getTimestampDisplay(long timestamp) {
}
/**
- * Method that deletes expired tokens based on the token timestamp.
+ * Method that deletes expired tokens based on the token timestamp as well as disabled KnoxSSO cookies.
*/
protected void evictExpiredTokens() {
if (readyForEviction()) {
final Set<String> tokensToEvict = getExpiredTokens();
+ tokensToEvict.addAll(getDisabledKnoxSsoCookies());
Review Comment:
Hmm...this seems to be not needed; I'll conduct another test round tomorrow morning.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "pzampino (via GitHub)" <gi...@apache.org>.
pzampino commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1344143622
##########
gateway-release/home/conf/topologies/homepage.xml:
##########
@@ -55,6 +55,11 @@
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
My mistake :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1342884637
##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SSOCookieFederationFilter.java:
##########
@@ -188,8 +194,25 @@ private void sendRedirectToLoginURL(HttpServletRequest request, HttpServletRespo
}
@Override
- protected void handleValidationError(HttpServletRequest request, HttpServletResponse response,
- int status, String error) throws IOException {
+ protected void handleValidationError(HttpServletRequest request, HttpServletResponse response, int status, String error) throws IOException {
+ if (error != null && error.startsWith("Token") && error.endsWith("disabled")) {
+ LOGGER.invalidSsoCookie();
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ removeAuthenticationToken(request, response);
+ SessionInvalidators.KNOX_SSO_INVALIDATOR.getSessionInvalidators().forEach(sessionInvalidator -> {
+ sessionInvalidator.onAuthenticationError(request, response);
+ });
+ final boolean doGlobalLogout = request.getAttribute("doGlobalLogout") == null ? false
Review Comment:
Fixed.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,20 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ for (String tokenId : disabledKnoxSsoCookies) {
Review Comment:
Fixed.
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidators.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public enum SessionInvalidators {
+
+ KNOX_SSO_INVALIDATOR;
+
+ private final Set<SessionInvalidator> sessionInvalidators = new HashSet<>();
+
+ public void registerSessionInvalidator(SessionInvalidator sessionInvalidator) {
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1343107208
##########
gateway-release/home/conf/topologies/knoxsso.xml:
##########
@@ -114,6 +114,11 @@
<name>knoxsso.token.ttl</name>
<value>86400000</value>
</param>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
The value is set to `false`.
##########
gateway-release/home/conf/topologies/homepage.xml:
##########
@@ -55,6 +55,11 @@
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
The value is set to `false`.
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidator.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public interface SessionInvalidator {
Review Comment:
Fair enough; I'll add the missing docs.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java:
##########
@@ -58,6 +58,9 @@ public class TokenStateDatabase {
private static final String GET_TOKENS_CREATED_BY_USER_NAME_SQL = "SELECT kt.token_id, kt.issue_time, kt.expiration, kt.max_lifetime, ktm.md_name, ktm.md_value FROM " + TOKENS_TABLE_NAME
+ " kt, " + TOKEN_METADATA_TABLE_NAME + " ktm WHERE kt.token_id = ktm.token_id AND kt.token_id IN (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " WHERE md_name = '" + TokenMetadata.CREATED_BY + "' AND md_value = ? )"
+ " ORDER BY kt.issue_time";
+ private static final String GET_DISABLED_SSO_COOKIE_TOKEN_IDS = "SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta1 WHERE meta1.md_name = 'knoxSSOCookie' AND meta1.md_value = 'true' "
+ + "AND EXISTS (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta2 WHERE meta1.token_id = meta2.token_id AND meta2.md_name = 'enabled' AND meta2.md_value = 'false')";
+ private static final String REMOVE_DISBLED_SSO_COOKIES_SQL = "DELETE FROM " + TOKENS_TABLE_NAME + " WHERE token_id IN (" + GET_DISABLED_SSO_COOKIE_TOKEN_IDS + ")";
Review Comment:
I'll fix that.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateServiceMessages.java:
##########
@@ -202,6 +202,15 @@ public interface TokenStateServiceMessages {
@Message(level = MessageLevel.ERROR, text = "An error occurred while removing expired tokens from the database : {0}")
void errorRemovingTokensFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
+ @Message(level = MessageLevel.INFO, text = "Removing {0} disabled KnoxSSO cookie(s) from the database: {1}")
+ void removingDisabledKnoxSsoCookiesFromDatabase(int size, String disabledKnoxSsoCookieList);
+
+ @Message(level = MessageLevel.DEBUG, text = "{0} disabled KnoxSSO cookies have been removed from the database")
+ void removedDisabledKnoxSsoCookiesFromDatabase(int size);
+
+ @Message(level = MessageLevel.ERROR, text = "An error occurred while removing disabled KnoxSSO cookies from the database : {0}")
+ void errorRemovingDisabledKnoxSsoCookiesFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
Review Comment:
The error itself is on the `ERROR` level. The stack trace which we bind to `DEBUG`, just like we do in many other cases across the code.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -350,11 +350,12 @@ private String getTimestampDisplay(long timestamp) {
}
/**
- * Method that deletes expired tokens based on the token timestamp.
+ * Method that deletes expired tokens based on the token timestamp as well as disabled KnoxSSO cookies.
*/
protected void evictExpiredTokens() {
if (readyForEviction()) {
final Set<String> tokensToEvict = getExpiredTokens();
+ tokensToEvict.addAll(getDisabledKnoxSsoCookies());
Review Comment:
It was working properly during my tests, but let me give it another try/thought.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,19 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ final int numOfRemovedDisabledKnoxSsoCookies = tokenDatabase.deleteDisabledKnoxSsoCookies();
Review Comment:
Yeah, there is a small chance for that. But this is also true for the expired tokens above too.
##########
gateway-release/home/conf/topologies/manager.xml:
##########
@@ -51,6 +51,11 @@
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
+ <param>
+ <!-- since 2.1.0: KnoxSSO cookie validation -->
+ <name>knox.token.exp.server-managed</name>
Review Comment:
The value is set to `false`.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -383,6 +384,23 @@ protected Set<String> getExpiredTokens() {
return expiredTokens;
}
+ protected Set<String> getDisabledKnoxSsoCookies() {
+ final Set<String> disbaledKnoxSsoCookies = new HashSet<>();
Review Comment:
I'll fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "pzampino (via GitHub)" <gi...@apache.org>.
pzampino commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1344141479
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateServiceMessages.java:
##########
@@ -202,6 +202,15 @@ public interface TokenStateServiceMessages {
@Message(level = MessageLevel.ERROR, text = "An error occurred while removing expired tokens from the database : {0}")
void errorRemovingTokensFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
+ @Message(level = MessageLevel.INFO, text = "Removing {0} disabled KnoxSSO cookie(s) from the database: {1}")
+ void removingDisabledKnoxSsoCookiesFromDatabase(int size, String disabledKnoxSsoCookieList);
+
+ @Message(level = MessageLevel.DEBUG, text = "{0} disabled KnoxSSO cookies have been removed from the database")
+ void removedDisabledKnoxSsoCookiesFromDatabase(int size);
+
+ @Message(level = MessageLevel.ERROR, text = "An error occurred while removing disabled KnoxSSO cookies from the database : {0}")
+ void errorRemovingDisabledKnoxSsoCookiesFromDatabase(String errorMessage, @StackTrace(level = MessageLevel.DEBUG) Exception e);
Review Comment:
Ack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 merged PR #797:
URL: https://github.com/apache/knox/pull/797
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "zeroflag (via GitHub)" <gi...@apache.org>.
zeroflag commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1342597594
##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SSOCookieFederationFilter.java:
##########
@@ -188,8 +194,25 @@ private void sendRedirectToLoginURL(HttpServletRequest request, HttpServletRespo
}
@Override
- protected void handleValidationError(HttpServletRequest request, HttpServletResponse response,
- int status, String error) throws IOException {
+ protected void handleValidationError(HttpServletRequest request, HttpServletResponse response, int status, String error) throws IOException {
+ if (error != null && error.startsWith("Token") && error.endsWith("disabled")) {
+ LOGGER.invalidSsoCookie();
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ removeAuthenticationToken(request, response);
+ SessionInvalidators.KNOX_SSO_INVALIDATOR.getSessionInvalidators().forEach(sessionInvalidator -> {
+ sessionInvalidator.onAuthenticationError(request, response);
+ });
+ final boolean doGlobalLogout = request.getAttribute("doGlobalLogout") == null ? false
Review Comment:
`doGlobalLogout` should be a constant, it is used in `Pac4jDispatcherFilter` too.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,20 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ for (String tokenId : disabledKnoxSsoCookies) {
Review Comment:
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.
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidators.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public enum SessionInvalidators {
+
+ KNOX_SSO_INVALIDATOR;
+
+ private final Set<SessionInvalidator> sessionInvalidators = new HashSet<>();
+
+ public void registerSessionInvalidator(SessionInvalidator sessionInvalidator) {
Review Comment:
What happens after a topology undeployent? Do we need to unregister the previously registered invalidator?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1343562115
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,19 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ final int numOfRemovedDisabledKnoxSsoCookies = tokenDatabase.deleteDisabledKnoxSsoCookies();
Review Comment:
I removed that method anyway.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java:
##########
@@ -58,6 +58,9 @@ public class TokenStateDatabase {
private static final String GET_TOKENS_CREATED_BY_USER_NAME_SQL = "SELECT kt.token_id, kt.issue_time, kt.expiration, kt.max_lifetime, ktm.md_name, ktm.md_value FROM " + TOKENS_TABLE_NAME
+ " kt, " + TOKEN_METADATA_TABLE_NAME + " ktm WHERE kt.token_id = ktm.token_id AND kt.token_id IN (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " WHERE md_name = '" + TokenMetadata.CREATED_BY + "' AND md_value = ? )"
+ " ORDER BY kt.issue_time";
+ private static final String GET_DISABLED_SSO_COOKIE_TOKEN_IDS = "SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta1 WHERE meta1.md_name = 'knoxSSOCookie' AND meta1.md_value = 'true' "
+ + "AND EXISTS (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta2 WHERE meta1.token_id = meta2.token_id AND meta2.md_name = 'enabled' AND meta2.md_value = 'false')";
+ private static final String REMOVE_DISBLED_SSO_COOKIES_SQL = "DELETE FROM " + TOKENS_TABLE_NAME + " WHERE token_id IN (" + GET_DISABLED_SSO_COOKIE_TOKEN_IDS + ")";
Review Comment:
Removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1342649405
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidators.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public enum SessionInvalidators {
+
+ KNOX_SSO_INVALIDATOR;
+
+ private final Set<SessionInvalidator> sessionInvalidators = new HashSet<>();
+
+ public void registerSessionInvalidator(SessionInvalidator sessionInvalidator) {
Review Comment:
Hm...that's a good question. I'd believe the previously registered one will be destroyed by Jetty, but it worth a try to see if this really happens.
##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidators.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public enum SessionInvalidators {
+
+ KNOX_SSO_INVALIDATOR;
+
+ private final Set<SessionInvalidator> sessionInvalidators = new HashSet<>();
+
+ public void registerSessionInvalidator(SessionInvalidator sessionInvalidator) {
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KNOX-2961 - Knox SSO cookie Invalidation - Phase I [knox]
Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1342647777
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,20 @@ protected void evictExpiredTokens() {
} catch (SQLException e) {
log.errorRemovingTokensFromDatabase(e.getMessage(), e);
}
+
+ //removing disabled KnoxSSO cookies since they are no longer needed
+ try {
+ final Set<String> disabledKnoxSsoCookies = tokenDatabase.getDisabledKnoxSsoCookies();
+ if (!disabledKnoxSsoCookies.isEmpty()) {
+ log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+ String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+ for (String tokenId : disabledKnoxSsoCookies) {
Review Comment:
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.
##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SSOCookieFederationFilter.java:
##########
@@ -188,8 +194,25 @@ private void sendRedirectToLoginURL(HttpServletRequest request, HttpServletRespo
}
@Override
- protected void handleValidationError(HttpServletRequest request, HttpServletResponse response,
- int status, String error) throws IOException {
+ protected void handleValidationError(HttpServletRequest request, HttpServletResponse response, int status, String error) throws IOException {
+ if (error != null && error.startsWith("Token") && error.endsWith("disabled")) {
+ LOGGER.invalidSsoCookie();
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ removeAuthenticationToken(request, response);
+ SessionInvalidators.KNOX_SSO_INVALIDATOR.getSessionInvalidators().forEach(sessionInvalidator -> {
+ sessionInvalidator.onAuthenticationError(request, response);
+ });
+ final boolean doGlobalLogout = request.getAttribute("doGlobalLogout") == null ? false
Review Comment:
Ack.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@knox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org