-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-14380. The user who starts Recon process will have administrator privilege #9627
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,16 +31,19 @@ | |
| import com.google.inject.Injector; | ||
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.util.Collection; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import javax.sql.DataSource; | ||
| import org.apache.hadoop.hdds.cli.GenericCli; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocolPB.SCMSecurityProtocolClientSideTranslatorPB; | ||
| import org.apache.hadoop.hdds.recon.ReconConfig; | ||
| import org.apache.hadoop.hdds.recon.ReconConfigKeys; | ||
| import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager; | ||
| import org.apache.hadoop.hdds.security.SecurityConfig; | ||
| import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient; | ||
| import org.apache.hadoop.hdds.server.OzoneAdmins; | ||
| import org.apache.hadoop.hdds.utils.HddsServerUtil; | ||
| import org.apache.hadoop.ozone.OzoneSecurityUtil; | ||
| import org.apache.hadoop.ozone.recon.api.types.FeatureProvider; | ||
|
|
@@ -85,6 +88,7 @@ public class ReconServer extends GenericCli implements Callable<Void> { | |
| private ReconStorageConfig reconStorage; | ||
| private CertificateClient certClient; | ||
| private ReconTaskStatusMetrics reconTaskStatusMetrics; | ||
| private OzoneAdmins reconAdmins; | ||
|
|
||
| private volatile boolean isStarted = false; | ||
|
|
||
|
|
@@ -104,9 +108,23 @@ public Void call() throws Exception { | |
| ReconServer.class, originalArgs, LOG, configuration); | ||
| ConfigurationProvider.setConfiguration(configuration); | ||
|
|
||
| String reconStarterUser = UserGroupInformation.getCurrentUser().getShortUserName(); | ||
| Collection<String> adminUsers = | ||
| OzoneAdmins.getOzoneAdminsFromConfig(configuration, reconStarterUser); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of calling Admins and AdminsGroups method separately here, can we use this method directly and then add recon admins and recon admin groups. this will minimise the code lines.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion! |
||
| adminUsers.addAll( | ||
| configuration.getStringCollection(ReconConfigKeys.OZONE_RECON_ADMINISTRATORS)); | ||
|
|
||
| Collection<String> adminGroups = | ||
| OzoneAdmins.getOzoneAdminsGroupsFromConfig(configuration); | ||
| adminGroups.addAll( | ||
| configuration.getStringCollection(ReconConfigKeys.OZONE_RECON_ADMINISTRATORS_GROUPS)); | ||
|
|
||
| reconAdmins = new OzoneAdmins(adminUsers, adminGroups); | ||
| LOG.info("Recon start with adminUsers: {}", reconAdmins.getAdminUsernames()); | ||
|
|
||
| LOG.info("Initializing Recon server..."); | ||
| try { | ||
| injector = Guice.createInjector(new ReconControllerModule(), | ||
| injector = Guice.createInjector(new ReconControllerModule(this), | ||
| new ReconRestServletModule(configuration), | ||
| new ReconSchemaGenerationModule()); | ||
|
|
||
|
|
@@ -427,4 +445,14 @@ public ReconTaskController getReconTaskController() { | |
| ReconHttpServer getHttpServer() { | ||
| return httpServer; | ||
| } | ||
|
|
||
| /** | ||
| * Check if a user is a Recon administrator. | ||
| * | ||
| * @param user UserGroupInformation | ||
| * @return true if the user is an admin, false otherwise | ||
| */ | ||
| public boolean isAdmin(UserGroupInformation user) { | ||
| return reconAdmins.isAdmin(user); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need
reconServerinstance to be passes explicitly toReconControllerModule? can we not use Singleton ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This follows the same pattern as OM and SCM. In OM, the starter user and admin information are stored as instance fields in the OzoneManager object itself (https://github.com/apache/ozone/blob/master/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java#L680-L682). Similarly, we store this information in the ReconServer instance and make it accessible to other components via Guice.
Using
bind(ReconServer.class).toInstance(reconServer)allows other components to inject and access the starter user information, just like how OM exposes this through its instance methods.