func (s *RaftServer) CreateRootUser() error { u := &cluster.ClusterAdmin{cluster.CommonUser{Name: "root", Hash: "", IsUserDeleted: false, CacheKey: "root"}} password := os.Getenv(DEFAULT_ROOT_PWD_ENVKEY) if password == "" { password = DEFAULT_ROOT_PWD } hash, _ := cluster.HashPassword(password) u.ChangePassword(string(hash)) return s.SaveClusterAdminUser(u) }
func (self *Coordinator) ChangeDbUserPassword(requester common.User, db, username, password string) error { if ok, err := self.permissions.AuthorizeChangeDbUserPassword(requester, db, username); !ok { return err } hash, err := cluster.HashPassword(password) if err != nil { return err } return self.raftServer.ChangeDbUserPassword(db, username, hash) }
func (self *Coordinator) ChangeClusterAdminPassword(requester common.User, username, password string) error { if ok, err := self.permissions.AuthorizeChangeClusterAdminPassword(requester); !ok { return err } user := self.clusterConfiguration.GetClusterAdmin(username) if user == nil { return fmt.Errorf("Invalid user name %s", username) } hash, err := cluster.HashPassword(password) if err != nil { return err } user.ChangePassword(string(hash)) return self.raftServer.SaveClusterAdminUser(user) }
func (self *Coordinator) CreateClusterAdminUser(requester common.User, username, password string) error { if ok, err := self.permissions.AuthorizeCreateClusterAdmin(requester); !ok { return err } if !isValidName(username) { return fmt.Errorf("%s isn't a valid username", username) } hash, err := cluster.HashPassword(password) if err != nil { return err } if self.clusterConfiguration.GetClusterAdmin(username) != nil { return fmt.Errorf("User %s already exists", username) } return self.raftServer.SaveClusterAdminUser(&cluster.ClusterAdmin{cluster.CommonUser{Name: username, CacheKey: username, Hash: string(hash)}}) }
func (self *Coordinator) CreateDbUser(requester common.User, db, username, password string, permissions ...string) error { if ok, err := self.permissions.AuthorizeCreateDbUser(requester, db); !ok { return err } if username == "" { return fmt.Errorf("Username cannot be empty") } if !isValidName(username) { return fmt.Errorf("%s isn't a valid username", username) } hash, err := cluster.HashPassword(password) if err != nil { return err } if !self.clusterConfiguration.DatabaseExists(db) { return fmt.Errorf("No such database %s", db) } if self.clusterConfiguration.GetDbUser(db, username) != nil { return fmt.Errorf("User %s already exists", username) } readMatcher := []*cluster.Matcher{{true, ".*"}} writeMatcher := []*cluster.Matcher{{true, ".*"}} switch len(permissions) { case 0: case 2: readMatcher[0].Name = permissions[0] writeMatcher[0].Name = permissions[1] } log.Debug("(raft:%s) Creating user %s:%s", self.raftServer.raftServer.Name(), db, username) return self.raftServer.SaveDbUser(&cluster.DbUser{cluster.CommonUser{ Name: username, Hash: string(hash), CacheKey: db + "%" + username, }, db, readMatcher, writeMatcher, false}) }