-
Notifications
You must be signed in to change notification settings - Fork 589
HDDS-11041. Add admin request filter for S3 requests and UGI support for GrpcOmTransport #7268
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
Merged
Merged
Changes from 8 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 b9002fb
Fixed checkstyle issues
devabhishekpal d5272f5
Using OzoneConfigUtils to fetch s3 admins
devabhishekpal 932fffc
Addressed codestyle review comments
devabhishekpal a0ac299
Add common utils to fetch S3 admin users
devabhishekpal 065f9fd
Added unauthorized test scenarios and fixed code style
devabhishekpal 4a3c3d5
Fixed findbug issues
devabhishekpal cf3c4e3
Mock ContainerRequestContext
devabhishekpal ff14d26
Addressed review comments
devabhishekpal 8e93f5c
Addressed review comments
devabhishekpal 44bad3b
Addressed checkstyle and RAT issues
devabhishekpal e0e8748
Addressed checkstyle issues
devabhishekpal 664489a
Fixed test verification and RPC failover config
devabhishekpal f8a4e2b
Fixed tests
devabhishekpal 0a32667
Fixed checkstyles
devabhishekpal db908fb
Fixed checkstyles
devabhishekpal 2daecc9
Added test coverage for S3 admin utils
devabhishekpal e67269e
Fixed checkstyle issue
devabhishekpal d2653a5
Fixed build issues
devabhishekpal 9c9a9da
Fixed checkstyle issues
devabhishekpal fb6dcb9
Fix tests
devabhishekpal 30e55e2
Add newline at file end for checkstyles
devabhishekpal f4cfed4
Remove print line
devabhishekpal ad12dfe
Re-enable robot tests and add robot tests for non-admin user
devabhishekpal bf6fb02
Refactor S3 config utils to hdds-framework
devabhishekpal e2f9248
Fixed checkstyle issues
devabhishekpal 2acffda
Refactored createOMProxy to parent provider and enabled GrpcOmTranspo…
devabhishekpal c52deae
Removed unused imports and variables
devabhishekpal 3a60637
Add fallback value to OM transport and set it to Hadoop3OmTransport i…
devabhishekpal 9e8c64e
Addressed review comments
devabhishekpal c674834
Fixed checkstyles
devabhishekpal bd8e47d
Fixed test issues
devabhishekpal c331c99
Fixed checkstyle issues
devabhishekpal e569e5f
Addressed review comments
devabhishekpal bf5b181
Fix findbugs
adoroszlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * 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.common; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.server.OzoneAdmins; | ||
|
|
||
| import org.apache.hadoop.ozone.om.OzoneConfigUtil; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Utility class to store User related utilities. | ||
| */ | ||
| public final class OmUserUtils { | ||
| private static final Logger LOG = | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| LoggerFactory.getLogger(OmUserUtils.class); | ||
|
|
||
| private OmUserUtils() { } | ||
|
|
||
| /** | ||
| * Get the users and groups that are S3 admin. | ||
| * @param conf Stores the Ozone configuration being used | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups | ||
| */ | ||
| public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { | ||
| Collection<String> s3Admins; | ||
| try { | ||
| s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); | ||
| } catch (IOException ie) { | ||
| s3Admins = null; | ||
| } | ||
| Collection<String> s3AdminGroups = | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OzoneConfigUtil.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 a part of the S3 admins. | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param user Stores the user to verify | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param conf Stores the Ozone configuration being used | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return true if the provided user is an S3 admin else false | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public static boolean isS3Admin(UserGroupInformation user, | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OzoneConfiguration conf) { | ||
| OzoneAdmins s3Admins = getS3Admins(conf); | ||
| return null != user && s3Admins.isAdmin(user); | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Check if the provided user is a part of the S3 admins. | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param user Stores the user to verify | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param s3Admins Stores the users and groups that are admins | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return true if the provided user is an S3 admin else false | ||
devabhishekpal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public static boolean isS3Admin(UserGroupInformation user, | ||
| OzoneAdmins s3Admins) { | ||
| return null != user && s3Admins.isAdmin(user); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3secret/S3AdminEndpoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 only allow admin users to access the endpoint. | ||
| */ | ||
| @NameBinding | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| public @interface S3AdminEndpoint { | ||
| } |
60 changes: 60 additions & 0 deletions
60
...p-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3secret/S3SecretAdminFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.core.Response.Status; | ||
| import javax.ws.rs.ext.Provider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.common.OmUserUtils; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
|
|
||
| import java.io.IOException; | ||
| import java.security.Principal; | ||
|
|
||
| /** | ||
| * Filter that only allows admin to access endpoints annotated with {@link S3AdminEndpoint}. | ||
| * Condition is based on the value of the configuration keys for: | ||
| * <ul> | ||
| * <li>ozone.administrators</li> | ||
| * <li>ozone.administrators.groups</li> | ||
| * </ul> | ||
| */ | ||
| @S3AdminEndpoint | ||
| @Provider | ||
| public class S3SecretAdminFilter implements ContainerRequestFilter { | ||
|
|
||
| @Inject | ||
| private OzoneConfiguration conf; | ||
|
|
||
| @Override | ||
| public void filter(ContainerRequestContext requestContext) throws IOException { | ||
| final Principal userPrincipal = requestContext.getSecurityContext().getUserPrincipal(); | ||
| if (null != userPrincipal) { | ||
| UserGroupInformation user = UserGroupInformation.createRemoteUser(userPrincipal.getName()); | ||
| if (!OmUserUtils.isS3Admin(user, conf)) { | ||
| requestContext.abortWith(Response.status(Status.FORBIDDEN).build()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.