diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index f7890c2c4..5cf99b3d7 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -468,6 +468,21 @@ func initJobService(dockerClientFactory *docker.ClientFactory) portainer.JobServ return docker.NewJobService(dockerClientFactory) } +func terminateIfNoAdminCreated(userService portainer.UserService) { + timer1 := time.NewTimer(5 * time.Minute) + <-timer1.C + + users, err := userService.UsersByRole(portainer.AdministratorRole) + if err != nil { + log.Fatal(err) + } + + if len(users) == 0 { + log.Fatal("No administrator account was created after 5 min. Shutting down the Portainer instance for security reasons.") + return + } +} + func main() { flags := initCLI() @@ -586,6 +601,10 @@ func main() { } } + if !*flags.NoAuth { + go terminateIfNoAdminCreated(store.UserService) + } + var server portainer.Server = &http.Server{ Status: applicationStatus, BindAddress: *flags.Addr,