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

Merged
merged 35 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 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
e569e5f
Addressed review comments
devabhishekpal Oct 25, 2024
bf5b181
Fix findbugs
adoroszlai Oct 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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.RPC;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OmUtils;
Expand All @@ -41,6 +43,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 +62,14 @@ public class GrpcOMFailoverProxyProvider<T> extends
public static final Logger LOG =
LoggerFactory.getLogger(GrpcOMFailoverProxyProvider.class);

private final UserGroupInformation ugi;

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

@Override
Expand Down Expand Up @@ -118,9 +125,21 @@ private T createOMProxy() throws IOException {
InetSocketAddress addr = new InetSocketAddress(0);
Configuration hadoopConf =
LegacyHadoopConfigurationSource.asHadoopConfiguration(getConf());
return (T) RPC.getProxy(getInterface(), 0, addr, hadoopConf);

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

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


devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get the proxy object which should be used until the next failover event
* occurs. RPC proxy object is initialized lazily.
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,34 @@
/*
* 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.s3secret;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.ws.rs.NameBinding;

/**
* Annotation to disable S3 Secure Endpoint.
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
*/
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface S3AdminEndpoint {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.s3secret;


import javax.inject.Inject;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Response;
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
import javax.ws.rs.ext.Provider;
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 java.io.IOException;
import java.security.Principal;
import java.util.Collection;

/**
* Filter that disables all endpoints annotated with {@link S3AdminEndpoint}.
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
* Condition is based on the value of the configuration keys for
* - ozone.administrators
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
* - ozone.administrators.groups
*/

devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
@S3AdminEndpoint
@Provider
public class S3SecretAdminFilter implements ContainerRequestFilter {
@Inject
private OzoneConfiguration conf;

@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
final Principal userPrincipal = requestContext.getSecurityContext().getUserPrincipal();
if (null != userPrincipal) {
UserGroupInformation user =
UserGroupInformation.createRemoteUser(userPrincipal.getName());
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
if (!isAdmin(user)) {
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN)
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
.entity("Non-Admin user accessing endpoint")
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
.build());
}
}
}

/**
* Checks if the user that is passed is an Admin.
* @param user Stores the user to filter
* @return true if the user is admin else false
*/
private boolean isAdmin(UserGroupInformation user) {
devabhishekpal marked this conversation as resolved.
Show resolved Hide resolved
Collection<String> admins =
conf.getStringCollection(OzoneConfigKeys.OZONE_ADMINISTRATORS);
Collection<String> adminGroups =
conf.getStringCollection(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS);
// If there are no admins or admin groups specified, return false
if (admins.isEmpty() || adminGroups.isEmpty()) {
return false;
}
return new OzoneAdmins(admins, adminGroups).isAdmin(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
@Path("/secret")
@S3SecretEnabled
@S3AdminEndpoint
public class S3SecretManagementEndpoint extends S3SecretEndpointBase {
private static final Logger LOG =
LoggerFactory.getLogger(S3SecretManagementEndpoint.class);
Expand All @@ -54,8 +55,7 @@ public Response generate() throws IOException {
@Path("/{username}")
public Response generate(@PathParam("username") String username)
throws IOException {
// TODO: It is a temporary solution. To be removed after HDDS-11041 is done.
return Response.status(METHOD_NOT_ALLOWED).build();
return generateInternal(username);
}

private Response generateInternal(@Nullable String username) throws IOException {
Expand Down