feat(security): shutdown instance after 5minutes if no admin account created (#2500)

* feat(security): skip admin check if --no-auth

* fix(security): change error message
pull/2472/head
Chaim Lev-Ari 2018-12-04 05:50:41 +02:00 committed by Anthony Lapenna
parent acce5e0023
commit 101bb41587
1 changed files with 19 additions and 0 deletions

View File

@ -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,