elastic/elasticsearch

migrate tool throws a NPE when user exists without role

Open

#29,837 opened on Nov 13, 2017

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Java (76,700 stars) (25,882 forks)batch import
:Security/Authentication>bugTeam:Securityhelp wanted

Description

Original comment by @PhaedrusTheGreek:

Pretty easy to reproduce:

$ bin/x-pack/users useradd testguy
$ bin/x-pack/users useradd testguy2 -r admin
$ bin/x-pack/migrate native -U http://localhost:9200 -u elastic -p changeme
starting migration of users and roles...
importing users from [/Users/jay/workspace/elasticsearch-5.6.4/config/x-pack/users]...
found existing users: [logstash, logstash_system, elsearch_watcher, elastic, es_admin, kibanaadmin, kibana]
migrating user [testguy2]
{"user":{"created":true}}
migrating user [testguy]
Exception in thread "main" ElasticsearchException[failed to migrate user [testguy] with body: n/a]; nested: NullPointerException;
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.importUsers(ESNativeRealmMigrateTool.java:289)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.execute(ESNativeRealmMigrateTool.java:143)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134)
	at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:69)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool.main(ESNativeRealmMigrateTool.java:91)
Caused by: java.lang.NullPointerException
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.createUserJson(ESNativeRealmMigrateTool.java:240)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.importUsers(ESNativeRealmMigrateTool.java:284)
	... 7 more

Contributor guide