fmorg-git commented on code in PR #766:
URL: https://github.com/apache/ranger/pull/766#discussion_r2608395203


##########
plugin-ozone/src/test/java/org/apache/ranger/authorization/ozone/authorizer/TestRangerOzoneAuthorizer.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.ranger.authorization.ozone.authorizer;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.AssumeRoleRequest;
+import org.apache.hadoop.ozone.security.acl.AssumeRoleRequest.OzoneGrant;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
+import org.apache.hadoop.ozone.security.acl.RequestContext;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
+import org.apache.ranger.plugin.model.RangerInlinePolicy;
+import org.apache.ranger.plugin.policyengine.RangerPluginContext;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+import org.apache.ranger.plugin.util.JsonUtilsV2;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class TestRangerOzoneAuthorizer {
+    static RangerOzoneAuthorizer ozoneAuthorizer;
+
+    private final String               hostname  = "localhost";
+    private final InetAddress          ipAddress = 
InetAddress.getLoopbackAddress();
+    private final UserGroupInformation user1     = 
UserGroupInformation.createRemoteUser("user1");
+    private final UserGroupInformation user2     = 
UserGroupInformation.createRemoteUser("user2");
+    private final String               role1     = "role1";
+
+    private final OzoneObj vol1  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.VOLUME).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").build();
+    private final OzoneObj buck1 = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.BUCKET).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").setBucketName("buck1").build();
+    private final OzoneObj key1  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.KEY).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol1").setBucketName("buck1").setKeyName("key1").build();
+    private final OzoneObj vol2  = new 
OzoneObjInfo.Builder().setResType(OzoneObj.ResourceType.VOLUME).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName("vol2").build();
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        RangerPluginContext pluginContext = new RangerPluginContext(new 
RangerPluginConfig("ozone", null, "om", null, null, null));
+        RangerBasePlugin    plugin        = new 
RangerBasePlugin(pluginContext.getConfig());
+
+        plugin.init();
+
+        ozoneAuthorizer = new RangerOzoneAuthorizer(plugin);
+
+        assertNotNull(ozoneAuthorizer);
+    }
+
+    @Test
+    public void testAssumeRoleDeny() throws Exception {
+        // user1 should not be allowed to assume role1
+        AssumeRoleRequest request = new AssumeRoleRequest(hostname, ipAddress, 
user1, role1, null);

Review Comment:
   For reference, here are some cases for the `grants` parameter in 
`AssumeRoleRequest` that Ozone sends:
   
   1) grants = `null` => no IAM session policy was supplied => user gets all 
permissions of role
   2) grants = `Collections.emptySet()` => Ozone determined IAM session policy 
had mismatched action and resources, so it can't grant anything => user should 
get no permissions and STS token would be useless
   3) grants = `Set<OzoneGrant>` => valid IAM session policy was supplied => 
user gets intersection of role permissions and policy grants.  
   
   It looks like one test case might be missing that can be added - user is 
allowed to assume role and grants parameter is `null` => should grant access to 
the permissions of the role.
   



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

Reply via email to