aryangupta1998 commented on code in PR #12193:
URL: https://github.com/apache/ozone/pull/12193#discussion_r4772309127


##########
hadoop-ozone/ozonefs-common/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneClientAdapterFilePermission.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.fs.ozone;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.ozone.OzoneManagerVersion;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.client.protocol.ListStatusLightOptions;
+import org.apache.hadoop.ozone.om.helpers.ListStatusResult;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
+import org.apache.hadoop.ozone.om.helpers.OzoneFileStatusLight;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Tests that ofs and o3fs report the configured file permission for files and 
777 for directories, in both full and
+ * lite listings. Uses partial mocks so no OM connection is required.
+ */
+public class TestOzoneClientAdapterFilePermission {
+
+  private static final short FILE_PERMISSION = 0600;
+  private static final Path WORKING_DIR = new Path("/");
+
+  private static OzoneFileStatus status(String keyName, boolean isDir) {
+    OmKeyInfo keyInfo = new OmKeyInfo.Builder()
+        .setVolumeName("vol")
+        .setBucketName("bucket")
+        .setKeyName(keyName)
+        
.setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE))
+        .setOmKeyLocationInfos(Collections.emptyList())
+        .setDataSize(0)
+        .setCreationTime(0)
+        .setModificationTime(0)
+        .setAcls(Collections.emptyList())
+        .build();
+    return new OzoneFileStatus(keyInfo, 512, isDir);
+  }
+
+  private static List<OzoneFileStatus> statuses() {
+    return Arrays.asList(status("dir/file", false), status("dir/sub", true));
+  }
+
+  private static List<OzoneFileStatusLight> lightStatuses() {
+    return 
statuses().stream().map(OzoneFileStatusLight::fromOzoneFileStatus).collect(Collectors.toList());
+  }
+
+  private static void assertPermissions(List<FileStatusAdapter> result) {
+    assertEquals(2, result.size());
+    assertFalse(result.get(0).isDir());
+    assertEquals(FILE_PERMISSION, result.get(0).getPermission());
+    assertTrue(result.get(1).isDir());
+    assertEquals((short) 0777, result.get(1).getPermission());
+  }
+
+  private static void setField(Class<?> type, Object target, String name, 
Object value) throws Exception {

Review Comment:
   Agreed, the IT exercises getFileStatus and listStatus through both adapters. 
Removed the unit test.



##########
hadoop-hdds/common/src/main/resources/ozone-default.xml:
##########
@@ -4744,6 +4744,21 @@
     </description>
   </property>
 
+  <property>
+    <name>ozone.fs.file.permission.reported</name>
+    <value>666</value>
+    <tag>OZONE, CLIENT</tag>
+    <description>
+      Permission that ofs and o3fs report for files, in octal or symbolic 
form. Ozone does not persist or enforce

Review Comment:
   Yes, FileSystem.access() falls back to the reported permission bits, so with 
600 non-owners are denied even when ACLs allow. Added a note.



##########
hadoop-hdds/common/src/main/resources/ozone-default.xml:
##########
@@ -4744,6 +4744,18 @@
     </description>
   </property>
 
+  <property>
+    <name>ozone.fs.file.permission.reported</name>
+    <value>666</value>
+    <tag>OZONE, CLIENT</tag>
+    <description>
+      Permission that ofs and o3fs report for files, in octal or symbolic 
form. Ozone does not persist or enforce
+      this permission; access is controlled by ACLs. When ACLs are enabled, 
set it to 600 so that applications which
+      check whether a file is readable by others, such as YARN when deciding 
if a resource can be localized
+      publicly, do not treat every file as world-readable. Directories are 
always reported as 777.

Review Comment:
   Right, a directory in -files hits the same mismatch: the client checks the 
directory, which reports 777, and the NodeManager checks the files inside. I've 
generalized the note to cover directory resources, not just libjars/*.



-- 
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