fix(api): prevent the creation of multiple admin users (#1251)

pull/1188/merge
Anthony Lapenna 7 years ago committed by GitHub
parent 9c10a1def2
commit 249bcf5bac

@ -186,7 +186,6 @@ func main() {
applicationStatus := initStatus(authorizeEndpointMgmt, flags)
if *flags.Endpoint != "" {
var endpoints []portainer.Endpoint
endpoints, err := store.EndpointService.Endpoints()
if err != nil {
log.Fatal(err)
@ -229,7 +228,12 @@ func main() {
}
if adminPasswordHash != "" {
users, err := store.UserService.UsersByRole(portainer.AdministratorRole)
if err != nil {
log.Fatal(err)
}
if len(users) == 0 {
log.Printf("Creating admin user with password hash %s", adminPasswordHash)
user := &portainer.User{
Username: "admin",
@ -240,6 +244,9 @@ func main() {
if err != nil {
log.Fatal(err)
}
} else {
log.Println("Instance already has an administrator user defined. Skipping admin password related flags.")
}
}
var server portainer.Server = &http.Server{

Loading…
Cancel
Save