Class BaseRunAsSuperuserCommand

java.lang.Object
org.elasticsearch.cli.Command
org.elasticsearch.common.cli.EnvironmentAwareCommand
org.elasticsearch.common.cli.KeyStoreAwareCommand
org.elasticsearch.xpack.security.tool.BaseRunAsSuperuserCommand
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
CreateEnrollmentTokenTool, ResetPasswordTool

public abstract class BaseRunAsSuperuserCommand extends org.elasticsearch.common.cli.KeyStoreAwareCommand
A KeyStoreAwareCommand that can be extended fpr any CLI tool that needs to allow a local user with filesystem write access to perform actions on the node as a superuser. It leverages temporary file realm users with a `superuser` role.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final joptsimple.OptionSpec<String>
     

    Fields inherited from class org.elasticsearch.cli.Command

    description, parser
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseRunAsSuperuserCommand(Function<org.elasticsearch.env.Environment,org.elasticsearch.xpack.core.security.CommandLineHttpClient> clientFunction, org.elasticsearch.core.CheckedFunction<org.elasticsearch.env.Environment,org.elasticsearch.common.settings.KeyStoreWrapper,Exception> keyStoreFunction, String description)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final void
    execute(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env)
     
    protected abstract void
    executeCommand(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env, String username, org.elasticsearch.common.settings.SecureString password)
    This is called after we have created a temporary superuser in the file realm and verified that its credentials work.
    protected abstract void
    validate(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env)
    This method is called before we attempt to crete a temporary superuser in the file realm.

    Methods inherited from class org.elasticsearch.common.cli.KeyStoreAwareCommand

    decryptKeyStore, readPassword

    Methods inherited from class org.elasticsearch.common.cli.EnvironmentAwareCommand

    createEnv, createEnv, execute

    Methods inherited from class org.elasticsearch.cli.Command

    addShutdownHook, close, exit, main, mainWithoutErrorHandling, printAdditionalHelp, printUserException

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • urlOption

      protected final joptsimple.OptionSpec<String> urlOption
  • Constructor Details

    • BaseRunAsSuperuserCommand

      public BaseRunAsSuperuserCommand(Function<org.elasticsearch.env.Environment,org.elasticsearch.xpack.core.security.CommandLineHttpClient> clientFunction, org.elasticsearch.core.CheckedFunction<org.elasticsearch.env.Environment,org.elasticsearch.common.settings.KeyStoreWrapper,Exception> keyStoreFunction, String description)
  • Method Details

    • execute

      protected final void execute(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env) throws Exception
      Specified by:
      execute in class org.elasticsearch.common.cli.KeyStoreAwareCommand
      Throws:
      Exception
    • executeCommand

      protected abstract void executeCommand(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env, String username, org.elasticsearch.common.settings.SecureString password) throws Exception
      This is called after we have created a temporary superuser in the file realm and verified that its credentials work. The username and password of the generated user are passed as parameters. Overriding methods should not try to close the password.
      Throws:
      Exception
    • validate

      protected abstract void validate(org.elasticsearch.cli.Terminal terminal, joptsimple.OptionSet options, org.elasticsearch.env.Environment env) throws Exception
      This method is called before we attempt to crete a temporary superuser in the file realm. Commands that implement BaseRunAsSuperuserCommand can do preflight checks such as parsing and validating options without the need to go through the process of attempting to create and remove the temporary user unnecessarily.
      Throws:
      Exception