adoroszlai commented on code in PR #3693:
URL: https://github.com/apache/ozone/pull/3693#discussion_r954724468
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/http/BaseHttpServer.java:
##########
@@ -194,9 +195,18 @@ public static HttpServer2.Builder
newHttpServer2BuilderForOzone(
final InetSocketAddress httpsAddr, String name) throws IOException {
HttpConfig.Policy policy = getHttpPolicy(conf);
+ String userString = conf.get(OZONE_ADMINISTRATORS, " ");
+ String groupString = conf.get(OZONE_ADMINISTRATORS_GROUPS, "");
+ String userGroupString;
+ if (!groupString.trim().isEmpty()) {
+ userGroupString = userString.trim() + " " + groupString.trim();
+ } else {
+ userGroupString = userString;
+ }
+
HttpServer2.Builder builder = new HttpServer2.Builder().setName(name)
- .setConf(conf).setACL(new AccessControlList(conf.get(
- OZONE_ADMINISTRATORS, " ")));
+ .setConf(conf)
+ .setACL(new AccessControlList(userGroupString));
Review Comment:
Can we skip this string magic by using the `AccessControlList(String user,
String groups)` constructor?
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hdds.server;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+
+import org.apache.hadoop.security.UserGroupInformation;
+
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS_WILDCARD;
+
+/**
+ * This class contains ozone admin user information, username and group,
+ * and is able to check whether the provided {@link UserGroupInformation}
+ * has admin permissions.
+ */
+public class OzoneAdmins {
+
+ /**
+ * Ozone super user / admin username list.
+ */
+ private final Set<String> adminUsernames;
+ /**
+ * Ozone super user / admin group list.
+ */
+ private final Set<String> adminGroups;
+
+ public OzoneAdmins(Collection<String> adminUsernames) {
+ this(adminUsernames, null);
+ }
+
+ public OzoneAdmins(Collection<String> adminUsernames,
+ Collection<String> adminGroups) {
+ this.adminUsernames = adminUsernames != null ?
+ new LinkedHashSet<>(adminUsernames) : Collections.emptySet();
+ this.adminGroups = adminGroups != null ?
+ new LinkedHashSet<>(adminGroups) : Collections.emptySet();
+ }
+
+ private boolean hasAdminGroup(Collection<String> userGroups) {
+ return !Sets.intersection(adminGroups,
+ new LinkedHashSet<>(userGroups)).isEmpty();
+ }
+
+ /**
+ * Check whether the provided {@link UserGroupInformation user}
+ * has admin permissions.
+ *
+ * @param user
+ *
+ * @return
+ */
+ public boolean isAdmin(UserGroupInformation user) {
+ return adminUsernames.contains(OZONE_ADMINISTRATORS_WILDCARD)
+ || adminUsernames.contains(user.getShortUserName())
+ || adminUsernames.contains(user.getUserName())
+ || hasAdminGroup(user.getGroups());
+ }
+
+ public Collection<String> getAdminGroups() {
+ return Collections.unmodifiableSet(adminGroups);
Review Comment:
Nit: could wrap the underlying sets in unmodifiable once, in the constructor.
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/filters/TestAdminFilter.java:
##########
@@ -102,6 +103,17 @@ public void testAdminFilterOzoneAdminsOnly() throws
Exception {
conf.setStrings(OzoneConfigKeys.OZONE_ADMINISTRATORS,
OzoneConfigKeys.OZONE_ADMINISTRATORS_WILDCARD);
testAdminFilterWithPrincipal(conf, "other", true);
+
+ UserGroupInformation.createUserForTesting("user1",
+ new String[]{"admingroup"});
+ try {
+ conf.setStrings(OzoneConfigKeys.OZONE_ADMINISTRATORS, "ozone");
+ conf.setStrings(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS,
+ "admingroup");
+ testAdminFilterWithPrincipal(conf, "user1", true);
+ } finally {
+ UserGroupInformation.reset();
+ }
Review Comment:
This should be tested before setting admin users to wildcard (in lines
103-104), which allows any user regardless of the group.
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/filters/TestAdminFilter.java:
##########
@@ -114,6 +126,17 @@ public void testAdminFilterReconAdminsOnly() throws
Exception {
conf.setStrings(ReconConfigKeys.OZONE_RECON_ADMINISTRATORS,
OzoneConfigKeys.OZONE_ADMINISTRATORS_WILDCARD);
testAdminFilterWithPrincipal(conf, "other", true);
+
+ UserGroupInformation.createUserForTesting("user1",
+ new String[]{"reconadmingroup"});
+ try {
+ conf.setStrings(ReconConfigKeys.OZONE_RECON_ADMINISTRATORS, "recon");
+ conf.setStrings(ReconConfigKeys.OZONE_RECON_ADMINISTRATORS_GROUPS,
+ "reconadmingroup");
+ testAdminFilterWithPrincipal(conf, "user1", true);
+ } finally {
+ UserGroupInformation.reset();
+ }
Review Comment:
Same here: please move this test before the wildcard case.
--
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]