This is an automated email from the ASF dual-hosted git repository. smengcl pushed a commit to branch ozone-2.1 in repository https://gitbox.apache.org/repos/asf/ozone.git
commit 217bfb45b72eb98a8dceb1665444f12456da99e6 Author: Gargi Jaiswal <[email protected]> AuthorDate: Fri Oct 2 14:32:22 2026 +0530 HDDS-16530. Allow Recon service principal to call OM getDBUpdates (#11382). (cherry picked from commit fd90ad1b7a5da8c2e34871d1009e8dc14c41a537) --- .../org/apache/hadoop/ozone/om/OzoneManager.java | 53 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java index fa88d8bd994..46892d3b932 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java @@ -180,6 +180,7 @@ import org.apache.hadoop.hdds.protocolPB.ReconfigureProtocolServerSideTranslatorPB; import org.apache.hadoop.hdds.protocolPB.SCMSecurityProtocolClientSideTranslatorPB; import org.apache.hadoop.hdds.ratis.RatisHelper; +import org.apache.hadoop.hdds.recon.ReconConfig; import org.apache.hadoop.hdds.scm.ScmConfigKeys; import org.apache.hadoop.hdds.scm.ScmInfo; import org.apache.hadoop.hdds.scm.client.HddsClientUtils; @@ -411,6 +412,8 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl private final OzoneAdmins omAdmins; private final OzoneAdmins readOnlyAdmins; private final OzoneAdmins s3OzoneAdmins; + /** Short name of the Recon service principal, null when Recon is not configured. */ + private final String reconUser; private final OMMetrics metrics; private final OmSnapshotInternalMetrics omSnapshotIntMetrics; @@ -689,6 +692,8 @@ private OzoneManager(OzoneConfiguration conf, StartupOption startupOption) // Get read only admin list readOnlyAdmins = OzoneAdmins.getReadonlyAdmins(conf); + reconUser = resolveReconUserShortName(conf); + s3OzoneAdmins = OzoneAdmins.getS3Admins(conf); instantiateServices(false); @@ -4467,10 +4472,9 @@ public DBUpdates getDBUpdates( throws IOException { // getDBUpdates returns the raw RocksDB delta of the entire OM metadata DB (all // volume/bucket/key names, ACLs, block locations, tenant/S3-secret state). It backs - // OM->Recon replication and is not a per-object client read, so restrict it to admins - // and read-only admins (the Recon service principal is expected to be one), consistent - // with the gating already applied to the other whole-system reads such as listOpenFiles - // and getQuotaRepairStatus. + // OM->Recon replication and is not a per-object client read, so restrict it to admins, + // read-only admins and the configured Recon service principal, matching + // {@link OMDBCheckpointServlet} checkpoint download access. checkGetDBUpdatesPrivilege(); long limitCount = Long.MAX_VALUE; if (dbUpdatesRequest.hasLimitCount()) { @@ -4541,10 +4545,10 @@ private void checkAdminUserPrivilege(String operation) throws IOException { /** * Authorize a getDBUpdates call, which returns the raw whole-DB metadata delta. - * Allowed for full OM admins and read-only admins (the read-only-admin allow-list is the - * mechanism intended to grant the Recon service principal read access to the metadata feed - * without full admin rights). Only enforced when admin authorization is enabled, matching - * {@link #checkAdminUserPrivilege(String)}. + * Allowed for full OM admins, read-only admins and the configured Recon service principal, + * which consumes this feed to replicate the OM DB. Only enforced when admin authorization is + * enabled. Recon access follows the same {@code ozone.recon.kerberos.principal} config as + * {@link OMDBCheckpointServlet}. */ private void checkGetDBUpdatesPrivilege() throws IOException { // Skip check if authorization is disabled @@ -4553,12 +4557,41 @@ private void checkGetDBUpdatesPrivilege() throws IOException { } final UserGroupInformation ugi = ProtobufRpcEngine.Server.getRemoteUser(); - if (!isAdmin(ugi) && !isReadOnlyAdmin(ugi)) { - throw new OMException("Only Ozone admins and read-only admins are allowed to " + if (!isAdmin(ugi) && !isReadOnlyAdmin(ugi) && !isReconUser(ugi)) { + throw new OMException("Only Ozone admins, read-only admins and Recon are allowed to " + "access the OM metadata database via getDBUpdates.", PERMISSION_DENIED); } } + /** + * Resolve the short name of the Recon service principal from {@code ozone.recon.kerberos.principal}, + * using the same mapping as {@link OMDBCheckpointServlet}. + * + * @return the Recon short name, or null when Recon is unconfigured or the principal cannot be mapped + */ + private static String resolveReconUserShortName(OzoneConfiguration conf) { + String reconPrincipal = conf.getObject(ReconConfig.class).getKerberosPrincipal(); + if (reconPrincipal.isEmpty()) { + return null; + } + try { + return UserGroupInformation.createRemoteUser(reconPrincipal).getShortUserName(); + } catch (IllegalArgumentException e) { + LOG.warn("Unable to map Recon principal {} to a short name. Recon will be denied access to" + + " getDBUpdates unless it is listed in {} or {}.", reconPrincipal, OZONE_ADMINISTRATORS, + OZONE_READONLY_ADMINISTRATORS, e); + return null; + } + } + + /** + * @param callerUgi Caller UserGroupInformation + * @return true if {@code callerUgi} is the configured Recon service principal + */ + private boolean isReconUser(UserGroupInformation callerUgi) { + return reconUser != null && callerUgi != null && reconUser.equals(callerUgi.getShortUserName()); + } + public boolean isS3Admin(UserGroupInformation callerUgi) { return OzoneAdmins.isS3Admin(callerUgi, s3OzoneAdmins); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
