-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Retain reference to stdout for exceptional cases #77460
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
Changes from 2 commits
6d5c2fd
2f221b4
0152f99
bc256ed
ec3f566
330320b
dfe8e88
d4fa04c
5087a48
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 |
|---|---|---|
|
|
@@ -12,13 +12,15 @@ | |
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.DocWriteRequest; | ||
| import org.elasticsearch.action.support.WriteRequest; | ||
| import org.elasticsearch.bootstrap.BootstrapInfo; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.index.engine.VersionConflictEngineException; | ||
| import org.elasticsearch.xpack.core.security.user.ElasticUser; | ||
| import org.elasticsearch.xpack.core.security.user.KibanaSystemUser; | ||
| import org.elasticsearch.xpack.security.authc.esnative.NativeUsersStore; | ||
| import org.elasticsearch.xpack.security.support.SecurityIndexManager; | ||
|
|
||
| import java.io.PrintStream; | ||
| import java.util.function.BiConsumer; | ||
|
|
||
| import static org.elasticsearch.xpack.security.tool.CommandUtils.generatePassword; | ||
|
|
@@ -36,6 +38,11 @@ public GenerateInitialBuiltinUsersPasswordListener(NativeUsersStore nativeUsersS | |
|
|
||
| @Override | ||
| public void accept(SecurityIndexManager.State previousState, SecurityIndexManager.State currentState) { | ||
| final PrintStream out = BootstrapInfo.getOriginalStandardOut(); | ||
| if (null == out) { | ||
| outputOnError(new IllegalStateException("Stashed standard output stream is not available.")); | ||
| return; | ||
| } | ||
| if (previousState.equals(SecurityIndexManager.State.UNRECOVERED_STATE) | ||
| && currentState.equals(SecurityIndexManager.State.UNRECOVERED_STATE) == false | ||
| && securityIndexManager.indexExists() == false) { | ||
|
|
@@ -57,7 +64,7 @@ public void accept(SecurityIndexManager.State previousState, SecurityIndexManage | |
| WriteRequest.RefreshPolicy.IMMEDIATE, | ||
| ActionListener.wrap( | ||
| r -> { | ||
| outputOnSuccess(elasticPassword, kibanaSystemPassword); | ||
| outputOnSuccess(elasticPassword, kibanaSystemPassword, out); | ||
| }, this::outputOnError | ||
| ) | ||
| ); | ||
|
|
@@ -66,32 +73,25 @@ public void accept(SecurityIndexManager.State previousState, SecurityIndexManage | |
| } | ||
| } | ||
|
|
||
| private void outputOnSuccess(SecureString elasticPassword, SecureString kibanaSystemPassword) { | ||
| LOGGER.info(""); | ||
| LOGGER.info("-----------------------------------------------------------------"); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info("Password for the elastic user is: " + elasticPassword); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info("Password for the kibana_system user is: " + kibanaSystemPassword); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info("Please note these down as they will not be shown again."); | ||
| LOGGER.info(""); | ||
| LOGGER.info("You can use 'bin/elasticsearch-reset-elastic-password' at any time"); | ||
| LOGGER.info("in order to reset the password for the elastic user."); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info("You can use 'bin/elasticsearch-reset-kibana-system-password' at any time"); | ||
| LOGGER.info("in order to reset the password for the kibana_system user."); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info(""); | ||
| LOGGER.info("-----------------------------------------------------------------"); | ||
| LOGGER.info(""); | ||
| private void outputOnSuccess(SecureString elasticPassword, SecureString kibanaSystemPassword, PrintStream out) { | ||
| out.println(); | ||
|
Member
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. The stream could still have been closed, in which case we are not attached to a terminal. So we need to catch that case, and probably log a warning?
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. Yes, I'll check this first before even generating the passwords. If we can't show them, there is no need to even generate them |
||
| out.println("-----------------------------------------------------------------"); | ||
| out.println(); | ||
| out.println("Password for the elastic user is: " + elasticPassword); | ||
| out.println(); | ||
| out.println("Password for the kibana_system user is: " + kibanaSystemPassword); | ||
| out.println(); | ||
| out.println("Please note these down as they will not be shown again."); | ||
| out.println(); | ||
| out.println(); | ||
| out.println("You can use 'bin/elasticsearch-reset-elastic-password' at any time"); | ||
| out.println("in order to reset the password for the elastic user."); | ||
| out.println(); | ||
| out.println("You can use 'bin/elasticsearch-reset-kibana-system-password' at any time"); | ||
| out.println("in order to reset the password for the kibana_system user."); | ||
| out.println(); | ||
| out.println("-----------------------------------------------------------------"); | ||
| out.println(); | ||
| } | ||
|
|
||
| private void outputOnError(Exception e) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
How is this case possible? We could add a not null assertion when setting in BootstrapInfo?
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.
Yes, you are right. There should be nothing else calling
BootstrapInfo#initand there is no setter fororiginalStandardOutso I think we are ok ?