-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-4704. Add permission check in OMDBCheckpointServlet #1801
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3c98fe0
HDDS-4704. Add permission check in OMDBCheckpointServlet
smengcl 949f6bd
request.getRemoteUser() always return 'root' in my testing in Docker …
smengcl 99be8dd
Improve checking logic and UT.
smengcl 2b412a4
Address nits, rename func.
smengcl d281832
Doc.
smengcl b4c4133
More doc.
smengcl b120597
Clean up web.robot.
smengcl 5c09af3
Remove fallback to login user name check.
smengcl b1e2f83
Merge remote-tracking branch 'asf/master' into HDDS-4704
smengcl ed749d0
Nits.
smengcl f9555c1
Add instruction.
smengcl 24af74e
Fix robot test.
smengcl 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ OZONE-SITE.XML_ozone.recon.address=recon:9891 | |
| OZONE-SITE.XML_ozone.security.enabled=true | ||
| OZONE-SITE.XML_ozone.acl.enabled=true | ||
| OZONE-SITE.XML_ozone.acl.authorizer.class=org.apache.hadoop.ozone.security.acl.OzoneNativeAuthorizer | ||
| OZONE-SITE.XML_ozone.administrators="testuser/[email protected],testuser/[email protected]" | ||
| OZONE-SITE.XML_ozone.administrators="testuser/[email protected],testuser/[email protected],recon/[email protected]" | ||
|
|
||
| OZONE-SITE.XML_hdds.datanode.dir=/data/hdds | ||
| HDFS-SITE.XML_dfs.datanode.address=0.0.0.0:1019 | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import java.nio.file.Path; | ||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Collection; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
|
|
@@ -47,12 +48,25 @@ | |
| import org.apache.commons.compress.compressors.CompressorStreamFactory; | ||
| import org.apache.commons.compress.utils.IOUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS_WILDCARD; | ||
| import static org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_FLUSH; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Provides the current checkpoint Snapshot of the OM DB. (tar.gz) | ||
| * | ||
| * When Ozone ACL is enabled (`ozone.acl.enabled`=`true`), only users/principals | ||
| * configured in `ozone.administrator` (along with the user that starts OM, | ||
| * which automatically becomes an Ozone administrator but not necessarily in | ||
| * the config) are allowed to access this endpoint. | ||
| * | ||
| * If Kerberos is enabled, the principal should be appended to | ||
| * `ozone.administrator`, e.g. `scm/[email protected]` | ||
| * If Kerberos is not enabled, simply append the login user name to | ||
| * `ozone.administrator`, e.g. `scm` | ||
| */ | ||
| public class OMDBCheckpointServlet extends HttpServlet { | ||
|
|
||
|
|
@@ -89,6 +103,25 @@ public void init() throws ServletException { | |
| } | ||
| } | ||
|
|
||
| private boolean hasPermission(String username) { | ||
| // Check ACL for dbCheckpoint only when global Ozone ACL is enabled | ||
| if (om.getAclsEnabled()) { | ||
| // Only Ozone admins are allowed | ||
| try { | ||
| Collection<String> admins = om.getOzoneAdmins(om.getConfiguration()); | ||
| if (admins.contains(OZONE_ADMINISTRATORS_WILDCARD) || | ||
| admins.contains(username)) { | ||
| return true; | ||
| } | ||
| } catch (IOException e) { | ||
| LOG.warn("Error checking permission: {}", e.getMessage()); | ||
| } | ||
| return false; | ||
| } else { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Process a GET request for the Ozone Manager DB checkpoint snapshot. | ||
| * | ||
|
|
@@ -106,6 +139,33 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) { | |
| return; | ||
| } | ||
|
|
||
| // Check ACL for dbCheckpoint only when global Ozone ACL is enable | ||
| if (om.getAclsEnabled()) { | ||
| final java.security.Principal userPrincipal = request.getUserPrincipal(); | ||
| if (userPrincipal == null) { | ||
| final String remoteUser = request.getRemoteUser(); | ||
| LOG.error("Permission denied: Unauthorized access to /dbCheckpoint," | ||
| + " no user principal found. Current login user is {}.", | ||
| remoteUser != null ? "'" + remoteUser + "'" : "UNKNOWN"); | ||
| response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
| return; | ||
| } else { | ||
| final String userPrincipalName = userPrincipal.getName(); | ||
| if (!hasPermission(userPrincipalName)) { | ||
smengcl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOG.error("Permission denied: User principal '{}' does not have" | ||
| + " access to /dbCheckpoint.\nThis can happen when Ozone Manager" | ||
| + " is started with a different user.\nPlease append '{}' to OM" | ||
| + " 'ozone.administrators' config and restart OM to grant current" | ||
| + " user access to this endpoint.", | ||
| userPrincipalName, userPrincipalName); | ||
| response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
| return; | ||
| } | ||
| LOG.debug("Granted user principal '{}' access to /dbCheckpoint.", | ||
| userPrincipalName); | ||
| } | ||
| } | ||
|
|
||
| DBCheckpoint checkpoint = null; | ||
| try { | ||
|
|
||
|
|
||
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
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.