Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: disabled binding logic for auth_provider (#437)

Luke Zhoua4c129518f01
diff --git a/api/principal.go b/api/principal.go
index d0956412e5..5166383582 100644
--- a/api/principal.go
+++ b/api/principal.go
@@ -46,10 +46,9 @@ type Principal struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Domain specific fields
- Type PrincipalType `jsonapi:"attr,type"`
- AuthProvider PrincipalAuthProvider `jsonapi:"attr,authProvider"`
- Name string `jsonapi:"attr,name"`
- Email string `jsonapi:"attr,email"`
+ Type PrincipalType `jsonapi:"attr,type"`
+ Name string `jsonapi:"attr,name"`
+ Email string `jsonapi:"attr,email"`
// Do not return to the client
PasswordHash string
// Role is stored in the member table, but we include it when returning the principal.
@@ -61,27 +60,25 @@ type Principal struct {
// can map directly to the frontend Principal object without any conversion.
func (p *Principal) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
- ID int `json:"id"`
- CreatorID int `json:"creatorId"`
- CreatedTs int64 `json:"createdTs"`
- UpdaterID int `json:"updaterId"`
- UpdatedTs int64 `json:"updatedTs"`
- Type PrincipalType `json:"type"`
- AuthProvider PrincipalAuthProvider `json:"authProvider"`
- Name string `json:"name"`
- Email string `json:"email"`
- Role Role `json:"role"`
+ ID int `json:"id"`
+ CreatorID int `json:"creatorId"`
+ CreatedTs int64 `json:"createdTs"`
+ UpdaterID int `json:"updaterId"`
+ UpdatedTs int64 `json:"updatedTs"`
+ Type PrincipalType `json:"type"`
+ Name string `json:"name"`
+ Email string `json:"email"`
+ Role Role `json:"role"`
}{
- ID: p.ID,
- CreatorID: p.CreatorID,
- CreatedTs: p.CreatedTs,
- UpdaterID: p.UpdaterID,
- UpdatedTs: p.UpdatedTs,
- Type: p.Type,
- AuthProvider: p.AuthProvider,
- Name: p.Name,
- Email: p.Email,
- Role: p.Role,
+ ID: p.ID,
+ CreatorID: p.CreatorID,
+ CreatedTs: p.CreatedTs,
+ UpdaterID: p.UpdaterID,
+ UpdatedTs: p.UpdatedTs,
+ Type: p.Type,
+ Name: p.Name,
+ Email: p.Email,
+ Role: p.Role,
})
}
@@ -94,10 +91,9 @@ type PrincipalCreate struct {
// Domain specific fields
Type PrincipalType
- AuthProvider PrincipalAuthProvider `jsonapi:"attr,authProvider"`
- Name string `jsonapi:"attr,name"`
- Email string `jsonapi:"attr,email"`
- Password string `jsonapi:"attr,password"`
+ Name string `jsonapi:"attr,name"`
+ Email string `jsonapi:"attr,email"`
+ Password string `jsonapi:"attr,password"`
PasswordHash string
}
diff --git a/frontend/src/components/MemberAddOrInvite.vue b/frontend/src/components/MemberAddOrInvite.vue
index f541cf6c47..9fbc228062 100644
--- a/frontend/src/components/MemberAddOrInvite.vue
+++ b/frontend/src/components/MemberAddOrInvite.vue
@@ -216,7 +216,6 @@ export default {
// This could happen if another client has just created the principal
// with this email.
const newPrincipal: PrincipalCreate = {
- authProvider: "BYTEBASE",
name: user.email.split("@")[0],
email: user.email,
};
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index 4824ad4d2e..2695e92aea 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -203,7 +203,6 @@ export default {
const switchToOwner = () => {
store.dispatch("auth/login", {
- authProvider: "BYTEBASE",
payload: {
password: "1024",
@@ -213,7 +212,6 @@ export default {
const switchToDBA = () => {
store.dispatch("auth/login", {
- authProvider: "BYTEBASE",
payload: {
password: "aaa",
@@ -223,7 +221,6 @@ export default {
const switchToDeveloper = () => {
store.dispatch("auth/login", {
- authProvider: "BYTEBASE",
payload: {
password: "aaa",
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index 31f87fdc4f..a1174833bf 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -10,7 +10,6 @@ import {
unknown,
PrincipalId,
AuthProvider,
- VCSLoginInfo,
} from "../../types";
import { getIntCookie } from "../../utils";
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
index a2e44dc129..50e3a50dbc 100644
--- a/frontend/src/store/modules/principal.ts
+++ b/frontend/src/store/modules/principal.ts
@@ -11,7 +11,6 @@ import {
EMPTY_ID,
PrincipalType,
RoleType,
- AuthProviderType,
} from "../../types";
import { randomString } from "../../utils";
@@ -22,7 +21,6 @@ function convert(principal: ResourceObject): Principal {
createdTs: principal.attributes.createdTs as number,
updaterId: principal.attributes.updaterId as PrincipalId,
updatedTs: principal.attributes.updatedTs as number,
- authProvider: principal.attributes.authProvider as AuthProviderType,
type: principal.attributes.type as PrincipalType,
name: principal.attributes.name as string,
email: principal.attributes.email as string,
@@ -90,7 +88,6 @@ const actions = {
data: {
type: "PrincipalCreate",
attributes: {
- authProvider: newPrincipal.authProvider,
name: newPrincipal.name,
email: newPrincipal.email,
password: randomString(),
diff --git a/frontend/src/types/principal.ts b/frontend/src/types/principal.ts
index f1f295e655..a1d2367f33 100644
--- a/frontend/src/types/principal.ts
+++ b/frontend/src/types/principal.ts
@@ -1,7 +1,5 @@
// This is a facet of the underlying identity entity.
// For now, there is only user type. In the future,
-
-import { AuthProviderType } from ".";
import { PrincipalId } from "./id";
import { RoleType } from "./member";
@@ -20,7 +18,6 @@ export type Principal = {
updatedTs: number;
// Domain specific fields
- authProvider: AuthProviderType;
type: PrincipalType;
name: string;
email: string;
@@ -29,7 +26,6 @@ export type Principal = {
export type PrincipalCreate = {
// Domain specific fields
- authProvider: AuthProviderType;
name: string;
email: string;
};
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index cb9729c624..6bc77540bb 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -3,7 +3,11 @@
<div class="flex items-center">
<div class="flex-shrink-0 w-44">
<router-link to="/" class="select-none" active-class exact-active-class>
- <img class="h-12 w-auto" src="../assets/logo-full.svg" alt="Bytebase" />
+ <img
+ class="h-12 w-auto"
+ src="../assets/logo-full.svg"
+ alt="Bytebase"
+ />
</router-link>
</div>
<div class="hidden sm:block">
@@ -12,34 +16,37 @@
v-if="showDBAItem"
to="/issue"
class="bar-link px-2 py-2 rounded-md"
- >{{ $t("common.issues") }}</router-link>
+ >{{ $t("common.issues") }}</router-link
+ >
<router-link to="/project" class="bar-link px-2 py-2 rounded-md">
- {{
- $t("common.projects")
- }}
+ {{ $t("common.projects") }}
</router-link>
- <router-link to="/db" class="bar-link px-2 py-2 rounded-md">{{ $t("common.databases") }}</router-link>
+ <router-link to="/db" class="bar-link px-2 py-2 rounded-md">{{
+ $t("common.databases")
+ }}</router-link>
- <router-link
- to="/instance"
- class="bar-link px-2 py-2 rounded-md"
- >{{ $t("common.instances") }}</router-link>
+ <router-link to="/instance" class="bar-link px-2 py-2 rounded-md">{{
+ $t("common.instances")
+ }}</router-link>
<router-link
to="/environment"
class="bar-link px-2 py-2 rounded-md"
- >{{ $t("common.environments") }}</router-link>
+ >{{ $t("common.environments") }}</router-link
+ >
<router-link
to="/setting/member"
class="bar-link px-2 py-2 rounded-md"
- >{{ $t("common.settings") }}</router-link>
+ >{{ $t("common.settings") }}</router-link
+ >
<router-link
v-if="isDevFeatures"
to="/sql-editor"
class="bar-link px-2 py-2 rounded-md"
- >{{ $t("sql-editor.self") }}</router-link>
+ >{{ $t("sql-editor.self") }}</router-link
+ >
</div>
</div>
</div>
@@ -50,20 +57,22 @@
class="hidden md:flex sm:flex-row items-center space-x-2 text-sm font-medium"
>
<span class="hidden lg:block font-normal text-accent">
- {{
- $t("setting.plan.self")
- }}
+ {{ $t("setting.plan.self") }}
</span>
<div
class="bar-link"
:class="currentPlan == 0 ? 'underline' : ''"
@click.prevent="switchToFree"
- >{{ $t("setting.plan.free") }}</div>
+ >
+ {{ $t("setting.plan.free") }}
+ </div>
<div
class="bar-link"
:class="currentPlan == 1 ? 'underline' : ''"
@click.prevent="switchToTeam"
- >{{ $t("setting.plan.team") }}</div>
+ >
+ {{ $t("setting.plan.team") }}
+ </div>
<!-- <div
class="bar-link"
:class="currentPlan == 2 ? 'underline' : ''"
@@ -77,25 +86,29 @@
class="hidden md:flex sm:flex-row items-center space-x-2 text-sm font-medium"
>
<span class="hidden lg:block font-normal text-accent">
- {{
- $t("settings.profile.role")
- }}
+ {{ $t("settings.profile.role") }}
</span>
<div
class="bar-link"
:class="currentUser.role == 'OWNER' ? 'underline' : ''"
@click.prevent="switchToOwner"
- >{{ $t("common.role.owner") }}</div>
+ >
+ {{ $t("common.role.owner") }}
+ </div>
<div
class="bar-link"
:class="currentUser.role == 'DBA' ? 'underline' : ''"
@click.prevent="switchToDBA"
- >{{ $t("common.role.dba") }}</div>
+ >
+ {{ $t("common.role.dba") }}
+ </div>
<div
class="bar-link"
:class="currentUser.role == 'DEVELOPER' ? 'underline' : ''"
@click.prevent="switchToDeveloper"
- >{{ $t("common.role.developer") }}</div>
+ >
+ {{ $t("common.role.developer") }}
+ </div>
</div>
<router-link to="/inbox" exact-active-class>
<span
@@ -135,38 +148,37 @@
Open: "block", closed: "hidden"
-->
<div v-if="state.showMobileMenu" class="block md:hidden">
- <router-link v-if="showDBAItem" to="/issue" class="bar-link rounded-md block px-3 py-2">
- {{
- $t("common.issues")
- }}
+ <router-link
+ v-if="showDBAItem"
+ to="/issue"
+ class="bar-link rounded-md block px-3 py-2"
+ >
+ {{ $t("common.issues") }}
</router-link>
<router-link to="/project" class="bar-link rounded-md block px-3 py-2">
- {{
- $t("common.projects")
- }}
+ {{ $t("common.projects") }}
</router-link>
<router-link to="/db" class="bar-link rounded-md block px-3 py-2">
- {{
- $t("common.databases")
- }}
+ {{ $t("common.databases") }}
</router-link>
- <router-link
- to="/instance"
- class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.instances") }}</router-link>
+ <router-link to="/instance" class="bar-link rounded-md block px-3 py-2">{{
+ $t("common.instances")
+ }}</router-link>
<router-link
to="/environment"
class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.environments") }}</router-link>
+ >{{ $t("common.environments") }}</router-link
+ >
<router-link
to="/setting/member"
class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.settings") }}</router-link>
+ >{{ $t("common.settings") }}</router-link
+ >
</div>
</template>
@@ -204,9 +216,7 @@ export default {
const currentPlan = computed(() => store.getters["plan/currentPlan"]());
const showDBAItem = computed((): boolean => {
- return (
- isDBAOrOwner(currentUser.value.role)
- );
+ return isDBAOrOwner(currentUser.value.role);
});
const isDevFeatures = computed((): boolean => {
diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vue
index e2ac51944a..2303aa267f 100644
--- a/frontend/src/views/auth/Signin.vue
+++ b/frontend/src/views/auth/Signin.vue
@@ -184,7 +184,7 @@ export default {
}
store.dispatch("auth/fetchProviderList");
-
+
window.addEventListener("bb.oauth.signin", eventListener, false);
});
diff --git a/server/auth.go b/server/auth.go
index 59840f2368..ac579ca878 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -68,10 +68,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
if user == nil {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found: %s", login.Email))
}
- // if user had already use third party method logged in, we will forbid she login via Bytebase
- if user.AuthProvider != api.PrincipalAuthProviderBytebase {
- return echo.NewHTTPError(http.StatusUnauthorized, "User has bond to Gitlab")
- }
+
// Compare the stored hashed password, with the hashed version of the password that was received.
if err := bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(login.Password)); err != nil {
// If the two passwords don't match, return a 401 status.
@@ -115,15 +112,14 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
if user == nil {
// if user login via gitlab at the first time, we will generate a random password.
// The random password is supposed to be not guessable.
- // But even one can guess the password, she won't be allowed to login.
- // If user signs up via 3rd party login like GitLab, we will disallow bytebase builtin password/email login unless user manually switch the login option later.
+ // If user signs up via 3rd party login like GitLab, we will disallow bytebase builtin password/email login unless user manually set up her password later.
signup := &api.Signup{
Email: GitlabUserInfo.Email,
Password: common.RandomString(20),
Name: GitlabUserInfo.Name,
}
var httpError *echo.HTTPError
- user, httpError = trySignup(ctx, s, signup, api.PrincipalAuthProviderGitlabSelfHost)
+ user, httpError = trySignup(ctx, s, signup)
if httpError != nil {
return httpError
}
@@ -175,7 +171,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signup request").SetInternal(err)
}
- user, err := trySignup(ctx, s, signup, api.PrincipalAuthProviderBytebase)
+ user, err := trySignup(ctx, s, signup)
if err != nil {
return err
}
@@ -192,7 +188,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
})
}
-func trySignup(ctx context.Context, s *Server, signup *api.Signup, authProvider api.PrincipalAuthProvider) (*api.Principal, *echo.HTTPError) {
+func trySignup(ctx context.Context, s *Server, signup *api.Signup) (*api.Principal, *echo.HTTPError) {
passwordHash, err := bcrypt.GenerateFromPassword([]byte(signup.Password), bcrypt.DefaultCost)
if err != nil {
return nil, echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate password hash").SetInternal(err)
@@ -201,7 +197,6 @@ func trySignup(ctx context.Context, s *Server, signup *api.Signup, authProvider
principalCreate := &api.PrincipalCreate{
CreatorID: api.SystemBotID,
Type: api.EndUser,
- AuthProvider: authProvider,
Name: signup.Name,
Email: signup.Email,
PasswordHash: string(passwordHash),
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index eb1ae52bca..5b49fdcdcb 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -12,8 +12,6 @@ CREATE TABLE principal (
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
-- allowed types are 'END_USER', 'SYSTEM_BOT'.
type TEXT NOT NULL,
- -- allowed auth providers are 'BYTEBASE', 'GITLAB_SELF_HOST'.
- auth_provider TEXT NOT NULL,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL
@@ -46,7 +44,6 @@ INSERT INTO
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
@@ -57,7 +54,6 @@ VALUES
1,
1,
'SYSTEM_BOT',
- 'BYTEBASE',
'Bytebase',
''
diff --git a/store/principal.go b/store/principal.go
index eb74d7a2b3..ef4ab63a0d 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -145,18 +145,16 @@ func createPrincipal(ctx context.Context, tx *Tx, create *api.PrincipalCreate) (
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
)
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, auth_provider, name, email, password_hash
+ VALUES (?, ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
`,
create.CreatorID,
create.CreatorID,
create.Type,
- create.AuthProvider,
create.Name,
create.Email,
create.PasswordHash,
@@ -176,7 +174,6 @@ func createPrincipal(ctx context.Context, tx *Tx, create *api.PrincipalCreate) (
&principal.UpdaterID,
&principal.UpdatedTs,
&principal.Type,
- &principal.AuthProvider,
&principal.Name,
&principal.Email,
&principal.PasswordHash,
@@ -205,7 +202,6 @@ func findPrincipalList(ctx context.Context, tx *Tx, find *api.PrincipalFind) (_
updater_id,
updated_ts,
type,
- auth_provider,
name,
email,
password_hash
@@ -229,7 +225,6 @@ func findPrincipalList(ctx context.Context, tx *Tx, find *api.PrincipalFind) (_
&principal.UpdaterID,
&principal.UpdatedTs,
&principal.Type,
- &principal.AuthProvider,
&principal.Name,
&principal.Email,
&principal.PasswordHash,
@@ -263,7 +258,7 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
UPDATE principal
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, auth_provider, name, email, password_hash
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, type, name, email, password_hash
`,
args...,
)
@@ -281,7 +276,6 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
&principal.UpdaterID,
&principal.UpdatedTs,
&principal.Type,
- &principal.AuthProvider,
&principal.Name,
&principal.Email,
&principal.PasswordHash,
diff --git a/store/seed/test/10001__principal.sql b/store/seed/test/10001__principal.sql
index 9ee80c3dd3..582c68db53 100644
--- a/store/seed/test/10001__principal.sql
+++ b/store/seed/test/10001__principal.sql
@@ -6,7 +6,6 @@ INSERT INTO
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
@@ -16,7 +15,6 @@ VALUES
1,
1,
'END_USER',
- 'BYTEBASE',
'Demo Owner',
-- 1024
@@ -29,7 +27,6 @@ INSERT INTO
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
@@ -39,7 +36,6 @@ VALUES
1,
1,
'END_USER',
- 'BYTEBASE',
'Jerry DBA',
-- 2048
@@ -52,7 +48,6 @@ INSERT INTO
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
@@ -62,7 +57,6 @@ VALUES
1,
1,
'END_USER',
- 'BYTEBASE',
'Tom Dev',
-- 4096
@@ -75,7 +69,6 @@ INSERT INTO
creator_id,
updater_id,
type,
- auth_provider,
name,
email,
password_hash
@@ -85,7 +78,6 @@ VALUES
1,
1,
'END_USER',
- 'BYTEBASE',
'Jane Dev',
-- 8192