Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11041. Add admin request filter for S3 requests and UGI support for GrpcOmTransport #7268

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a242b0
HDDS-11041. Add admin request filter for S3 requests and passing UGI …
devabhishekpal Oct 4, 2024
b9002fb
Fixed checkstyle issues
devabhishekpal Oct 4, 2024
d5272f5
Using OzoneConfigUtils to fetch s3 admins
devabhishekpal Oct 4, 2024
932fffc
Addressed codestyle review comments
devabhishekpal Oct 4, 2024
a0ac299
Add common utils to fetch S3 admin users
devabhishekpal Oct 6, 2024
065f9fd
Added unauthorized test scenarios and fixed code style
devabhishekpal Oct 6, 2024
4a3c3d5
Fixed findbug issues
devabhishekpal Oct 6, 2024
cf3c4e3
Mock ContainerRequestContext
devabhishekpal Oct 6, 2024
ff14d26
Addressed review comments
devabhishekpal Oct 10, 2024
8e93f5c
Addressed review comments
devabhishekpal Oct 11, 2024
44bad3b
Addressed checkstyle and RAT issues
devabhishekpal Oct 11, 2024
e0e8748
Addressed checkstyle issues
devabhishekpal Oct 11, 2024
664489a
Fixed test verification and RPC failover config
devabhishekpal Oct 14, 2024
f8a4e2b
Fixed tests
devabhishekpal Oct 14, 2024
0a32667
Fixed checkstyles
devabhishekpal Oct 14, 2024
db908fb
Fixed checkstyles
devabhishekpal Oct 14, 2024
2daecc9
Added test coverage for S3 admin utils
devabhishekpal Oct 20, 2024
e67269e
Fixed checkstyle issue
devabhishekpal Oct 20, 2024
d2653a5
Fixed build issues
devabhishekpal Oct 20, 2024
9c9a9da
Fixed checkstyle issues
devabhishekpal Oct 21, 2024
fb6dcb9
Fix tests
devabhishekpal Oct 21, 2024
30e55e2
Add newline at file end for checkstyles
devabhishekpal Oct 21, 2024
f4cfed4
Remove print line
devabhishekpal Oct 21, 2024
ad12dfe
Re-enable robot tests and add robot tests for non-admin user
devabhishekpal Oct 21, 2024
bf6fb02
Refactor S3 config utils to hdds-framework
devabhishekpal Oct 21, 2024
e2f9248
Fixed checkstyle issues
devabhishekpal Oct 21, 2024
2acffda
Refactored createOMProxy to parent provider and enabled GrpcOmTranspo…
devabhishekpal Oct 23, 2024
c52deae
Removed unused imports and variables
devabhishekpal Oct 23, 2024
3a60637
Add fallback value to OM transport and set it to Hadoop3OmTransport i…
devabhishekpal Oct 23, 2024
9e8c64e
Addressed review comments
devabhishekpal Oct 24, 2024
c674834
Fixed checkstyles
devabhishekpal Oct 24, 2024
bd8e47d
Fixed test issues
devabhishekpal Oct 24, 2024
c331c99
Fixed checkstyle issues
devabhishekpal Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hadoop-ozone/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-config</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-server-framework</artifactId>
</dependency>
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>org.apache.ozone</groupId>
<artifactId>hdds-interface-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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.ozone.conf;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.OzoneAdmins;
import org.apache.hadoop.security.UserGroupInformation;

import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_S3_ADMINISTRATORS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.annotation.Nullable;

import java.io.IOException;
import java.util.Collection;

/**
* Config based utilities for Ozone S3.
*/
public final class OzoneS3ConfigUtils {
private static final Logger LOG = LoggerFactory.getLogger(OzoneS3ConfigUtils.class);

private OzoneS3ConfigUtils() { }

/**
* Get the list of S3 administrators from Ozone config.
*
* @param conf An instance of {@link OzoneConfiguration} being used
* @return A {@link Collection} of the S3 administrator users
*
* If ozone.s3.administrators value is empty string or unset,
* defaults to ozone.administrators value.
*/
public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration conf) throws IOException {
Collection<String> ozoneAdmins = conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS);

if (ozoneAdmins == null || ozoneAdmins.isEmpty()) {
ozoneAdmins = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS);
}
String omSPN = UserGroupInformation.getCurrentUser().getShortUserName();
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
if (!ozoneAdmins.contains(omSPN)) {
ozoneAdmins.add(omSPN);
}

return ozoneAdmins;
}

/**
* Get the list of the groups that are a part S3 administrators from Ozone config.
*
* @param conf An instance of {@link OzoneConfiguration} being used
* @return A {@link Collection} of the S3 administrator groups
*
* If ozone.s3.administrators.groups value is empty or unset,
* defaults to the ozone.administrators.groups value
*/
public static Collection<String> getS3AdminsGroupsFromConfig(OzoneConfiguration conf) {
Collection<String> s3AdminsGroup = conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS_GROUPS);

if (s3AdminsGroup.isEmpty() && conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS).isEmpty()) {
s3AdminsGroup = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS_GROUPS);
}

return s3AdminsGroup;
}

/**
* Get the users and groups that are a part of S3 administrators.
* @param conf Stores an instance of {@link OzoneConfiguration} being used
* @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups
*/
public static OzoneAdmins getS3Admins(OzoneConfiguration conf) {
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
Collection<String> s3Admins;
try {
s3Admins = getS3AdminsFromConfig(conf);
} catch (IOException ie) {
s3Admins = null;
}
Collection<String> s3AdminGroups = getS3AdminsGroupsFromConfig(conf);

if (LOG.isDebugEnabled()) {
if (null == s3Admins) {
LOG.debug("S3 Admins are not set in configuration");
}
if (null == s3AdminGroups) {
LOG.debug("S3 Admin Groups are not set in configuration");
}
}
return new OzoneAdmins(s3Admins, s3AdminGroups);
}

/**
* Check if the provided user is an S3 administrator.
* @param user An instance of {@link UserGroupInformation} with information about the user to verify
* @param s3Admins An instance of {@link OzoneAdmins} containing information
* of the S3 administrator users and groups in the system
* @return {@code true} if the provided user is an S3 administrator else {@code false}
*/
public static boolean isS3Admin(@Nullable UserGroupInformation user, OzoneAdmins s3Admins) {
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
return null != user && s3Admins.isAdmin(user);
}

/**
* Check if the provided user is an S3 administrator.
* @param user An instance of {@link UserGroupInformation} with information about the user to verify
* @param conf An instance of {@link OzoneConfiguration} being used
* @return {@code true} if the provided user is an S3 administrator else {@code false}
*/
public static boolean isS3Admin(@Nullable UserGroupInformation user, OzoneConfiguration conf) {
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
OzoneAdmins s3Admins = getS3Admins(conf);
return isS3Admin(user, s3Admins);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.utils.LegacyHadoopConfigurationSource;
import org.apache.hadoop.io.retry.RetryPolicies;
import org.apache.hadoop.io.retry.RetryPolicy;
import org.apache.hadoop.ipc.ProtobufRpcEngine;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OmUtils;
Expand All @@ -41,6 +44,7 @@
import java.util.Optional;
import java.util.OptionalInt;
import io.grpc.StatusRuntimeException;
import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -59,10 +63,16 @@ public class GrpcOMFailoverProxyProvider<T> extends
public static final Logger LOG =
LoggerFactory.getLogger(GrpcOMFailoverProxyProvider.class);

private final UserGroupInformation ugi;
private final long protocolVer;

devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
public GrpcOMFailoverProxyProvider(ConfigurationSource configuration,
UserGroupInformation ugi,
String omServiceId,
Class<T> protocol) throws IOException {
super(configuration, omServiceId, protocol);
this.ugi = ugi;
this.protocolVer = RPC.getProtocolVersion(protocol);
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down Expand Up @@ -116,9 +126,35 @@ protected void loadOMClientConfigs(ConfigurationSource config, String omSvcId)

private T createOMProxy() throws IOException {
InetSocketAddress addr = new InetSocketAddress(0);
return createOmProxy(addr);
}

/**
* Get the protocol proxy for provided address.
* @param address An instance of {@link InetSocketAddress} which contains the address to connect
* @return the proxy connection to the address and the set of methods supported by the server at the address
* @throws IOException if any error occurs while trying to get the proxy
*/
private T createOmProxy(InetSocketAddress address) throws IOException {
Configuration hadoopConf =
LegacyHadoopConfigurationSource.asHadoopConfiguration(getConf());
return (T) RPC.getProxy(getInterface(), 0, addr, hadoopConf);

// TODO: Post upgrade to Protobuf 3.x we need to use ProtobufRpcEngine2
RPC.setProtocolEngine(hadoopConf, getInterface(), ProtobufRpcEngine.class);

// Ensure we do not attempt retry on the same OM in case of exceptions
RetryPolicy connectionRetryPolicy = RetryPolicies.failoverOnNetworkException(0);

return (T) RPC.getProtocolProxy(
getInterface(),
protocolVer,
address,
ugi,
hadoopConf,
NetUtils.getDefaultSocketFactory(hadoopConf),
(int) OmUtils.getOMClientRpcTimeOut(getConf()),
connectionRetryPolicy
).getProxy();
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public GrpcOmTransport(ConfigurationSource conf,

omFailoverProxyProvider = new GrpcOMFailoverProxyProvider(
conf,
ugi,
omServiceId,
OzoneManagerProtocolPB.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* 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.ozone.conf;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.OzoneAdmins;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;

import static org.assertj.core.api.Assertions.assertThat;

/**
* This class is to test S3 configuration based utils.
*/
class TestOzoneS3ConfigUtils {

@Test
void testS3AdminExtraction() throws IOException {
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS, "alice,bob");

assertThat(OzoneS3ConfigUtils.getS3AdminsFromConfig(configuration))
.containsAll(Arrays.asList("alice", "bob"));
}

@Test
void testS3AdminExtractionWithFallback() throws IOException {
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, "alice,bob");

assertThat(OzoneS3ConfigUtils.getS3AdminsFromConfig(configuration))
.containsAll(Arrays.asList("alice", "bob"));
}

@Test
void testS3AdminGroupExtraction() {
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS,
"test1, test2");

assertThat(OzoneS3ConfigUtils.getS3AdminsGroupsFromConfig(configuration))
.containsAll(Arrays.asList("test1", "test2"));
}

@Test
void testS3AdminGroupExtractionWithFallback() {
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS,
"test1, test2");

assertThat(OzoneS3ConfigUtils.getS3AdminsGroupsFromConfig(configuration))
.containsAll(Arrays.asList("test1", "test2"));
}

@Test
void testGetS3AdminsWhenS3AdminPresent() {
// When there is S3 admin present
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS, "alice");
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS, "test_group");

OzoneAdmins admins = OzoneS3ConfigUtils.getS3Admins(configuration);
UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
"alice", new String[] {"test_group"});

assertThat(admins.isAdmin(ugi)).isEqualTo(true);

// Test that when a user is present in an admin group but not an Ozone Admin
UserGroupInformation ugiGroupOnly = UserGroupInformation.createUserForTesting(
"bob", new String[] {"test_group"});
assertThat(admins.isAdmin(ugiGroupOnly)).isEqualTo(true);
}
@Test
void testGetS3AdminsWhenNoS3AdminPresent() {
// When there is no S3 admin, but Ozone admins present
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, "alice");
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS, "test_group");

OzoneAdmins admins = OzoneS3ConfigUtils.getS3Admins(configuration);
UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
"alice", new String[] {"test_group"});

assertThat(admins.isAdmin(ugi)).isEqualTo(true);

// Test that when a user is present in an admin group but not an Ozone Admin
UserGroupInformation ugiGroupOnly = UserGroupInformation.createUserForTesting(
"bob", new String[] {"test_group"});
assertThat(admins.isAdmin(ugiGroupOnly)).isEqualTo(true);
}

@Test
void testGetS3AdminsWithNoAdmins() {
OzoneAdmins admins = OzoneS3ConfigUtils.getS3Admins(new OzoneConfiguration());
UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
"alice", new String[] {"test_group"});
assertThat(admins.isAdmin(ugi)).isEqualTo(false);
}

@Test
void testIsS3AdminForS3AdminUser() {
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS, "alice");
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS, "test_group");

UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
"alice", new String[] {"test_group"});
// Scenario when user is present in an admin group but not an Ozone Admin
UserGroupInformation ugiGroupOnly = UserGroupInformation.createUserForTesting(
"bob", new String[] {"test_group"});

assertThat(OzoneS3ConfigUtils.isS3Admin(ugi, configuration)).isEqualTo(true);
assertThat(OzoneS3ConfigUtils.isS3Admin(ugiGroupOnly, configuration)).isEqualTo(true);
}

@Test
void testIsS3AdminForAdminUser() {
// When there is no S3 admin, but Ozone admins present
OzoneConfiguration configuration = new OzoneConfiguration();
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, "alice");
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS, "test_group");

OzoneAdmins admins = OzoneS3ConfigUtils.getS3Admins(configuration);
UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
"alice", new String[] {"test_group"});
// Test that when a user is present in an admin group but not an Ozone Admin
UserGroupInformation ugiGroupOnly = UserGroupInformation.createUserForTesting(
"bob", new String[] {"test_group"});

assertThat(admins.isAdmin(ugi)).isEqualTo(true);
assertThat(admins.isAdmin(ugiGroupOnly)).isEqualTo(true);
}

@Test
void testIsS3AdminForNoUser() {
OzoneConfiguration configuration = new OzoneConfiguration();
assertThat(OzoneS3ConfigUtils.isS3Admin(null, configuration)).isEqualTo(false);
}
}
Loading