neils-dev commented on a change in pull request #2655:
URL: https://github.com/apache/ozone/pull/2655#discussion_r718076845



##########
File path: 
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/UgiFilter.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.hadoop.ozone.s3;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.ozone.OzoneSecurityUtil;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.signature.SignatureInfo;
+import org.apache.hadoop.ozone.s3.signature.StringToSignProducer;
+import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Enumeration;
+import org.apache.hadoop.ozone.s3.signature.AWSSignatureProcessor;
+
+import com.google.common.annotations.VisibleForTesting;
+import static 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMTokenProto.Type.S3AUTHINFO;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.MALFORMED_HEADER;
+
+/**
+ * Preprocessing filter for every request.
+ * - creates OzoneToken containing aws signature
+ * aws id and stringToSign for aws authenication;  stores OzoneToken in
+ * thread local variable (UserGroupInformation object) avail to all
+ * s3 rest command endpoints
+ */
+public class UgiFilter implements Filter {
+  public static final Logger LOG = LoggerFactory.getLogger(UgiFilter.class);
+
+  @Inject
+  private OzoneConfiguration ozoneConfiguration;
+  @Inject
+  private Text omService;
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest,
+                       ServletResponse servletResponse, FilterChain 
filterChain)
+      throws IOException, ServletException {
+    Map<String, String> headerMap = new HashMap<>();

Review comment:
       > Question:
   > Previously we used to use context.getHeaders() which is multivalued map. 
So, for a single key it can have multiple values. Now with this logic of Map, 
if a key has multiple values.
   
   Thanks @bharatviswa504. Right, previously we had a multivalued map from 
getHeaders() however we only used the first value for each header. 
(AWSSignatureProcessor fromHeaderMap() headerEntry.getValue().get(0) )
   
   Here we use getHeader() as you wrote that is mapped in the same manner 
(first value entry). Also, for the injected ContainerRequestContext, we removed 
the injected context because it is unavailable when generating the stringToSign 
for the ozone S3AUTHINFO token in UgiFilter.
   
   For aws authentication, (stringToSign), is there a need for us to extend the 
implementation to support multi-valued headers? Right now the PR implementation 
should provide the same as the prior version (AWSSignatureProcessor) using the 
single header value.

##########
File path: 
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneClientProducer.java
##########
@@ -83,65 +75,20 @@ public OzoneClient createClient() throws 
WebApplicationException,
     return client;
   }
 
-  @PreDestroy
-  public void destroy() throws IOException {
-    client.close();
-  }
-
   private OzoneClient getClient(OzoneConfiguration config)
       throws WebApplicationException {
     OzoneClient ozoneClient = null;
     try {
-      SignatureInfo signatureInfo = signatureProcessor.parseSignature();
-
-      String stringToSign = "";
-      if (signatureInfo.getVersion() == Version.V4) {
-        stringToSign =
-            StringToSignProducer.createSignatureBase(signatureInfo, context);
-      }
-
-      String awsAccessId = signatureInfo.getAwsAccessId();
-      validateAccessId(awsAccessId);
-
-      UserGroupInformation remoteUser =
-          UserGroupInformation.createRemoteUser(awsAccessId);
-      if (OzoneSecurityUtil.isSecurityEnabled(config)) {
-        LOG.debug("Creating s3 auth info for client.");
-
-        if (signatureInfo.getVersion() == Version.NONE) {
-          throw MALFORMED_HEADER;
-        }
-
-        OzoneTokenIdentifier identifier = new OzoneTokenIdentifier();
-        identifier.setTokenType(S3AUTHINFO);
-        identifier.setStrToSign(stringToSign);
-        identifier.setSignature(signatureInfo.getSignature());
-        identifier.setAwsAccessId(awsAccessId);
-        identifier.setOwner(new Text(awsAccessId));
-        if (LOG.isTraceEnabled()) {
-          LOG.trace("Adding token for service:{}", omService);
-        }
-        Token<OzoneTokenIdentifier> token = new Token(identifier.getBytes(),
-            identifier.getSignature().getBytes(StandardCharsets.UTF_8),
-            identifier.getKind(),
-            omService);
-        remoteUser.addToken(token);
 
-      }
+      this.remoteUser = UserGroupInformation.getCurrentUser();
       ozoneClient =
-          remoteUser.doAs((PrivilegedExceptionAction<OzoneClient>) () -> {
-            return createOzoneClient();
-          });
-    } catch (OS3Exception ex) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Error during Client Creation: ", ex);
-      }
-      throw wrapOS3Exception(ex);
-    } catch (Exception e) {
+          OzoneClientCache.getOzoneClientInstance(omServiceID,

Review comment:
       The s3 gateway Grpc client only supports the `GrpcOmTransport`.  The 
previous `Hadoop3OmTransport` is unavailable as the `OmTransportFactory` 
selects the OmTransport through the ServiceProvider (set to `GrpcOmTransport` 
in the META-INF file for the s3gateway).
   
   Right, once the feature comes in the client (s3 gateway) does not support 
the hadoop rpc based code, however the server (OzoneManager) supports both Grpc 
and Hadoop rpc based s3 gateways.  During the instability period (issues, 
whatever as it matures) the server can support both.  In that case, for the 
client, it can be swapped with a prior release hadoop rpc support.  Let me know 
what you think.

##########
File path: 
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/UgiFilter.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.hadoop.ozone.s3;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.ozone.OzoneSecurityUtil;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.signature.SignatureInfo;
+import org.apache.hadoop.ozone.s3.signature.StringToSignProducer;
+import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Enumeration;
+import org.apache.hadoop.ozone.s3.signature.AWSSignatureProcessor;
+
+import com.google.common.annotations.VisibleForTesting;
+import static 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMTokenProto.Type.S3AUTHINFO;
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.MALFORMED_HEADER;
+
+/**
+ * Preprocessing filter for every request.
+ * - creates OzoneToken containing aws signature
+ * aws id and stringToSign for aws authenication;  stores OzoneToken in
+ * thread local variable (UserGroupInformation object) avail to all
+ * s3 rest command endpoints
+ */
+public class UgiFilter implements Filter {
+  public static final Logger LOG = LoggerFactory.getLogger(UgiFilter.class);
+
+  @Inject
+  private OzoneConfiguration ozoneConfiguration;
+  @Inject
+  private Text omService;
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest,
+                       ServletResponse servletResponse, FilterChain 
filterChain)
+      throws IOException, ServletException {
+    Map<String, String> headerMap = new HashMap<>();

Review comment:
       > Question:
   > Previously we used to use context.getHeaders() which is multivalued map. 
So, for a single key it can have multiple values. Now with this logic of Map, 
if a key has multiple values.
   
   Thanks @bharatviswa504. Right, previously we had a multivalued map from 
getHeaders() however we only used the first value for each header. 
(`AWSSignatureProcessor` `fromHeaderMap()` headerEntry.getValue().get(0) )
   
   Here we use `getHeader()` as you wrote that is mapped in the same manner 
(first value entry). Also, for the injected `ContainerRequestContext`, we 
removed the injected context because it is unavailable when generating the 
`stringToSign` for the ozone S3AUTHINFO token in `UgiFilter`.
   
   For aws authentication, (`stringToSign`), is there a need for us to extend 
the implementation to support multi-valued headers? Right now the PR 
implementation should provide the same as the prior version 
(`AWSSignatureProcessor`) using the single header value.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to