Skip to content

Commit a4d9335

Browse files
committed
Fix message content in users tool (#30293)
The elasticsearch-users utility had various messages that were outdated or incorrect. This commit updates the output from this command to reflect current terminology and configuration.
1 parent 706f3ad commit a4d9335

File tree

2 files changed

+19
-28
lines changed
  • x-pack
    • plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/file/tool
    • qa/security-tools-tests/src/test/java/org/elasticsearch/xpack/security/authc/file/tool

2 files changed

+19
-28
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/file/tool/UsersTool.java

+15-24
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import org.elasticsearch.common.settings.Settings;
1818
import org.elasticsearch.common.util.set.Sets;
1919
import org.elasticsearch.env.Environment;
20-
import org.elasticsearch.xpack.core.XPackField;
2120
import org.elasticsearch.xpack.core.XPackSettings;
2221
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
23-
import org.elasticsearch.xpack.security.authz.store.FileRolesStore;
2422
import org.elasticsearch.xpack.core.security.authz.store.ReservedRolesStore;
2523
import org.elasticsearch.xpack.core.security.support.Validation;
2624
import org.elasticsearch.xpack.core.security.support.Validation.Users;
2725
import org.elasticsearch.xpack.security.authc.file.FileUserPasswdStore;
2826
import org.elasticsearch.xpack.security.authc.file.FileUserRolesStore;
27+
import org.elasticsearch.xpack.security.authz.store.FileRolesStore;
2928
import org.elasticsearch.xpack.security.support.FileAttributesChecker;
3029

3130
import java.nio.file.Files;
@@ -47,7 +46,7 @@ public static void main(String[] args) throws Exception {
4746
}
4847

4948
UsersTool() {
50-
super("Manages elasticsearch native users");
49+
super("Manages elasticsearch file users");
5150
subcommands.put("useradd", newAddUserCommand());
5251
subcommands.put("userdel", newDeleteUserCommand());
5352
subcommands.put("passwd", newPasswordCommand());
@@ -82,7 +81,7 @@ static class AddUserCommand extends EnvironmentAwareCommand {
8281
private final OptionSpec<String> arguments;
8382

8483
AddUserCommand() {
85-
super("Adds a native user");
84+
super("Adds a file user");
8685

8786
this.passwordOption = parser.acceptsAll(Arrays.asList("p", "password"),
8887
"The user password")
@@ -96,11 +95,8 @@ static class AddUserCommand extends EnvironmentAwareCommand {
9695
@Override
9796
protected void printAdditionalHelp(Terminal terminal) {
9897
terminal.println("Adds a file based user to elasticsearch (via internal realm). The user will");
99-
terminal.println("be added to the users file and its roles will be added to the");
100-
terminal.println("users_roles file. If non-default files are used (different file");
101-
terminal.println("locations are configured in elasticsearch.yml) the appropriate files");
102-
terminal.println("will be resolved from the settings and the user and its roles will be");
103-
terminal.println("added to them.");
98+
terminal.println("be added to the \"users\" file and its roles will be added to the");
99+
terminal.println("\"users_roles\" file in the elasticsearch config directory.");
104100
terminal.println("");
105101
}
106102

@@ -123,7 +119,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
123119

124120
Map<String, char[]> users = FileUserPasswdStore.parseFile(passwordFile, null, env.settings());
125121
if (users == null) {
126-
throw new UserException(ExitCodes.CONFIG, "Configuration file [users] is missing");
122+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + passwordFile + "] is missing");
127123
}
128124
if (users.containsKey(username)) {
129125
throw new UserException(ExitCodes.CODE_ERROR, "User [" + username + "] already exists");
@@ -155,11 +151,8 @@ static class DeleteUserCommand extends EnvironmentAwareCommand {
155151
@Override
156152
protected void printAdditionalHelp(Terminal terminal) {
157153
terminal.println("Removes an existing file based user from elasticsearch. The user will be");
158-
terminal.println("removed from the users file and its roles will be removed from the");
159-
terminal.println("users_roles file. If non-default files are used (different file");
160-
terminal.println("locations are configured in elasticsearch.yml) the appropriate files");
161-
terminal.println("will be resolved from the settings and the user and its roles will be");
162-
terminal.println("removed from them.");
154+
terminal.println("removed from the \"users\" file and its roles will be removed from the");
155+
terminal.println("\"users_roles\" file in the elasticsearch config directory.");
163156
terminal.println("");
164157
}
165158

@@ -173,7 +166,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
173166

174167
Map<String, char[]> users = FileUserPasswdStore.parseFile(passwordFile, null, env.settings());
175168
if (users == null) {
176-
throw new UserException(ExitCodes.CONFIG, "Configuration file [users] is missing");
169+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + passwordFile + "] is missing");
177170
}
178171
if (users.containsKey(username) == false) {
179172
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
@@ -213,12 +206,10 @@ static class PasswordCommand extends EnvironmentAwareCommand {
213206

214207
@Override
215208
protected void printAdditionalHelp(Terminal terminal) {
216-
terminal.println("The passwd command changes passwords for files based users. The tool");
209+
terminal.println("The passwd command changes passwords for file based users. The tool");
217210
terminal.println("prompts twice for a replacement password. The second entry is compared");
218211
terminal.println("against the first and both are required to match in order for the");
219-
terminal.println("password to be changed. If non-default users file is used (a different");
220-
terminal.println("file location is configured in elasticsearch.yml) the appropriate file");
221-
terminal.println("will be resolved from the settings.");
212+
terminal.println("password to be changed.");
222213
terminal.println("");
223214
}
224215

@@ -232,7 +223,7 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
232223
FileAttributesChecker attributesChecker = new FileAttributesChecker(file);
233224
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null, env.settings()));
234225
if (users == null) {
235-
throw new UserException(ExitCodes.CONFIG, "Configuration file [users] is missing");
226+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + file + "] is missing");
236227
}
237228
if (users.containsKey(username) == false) {
238229
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
@@ -345,19 +336,19 @@ static void listUsersAndRoles(Terminal terminal, Environment env, String usernam
345336
Path userRolesFilePath = FileUserRolesStore.resolveFile(env);
346337
Map<String, String[]> userRoles = FileUserRolesStore.parseFile(userRolesFilePath, null);
347338
if (userRoles == null) {
348-
throw new UserException(ExitCodes.CONFIG, "Configuration file [users_roles] is missing");
339+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + userRolesFilePath + "] is missing");
349340
}
350341

351342
Path userFilePath = FileUserPasswdStore.resolveFile(env);
352343
Map<String, char[]> users = FileUserPasswdStore.parseFile(userFilePath, null, env.settings());
353344
if (users == null) {
354-
throw new UserException(ExitCodes.CONFIG, "Configuration file [users] is missing");
345+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + userFilePath + "] is missing");
355346
}
356347

357348
Path rolesFilePath = FileRolesStore.resolveFile(env);
358349
Set<String> knownRoles = Sets.union(FileRolesStore.parseFileForRoleNames(rolesFilePath, null), ReservedRolesStore.names());
359350
if (knownRoles == null) {
360-
throw new UserException(ExitCodes.CONFIG, "Configuration file [roles.xml] is missing");
351+
throw new UserException(ExitCodes.CONFIG, "Configuration file [" + rolesFilePath + "] is missing");
361352
}
362353

363354
if (username != null) {

x-pack/qa/security-tools-tests/src/test/java/org/elasticsearch/xpack/security/authc/file/tool/UsersToolTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public void testUserAddNoConfig() throws Exception {
500500
execute("useradd", pathHomeParameter, fileTypeParameter, "username", "-p", SecuritySettingsSourceField.TEST_PASSWORD);
501501
});
502502
assertEquals(ExitCodes.CONFIG, e.exitCode);
503-
assertThat(e.getMessage(), containsString("Configuration file [users] is missing"));
503+
assertThat(e.getMessage(), containsString("Configuration file [eshome/config/users] is missing"));
504504
}
505505

506506
public void testUserListNoConfig() throws Exception {
@@ -512,7 +512,7 @@ public void testUserListNoConfig() throws Exception {
512512
execute("list", pathHomeParameter, fileTypeParameter);
513513
});
514514
assertEquals(ExitCodes.CONFIG, e.exitCode);
515-
assertThat(e.getMessage(), containsString("Configuration file [users] is missing"));
515+
assertThat(e.getMessage(), containsString("Configuration file [eshome/config/users] is missing"));
516516
}
517517

518518
public void testUserDelNoConfig() throws Exception {
@@ -524,7 +524,7 @@ public void testUserDelNoConfig() throws Exception {
524524
execute("userdel", pathHomeParameter, fileTypeParameter, "username");
525525
});
526526
assertEquals(ExitCodes.CONFIG, e.exitCode);
527-
assertThat(e.getMessage(), containsString("Configuration file [users] is missing"));
527+
assertThat(e.getMessage(), containsString("Configuration file [eshome/config/users] is missing"));
528528
}
529529

530530
public void testListUserRolesNoConfig() throws Exception {
@@ -536,6 +536,6 @@ public void testListUserRolesNoConfig() throws Exception {
536536
execute("roles", pathHomeParameter, fileTypeParameter, "username");
537537
});
538538
assertEquals(ExitCodes.CONFIG, e.exitCode);
539-
assertThat(e.getMessage(), containsString("Configuration file [users_roles] is missing"));
539+
assertThat(e.getMessage(), containsString("Configuration file [eshome/config/users_roles] is missing"));
540540
}
541541
}

0 commit comments

Comments
 (0)