Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: use public email for auth (#829)
Zilong Zhou76a584fe84e8
diff --git a/frontend/src/components/ProjectMemberPanel.vue b/frontend/src/components/ProjectMemberPanel.vueindex 310bbdafaa..6909e2dbc1 100644--- a/frontend/src/components/ProjectMemberPanel.vue+++ b/frontend/src/components/ProjectMemberPanel.vue@@ -35,7 +35,6 @@:mask-closable="false"preset="dialog":title="$t('settings.members.toggle-role-provider.title')"- :content="$t('settings.members.change-role-provider-to-vcs.content')":on-after-leave="() => {state.previewMember = false;@@ -86,6 +85,16 @@/></div></template>++ <template v-else>+ <div class="mx-1">+ <span class="font-bold">+ {{ $t("settings.members.change-role-provider-to-vcs.emphasize") }}+ </span>+ <br />+ {{ $t("settings.members.change-role-provider-to-vcs.content") }}+ </div>+ </template></NModal><divdiff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex 81b526db38..8f504b1c2b 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -303,6 +303,7 @@ settings:members from the corresponding VCS project.The existing members will become inactive. You can turn off VCS sync to restore those members.+ emphasize: Please be noticed that this function requires all project members from the VCS have a public email set.change-role-provider-to-bytebase:content: >-You are about to restore the following members. All existing membersdiff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 237558120b..56eb54eff2 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -294,6 +294,7 @@ settings:content: |-开启 VCS 同步将会用 VCS 中对应仓库的成员列表替换现存的所有成员。原来的成员将会无效,您之后也可以关闭该 VCS 同步来撤销这一操作。+ emphasize: 请注意,该功能需要 VCS 仓库内所有成员均设置了公开邮箱。change-role-provider-to-bytebase:content: 将会恢复成以下成员的权限。所有由 VCS 提供的成员将会被移除。activity:diff --git a/plugin/vcs/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.goindex 2dd1abe64c..2eccf579c1 100644--- a/plugin/vcs/gitlab/gitlab.go+++ b/plugin/vcs/gitlab/gitlab.go@@ -288,20 +288,26 @@ func (provider *Provider) FetchRepositoryActiveMemberList(ctx context.Context, o}// we only return active member (both state and membership_state is active)+ var emptyEmailUserIDList []stringvar activeRepositoryMemberList []*vcs.RepositoryMemberfor _, gitLabMember := range gitLabrepositoryMember {if gitLabMember.State == vcs.StateActive {- // the email field does not return as expected via projects/<<projectId>>/members/all, possibly caused by: https://gitlab.com/gitlab-org/gitlab/-/issues/25077- // so we need to fetch this field one by one+ // The email field will only be returned if the caller credential is associated with a GitLab admin account.+ // And since most callers are not GitLab admins, thus we fetch public email+ // TODO: need to work around this if the user does not set public email. For now, we just return an error listing users not having public emails.// TODO: if the number of the member is too large, fetching sequentially may cause performance issueuserInfo, err := provider.FetchUserInfo(ctx, oauthCtx, instanceURL, gitLabMember.ID)if err != nil {return nil, err}+ if userInfo.PublicEmail == "" {+ emptyEmailUserIDList = append(emptyEmailUserIDList, gitLabMember.Name)+ }+gitLabRole, bytebaseRole := getRoleAndMappedRole(gitLabMember.AccessLevel)repositoryMember := &vcs.RepositoryMember{Name: gitLabMember.Name,- Email: userInfo.Email,+ Email: userInfo.PublicEmail,Role: bytebaseRole,VCSRole: gitLabRole.String(),State: vcs.StateActive,@@ -311,6 +317,10 @@ func (provider *Provider) FetchRepositoryActiveMemberList(ctx context.Context, o}}+ if len(emptyEmailUserIDList) != 0 {+ return nil, fmt.Errorf("[ %v ] did not configure their public email in GitLab, please make sure every members' public email is configured before syncing, see https://docs.gitlab.com/ee/user/profile", strings.Join(emptyEmailUserIDList, ", "))+ }+return activeRepositoryMemberList, nil}diff --git a/plugin/vcs/vcs.go b/plugin/vcs/vcs.goindex b14eb11681..2de537a1bc 100644--- a/plugin/vcs/vcs.go+++ b/plugin/vcs/vcs.go@@ -76,9 +76,10 @@ const (// UserInfo is the API message for user info.type UserInfo struct {- Email string `json:"email"`- Name string `json:"name"`- State State `json:"state"`+ // NOTICE: we use public email here because user's primary email can only be accessed by the admin+ PublicEmail string `json:"public_email"`+ Name string `json:"name"`+ State State `json:"state"`}// RepositoryMember is the API message for repository member info.diff --git a/server/auth.go b/server/auth.goindex 006703f67f..8a6dc4ee60 100644--- a/server/auth.go+++ b/server/auth.go@@ -101,7 +101,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {}principalFind := &api.PrincipalFind{- Email: &gitlabUserInfo.Email,+ Email: &gitlabUserInfo.PublicEmail,}user, err = s.PrincipalService.FindPrincipal(ctx, principalFind)if err != nil {@@ -110,11 +110,14 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {// create a new user if not existif user == nil {+ if gitlabUserInfo.PublicEmail == "" {+ return echo.NewHTTPError(http.StatusNotFound, "Please configure your public email first, https://docs.gitlab.com/ee/user/profile/")+ }// if user login via gitlab at the first time, we will generate a random password.// The random password is supposed to be not guessable. If user wants to login// via password, she needs to set the new password from the profile page.signUp := &api.SignUp{- Email: gitlabUserInfo.Email,+ Email: gitlabUserInfo.PublicEmail,Password: common.RandomString(20),Name: gitlabUserInfo.Name,}