Skip to content

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

feat: request any roles (#16153)

ecmadao531df80e3d2c
diff --git a/backend/api/v1/risk_service.go b/backend/api/v1/risk_service.go
index d11a4a2962..b890911e4d 100644
--- a/backend/api/v1/risk_service.go
+++ b/backend/api/v1/risk_service.go
@@ -33,7 +33,7 @@ func NewRiskService(store *store.Store, licenseService enterprise.LicenseService
func convertToRisk(risk *store.RiskMessage) (*v1pb.Risk, error) {
return &v1pb.Risk{
Name: fmt.Sprintf("%s%v", common.RiskPrefix, risk.ID),
- Source: convertToV1Source(risk.Source),
+ Source: ConvertToV1Source(risk.Source),
Title: risk.Name,
Level: risk.Level,
Condition: risk.Expression,
@@ -162,7 +162,7 @@ func (s *RiskService) getRiskByName(ctx context.Context, name string) (*store.Ri
return risk, nil
}
-func convertToV1Source(source store.RiskSource) v1pb.Risk_Source {
+func ConvertToV1Source(source store.RiskSource) v1pb.Risk_Source {
switch source {
case store.RiskSourceDatabaseCreate:
return v1pb.Risk_CREATE_DATABASE
@@ -176,6 +176,8 @@ func convertToV1Source(source store.RiskSource) v1pb.Risk_Source {
return v1pb.Risk_REQUEST_EXPORT
case store.RiskSourceDatabaseDataExport:
return v1pb.Risk_DATA_EXPORT
+ case store.RiskRequestRole:
+ return v1pb.Risk_REQUEST_ROLE
}
return v1pb.Risk_SOURCE_UNSPECIFIED
}
@@ -194,6 +196,8 @@ func convertToSource(source v1pb.Risk_Source) store.RiskSource {
return store.RiskRequestExport
case v1pb.Risk_DATA_EXPORT:
return store.RiskSourceDatabaseDataExport
+ case v1pb.Risk_REQUEST_ROLE:
+ return store.RiskRequestRole
}
return store.RiskSourceUnknown
}
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 635cf0c512..f98403408c 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -28,7 +28,6 @@ import (
"github.com/bytebase/bytebase/backend/store"
"github.com/bytebase/bytebase/backend/utils"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
// Runner is the runner for finding approval templates for issues.
@@ -93,6 +92,7 @@ func (r *Runner) runOnce(ctx context.Context) {
approvalSetting, err := r.store.GetWorkspaceApprovalSetting(ctx)
if err != nil {
slog.Error("failed to get workspace approval setting", log.BBError(err))
+ return
}
r.stateCfg.ApprovalFinding.Range(func(key, value any) bool {
@@ -293,7 +293,7 @@ func getApprovalTemplate(approvalSetting *storepb.WorkspaceApprovalSetting, risk
out, _, err := prg.Eval(map[string]any{
"level": riskLevel,
- "source": convertToSource(riskSource).String(),
+ "source": apiv1.ConvertToV1Source(riskSource).String(),
})
if err != nil {
return nil, err
@@ -610,6 +610,52 @@ func (r *Runner) getDatabaseDataExportIssueRisk(ctx context.Context, issue *stor
return maxRiskLevel, riskSource, true, nil
}
+func (r *Runner) getDatabaseListByRequestRole(ctx context.Context, projectID string, riskSource store.RiskSource, databaseNames []string) ([]*store.DatabaseMessage, error) {
+ if riskSource != store.RiskRequestExport && riskSource != store.RiskRequestQuery {
+ return nil, nil
+ }
+
+ databases := []*store.DatabaseMessage{}
+ if len(databaseNames) == 0 {
+ list, err := r.store.ListDatabases(ctx, &store.FindDatabaseMessage{
+ ProjectID: &projectID,
+ })
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to list databases")
+ }
+ databases = list
+ } else {
+ for _, dbName := range databaseNames {
+ instanceID, databaseName, err := common.GetInstanceDatabaseID(dbName)
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to get instance database id")
+ }
+
+ instance, err := r.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &instanceID})
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to get instance")
+ }
+ if instance == nil || instance.Deleted {
+ continue
+ }
+ database, err := r.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{
+ ProjectID: &projectID,
+ InstanceID: &instanceID,
+ DatabaseName: &databaseName,
+ IsCaseSensitive: store.IsObjectCaseSensitive(instance),
+ })
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to get database")
+ }
+ if database == nil {
+ return nil, errors.Errorf("database %q not found", databaseName)
+ }
+ databases = append(databases, database)
+ }
+ }
+ return databases, nil
+}
+
func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.IssueMessage, risks []*store.RiskMessage) (int32, store.RiskSource, bool, error) {
payload := issue.Payload
if payload.GrantRequest == nil {
@@ -623,7 +669,7 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issu
case common.FormatRole(base.SQLEditorUser.String()):
riskSource = store.RiskRequestQuery
default:
- return 0, store.RiskSourceUnknown, false, errors.Errorf("unknown grant request role %v", payload.GrantRequest.Role)
+ riskSource = store.RiskRequestRole
}
// fast path, no risks so return the DEFAULT risk level "0"
@@ -645,43 +691,9 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issu
if payload.GrantRequest.Expiration != nil {
expirationDays = payload.GrantRequest.Expiration.AsDuration().Hours() / 24
}
- databases := []*store.DatabaseMessage{}
- if len(factors.DatabaseNames) == 0 {
- list, err := r.store.ListDatabases(ctx, &store.FindDatabaseMessage{
- ProjectID: &issue.Project.ResourceID,
- })
- if err != nil {
- return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to list databases")
- }
- databases = list
- } else {
- for _, dbName := range factors.DatabaseNames {
- instanceID, databaseName, err := common.GetInstanceDatabaseID(dbName)
- if err != nil {
- return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to get instance database id")
- }
-
- instance, err := r.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &instanceID})
- if err != nil {
- return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to get instance")
- }
- if instance == nil || instance.Deleted {
- continue
- }
- database, err := r.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{
- ProjectID: &issue.Project.ResourceID,
- InstanceID: &instanceID,
- DatabaseName: &databaseName,
- IsCaseSensitive: store.IsObjectCaseSensitive(instance),
- })
- if err != nil {
- return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to get database")
- }
- if database == nil {
- return 0, store.RiskSourceUnknown, false, errors.Errorf("database %q not found", databaseName)
- }
- databases = append(databases, database)
- }
+ databases, err := r.getDatabaseListByRequestRole(ctx, issue.Project.ResourceID, riskSource, factors.DatabaseNames)
+ if err != nil {
+ return 0, store.RiskSourceUnknown, false, errors.Wrap(err, "failed to list databases")
}
var maxRisk int32
@@ -705,6 +717,25 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issu
return 0, store.RiskSourceUnknown, false, err
}
+ if databases == nil {
+ args := map[string]any{
+ "project_id": issue.Project.ResourceID,
+ "expiration_days": expirationDays,
+ "role": payload.GrantRequest.Role,
+ }
+ out, _, err := prg.Eval(args)
+ if err != nil {
+ return 0, store.RiskSourceUnknown, false, err
+ }
+ if res, ok := out.Equal(celtypes.True).Value().(bool); ok && res {
+ maxRisk = risk.Level
+ }
+ if maxRisk > 0 {
+ break
+ }
+ continue
+ }
+
for _, database := range databases {
instance, err := r.store.GetInstanceV2(ctx, &store.FindInstanceMessage{
ResourceID: &database.InstanceID,
@@ -782,24 +813,6 @@ func updateIssueApprovalPayload(ctx context.Context, s *store.Store, issue *stor
return nil
}
-func convertToSource(source store.RiskSource) v1pb.Risk_Source {
- switch source {
- case store.RiskSourceDatabaseCreate:
- return v1pb.Risk_CREATE_DATABASE
- case store.RiskSourceDatabaseSchemaUpdate:
- return v1pb.Risk_DDL
- case store.RiskSourceDatabaseDataUpdate:
- return v1pb.Risk_DML
- case store.RiskRequestQuery:
- return v1pb.Risk_REQUEST_QUERY
- case store.RiskRequestExport:
- return v1pb.Risk_REQUEST_EXPORT
- case store.RiskSourceDatabaseDataExport:
- return v1pb.Risk_DATA_EXPORT
- }
- return v1pb.Risk_SOURCE_UNSPECIFIED
-}
-
func convertRiskLevel(riskLevel int32) (storepb.IssuePayloadApproval_RiskLevel, error) {
switch riskLevel {
case 0:
diff --git a/backend/store/risk.go b/backend/store/risk.go
index e17b276843..54021f8bc0 100644
--- a/backend/store/risk.go
+++ b/backend/store/risk.go
@@ -31,6 +31,8 @@ const (
RiskRequestQuery RiskSource = "bb.risk.request.query"
// RiskRequestExport is for requesting export grant.
RiskRequestExport RiskSource = "bb.risk.request.export"
+ // RiskRequestRole is for requesting role.
+ RiskRequestRole RiskSource = "bb.risk.request.role"
)
// RiskMessage is the message for risks.
diff --git a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
index 878d78412f..ebbdfcc796 100644
--- a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
+++ b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
@@ -9,10 +9,12 @@ import {
environmentNamePrefix,
useEnvironmentV1Store,
useProjectV1Store,
+ useRoleStore,
} from "@/store";
import {
PresetRiskLevelList,
DEFAULT_PROJECT_NAME,
+ PRESET_WORKSPACE_ROLES,
useSupportedSourceList,
type ComposedProject,
} from "@/types";
@@ -23,6 +25,7 @@ import {
extractProjectResourceName,
supportedEngineV1List,
getDefaultPagination,
+ displayRoleTitle,
} from "@/utils";
export const sourceText = (source: Risk_Source) => {
@@ -41,6 +44,8 @@ export const sourceText = (source: Risk_Source) => {
return t("custom-approval.risk-rule.risk.namespace.request_query");
case Risk_Source.REQUEST_EXPORT:
return t("custom-approval.risk-rule.risk.namespace.request_export");
+ case Risk_Source.REQUEST_ROLE:
+ return t("custom-approval.risk-rule.risk.namespace.request-role");
default:
return Risk_Source.UNRECOGNIZED;
}
@@ -85,6 +90,7 @@ const StringFactorList = [
"database_name",
"schema_name",
"table_name",
+ "role",
] as const;
export const RiskSourceFactorMap: Map<Risk_Source, string[]> = new Map([
@@ -167,6 +173,7 @@ export const RiskSourceFactorMap: Map<Risk_Source, string[]> = new Map([
)
),
],
+ [Risk_Source.REQUEST_ROLE, ["project_id", "expiration_days", "role"]],
]);
export const getFactorList = (source: Risk_Source) => {
@@ -262,6 +269,15 @@ const getSQLTypeOptions = (source: Risk_Source) => {
return [];
};
+const getRoleOptions = () => {
+ return useRoleStore()
+ .roleList.filter((role) => !PRESET_WORKSPACE_ROLES.includes(role.name))
+ .map((role) => ({
+ label: displayRoleTitle(role.name),
+ value: role.name,
+ }));
+};
+
export const getOptionConfigMap = (source: Risk_Source) => {
const factorList = getFactorList(source);
return factorList.reduce((map, factor) => {
@@ -299,6 +315,9 @@ export const getOptionConfigMap = (source: Risk_Source) => {
case "sql_type":
options = getSQLTypeOptions(source);
break;
+ case "role":
+ options = getRoleOptions();
+ break;
}
map.set(factor, {
remote: false,
@@ -315,4 +334,5 @@ export const factorSupportDropdown: Factor[] = [
"sql_type",
"level",
"source",
+ "role",
];
diff --git a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
index ff20ce03d8..901824cf79 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/ReviewSection/ReviewSection.vue
@@ -1,6 +1,6 @@
<template>
<div v-if="!isCreating" class="flex flex-col gap-y-2">
- <div class="w-full flex flex-row justify-between items-center gap-2">
+ <div class="w-full flex flex-row items-center gap-2">
<NTooltip placement="bottom">
<template #trigger>
<div>
diff --git a/frontend/src/components/User/Settings/UserPassword.vue b/frontend/src/components/User/Settings/UserPassword.vue
index 457ff6a2aa..9cd49f6f53 100644
--- a/frontend/src/components/User/Settings/UserPassword.vue
+++ b/frontend/src/components/User/Settings/UserPassword.vue
@@ -4,6 +4,7 @@
<div>
<label class="block text-sm font-medium leading-5 text-control">
{{ $t("settings.profile.password") }}
+ <RequiredStar />
</label>
<span
:class="[
@@ -56,6 +57,7 @@
class="block text-sm font-medium leading-5 text-control"
>
{{ $t("settings.profile.password-confirm") }}
+ <RequiredStar />
</label>
<div class="w-full mt-1 flex flex-col justify-start items-start">
<div class="w-full relative flex flex-row items-center">
@@ -99,6 +101,7 @@ import { NInput, NTooltip } from "naive-ui";
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import LearnMoreLink from "@/components/LearnMoreLink.vue";
+import RequiredStar from "@/components/RequiredStar.vue";
import { type PasswordRestrictionSetting } from "@/types/proto/v1/setting_service";
const props = withDefaults(
diff --git a/frontend/src/layouts/ProjectV1Layout.vue b/frontend/src/layouts/ProjectV1Layout.vue
index 31b3fb48d4..54fd492449 100644
--- a/frontend/src/layouts/ProjectV1Layout.vue
+++ b/frontend/src/layouts/ProjectV1Layout.vue
@@ -35,7 +35,13 @@
:allow-edit="allowEdit"
v-bind="$attrs"
/>
- <NoPermissionPlaceholder v-else class="py-6" />
+ <NoPermissionPlaceholder v-else class="py-6">
+ <template v-if="hasCreateIssuePermission" #extra>
+ <NButton type="primary" @click="state.showRequestRolePanel = true">
+ {{ $t("issue.title.request-role") }}
+ </NButton>
+ </template>
+ </NoPermissionPlaceholder>
</div>
</template>
<div
@@ -48,10 +54,6 @@
<GrantRequestPanel
v-if="state.showRequestRolePanel"
:project-name="project.name"
- :support-roles="[
- PresetRoleType.PROJECT_EXPORTER,
- PresetRoleType.SQL_EDITOR_USER,
- ]"
@close="state.showRequestRolePanel = false"
/>
</template>
@@ -161,6 +163,10 @@ const requiredPermissions = computed(() => {
return permissions;
});
+const hasCreateIssuePermission = computed(() =>
+ hasProjectPermissionV2(project.value, "bb.issues.create")
+);
+
const hasPermission = computed(() => {
return requiredPermissions.value.every((permission) =>
hasProjectPermissionV2(project.value, permission)
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index b3fcb150a6..f847869747 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2275,7 +2275,8 @@
"create_database": "Create Database",
"data_export": "Export Data",
"request_query": "Request Querier Role",
- "request_export": "Request Exporter Role"
+ "request_export": "Request Exporter Role",
+ "request-role": "Request Role"
}
},
"template": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 597348d2db..4b12112621 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2275,7 +2275,8 @@
"create_database": "Crear base de datos",
"data_export": "Exportar datos",
"request_query": "Solicitar Rol de Consultor",
- "request_export": "Solicitar Rol de Exportador"
+ "request_export": "Solicitar Rol de Exportador",
+ "request-role": "Rol de solicitud"
}
},
"template": {
@@ -2614,4 +2615,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 25c903e27a..823c6ae2ce 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2275,7 +2275,8 @@
"create_database": "データベースの作成",
"data_export": "データのエクスポート",
"request_query": "クエリ権限を申請する",
- "request_export": "出力権限を申請する"
+ "request_export": "出力権限を申請する",
+ "request-role": "ロールのリクエスト"
}
},
"template": {
@@ -2614,4 +2615,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index e9ee38c207..fb3a97936a 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2275,7 +2275,8 @@
"create_database": "Tạo cơ sở dữ liệu",
"data_export": "Xuất dữ liệu",
"request_query": "Yêu cầu vai trò Người truy vấn",
- "request_export": "Yêu cầu vai trò Người xuất"
+ "request_export": "Yêu cầu vai trò Người xuất",
+ "request-role": "Yêu cầu vai trò"
}
},
"template": {
@@ -2614,4 +2615,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 3083dfc4ca..32050b2eb8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2275,7 +2275,8 @@
"create_database": "创建数据库",
"data_export": "导出数据",
"request_query": "申请查询权限",
- "request_export": "申请导出权限"
+ "request_export": "申请导出权限",
+ "request-role": "请求角色"
}
},
"template": {
@@ -2614,4 +2615,4 @@
"last-visit": "上次访问",
"changelog-for-version": "{version} 的更新日志"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/plugins/cel/types/factor.ts b/frontend/src/plugins/cel/types/factor.ts
index b71d058375..da63b28141 100644
--- a/frontend/src/plugins/cel/types/factor.ts
+++ b/frontend/src/plugins/cel/types/factor.ts
@@ -25,6 +25,7 @@ export const StringFactorList = [
"db_engine",
"sql_type",
"sql_statement",
+ "role",
// Grant request issue related factors
"resource.database",
diff --git a/frontend/src/plugins/cel/types/operator.ts b/frontend/src/plugins/cel/types/operator.ts
index 4d56da590f..8cbd929452 100644
--- a/frontend/src/plugins/cel/types/operator.ts
+++ b/frontend/src/plugins/cel/types/operator.ts
@@ -124,6 +124,11 @@ const OperatorList: Record<Factor, Operator[]> = {
// Request query/export factors
expiration_days: uniq([...EqualityOperatorList, ...CompareOperatorList]),
export_rows: uniq([...EqualityOperatorList, ...CompareOperatorList]),
+ role: uniq([
+ ...EqualityOperatorList,
+ ...CollectionOperatorList,
+ ...StringOperatorList,
+ ]),
};
export const getOperatorListByFactor = (factor: Factor) => {
diff --git a/frontend/src/types/proto/v1/risk_service.ts b/frontend/src/types/proto/v1/risk_service.ts
index 97f1589b5d..e02e9bf025 100644
--- a/frontend/src/types/proto/v1/risk_service.ts
+++ b/frontend/src/types/proto/v1/risk_service.ts
@@ -103,6 +103,7 @@ export interface Risk {
* sql_statement: the SQL statement, support "contains()", "matches()", "startsWith()", "endsWith()" operations.
* export_rows: export data count, support "==", "!=", "<", "<=", ">", ">=" operations.
* expiration_days: the role expiration days for the request, support "==", "!=", "<", "<=", ">", ">=" operations.
+ * role: the request role full name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations.
*
* When the risk source is DDL/DML, support following variables:
* affected_rows
@@ -149,6 +150,11 @@ export interface Risk {
* table_name
* expiration_days
* export_rows
+ *
+ * When the risk source is REQUEST_ROLE, support following variables:
+ * project_id
+ * expiration_days
+ * role
*/
condition: Expr | undefined;
}
@@ -158,9 +164,12 @@ export enum Risk_Source {
DDL = "DDL",
DML = "DML",
CREATE_DATABASE = "CREATE_DATABASE",
+ /** REQUEST_QUERY - TODO(ed): migrate and deprecate */
REQUEST_QUERY = "REQUEST_QUERY",
+ /** REQUEST_EXPORT - TODO(ed): migrate and deprecate */
REQUEST_EXPORT = "REQUEST_EXPORT",
DATA_EXPORT = "DATA_EXPORT",
+ REQUEST_ROLE = "REQUEST_ROLE",
UNRECOGNIZED = "UNRECOGNIZED",
}
@@ -187,6 +196,9 @@ export function risk_SourceFromJSON(object: any): Risk_Source {
case 6:
case "DATA_EXPORT":
return Risk_Source.DATA_EXPORT;
+ case 7:
+ case "REQUEST_ROLE":
+ return Risk_Source.REQUEST_ROLE;
case -1:
case "UNRECOGNIZED":
default:
@@ -210,6 +222,8 @@ export function risk_SourceToJSON(object: Risk_Source): string {
return "REQUEST_EXPORT";
case Risk_Source.DATA_EXPORT:
return "DATA_EXPORT";
+ case Risk_Source.REQUEST_ROLE:
+ return "REQUEST_ROLE";
case Risk_Source.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
@@ -232,6 +246,8 @@ export function risk_SourceToNumber(object: Risk_Source): number {
return 5;
case Risk_Source.DATA_EXPORT:
return 6;
+ case Risk_Source.REQUEST_ROLE:
+ return 7;
case Risk_Source.UNRECOGNIZED:
default:
return -1;
diff --git a/frontend/src/types/risk.ts b/frontend/src/types/risk.ts
index f26a4fb4b5..7150d3ec7a 100644
--- a/frontend/src/types/risk.ts
+++ b/frontend/src/types/risk.ts
@@ -27,6 +27,7 @@ export const useSupportedSourceList = () => {
Risk_Source.DATA_EXPORT,
Risk_Source.REQUEST_QUERY,
Risk_Source.REQUEST_EXPORT,
+ Risk_Source.REQUEST_ROLE,
];
}
@@ -34,6 +35,7 @@ export const useSupportedSourceList = () => {
Risk_Source.DATA_EXPORT,
Risk_Source.REQUEST_QUERY,
Risk_Source.REQUEST_EXPORT,
+ Risk_Source.REQUEST_ROLE,
];
});
};
diff --git a/frontend/src/utils/issue/cel.ts b/frontend/src/utils/issue/cel.ts
index 4c3395781e..dd2a9099ca 100644
--- a/frontend/src/utils/issue/cel.ts
+++ b/frontend/src/utils/issue/cel.ts
@@ -71,22 +71,26 @@ const buildConditionTitle = ({
const title = [displayRoleTitle(role)];
let conditionSuffix = "";
- if (!databaseResources || databaseResources.length === 0) {
- conditionSuffix = `All databases`;
- } else if (databaseResources.length <= 3) {
- const databaseResourceNames = databaseResources.map((ds) =>
- getDatabaseResourceName(ds)
- );
- conditionSuffix = `${databaseResourceNames.join(", ")}`;
- } else {
- const firstDatabaseResourceName = getDatabaseResourceName(
- head(databaseResources)!
- );
- conditionSuffix = `${firstDatabaseResourceName} and ${
- databaseResources.length - 1
- } more`;
+ if (databaseResources !== undefined) {
+ if (databaseResources.length === 0) {
+ conditionSuffix = `All databases`;
+ } else if (databaseResources.length <= 3) {
+ const databaseResourceNames = databaseResources.map((ds) =>
+ getDatabaseResourceName(ds)
+ );
+ conditionSuffix = `${databaseResourceNames.join(", ")}`;
+ } else {
+ const firstDatabaseResourceName = getDatabaseResourceName(
+ head(databaseResources)!
+ );
+ conditionSuffix = `${firstDatabaseResourceName} and ${
+ databaseResources.length - 1
+ } more`;
+ }
+ }
+ if (conditionSuffix) {
+ title.push(conditionSuffix);
}
- title.push(conditionSuffix);
if (expirationTimestampInMS) {
title.push(
diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vue
index 6783730d33..45ced6f908 100644
--- a/frontend/src/views/auth/Signup.vue
+++ b/frontend/src/views/auth/Signup.vue
@@ -29,7 +29,8 @@
for="email"
class="block text-sm font-medium leading-5 text-control"
>
- {{ $t("common.email") }} <span class="text-red-600">*</span>
+ {{ $t("common.email") }}
+ <RequiredStar />
</label>
<div class="mt-1 rounded-md shadow-sm">
<BBTextField
@@ -56,7 +57,7 @@
class="block text-sm font-medium leading-5 text-control"
>
{{ $t("common.username") }}
- <span class="text-red-600"> * </span>
+ <RequiredStar />
</label>
<div class="mt-1 rounded-md shadow-sm">
<BBTextField
@@ -144,6 +145,7 @@ import { storeToRefs } from "pinia";
import { computed, onMounted, reactive, ref } from "vue";
import { BBTextField } from "@/bbkit";
import BytebaseLogo from "@/components/BytebaseLogo.vue";
+import RequiredStar from "@/components/RequiredStar.vue";
import UserPassword from "@/components/User/Settings/UserPassword.vue";
import { AUTH_SIGNIN_MODULE } from "@/router/auth";
import { useActuatorV1Store, useAuthStore } from "@/store";
@@ -181,6 +183,7 @@ const allowSignup = computed(() => {
return (
isValidEmail(state.email) &&
state.password &&
+ state.name &&
!userPasswordRef.value?.passwordHint &&
!userPasswordRef.value?.passwordMismatch &&
state.acceptTermsAndPolicy &&
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 64bc12fff0..f388799191 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -12107,6 +12107,7 @@ components:
- REQUEST_QUERY
- REQUEST_EXPORT
- DATA_EXPORT
+ - REQUEST_ROLE
type: string
format: enum
title:
@@ -12138,6 +12139,7 @@ components:
sql_statement: the SQL statement, support "contains()", "matches()", "startsWith()", "endsWith()" operations.
export_rows: export data count, support "==", "!=", "<", "<=", ">", ">=" operations.
expiration_days: the role expiration days for the request, support "==", "!=", "<", "<=", ">", ">=" operations.
+ role: the request role full name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations.
When the risk source is DDL/DML, support following variables:
affected_rows
@@ -12184,6 +12186,11 @@ components:
table_name
expiration_days
export_rows
+
+ When the risk source is REQUEST_ROLE, support following variables:
+ project_id
+ expiration_days
+ role
Role:
type: object
properties:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index df077cb2fe..e9e430eeaa 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -9620,7 +9620,7 @@ When paginating, all other parameters provided to `LiskRisks` must match the cal
| active | [bool](#bool) | | |
| condition | [google.type.Expr](#google-type-Expr) | | The condition that is associated with the risk. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec
-All supported variables: affected_rows: affected row count in the DDL/DML, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. table_rows: table row count number, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. environment_id: the environment resource id, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. project_id: the project resource id, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. db_engine: the database engine type, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. Check the Engine enum for the values. sql_type: the SQL type, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. when the risk source is DDL, check https://github.com/bytebase/bytebase/blob/main/frontend/src/plugins/cel/types/values.ts#L70 for supported values. when the risk source is DML, check https://github.com/bytebase/bytebase/blob/main/frontend/src/plugins/cel/types/values.ts#L71 for supported values. database_name: the database name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. schema_name: the schema name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. table_name: the table name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. sql_statement: the SQL statement, support &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. export_rows: export data count, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. expiration_days: the role expiration days for the request, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations.
+All supported variables: affected_rows: affected row count in the DDL/DML, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. table_rows: table row count number, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. environment_id: the environment resource id, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. project_id: the project resource id, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. db_engine: the database engine type, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. Check the Engine enum for the values. sql_type: the SQL type, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operations. when the risk source is DDL, check https://github.com/bytebase/bytebase/blob/main/frontend/src/plugins/cel/types/values.ts#L70 for supported values. when the risk source is DML, check https://github.com/bytebase/bytebase/blob/main/frontend/src/plugins/cel/types/values.ts#L71 for supported values. database_name: the database name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. schema_name: the schema name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. table_name: the table name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. sql_statement: the SQL statement, support &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations. export_rows: export data count, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. expiration_days: the role expiration days for the request, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations. role: the request role full name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations.
When the risk source is DDL/DML, support following variables: affected_rows table_rows environment_id project_id db_engine sql_type database_name schema_name table_name sql_statement
@@ -9630,7 +9630,9 @@ When the risk source is DATA_EXPORT, support following variables: environment_id
When the risk source is REQUEST_QUERY, support following variables: environment_id project_id db_engine database_name schema_name table_name expiration_days
-When the risk source is REQUEST_EXPORT, support following variables: environment_id project_id db_engine database_name schema_name table_name expiration_days export_rows |
+When the risk source is REQUEST_EXPORT, support following variables: environment_id project_id db_engine database_name schema_name table_name expiration_days export_rows
+
+When the risk source is REQUEST_ROLE, support following variables: project_id expiration_days role |
@@ -9668,9 +9670,10 @@ The risk&#39;s `name` field is used to identify the risk to update. Format: risk
| DDL | 1 | |
| DML | 2 | |
| CREATE_DATABASE | 3 | |
-| REQUEST_QUERY | 4 | |
-| REQUEST_EXPORT | 5 | |
+| REQUEST_QUERY | 4 | TODO(ed): migrate and deprecate |
+| REQUEST_EXPORT | 5 | TODO(ed): migrate and deprecate |
| DATA_EXPORT | 6 | |
+| REQUEST_ROLE | 7 | |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index b8b755d247..b13b6da981 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -26620,6 +26620,7 @@ table_name: the table name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34
sql_statement: the SQL statement, support &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations.
export_rows: export data count, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations.
expiration_days: the role expiration days for the request, support &#34;==&#34;, &#34;!=&#34;, &#34;&lt;&#34;, &#34;&lt;=&#34;, &#34;&gt;&#34;, &#34;&gt;=&#34; operations.
+role: the request role full name, support &#34;==&#34;, &#34;!=&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34;, &#34;contains()&#34;, &#34;matches()&#34;, &#34;startsWith()&#34;, &#34;endsWith()&#34; operations.
When the risk source is DDL/DML, support following variables:
affected_rows
@@ -26665,7 +26666,12 @@ database_name
schema_name
table_name
expiration_days
-export_rows </p></td>
+export_rows
+
+When the risk source is REQUEST_ROLE, support following variables:
+project_id
+expiration_days
+role </p></td>
</tr>
</tbody>
@@ -26746,13 +26752,13 @@ Format: risks/{risk} </p></td>
<tr>
<td>REQUEST_QUERY</td>
<td>4</td>
- <td><p></p></td>
+ <td><p>TODO(ed): migrate and deprecate</p></td>
</tr>
<tr>
<td>REQUEST_EXPORT</td>
<td>5</td>
- <td><p></p></td>
+ <td><p>TODO(ed): migrate and deprecate</p></td>
</tr>
<tr>
@@ -26761,6 +26767,12 @@ Format: risks/{risk} </p></td>
<td><p></p></td>
</tr>
+ <tr>
+ <td>REQUEST_ROLE</td>
+ <td>7</td>
+ <td><p></p></td>
+ </tr>
+
</tbody>
</table>
diff --git a/proto/generated-go/v1/risk_service.pb.go b/proto/generated-go/v1/risk_service.pb.go
index 5e05c0051e..1d2b6bb50f 100644
--- a/proto/generated-go/v1/risk_service.pb.go
+++ b/proto/generated-go/v1/risk_service.pb.go
@@ -32,9 +32,12 @@ const (
Risk_DDL Risk_Source = 1
Risk_DML Risk_Source = 2
Risk_CREATE_DATABASE Risk_Source = 3
- Risk_REQUEST_QUERY Risk_Source = 4
- Risk_REQUEST_EXPORT Risk_Source = 5
- Risk_DATA_EXPORT Risk_Source = 6
+ // TODO(ed): migrate and deprecate
+ Risk_REQUEST_QUERY Risk_Source = 4
+ // TODO(ed): migrate and deprecate
+ Risk_REQUEST_EXPORT Risk_Source = 5
+ Risk_DATA_EXPORT Risk_Source = 6
+ Risk_REQUEST_ROLE Risk_Source = 7
)
// Enum value maps for Risk_Source.
@@ -47,6 +50,7 @@ var (
4: "REQUEST_QUERY",
5: "REQUEST_EXPORT",
6: "DATA_EXPORT",
+ 7: "REQUEST_ROLE",
}
Risk_Source_value = map[string]int32{
"SOURCE_UNSPECIFIED": 0,
@@ -56,6 +60,7 @@ var (
"REQUEST_QUERY": 4,
"REQUEST_EXPORT": 5,
"DATA_EXPORT": 6,
+ "REQUEST_ROLE": 7,
}
)
@@ -425,6 +430,7 @@ type Risk struct {
// sql_statement: the SQL statement, support "contains()", "matches()", "startsWith()", "endsWith()" operations.
// export_rows: export data count, support "==", "!=", "<", "<=", ">", ">=" operations.
// expiration_days: the role expiration days for the request, support "==", "!=", "<", "<=", ">", ">=" operations.
+ // role: the request role full name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations.
//
// When the risk source is DDL/DML, support following variables:
// affected_rows
@@ -471,6 +477,11 @@ type Risk struct {
// table_name
// expiration_days
// export_rows
+ //
+ // When the risk source is REQUEST_ROLE, support following variables:
+ // project_id
+ // expiration_days
+ // role
Condition *expr.Expr `protobuf:"bytes,8,opt,name=condition,proto3" json:"condition,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -571,14 +582,14 @@ const file_v1_risk_service_proto_rawDesc = "" +
"updateMask\"C\n" +
"\x11DeleteRiskRequest\x12.\n" +
"\x04name\x18\x01 \x01(\tB\x1a\xe2A\x01\x02\xfaA\x13\n" +
- "\x11bytebase.com/RiskR\x04name\"\xee\x02\n" +
+ "\x11bytebase.com/RiskR\x04name\"\x81\x03\n" +
"\x04Risk\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x120\n" +
"\x06source\x18\x03 \x01(\x0e2\x18.bytebase.v1.Risk.SourceR\x06source\x12\x14\n" +
"\x05title\x18\x04 \x01(\tR\x05title\x12\x14\n" +
"\x05level\x18\x05 \x01(\x05R\x05level\x12\x16\n" +
"\x06active\x18\a \x01(\bR\x06active\x12/\n" +
- "\tcondition\x18\b \x01(\v2\x11.google.type.ExprR\tcondition\"\x7f\n" +
+ "\tcondition\x18\b \x01(\v2\x11.google.type.ExprR\tcondition\"\x91\x01\n" +
"\x06Source\x12\x16\n" +
"\x12SOURCE_UNSPECIFIED\x10\x00\x12\a\n" +
"\x03DDL\x10\x01\x12\a\n" +
@@ -586,7 +597,8 @@ const file_v1_risk_service_proto_rawDesc = "" +
"\x0fCREATE_DATABASE\x10\x03\x12\x11\n" +
"\rREQUEST_QUERY\x10\x04\x12\x12\n" +
"\x0eREQUEST_EXPORT\x10\x05\x12\x0f\n" +
- "\vDATA_EXPORT\x10\x06:$\xeaA!\n" +
+ "\vDATA_EXPORT\x10\x06\x12\x10\n" +
+ "\fREQUEST_ROLE\x10\a:$\xeaA!\n" +
"\x11bytebase.com/Risk\x12\frisks/{risk}J\x04\b\x02\x10\x032\x87\x05\n" +
"\vRiskService\x12u\n" +
"\tListRisks\x12\x1d.bytebase.v1.ListRisksRequest\x1a\x1e.bytebase.v1.ListRisksResponse\")\xdaA\x00\x8a\xea0\rbb.risks.list\x90\xea0\x01\x82\xd3\xe4\x93\x02\v\x12\t/v1/risks\x12z\n" +
diff --git a/proto/v1/v1/risk_service.proto b/proto/v1/v1/risk_service.proto
index c109b55f23..9cb388711a 100644
--- a/proto/v1/v1/risk_service.proto
+++ b/proto/v1/v1/risk_service.proto
@@ -133,9 +133,12 @@ message Risk {
DDL = 1;
DML = 2;
CREATE_DATABASE = 3;
+ // TODO(ed): migrate and deprecate
REQUEST_QUERY = 4;
+ // TODO(ed): migrate and deprecate
REQUEST_EXPORT = 5;
DATA_EXPORT = 6;
+ REQUEST_ROLE = 7;
}
Source source = 3;
@@ -161,6 +164,7 @@ message Risk {
// sql_statement: the SQL statement, support "contains()", "matches()", "startsWith()", "endsWith()" operations.
// export_rows: export data count, support "==", "!=", "<", "<=", ">", ">=" operations.
// expiration_days: the role expiration days for the request, support "==", "!=", "<", "<=", ">", ">=" operations.
+ // role: the request role full name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations.
//
// When the risk source is DDL/DML, support following variables:
// affected_rows
@@ -207,5 +211,10 @@ message Risk {
// table_name
// expiration_days
// export_rows
+ //
+ // When the risk source is REQUEST_ROLE, support following variables:
+ // project_id
+ // expiration_days
+ // role
google.type.Expr condition = 8;
}