You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "vtutrinov (via GitHub)" <gi...@apache.org> on 2023/11/13 11:07:53 UTC
[PR] HDDS-9663. om grpc transport - provide client ip and hostname [ozone]
vtutrinov opened a new pull request, #5590:
URL: https://github.com/apache/ozone/pull/5590
## What changes were proposed in this pull request?
A lot of code pieces in OM proto method handlers use OMClientRequest.preExecute method to define/detect userInfo for consequent ACLs checks. But if the provided client hostname is null (in case of GRPC transport) the user will be replaced by an 'om' one and the consequent ACLs check through a custom authorizer (e.g. Ranger) will fail due to non-existent permission policies for the 'om' user.
So, the PR introduces a new client&server interceptor to send/receive header with the client IP and hostname and uses it in GrpcOmTransport
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-9663
## How was this patch tested?
1 unit test to check that userInfo has hostname and IP in case of GRPC transport (ozone-manager)
2 unit tests to check that client and server interceptors set and read client IP and hostname to/from the GRPC request header
Manual test of the expected behavior (the ACLs will be checked for the current user, not for 'om' on committing the key) on cluster with Ranger
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "vtutrinov (via GitHub)" <gi...@apache.org>.
vtutrinov commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393861761
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java:
##########
@@ -565,7 +566,11 @@ public boolean checkAcls(OzoneObj obj, RequestContext context,
static String getClientAddress() {
Review Comment:
Done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "vtutrinov (via GitHub)" <gi...@apache.org>.
vtutrinov commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393858830
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/GrpcOmTransport.java:
##########
@@ -175,15 +181,22 @@ public void start() throws IOException {
@Override
public OMResponse submitRequest(OMRequest payload) throws IOException {
- OMResponse resp = null;
+ AtomicReference<OMResponse> resp = new AtomicReference<>();
boolean tryOtherHost = true;
int expectedFailoverCount = 0;
ResultCodes resultCode = ResultCodes.INTERNAL_ERROR;
while (tryOtherHost) {
tryOtherHost = false;
expectedFailoverCount = syncFailoverCount.get();
try {
- resp = clients.get(host.get()).submitRequest(payload);
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ Context.current()
+ .withValue(GrpcClientConstants.CLIENT_IP_ADDRESS_CTX_KEY,
+ inetAddress.getHostAddress())
+ .withValue(GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY,
+ inetAddress.getHostName()).run(() -> {
+ resp.set(clients.get(host.get()).submitRequest(payload));
+ });
Review Comment:
Done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #5590:
URL: https://github.com/apache/ozone/pull/5590#issuecomment-1816889672
@kerneltime would you like to take a look?
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393734116
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/GrpcOmTransport.java:
##########
@@ -175,15 +181,22 @@ public void start() throws IOException {
@Override
public OMResponse submitRequest(OMRequest payload) throws IOException {
- OMResponse resp = null;
+ AtomicReference<OMResponse> resp = new AtomicReference<>();
boolean tryOtherHost = true;
int expectedFailoverCount = 0;
ResultCodes resultCode = ResultCodes.INTERNAL_ERROR;
while (tryOtherHost) {
tryOtherHost = false;
expectedFailoverCount = syncFailoverCount.get();
try {
- resp = clients.get(host.get()).submitRequest(payload);
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ Context.current()
+ .withValue(GrpcClientConstants.CLIENT_IP_ADDRESS_CTX_KEY,
+ inetAddress.getHostAddress())
+ .withValue(GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY,
+ inetAddress.getHostName()).run(() -> {
+ resp.set(clients.get(host.get()).submitRequest(payload));
+ });
Review Comment:
nit: formatting is a bit misleading, as if `run()` had to do only with hostname
```suggestion
Context.current()
.withValue(GrpcClientConstants.CLIENT_IP_ADDRESS_CTX_KEY,
inetAddress.getHostAddress())
.withValue(GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY,
inetAddress.getHostName())
.run(() ->
resp.set(clients.get(host.get()).submitRequest(payload)));
```
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/package-info.java:
##########
@@ -0,0 +1,22 @@
+/**
+ * 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.om.protocolPB.grpc;
+/**
+ * This package contains grpc interceptors and their related classes
+ * to provide specific grpc headers
+ */
Review Comment:
nit: misplaced javadoc comment
```suggestion
/**
* This package contains grpc interceptors and their related classes
* to provide specific grpc headers
*/
package org.apache.hadoop.ozone.om.protocolPB.grpc;
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java:
##########
@@ -565,7 +566,11 @@ public boolean checkAcls(OzoneObj obj, RequestContext context,
static String getClientAddress() {
Review Comment:
Please replace calls to `Server.getRemoteAddress()` with `getClientAddress()` in the following places to apply the improved address detection to audit log for read requests.
https://github.com/apache/ozone/blob/fea5c1545fd19355d1c3e7449e9bcc53e5a409de/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java#L584
https://github.com/apache/ozone/blob/fea5c1545fd19355d1c3e7449e9bcc53e5a409de/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java#L597
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
nit: license header is not a javadoc
```suggestion
/*
* Licensed to the Apache Software Foundation (ASF) under one
```
Also in other new files.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * 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.om.protocolPB.grpc;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ClientInterceptor;
+import io.grpc.ForwardingClientCall;
+import io.grpc.Metadata;
+import io.grpc.MethodDescriptor;
+
+/**
+ * GRPC client side interceptor to provide client hostname and IP address.
+ */
+public class ClientAddressClientInterceptor implements ClientInterceptor {
+ @Override
+ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
+ MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions,
+ Channel channel) {
+ return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
+ channel.newCall(methodDescriptor, callOptions)) {
+ @Override
+ public void start(Listener<RespT> responseListener, Metadata headers) {
+ if (GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get() != null) {
+ headers.put(GrpcClientConstants.CLIENT_HOSTNAME_METADATA_KEY,
+ GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get());
+ }
Review Comment:
nit: save value and reuse
```suggestion
String hostname = GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get();
if (hostname != null) {
headers.put(GrpcClientConstants.CLIENT_HOSTNAME_METADATA_KEY,
hostname);
}
```
Also for IP address. Also in other files (`OmMetadataReader`, `OMClientRequest`, etc.).
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "vtutrinov (via GitHub)" <gi...@apache.org>.
vtutrinov commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393859197
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * 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.om.protocolPB.grpc;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ClientInterceptor;
+import io.grpc.ForwardingClientCall;
+import io.grpc.Metadata;
+import io.grpc.MethodDescriptor;
+
+/**
+ * GRPC client side interceptor to provide client hostname and IP address.
+ */
+public class ClientAddressClientInterceptor implements ClientInterceptor {
+ @Override
+ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
+ MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions,
+ Channel channel) {
+ return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
+ channel.newCall(methodDescriptor, callOptions)) {
+ @Override
+ public void start(Listener<RespT> responseListener, Metadata headers) {
+ if (GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get() != null) {
+ headers.put(GrpcClientConstants.CLIENT_HOSTNAME_METADATA_KEY,
+ GrpcClientConstants.CLIENT_HOSTNAME_CTX_KEY.get());
+ }
Review Comment:
Done
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/ClientAddressClientInterceptor.java:
##########
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
Done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "vtutrinov (via GitHub)" <gi...@apache.org>.
vtutrinov commented on code in PR #5590:
URL: https://github.com/apache/ozone/pull/5590#discussion_r1393861306
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/grpc/package-info.java:
##########
@@ -0,0 +1,22 @@
+/**
+ * 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.om.protocolPB.grpc;
+/**
+ * This package contains grpc interceptors and their related classes
+ * to provide specific grpc headers
+ */
Review Comment:
Done
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-9663. Allow OM to detect client address when using gRPC [ozone]
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #5590:
URL: https://github.com/apache/ozone/pull/5590
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org