Skip to content

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

feat: implement 2FA setup UI (#5023)

boojackb732b869f9b4
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 4d3f659409..1195091e09 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -21,6 +21,7 @@ import (
"github.com/bytebase/bytebase/backend/api/auth"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/config"
+ enterpriseAPI "github.com/bytebase/bytebase/backend/enterprise/api"
api "github.com/bytebase/bytebase/backend/legacyapi"
metricAPI "github.com/bytebase/bytebase/backend/metric"
"github.com/bytebase/bytebase/backend/plugin/idp/oauth2"
@@ -37,16 +38,18 @@ type AuthService struct {
v1pb.UnimplementedAuthServiceServer
store *store.Store
secret string
+ licenseService enterpriseAPI.LicenseService
metricReporter *metricreport.Reporter
profile *config.Profile
postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error
}
// NewAuthService creates a new AuthService.
-func NewAuthService(store *store.Store, secret string, metricReporter *metricreport.Reporter, profile *config.Profile, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) *AuthService {
+func NewAuthService(store *store.Store, secret string, licenseService enterpriseAPI.LicenseService, metricReporter *metricreport.Reporter, profile *config.Profile, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) *AuthService {
return &AuthService{
store: store,
secret: secret,
+ licenseService: licenseService,
metricReporter: metricReporter,
profile: profile,
postCreateUser: postCreateUser,
@@ -305,9 +308,10 @@ func (s *AuthService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
return nil, status.Errorf(codes.InvalidArgument, "invalid OTP code")
}
}
- // This flag is mainly used for regenerating temp secret and recovery codes when user setup MFA.
+ // This flag will regenerate temp secret and temp recovery codes.
+ // It will be used when user setup MFA and regenerating recovery codes.
if request.RegenerateTempMfaSecret {
- tempSecret, err := generateRandSecret(fmt.Sprintf("%s%d", userNamePrefix, user.ID))
+ tempSecret, err := generateRandSecret(user.Email)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to generate MFA secret, error: %v", err)
}
@@ -322,18 +326,18 @@ func (s *AuthService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
TempRecoveryCodes: tempRecoveryCodes,
}
}
- // This flag is mainly used for regenerating recovery codes with MFA enabled.
+ // This flag will update user's recovery codes with temp recovery codes.
+ // It will be used when user regenerate recovery codes after two phase commit.
if request.RegenerateRecoveryCodes {
if user.MFAConfig.OtpSecret == "" {
return nil, status.Errorf(codes.InvalidArgument, "MFA is not enabled")
}
- recoveryCodes, err := generateRecoveryCodes(10)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to generate recovery codes, error: %v", err)
+ if len(user.MFAConfig.TempRecoveryCodes) == 0 {
+ return nil, status.Errorf(codes.InvalidArgument, "No recovery codes to update")
}
patch.MFAConfig = &storepb.MFAConfig{
OtpSecret: user.MFAConfig.OtpSecret,
- RecoveryCodes: recoveryCodes,
+ RecoveryCodes: user.MFAConfig.TempRecoveryCodes,
}
}
@@ -489,18 +493,21 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*v
if loginUser.MemberDeleted {
return nil, status.Errorf(codes.Unauthenticated, "user has been deactivated by administrators")
}
- if loginUser.MFAConfig != nil && loginUser.MFAConfig.OtpSecret != "" {
- if request.OtpCode != nil {
- if err := challengeMFACode(loginUser, *request.OtpCode); err != nil {
- return nil, err
- }
- } else if request.RecoveryCode != nil {
- if err := s.challengeRecoveryCode(ctx, loginUser, *request.RecoveryCode); err != nil {
- return nil, err
+
+ if s.licenseService.IsFeatureEnabled(api.Feature2FA) {
+ if loginUser.MFAConfig != nil && loginUser.MFAConfig.OtpSecret != "" {
+ if request.OtpCode != nil {
+ if err := challengeMFACode(loginUser, *request.OtpCode); err != nil {
+ return nil, err
+ }
+ } else if request.RecoveryCode != nil {
+ if err := s.challengeRecoveryCode(ctx, loginUser, *request.RecoveryCode); err != nil {
+ return nil, err
+ }
+ } else {
+ // Return FailedPrecondition error to indicate MFA is required.
+ return nil, status.Errorf(codes.FailedPrecondition, "MFA is required")
}
- } else {
- // Return FailedPrecondition error to indicate MFA is required.
- return nil, status.Errorf(codes.FailedPrecondition, "MFA is required")
}
}
@@ -730,7 +737,7 @@ func validateEmail(email string) error {
const (
// issuerName is the name of the issuer of the OTP token.
- issuerName = "bytebase"
+ issuerName = "Bytebase"
)
// generateRandSecret generates a random secret for the given account name.
diff --git a/backend/legacyapi/plan.go b/backend/legacyapi/plan.go
index 41c7184def..3afa6726ce 100644
--- a/backend/legacyapi/plan.go
+++ b/backend/legacyapi/plan.go
@@ -52,6 +52,8 @@ const (
// FeatureSSO allows user to manage SSO provider and authenticate (login) with SSO.
FeatureSSO FeatureType = "bb.feature.sso"
+ // Feature2FA allows user to manage 2FA provider and authenticate (login) with 2FA.
+ Feature2FA FeatureType = "bb.feature.2fa"
// FeatureRBAC enables RBAC.
//
// - Workspace level RBAC
@@ -161,6 +163,8 @@ func (e FeatureType) Name() string {
// Admin & Security
case FeatureSSO:
return "SSO"
+ case Feature2FA:
+ return "2FA"
case FeatureRBAC:
return "RBAC"
case FeatureWatermark:
@@ -240,6 +244,7 @@ func (e FeatureType) minimumSupportedPlan() PlanType {
var FeatureMatrix = map[FeatureType][3]bool{
// Admin & Security
FeatureSSO: {false, false, true},
+ Feature2FA: {false, false, true},
FeatureRBAC: {false, true, true},
FeatureWatermark: {false, false, true},
FeatureAuditLog: {false, false, true},
diff --git a/backend/server/server.go b/backend/server/server.go
index ce16da6f84..73f910f34d 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -470,7 +470,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.grpcServer = grpc.NewServer(
grpc.ChainUnaryInterceptor(authProvider.AuthenticationInterceptor, aclProvider.ACLInterceptor),
)
- v1pb.RegisterAuthServiceServer(s.grpcServer, v1.NewAuthService(s.store, s.secret, s.MetricReporter, &profile,
+ v1pb.RegisterAuthServiceServer(s.grpcServer, v1.NewAuthService(s.store, s.secret, s.licenseService, s.MetricReporter, &profile,
func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error {
if s.profile.TestOnlySkipOnboardingData {
return nil
diff --git a/frontend/package.json b/frontend/package.json
index fe9f7249c6..c0da1e111a 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -50,6 +50,7 @@
"pinia": "2.0.23",
"pouchdb": "^8.0.1",
"pouchdb-find": "^8.0.1",
+ "qrcode": "^1.5.1",
"qs": "6.11.0",
"rollup": "3.2.5",
"scroll-into-view-if-needed": "^2.2.29",
@@ -90,6 +91,7 @@
"@types/pouchdb": "^6.4.0",
"@types/pouchdb-find": "^7.3.0",
"@types/prettier": "2.7.1",
+ "@types/qrcode": "^1.5.0",
"@types/qs": "6.9.7",
"@types/scrollparent": "^2.0.1",
"@types/semver": "7.3.13",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index e662282933..a8fd61c055 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -28,6 +28,7 @@ specifiers:
'@types/pouchdb': ^6.4.0
'@types/pouchdb-find': ^7.3.0
'@types/prettier': 2.7.1
+ '@types/qrcode': ^1.5.0
'@types/qs': 6.9.7
'@types/scrollparent': ^2.0.1
'@types/semver': 7.3.13
@@ -81,6 +82,7 @@ specifiers:
pouchdb-find: ^8.0.1
prettier: 2.7.1
protobufjs: ^7.1.2
+ qrcode: ^1.5.1
qs: 6.11.0
rollup: 3.2.5
scroll-into-view-if-needed: ^2.2.29
@@ -149,6 +151,7 @@ dependencies:
pinia: 2.0.23_l7r24p6nevbtlimqmqcwa3ouhu
pouchdb: 8.0.1
pouchdb-find: 8.0.1
+ qrcode: 1.5.1
qs: 6.11.0
rollup: 3.2.5
scroll-into-view-if-needed: 2.2.29
@@ -189,6 +192,7 @@ devDependencies:
'@types/pouchdb': 6.4.0
'@types/pouchdb-find': 7.3.0
'@types/prettier': 2.7.1
+ '@types/qrcode': 1.5.0
'@types/qs': 6.9.7
'@types/scrollparent': 2.0.1
'@types/semver': 7.3.13
@@ -1136,6 +1140,12 @@ packages:
resolution: {integrity: sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==}
dev: true
+ /@types/qrcode/1.5.0:
+ resolution: {integrity: sha512-x5ilHXRxUPIMfjtM+1vf/GPTRWZ81nqscursm5gMznJeK9M0YnZ1c3bEvRLQ0zSSgedLx1J6MGL231ObQGGhaA==}
+ dependencies:
+ '@types/node': 18.11.18
+ dev: true
+
/@types/qs/6.9.7:
resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==}
dev: true
@@ -1605,14 +1615,12 @@ packages:
/ansi-regex/5.0.1:
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
engines: {node: '>=8'}
- dev: true
/ansi-styles/4.3.0:
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
engines: {node: '>=8'}
dependencies:
color-convert: 2.0.1
- dev: true
/anymatch/3.1.2:
resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==}
@@ -1770,6 +1778,11 @@ packages:
engines: {node: '>= 6'}
dev: true
+ /camelcase/5.3.1:
+ resolution: {integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==}
+ engines: {node: '>=6'}
+ dev: false
+
/caniuse-lite/1.0.30001430:
resolution: {integrity: sha512-IB1BXTZKPDVPM7cnV4iaKaHxckvdr/3xtctB3f7Hmenx3qYBhGtTZ//7EllK66aKXW98Lx0+7Yr0kxBtIt3tzg==}
dev: true
@@ -1835,6 +1848,14 @@ packages:
tiny-emitter: 2.1.0
dev: false
+ /cliui/6.0.0:
+ resolution: {integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==}
+ dependencies:
+ string-width: 4.2.3
+ strip-ansi: 6.0.1
+ wrap-ansi: 6.2.0
+ dev: false
+
/clone-buffer/1.0.0:
resolution: {integrity: sha512-KLLTJWrvwIP+OPfMn0x2PheDEP20RPUcGXj/ERegTgdmPEZylALQldygiqrPPu8P45uNuPs7ckmReLY6v/iA5g==}
engines: {node: '>= 0.10'}
@@ -1845,11 +1866,9 @@ packages:
engines: {node: '>=7.0.0'}
dependencies:
color-name: 1.1.4
- dev: true
/color-name/1.1.4:
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
- dev: true
/combined-stream/1.0.8:
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
@@ -2212,6 +2231,11 @@ packages:
ms: 2.1.2
dev: true
+ /decamelize/1.2.0:
+ resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==}
+ engines: {node: '>=0.10.0'}
+ dev: false
+
/deep-eql/3.0.1:
resolution: {integrity: sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==}
engines: {node: '>=0.12'}
@@ -2285,6 +2309,10 @@ packages:
highlight.js: 11.6.0
dev: false
+ /dijkstrajs/1.0.2:
+ resolution: {integrity: sha512-QV6PMaHTCNmKSeP6QoXhVTw9snc9VD8MulTT0Bd99Pacp4SS1cjcrYPgBPmibqKVtMJJfqC6XvOXgPMEEPH/fg==}
+ dev: false
+
/dir-glob/3.0.1:
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
engines: {node: '>=8'}
@@ -2338,6 +2366,14 @@ packages:
engines: {node: '>=14.16'}
dev: false
+ /emoji-regex/8.0.0:
+ resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
+ dev: false
+
+ /encode-utf8/1.0.3:
+ resolution: {integrity: sha512-ucAnuBEhUK4boH2HjVYG5Q2mQyPorvv0u/ocS+zhdw0S8AlHYY+GOFhP1Gio5z4icpP2ivFSvhtFjQi8+T9ppw==}
+ dev: false
+
/encoding-down/6.3.0:
resolution: {integrity: sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==}
engines: {node: '>=6'}
@@ -2858,6 +2894,14 @@ packages:
dependencies:
to-regex-range: 5.0.1
+ /find-up/4.1.0:
+ resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==}
+ engines: {node: '>=8'}
+ dependencies:
+ locate-path: 5.0.0
+ path-exists: 4.0.0
+ dev: false
+
/find-up/5.0.0:
resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==}
engines: {node: '>=10'}
@@ -2915,6 +2959,11 @@ packages:
/function-bind/1.1.1:
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
+ /get-caller-file/2.0.5:
+ resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
+ engines: {node: 6.* || 8.* || >= 10.*}
+ dev: false
+
/get-func-name/2.0.0:
resolution: {integrity: sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==}
dev: true
@@ -3112,6 +3161,11 @@ packages:
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
+ /is-fullwidth-code-point/3.0.0:
+ resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
+ engines: {node: '>=8'}
+ dev: false
+
/is-glob/4.0.3:
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
engines: {node: '>=0.10.0'}
@@ -3286,6 +3340,13 @@ packages:
engines: {node: '>=14'}
dev: true
+ /locate-path/5.0.0:
+ resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==}
+ engines: {node: '>=8'}
+ dependencies:
+ p-locate: 4.1.0
+ dev: false
+
/locate-path/6.0.0:
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
engines: {node: '>=10'}
@@ -3612,6 +3673,13 @@ packages:
word-wrap: 1.2.3
dev: true
+ /p-limit/2.3.0:
+ resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==}
+ engines: {node: '>=6'}
+ dependencies:
+ p-try: 2.2.0
+ dev: false
+
/p-limit/3.1.0:
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
engines: {node: '>=10'}
@@ -3619,6 +3687,13 @@ packages:
yocto-queue: 0.1.0
dev: true
+ /p-locate/4.1.0:
+ resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==}
+ engines: {node: '>=8'}
+ dependencies:
+ p-limit: 2.3.0
+ dev: false
+
/p-locate/5.0.0:
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
engines: {node: '>=10'}
@@ -3626,6 +3701,11 @@ packages:
p-limit: 3.1.0
dev: true
+ /p-try/2.2.0:
+ resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==}
+ engines: {node: '>=6'}
+ dev: false
+
/papaparse/5.3.2:
resolution: {integrity: sha512-6dNZu0Ki+gyV0eBsFKJhYr+MdQYAzFUGlBMNj3GNrmHxmz1lfRa24CjFObPXtjcetlOv5Ad299MhIK0znp3afw==}
dev: false
@@ -3640,7 +3720,6 @@ packages:
/path-exists/4.0.0:
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
engines: {node: '>=8'}
- dev: true
/path-is-absolute/1.0.1:
resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==}
@@ -3726,6 +3805,11 @@ packages:
dev: false
+ /pngjs/5.0.0:
+ resolution: {integrity: sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==}
+ engines: {node: '>=10.13.0'}
+ dev: false
+
/popper.js/1.16.1:
resolution: {integrity: sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==}
deprecated: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
@@ -3986,6 +4070,17 @@ packages:
resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==}
engines: {node: '>=6'}
+ /qrcode/1.5.1:
+ resolution: {integrity: sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg==}
+ engines: {node: '>=10.13.0'}
+ hasBin: true
+ dependencies:
+ dijkstrajs: 1.0.2
+ encode-utf8: 1.0.3
+ pngjs: 5.0.0
+ yargs: 15.4.1
+ dev: false
+
/qs/6.11.0:
resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==}
engines: {node: '>=0.6'}
@@ -4065,6 +4160,15 @@ packages:
resolution: {integrity: sha1-CkPTqq4egNuRngeuJUsoXZ4ce7U=}
dev: false
+ /require-directory/2.1.1:
+ resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
+ engines: {node: '>=0.10.0'}
+ dev: false
+
+ /require-main-filename/2.0.0:
+ resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}
+ dev: false
+
/requires-port/1.0.0:
resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==}
dev: false
@@ -4177,6 +4281,10 @@ packages:
dependencies:
lru-cache: 6.0.0
+ /set-blocking/2.0.0:
+ resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==}
+ dev: false
+
/shebang-command/2.0.0:
resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
engines: {node: '>=8'}
@@ -4242,6 +4350,15 @@ packages:
nearley: 2.20.1
dev: false
+ /string-width/4.2.3:
+ resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
+ engines: {node: '>=8'}
+ dependencies:
+ emoji-regex: 8.0.0
+ is-fullwidth-code-point: 3.0.0
+ strip-ansi: 6.0.1
+ dev: false
+
/string_decoder/0.10.31:
resolution: {integrity: sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==}
dev: false
@@ -4257,7 +4374,6 @@ packages:
engines: {node: '>=8'}
dependencies:
ansi-regex: 5.0.1
- dev: true
/strip-final-newline/2.0.0:
resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==}
@@ -4877,6 +4993,10 @@ packages:
webidl-conversions: 3.0.1
dev: false
+ /which-module/2.0.0:
+ resolution: {integrity: sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==}
+ dev: false
+
/which/2.0.2:
resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
engines: {node: '>= 8'}
@@ -4890,6 +5010,15 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
+ /wrap-ansi/6.2.0:
+ resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==}
+ engines: {node: '>=8'}
+ dependencies:
+ ansi-styles: 4.3.0
+ string-width: 4.2.3
+ strip-ansi: 6.0.1
+ dev: false
+
/wrappy/1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
dev: true
@@ -4909,6 +5038,10 @@ packages:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}
+ /y18n/4.0.3:
+ resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==}
+ dev: false
+
/yallist/4.0.0:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
@@ -4925,6 +5058,31 @@ packages:
engines: {node: '>= 6'}
dev: true
+ /yargs-parser/18.1.3:
+ resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ camelcase: 5.3.1
+ decamelize: 1.2.0
+ dev: false
+
+ /yargs/15.4.1:
+ resolution: {integrity: sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==}
+ engines: {node: '>=8'}
+ dependencies:
+ cliui: 6.0.0
+ decamelize: 1.2.0
+ find-up: 4.1.0
+ get-caller-file: 2.0.5
+ require-directory: 2.1.1
+ require-main-filename: 2.0.0
+ set-blocking: 2.0.0
+ string-width: 4.2.3
+ which-module: 2.0.0
+ y18n: 4.0.3
+ yargs-parser: 18.1.3
+ dev: false
+
/yocto-queue/0.1.0:
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
engines: {node: '>=10'}
diff --git a/frontend/src/bbkit/BBModal.vue b/frontend/src/bbkit/BBModal.vue
index 36c68903d4..6456814992 100644
--- a/frontend/src/bbkit/BBModal.vue
+++ b/frontend/src/bbkit/BBModal.vue
@@ -10,7 +10,7 @@
:data-bb-modal-active="active"
>
<div class="modal-header" :class="headerClass">
- <div class="text-xl text-main">
+ <div class="text-xl text-main mr-2">
<slot name="title"><component :is="renderTitle" /></slot>
<component :is="renderSubtitle" />
</div>
diff --git a/frontend/src/components/FeatureModal.vue b/frontend/src/components/FeatureModal.vue
index 272396db9e..7b142286af 100644
--- a/frontend/src/components/FeatureModal.vue
+++ b/frontend/src/components/FeatureModal.vue
@@ -3,7 +3,7 @@
:title="$t('subscription.disabled-feature')"
@close="$emit('cancel')"
>
- <div class="min-w-0 md:min-w-400">
+ <div class="min-w-0 md:min-w-[400px] max-w-4xl">
<div class="flex items-start space-x-2">
<div class="flex items-center">
<heroicons-solid:sparkles class="h-6 w-6 text-accent" />
diff --git a/frontend/src/components/RecoveryCodesView.vue b/frontend/src/components/RecoveryCodesView.vue
new file mode 100644
index 0000000000..f0f37a429e
--- /dev/null
+++ b/frontend/src/components/RecoveryCodesView.vue
@@ -0,0 +1,63 @@
+<template>
+ <div
+ class="w-full max-w-2xl mx-auto flex flex-col justify-start items-start space-y-4 my-8"
+ >
+ <p>
+ {{ $t("two-factor.setup-steps.download-recovery-codes.tips") }}
+ </p>
+ <BBAttention
+ :style="'INFO'"
+ :title="
+ $t('two-factor.setup-steps.download-recovery-codes.keep-safe.self')
+ "
+ :description="
+ $t(
+ 'two-factor.setup-steps.download-recovery-codes.keep-safe.description'
+ )
+ "
+ />
+ <div
+ class="mt-8 w-112 mx-auto flex flex-col justify-start items-start"
+ v-bind="$attrs"
+ >
+ <ul
+ class="w-full grid grid-cols-2 list-disc list-inside mx-auto gap-4 gap-x-24 p-8 px-12 border rounded-md bg-gray-50"
+ >
+ <li v-for="code in props.recoveryCodes" :key="code">
+ <code class="-ml-2">{{ code }}</code>
+ </li>
+ </ul>
+ </div>
+ <div class="w-112 mx-auto flex flex-row justify-end items-center">
+ <button class="btn-success" @click="downloadRecoveryCodes">
+ <heroicons-outline:download class="w-5 h-auto mr-1 text-white" />
+ {{ $t("common.download") }}
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+const props = withDefaults(
+ defineProps<{
+ recoveryCodes: string[];
+ }>(),
+ {
+ recoveryCodes: () => [],
+ }
+);
+
+const emit = defineEmits(["download"]);
+
+const downloadRecoveryCodes = () => {
+ const content = props.recoveryCodes.join("\n");
+ const blob = new Blob([content], { type: "text/plain" });
+ const downloadLink = document.createElement("a");
+ downloadLink.href = URL.createObjectURL(blob);
+ downloadLink.download = "bytebase-recovery-codes.txt";
+ document.body.appendChild(downloadLink);
+ downloadLink.click();
+ URL.revokeObjectURL(downloadLink.href);
+ emit("download");
+};
+</script>
diff --git a/frontend/src/components/RegenerateRecoveryCodesView.vue b/frontend/src/components/RegenerateRecoveryCodesView.vue
new file mode 100644
index 0000000000..123c96724a
--- /dev/null
+++ b/frontend/src/components/RegenerateRecoveryCodesView.vue
@@ -0,0 +1,86 @@
+<template>
+ <RecoveryCodesView
+ :recovery-codes="props.recoveryCodes"
+ @download="state.recoveryCodesDownloaded = true"
+ />
+ <div class="w-112 mx-auto flex flex-row justify-between items-center mb-8">
+ <button class="btn-cancel" @click="emit('close')">
+ {{ $t("common.cancel") }}
+ </button>
+ <button
+ class="btn-primary"
+ :disabled="!state.recoveryCodesDownloaded"
+ @click="regenerateRecoveryCodes"
+ >
+ {{ $t("two-factor.setup-steps.recovery-codes-saved") }}
+ </button>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { pushNotification, useAuthStore, useUserStore } from "@/store";
+import { UpdateUserRequest } from "@/types/proto/v1/auth_service";
+import { computed, onMounted, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import RecoveryCodesView from "./RecoveryCodesView.vue";
+
+interface LocalState {
+ recoveryCodesDownloaded: boolean;
+}
+
+const props = withDefaults(
+ defineProps<{
+ recoveryCodes: string[];
+ }>(),
+ {
+ recoveryCodes: () => [],
+ }
+);
+
+const emit = defineEmits(["close"]);
+
+const { t } = useI18n();
+const authStore = useAuthStore();
+const userStore = useUserStore();
+const state = reactive<LocalState>({
+ recoveryCodesDownloaded: false,
+});
+
+const currentUser = computed(() => authStore.currentUser);
+
+onMounted(() => {
+ regenerateTempMfaSecret();
+});
+
+const regenerateTempMfaSecret = async () => {
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: currentUser.value.name,
+ },
+ updateMask: [],
+ regenerateTempMfaSecret: true,
+ })
+ );
+ await authStore.refreshUserIfNeeded(currentUser.value.name);
+};
+
+const regenerateRecoveryCodes = async () => {
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: currentUser.value.name,
+ },
+ updateMask: [],
+ regenerateRecoveryCodes: true,
+ })
+ );
+ await authStore.refreshUserIfNeeded(currentUser.value.name);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("two-factor.messages.recovery-codes-regenerated"),
+ });
+ emit("close");
+};
+</script>
diff --git a/frontend/src/components/SchemaEditor/Modals/ActionConfirmModal.vue b/frontend/src/components/SchemaEditor/Modals/ActionConfirmModal.vue
index b88f92e104..bfacd0216f 100644
--- a/frontend/src/components/SchemaEditor/Modals/ActionConfirmModal.vue
+++ b/frontend/src/components/SchemaEditor/Modals/ActionConfirmModal.vue
@@ -8,7 +8,7 @@
<p>{{ props.description }}</p>
</div>
<div class="w-full flex items-center justify-end mt-2 space-x-3 pr-1 pb-1">
- <button type="button" class="btn-normal" @click="dismissModal">
+ <button type="button" class="btn-cancel" @click="dismissModal">
{{ $t("common.cancel") }}
</button>
<button class="btn-primary" @click="handleConfirmButtonClick">
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 9a0bb2c16f..e610a9794c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -226,7 +226,9 @@
"operations": "Operations",
"on": "On",
"off": "Off",
- "verify": "Verify"
+ "verify": "Verify",
+ "regenerate": "Regenerate",
+ "download": "Download"
},
"error-page": {
"go-back-home": "Go back home"
@@ -1753,6 +1755,10 @@
"bb-feature-sso": {
"title": "Single Sign-On (SSO)",
"desc": "Enables users to securely authenticate with multiple applications and websites via a single set of credentials."
+ },
+ "bb-feature-2fa": {
+ "title": "Two-Factor Authentication (2FA)",
+ "desc": "Two-factor authentication provides an extra layer of security for member accounts. When signing in, you will be required to enter the security code generated by your Authenticator App."
}
}
},
@@ -1949,8 +1955,38 @@
"self": "Two-factor authentication",
"description": "Two-factor authentication provides an extra layer of security for member accounts. When signing in, you will be required to enter the security code generated by your Authenticator App.",
"setup-steps": {
- "setup-auth-app": "Setup authenticator app",
- "download-recovery-codes": "Download your recovery codes"
+ "setup-auth-app": {
+ "self": "Setup authenticator app",
+ "description": "Use a phone app like Google Authenticator, Microsoft Authenticator, or Authy to get 2FA codes when prompted during sign-in.",
+ "scan-qr-code": {
+ "self": "Scan the QR code",
+ "description": "Use an authenticator app from your phone to scan. If you are unable to scan, {action} instead.",
+ "enter-the-text": "enter the text"
+ },
+ "verify-code": "Verify the code from the app"
+ },
+ "download-recovery-codes": {
+ "self": "Download your recovery codes",
+ "tips": "Keep your recovery codes as safe as your password. We recommend saving them with a password manager such as Lastpass, 1Password, or Keeper.",
+ "keep-safe": {
+ "self": "Keep your recovery codes in a safe spot.",
+ "description": "These codes are the last resort for accessing your account in case you lose your password and second factors. If you cannot find these codes, you will lose access to your account."
+ }
+ },
+ "recovery-codes-saved": "I have saved my recovery codes"
+ },
+ "recovery-codes": {
+ "self": "Recovery codes",
+ "description": "Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes."
+ },
+ "disable": {
+ "self": "Disable Two-factor authentication",
+ "description": "You are about to disable two-factor authentication for your account. You will no longer be required to enter the security code generated by your Authenticator App when signing in."
+ },
+ "messages": {
+ "2fa-enabled": "Two-factor authentication is enabled.",
+ "2fa-disabled": "Two-factor authentication is disabled.",
+ "recovery-codes-regenerated": "Recovery codes are regenerated."
}
},
"plugin": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 97389633b1..bf1a9d6c1c 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -224,7 +224,9 @@
"operations": "操作",
"on": "开",
"off": "关",
- "verify": "验证"
+ "verify": "验证",
+ "regenerate": "重新生成",
+ "download": "下载"
},
"error-page": {
"go-back-home": "回到主页"
@@ -434,10 +436,10 @@
"domain": "域名",
"domain-description": "OAuth 提供商的域名",
"identity-provider-information": "OAuth 提供商信息",
- "identity-provider-information-description": "这些信息是由你的身份提供商提供的。",
- "identity-provider-needed-information": "用以下信息创建你的 SSO 应用程序。",
+ "identity-provider-information-description": "这些信息是由您的身份提供商提供的。",
+ "identity-provider-needed-information": "用以下信息创建您的 SSO 应用程序。",
"endpoints": "链接信息",
- "endpoints-description": "链接信息是由你的 OAuth 提供商提供。",
+ "endpoints-description": "链接信息是由您的 OAuth 提供商提供。",
"auth-url-description": "登录页面的链接",
"scopes-description": "访问 Auth URL 时携带的范围参数,使用空格分隔多个值",
"token-url-description": "用于获取 accessToken 的 API 地址",
@@ -481,7 +483,7 @@
}
},
"sensitive-data": {
- "description": "以下列的查询结果将会被显示为 \"******\"。在表详情页,你可以将多个列标记为敏感数据。",
+ "description": "以下列的查询结果将会被显示为 \"******\"。在表详情页,您可以将多个列标记为敏感数据。",
"remove-sensitive-column-tips": "不再对此列数据脱敏?"
},
"access-control": {
@@ -1074,7 +1076,7 @@
"preview-issue": "预览工单"
},
"sensitive": "敏感",
- "access-denied": "你没有访问该数据库的权限",
+ "access-denied": "您没有访问该数据库的权限",
"schema": {
"select": "选择 schema"
},
@@ -1296,7 +1298,7 @@
"gitops": {
"setting": {
"description": "Bytebase 支持 GitOps 工作流。该工作流下,数据库变更脚本存储在版本控制系统上 (VCS),新创建的变更脚本会自动触发对应的数据库变更。Bytebase 的所有者先在此配置 VCS,在这之后,项目的所有者就可以从所配置的 VCS 中选取他们的 Git 仓库。",
- "description-highlight": "如果你想通过你配置的VCS启用第三方登录,请在SSO中进行配置。",
+ "description-highlight": "如果您想通过您配置的VCS启用第三方登录,请在SSO中进行配置。",
"add-git-provider": {
"self": "添加 Git 提供方",
"description": "在项目可以启用 GitOps 工作流前,Bytebase 首先需要以在 VCS 中注册为 OAuth 应用的方式和 VCS 进行集成。以下是配置该集成的步骤,您也可以按照我们的{guide}。",
@@ -1370,7 +1372,7 @@
"stage-n": "阶段 {n}",
"add-selector": "添加选择条件",
"update-success": "成功更新部署配置",
- "this-is-example-deployment-config": "这是部署配置的样例,你需要在此基础上编辑并保存。",
+ "this-is-example-deployment-config": "这是部署配置的样例,您需要在此基础上编辑并保存。",
"n-databases": "{n} 个数据库",
"selectors": "选择条件",
"add-stage": "添加阶段",
@@ -1502,7 +1504,7 @@
"sql-review-result": "SQL 检查结果",
"alter-table": "修改表结构",
"visualize-explain": "可视化 Explain",
- "sql-execute-in-production-environment": "小心,你正在操作生产环境下的数据库。",
+ "sql-execute-in-production-environment": "小心,您正在操作生产环境下的数据库。",
"rows-upper-limit": "到达查询结果条数上限",
"tab-mode": {
"readonly": "只读",
@@ -1752,6 +1754,10 @@
"bb-feature-sso": {
"title": "Single Sign-On (SSO)",
"desc": "使得用户能够通过 SSO 安全地进行登录 Bytebase。"
+ },
+ "bb-feature-2fa": {
+ "title": "双重认证",
+ "desc": "双重认证为系统成员提供了一个额外的安全层。在登录时,用户需要输入由认证器应用程序生成的安全代码。"
}
}
},
@@ -1936,11 +1942,11 @@
"self": "其他方法",
"use-auth-app": {
"self": "使用身份验证器应用程序",
- "description": "在您的移动设备上打开双因素认证器(TOTP)应用程序,查看认证码。"
+ "description": "在您的移动设备上打开双重认证器(TOTP)应用程序,查看认证码。"
},
"use-recovery-code": {
"self": "使用恢复码",
- "description": "如果您无法访问你的移动设备,请输入一个恢复代码来验证您的身份。"
+ "description": "如果您无法访问您的移动设备,请输入一个恢复码来验证您的身份。"
}
}
},
@@ -1948,8 +1954,38 @@
"self": "双重认证",
"description": "双重认证为系统成员提供了一个额外的安全层。在登录时,用户需要输入由认证器应用程序生成的安全代码。",
"setup-steps": {
- "setup-auth-app": "设置认证器应用程序",
- "download-recovery-codes": "下载恢复码"
+ "setup-auth-app": {
+ "self": "设置认证器应用程序",
+ "description": "使用像 Google Authenticator、Microsoft Authenticator 或 Authy 这样的手机应用程序来进行 2FA 认证操作。",
+ "scan-qr-code": {
+ "self": "扫描二维码",
+ "description": "使用您手机中的认证器应用程序进行扫描。如果您无法扫描,可以{action}。",
+ "enter-the-text": "输入文本"
+ },
+ "verify-code": "验证应用程序的代码"
+ },
+ "download-recovery-codes": {
+ "self": "下载恢复码",
+ "tips": "保持您的恢复码和您的密码一样安全。建议将它们保存在一个密码管理器中,如 Lastpass、1Password 或 Keeper。",
+ "keep-safe": {
+ "self": "把您的恢复码放在一个安全的地方。",
+ "description": "这些代码是在您丢失密码和第二要素的情况下访问您的账户的最后手段。如果您找不到这些代码,您将失去对您账户的访问。"
+ }
+ },
+ "recovery-codes-saved": "确定已经保存了我的恢复码"
+ },
+ "recovery-codes": {
+ "self": "恢复码",
+ "description": "恢复码可以在您失去对设备的访问权和无法收到双因素认证代码的情况下用于访问您的账户。"
+ },
+ "disable": {
+ "self": "禁用双重认证",
+ "description": "您即将禁用您账户的双重认证。您在登录时将不再需要输入由您的 Authenticator 应用程序生成的安全代码。"
+ },
+ "messages": {
+ "2fa-enabled": "双重认证开启成功",
+ "2fa-disabled": "双重认证禁用成功",
+ "recovery-codes-regenerated": "恢复码已经重新生成"
}
},
"plugin": {
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index d6f7fcb128..bcf98c0631 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -5,6 +5,7 @@ import planData from "./plan.yaml";
export type FeatureType =
// Admin & Security
| "bb.feature.sso"
+ | "bb.feature.2fa"
| "bb.feature.rbac"
| "bb.feature.watermark"
| "bb.feature.audit-log"
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 4951bbd4b6..ad0b73239c 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -1,6 +1,6 @@
<template>
<main
- class="flex-1 relative z-0 overflow-auto focus:outline-none xl:order-last"
+ class="flex-1 h-full relative z-0 overflow-auto pb-8 focus:outline-none xl:order-last"
tabindex="0"
>
<!-- Profile header -->
@@ -175,7 +175,12 @@
class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 border-t mt-16 pt-8 pb-4"
>
<div class="w-full flex flex-row justify-between items-center">
- <span class="text-lg font-medium">{{ $t("two-factor.self") }}</span>
+ <span
+ class="text-lg font-medium flex flex-row justify-start items-center"
+ >
+ {{ $t("two-factor.self") }}
+ <FeatureBadge :feature="'bb.feature.2fa'" class="ml-2 text-accent" />
+ </span>
<BBSwitch
:value="isMFAEnabled"
@toggle="handle2FAEnableStatusChanged"
@@ -184,10 +189,61 @@
<p class="mt-4 text-sm text-gray-500">
{{ $t("two-factor.description") }}
<!-- TODO(steven): update the docs link -->
- <LearnMoreLink url="docs-link" />
+ <LearnMoreLink class="ml-1" url="" />
</p>
+ <template v-if="isMFAEnabled">
+ <div class="w-full flex flex-row justify-between items-center mt-8">
+ <span class="text-lg font-medium">{{
+ $t("two-factor.recovery-codes.self")
+ }}</span>
+ <div v-if="!state.showRegenerateRecoveryCodesView" class="relative">
+ <heroicons-outline:ellipsis-horizontal
+ class="w-8 p-1 h-auto cursor-pointer hover:bg-gray-100 rounded"
+ @click.prevent="recoveryCodesMenu.toggle()"
+ @contextmenu.capture.prevent="recoveryCodesMenu.toggle()"
+ />
+ <BBContextMenu
+ ref="recoveryCodesMenu"
+ class="origin-top-left mt-1 w-32 shadow"
+ >
+ <div class="py-1">
+ <a
+ class="menu-item"
+ role="menuitem"
+ @click="state.showRegenerateRecoveryCodesView = true"
+ >
+ {{ $t("common.regenerate") }}
+ </a>
+ </div>
+ </BBContextMenu>
+ </div>
+ </div>
+ <p class="mt-4 text-sm text-gray-500">
+ {{ $t("two-factor.recovery-codes.description") }}
+ </p>
+ <RegenerateRecoveryCodesView
+ v-if="state.showRegenerateRecoveryCodesView"
+ :recovery-codes="authStore.currentUser.recoveryCodes"
+ @close="state.showRegenerateRecoveryCodesView = false"
+ />
+ </template>
</div>
</main>
+
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.2fa"
+ @cancel="state.showFeatureModal = false"
+ />
+
+ <!-- Close modal confirm dialog -->
+ <ActionConfirmModal
+ v-if="state.showDisable2FAConfirmModal"
+ :title="$t('two-factor.disable.self')"
+ :description="$t('two-factor.disable.description')"
+ @close="state.showDisable2FAConfirmModal = false"
+ @confirm="handleDisable2FA"
+ />
</template>
<script lang="ts" setup>
@@ -197,34 +253,48 @@ import { PrincipalPatch } from "../types";
import { hasWorkspacePermission } from "../utils";
import {
featureToRef,
+ pushNotification,
useAuthStore,
useCurrentUser,
usePrincipalStore,
+ useUserStore,
} from "@/store";
import { BBSwitch } from "@/bbkit";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
import { useRouter } from "vue-router";
+import { UpdateUserRequest } from "@/types/proto/v1/auth_service";
+import RegenerateRecoveryCodesView from "@/components/RegenerateRecoveryCodesView.vue";
+import { useI18n } from "vue-i18n";
interface LocalState {
editing: boolean;
editingPrincipal?: PrincipalPatch;
passwordConfirm?: string;
+ showFeatureModal: boolean;
+ showDisable2FAConfirmModal: boolean;
+ showRegenerateRecoveryCodesView: boolean;
}
const props = defineProps<{
principalId?: string;
}>();
+const { t } = useI18n();
const router = useRouter();
const authStore = useAuthStore();
const currentUser = useCurrentUser();
+const userStore = useUserStore();
const principalStore = usePrincipalStore();
const state = reactive<LocalState>({
editing: false,
+ showFeatureModal: false,
+ showDisable2FAConfirmModal: false,
+ showRegenerateRecoveryCodesView: false,
});
const editNameTextField = ref();
+const recoveryCodesMenu = ref();
const keyboardHandler = (e: KeyboardEvent) => {
if (state.editing) {
@@ -247,6 +317,7 @@ onUnmounted(() => {
});
const hasRBACFeature = featureToRef("bb.feature.rbac");
+const has2FAFeature = featureToRef("bb.feature.2fa");
const isMFAEnabled = computed(() => {
return authStore.currentUser.mfaEnabled;
@@ -317,10 +388,34 @@ const saveEdit = async () => {
};
const handle2FAEnableStatusChanged = (enabled: boolean) => {
+ if (!has2FAFeature.value) {
+ state.showFeatureModal = true;
+ return;
+ }
if (enabled) {
router.push({ name: "setting.profile.two-factor" });
} else {
- // TODO(steven): double confirm user to disable 2FA.
+ state.showDisable2FAConfirmModal = true;
}
};
+
+const handleDisable2FA = async () => {
+ const user = authStore.currentUser;
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: user.name,
+ mfaEnabled: false,
+ },
+ updateMask: ["user.mfa_enabled"],
+ })
+ );
+ await authStore.refreshUserIfNeeded(user.name);
+ state.showDisable2FAConfirmModal = false;
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("two-factor.messages.2fa-disabled"),
+ });
+};
</script>
diff --git a/frontend/src/views/TwoFactorSetup.vue b/frontend/src/views/TwoFactorSetup.vue
index 279c1d2aba..cfbfdce44e 100644
--- a/frontend/src/views/TwoFactorSetup.vue
+++ b/frontend/src/views/TwoFactorSetup.vue
@@ -1,31 +1,216 @@
<template>
<p class="text-sm text-gray-500 mb-4">
{{ $t("two-factor.description") }}
- <LearnMoreLink url="doc-link" />
+ <LearnMoreLink url="" />
</p>
<BBStepTab
+ class="mb-8"
:step-item-list="stepTabList"
- :allow-next="true"
- :finish-title="$t('common.confirm-and-add')"
+ :allow-next="allowNext"
+ :finish-title="$t('two-factor.setup-steps.recovery-codes-saved')"
+ :current-step="state.currentStep"
+ @cancel="cancelSetup"
+ @try-change-step="tryChangeStep"
+ @try-finish="tryFinishSetup"
>
<template #0>
- <!-- placeholder -->
+ <div
+ class="w-full max-w-2xl mx-auto flex flex-col justify-start items-start space-y-4 my-8"
+ >
+ <p>
+ {{ $t("two-factor.setup-steps.setup-auth-app.description") }}
+ </p>
+ <p class="text-2xl">
+ {{ $t("two-factor.setup-steps.setup-auth-app.scan-qr-code.self") }}
+ </p>
+ <p>
+ <i18n-t
+ keypath="two-factor.setup-steps.setup-auth-app.scan-qr-code.description"
+ >
+ <template #action>
+ <span
+ :class="!state.showSecretText && 'cursor-pointer text-blue-600'"
+ @click="state.showSecretText = true"
+ >{{
+ $t(
+ "two-factor.setup-steps.setup-auth-app.scan-qr-code.enter-the-text"
+ )
+ }}</span
+ >
+ <code
+ v-if="state.showSecretText"
+ class="ml-1 bg-gray-100 px-1 rounded font-mono"
+ >{{ currentUser.mfaSecret }}</code
+ >
+ </template>
+ </i18n-t>
+ </p>
+ <div class="w-full flex flex-col justify-center items-center pb-8">
+ <img
+ :src="state.qrcodeDataUrl"
+ class="border w-64 mt-4 rounded-lg"
+ alt=""
+ />
+ <span class="mt-4 mb-2 text-sm font-medium">{{
+ $t("two-factor.setup-steps.setup-auth-app.verify-code")
+ }}</span>
+ <input
+ v-model="state.otpCode"
+ class="textfield w-64"
+ placeholder="XXXXXX"
+ type="text"
+ />
+ </div>
+ </div>
</template>
<template #1>
- <!-- placeholder -->
+ <RecoveryCodesView
+ :recovery-codes="currentUser.recoveryCodes"
+ @download="state.recoveryCodesDownloaded = true"
+ />
</template>
</BBStepTab>
</template>
<script lang="ts" setup>
import { useI18n } from "vue-i18n";
-import { BBStepTabItem } from "@/bbkit";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
+import { computed, onMounted, reactive, watch } from "vue";
+import { pushNotification, useAuthStore, useUserStore } from "@/store";
+import * as QRCode from "qrcode";
+import { UpdateUserRequest } from "@/types/proto/v1/auth_service";
+import RecoveryCodesView from "@/components/RecoveryCodesView.vue";
+import { useRouter } from "vue-router";
+
+const issuerName = "Bytebase";
+
+const SETUP_AUTH_APP_STEP = 0;
+const DOWNLOAD_RECOVERY_CODES_STEP = 1;
+
+type Step = typeof SETUP_AUTH_APP_STEP | typeof DOWNLOAD_RECOVERY_CODES_STEP;
+
+interface LocalState {
+ currentStep: Step;
+ showSecretText: boolean;
+ qrcodeDataUrl: string;
+ otpCode: string;
+ recoveryCodesDownloaded: boolean;
+}
const { t } = useI18n();
+const router = useRouter();
+const authStore = useAuthStore();
+const userStore = useUserStore();
+const state = reactive<LocalState>({
+ currentStep: SETUP_AUTH_APP_STEP,
+ showSecretText: false,
+ qrcodeDataUrl: "",
+ otpCode: "",
+ recoveryCodesDownloaded: false,
+});
+
+const stepTabList = computed(() => {
+ return [
+ { title: t("two-factor.setup-steps.setup-auth-app.self") },
+ { title: t("two-factor.setup-steps.download-recovery-codes.self") },
+ ];
+});
+const currentUser = computed(() => authStore.currentUser);
+const allowNext = computed(() => {
+ if (state.currentStep === SETUP_AUTH_APP_STEP) {
+ return state.otpCode.length >= 6;
+ } else {
+ return state.recoveryCodesDownloaded;
+ }
+});
+
+onMounted(async () => {
+ await regenerateTempMfaSecret();
+});
+
+const regenerateTempMfaSecret = async () => {
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: currentUser.value.name,
+ },
+ updateMask: [],
+ regenerateTempMfaSecret: true,
+ })
+ );
+ await authStore.refreshUserIfNeeded(currentUser.value.name);
+};
+
+const verifyTOPCode = async () => {
+ try {
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: currentUser.value.name,
+ },
+ updateMask: [],
+ otpCode: state.otpCode,
+ })
+ );
+ } catch (error: any) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: error.details,
+ });
+ return false;
+ }
+ return true;
+};
+
+const cancelSetup = () => {
+ router.replace({
+ name: "setting.profile",
+ });
+};
+
+const tryChangeStep = async (
+ oldStep: number,
+ newStep: number,
+ allowChangeCallback: () => void
+) => {
+ if (newStep === DOWNLOAD_RECOVERY_CODES_STEP) {
+ const result = await verifyTOPCode();
+ if (!result) {
+ return;
+ }
+ }
+ state.currentStep = newStep as Step;
+ allowChangeCallback();
+};
+
+const tryFinishSetup = async () => {
+ await userStore.updateUser(
+ UpdateUserRequest.fromPartial({
+ user: {
+ name: currentUser.value.name,
+ mfaEnabled: true,
+ },
+ updateMask: ["user.mfa_enabled"],
+ })
+ );
+ await authStore.refreshUserIfNeeded(currentUser.value.name);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("two-factor.messages.2fa-enabled"),
+ });
+ router.replace({
+ name: "setting.profile",
+ });
+};
-const stepTabList: BBStepTabItem[] = [
- { title: t("two-factor.setup-steps.setup-auth-app") },
- { title: t("two-factor.setup-steps.download-recovery-codes") },
-];
+watch(
+ [currentUser],
+ async () => {
+ const otpauthUrl = `otpauth://totp/${issuerName}:${currentUser.value.email}?algorithm=SHA1&digits=6&issuer=${issuerName}&period=30&secret=${currentUser.value.mfaSecret}`;
+ state.qrcodeDataUrl = await QRCode.toDataURL(otpauthUrl);
+ },
+ { deep: true, immediate: true }
+);
</script>