You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by GitBox <gi...@apache.org> on 2021/05/04 13:12:47 UTC
[GitHub] [knox] pzampino commented on a change in pull request #445: Knox 2582
pzampino commented on a change in pull request #445:
URL: https://github.com/apache/knox/pull/445#discussion_r625756920
##########
File path: gateway-provider-security-hadoopauth/src/main/java/org/apache/knox/gateway/hadoopauth/filter/HadoopAuthFilter.java
##########
@@ -129,10 +152,27 @@ public void init(FilterConfig filterConfig) throws ServletException {
jwtFilter.init(filterConfig);
LOG.initializedJwtFilter();
}
+
+ /* get unauthenticated paths list */
+ String unAuthPathString = filterConfig.getInitParameter(HADOOP_AUTH_UNAUTHENTICATED_PATHS_PARAM);
+ /* if no list specified use default value */
+ if (StringUtils.isBlank(unAuthPathString)) {
+ unAuthPathString = DEFAULT_HADOOP_AUTH_UNAUTHENTICATED_PATHS_PARAM;
Review comment:
Should this value not always be added to the set?
##########
File path: gateway-provider-security-hadoopauth/src/main/java/org/apache/knox/gateway/hadoopauth/HadoopAuthMessages.java
##########
@@ -41,4 +41,10 @@
@Message( level = MessageLevel.DEBUG, text = "Using JWT filter to serve the request" )
void useJwtFilter();
+
+ @Message( level = MessageLevel.INFO, text = "Request {0} matches unauthenticated path list {1}, letting it through" )
+ void unauthenticatedPathBypass(String uri, String unauthPathList);
+
+ @Message( level = MessageLevel.ERROR, text = "Error {1} while checking whether path {0} should be allowed unauthenticated access" )
Review comment:
nit: I would prefer to see the error at the end of the message; I think it's clearer that way.
"Error while checking whether path {0} should be allowed unauthenticated access : {1}"
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SSOCookieFederationFilter.java
##########
@@ -146,11 +146,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
if (ssoCookies.isEmpty()) {
/* check for unauthenticated paths to bypass */
for (final String path : unAuthenticatedPaths) {
- if (req.getRequestURI().contains(path)) {
+ if (req.getPathInfo().equals(path)) {
/* This path is configured as an unauthenticated path let the request through */
final Subject sub = new Subject();
sub.getPrincipals().add(new PrimaryPrincipal("anonymous"));
- LOGGER.unauthenticatedPathBypass(path, req.getRequestURI());
+ LOGGER.unauthenticatedPathBypass(req.getRequestURI(), unAuthenticatedPaths.toString());
continueWithEstablishedSecurityContext(sub, req, res, chain);
}
Review comment:
Is a break statement needed here to terminate the for loop?
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/JWTMessages.java
##########
@@ -59,8 +59,11 @@
@Message( level = MessageLevel.DEBUG, text = "Audience claim has been validated." )
void jwtAudienceValidated();
- @Message( level = MessageLevel.INFO, text = "Path {0} is configured as unauthenticated path, letting the request {1} through" )
- void unauthenticatedPathBypass(String path, String uri);
+ @Message( level = MessageLevel.INFO, text = "Request {0} matches unauthenticated path list {1}, letting it through" )
+ void unauthenticatedPathBypass(String uri, String unauthPathList);
+
+ @Message( level = MessageLevel.ERROR, text = "Error {1} while checking whether path {0} should be allowed unauthenticated access" )
Review comment:
nit: I would prefer to see the error at the end of the message; I think it's clearer that way.
"Error while checking whether path {0} should be allowed unauthenticated access : {1}"
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java
##########
@@ -90,6 +102,18 @@ public void init( FilterConfig filterConfig ) throws ServletException {
publicKey = CertificateUtils.parseRSAPublicKey(verificationPEM);
}
+ /* get unauthenticated paths list */
+ String unAuthPathString = filterConfig.getInitParameter(JWT_UNAUTHENTICATED_PATHS_PARAM);
+ /* if no list specified use default value */
+ if (StringUtils.isBlank(unAuthPathString)) {
+ unAuthPathString = DEFAULT_JWT_UNAUTHENTICATED_PATHS_PARAM;
Review comment:
Should this not always be added to the Set?
##########
File path: gateway-provider-security-hadoopauth/src/main/java/org/apache/knox/gateway/hadoopauth/filter/HadoopAuthFilter.java
##########
@@ -201,6 +246,86 @@ public Principal getUserPrincipal() {
super.doFilter(filterChain, request, response);
}
+ /**
+ * A helper method that checks whether request contains
+ * unauthenticated path
+ * @param request
+ * @return
+ */
+ private boolean doesRequestContainUnauthPath(final ServletRequest request) {
+ for (final String path : unAuthenticatedPaths) {
+ /* make sure the path matches EXACTLY to prevent auth bypass */
+ if (((HttpServletRequest) request).getPathInfo().equals(path)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * A function that let's configured unauthenticated path requests to
+ * pass through without requiring authentication.
+ * An anonymous subject is created and the request is audited.
+ *
+ * Fail gracefully by logging error message.
+ * @param request
+ * @param response
+ * @param chain
+ */
+ private void checkForUnauthenticatedPaths(final ServletRequest request,
Review comment:
This method does not appear to be "checking" for unauthenticated paths. I think it could be more accurately named something like `handleUnauthenticatedPath` or `bypassAuthForPath`.
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java
##########
@@ -31,15 +35,22 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.Base64;
+import java.util.HashSet;
import java.util.Locale;
+import java.util.Set;
+import java.util.StringTokenizer;
public class JWTFederationFilter extends AbstractJWTFilter {
+ private static final JWTMessages LOGGER = MessagesFactory.get( JWTMessages.class );
+ /* A semicolon separated list of paths that need to bypass authentication */
+ public static final String JWT_UNAUTHENTICATED_PATHS_PARAM = "jwt.unauthenticated.path.list";
+ public static final String DEFAULT_JWT_UNAUTHENTICATED_PATHS_PARAM = "/knoxtoken/api/v1/jwks.json";
Review comment:
It would be ideal if these constants could be defined elsewhere and shared between HadoopAuthFilter and here instead of being defined in both places.
##########
File path: gateway-provider-security-hadoopauth/src/main/java/org/apache/knox/gateway/hadoopauth/filter/HadoopAuthFilter.java
##########
@@ -201,6 +246,86 @@ public Principal getUserPrincipal() {
super.doFilter(filterChain, request, response);
}
+ /**
+ * A helper method that checks whether request contains
+ * unauthenticated path
+ * @param request
+ * @return
+ */
+ private boolean doesRequestContainUnauthPath(final ServletRequest request) {
+ for (final String path : unAuthenticatedPaths) {
Review comment:
Is there a reason to not use `return unAuthenticatedPaths.contains(((HttpServletRequest) request).getPathInfo())` ?
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java
##########
@@ -186,4 +215,46 @@ protected void handleValidationError(HttpServletRequest request, HttpServletResp
}
}
+ /**
+ * A helper method that checks whether request contains
+ * unauthenticated path
+ * @param request
+ * @return
+ */
+ private boolean doesRequestContainUnauthPath(final ServletRequest request) {
+ for (final String path : unAuthenticatedPaths) {
+ if (((HttpServletRequest) request).getPathInfo().equals(path)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * A function that let's configured unauthenticated path requests to
+ * pass through without requiring authentication.
+ * An anonymous subject is created and the request is audited.
+ *
+ * Fail gracefully by logging error message.
+ * @param request
+ * @param response
+ * @param chain
+ */
+ private void checkForUnauthenticatedPaths(final ServletRequest request,
Review comment:
Same as previous comment about this method name in HadoopAuthFilter
##########
File path: gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SSOCookieFederationFilter.java
##########
@@ -146,11 +146,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
if (ssoCookies.isEmpty()) {
/* check for unauthenticated paths to bypass */
for (final String path : unAuthenticatedPaths) {
- if (req.getRequestURI().contains(path)) {
+ if (req.getPathInfo().equals(path)) {
Review comment:
Could unAuthenticatedPaths.contains(req.getPathInfo()) be employed here? Should this logic go into a util method, which could be shared across all these implementations?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org