Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: allow set masking algorithm setting (#8803)
h3n4l97020f1e8ef9
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.goindex 30fa3f7836..ca7eb62dbc 100644--- a/backend/api/v1/setting_service.go+++ b/backend/api/v1/setting_service.go@@ -140,10 +140,6 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettinreturn nil, status.Errorf(codes.InvalidArgument, "feature %s is unavailable in current mode", settingName)}apiSettingName := api.SettingName(settingName)- // TODO(zp): remove the following hard code when we persist the algorithm setting.- if apiSettingName == api.SettingMaskingAlgorithm {- return nil, status.Errorf(codes.InvalidArgument, "setting masking algorithm is not available")- }var storeSettingValue stringswitch apiSettingName {@@ -435,24 +431,20 @@ func (s *SettingService) SetSetting(ctx context.Context, request *v1pb.SetSettin}storeSettingValue = string(bytes)case api.SettingMaskingAlgorithm:- storeMaskingAlgorithmSetting := new(storepb.MaskingAlgorithmSetting)- if err := convertV1PbToStorePb(request.Setting.Value.GetMaskingAlgorithmSettingValue(), storeMaskingAlgorithmSetting); err != nil {- return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", apiSettingName, err)- }idMap := make(map[string]struct{})- for _, algorithm := range storeMaskingAlgorithmSetting.Algorithms {- if !isValidUUID(algorithm.Id) {- return nil, status.Errorf(codes.InvalidArgument, "invalid masking algorithm id format: %s", algorithm.Id)- }- if algorithm.Title == "" {- return nil, status.Errorf(codes.InvalidArgument, "masking algorithm title cannot be empty: %s", algorithm.Id)+ for _, algorithm := range request.Setting.Value.GetMaskingAlgorithmSettingValue().Algorithms {+ if err := validateMaskingAlgorithm(algorithm); err != nil {+ return nil, err}-if _, ok := idMap[algorithm.Id]; ok {return nil, status.Errorf(codes.InvalidArgument, "duplicate masking algorithm id: %s", algorithm.Id)}idMap[algorithm.Id] = struct{}{}}+ storeMaskingAlgorithmSetting := new(storepb.MaskingAlgorithmSetting)+ if err := convertV1PbToStorePb(request.Setting.Value.GetMaskingAlgorithmSettingValue(), storeMaskingAlgorithmSetting); err != nil {+ return nil, status.Errorf(codes.Internal, "failed to unmarshal setting value for %s with error: %v", apiSettingName, err)+ }bytes, err := protojson.Marshal(storeMaskingAlgorithmSetting)if err != nil {return nil, status.Errorf(codes.Internal, "failed to marshal setting for %s with error: %v", apiSettingName, err)@@ -1095,3 +1087,38 @@ func convertV1SchemaTemplateSetting(template *v1pb.SchemaTemplateSetting) *storereturn v1Setting}++func validateMaskingAlgorithm(algorithm *v1pb.MaskingAlgorithmSetting_Algorithm) error {+ if !isValidUUID(algorithm.Id) {+ return status.Errorf(codes.InvalidArgument, "invalid masking algorithm id format: %s", algorithm.Id)+ }+ if algorithm.Title == "" {+ return status.Errorf(codes.InvalidArgument, "masking algorithm title cannot be empty: %s", algorithm.Id)+ }++ switch algorithm.Category {+ case "MASK":+ if algorithm.Mask == nil {+ return nil+ }+ switch algorithm.Mask.(type) {+ case *v1pb.MaskingAlgorithmSetting_Algorithm_FullMask_:+ case *v1pb.MaskingAlgorithmSetting_Algorithm_RangeMask_:+ default:+ return status.Errorf(codes.InvalidArgument, "mismatch masking algorithm category and mask type: %T, %s", algorithm.Mask, algorithm.Category)+ }+ case "HASH":+ if algorithm.Mask == nil {+ return nil+ }+ switch algorithm.Mask.(type) {+ case *v1pb.MaskingAlgorithmSetting_Algorithm_Md5Mask:+ default:+ return status.Errorf(codes.InvalidArgument, "mismatch masking algorithm category and mask type: %T, %s", algorithm.Mask, algorithm.Category)+ }+ default:+ return status.Errorf(codes.InvalidArgument, "invalid masking algorithm category: %s", algorithm.Category)+ }++ return nil+}diff --git a/frontend/src/types/proto/store/setting.ts b/frontend/src/types/proto/store/setting.tsindex 5f6164fba2..1eaa722e6c 100644--- a/frontend/src/types/proto/store/setting.ts+++ b/frontend/src/types/proto/store/setting.ts@@ -352,8 +352,8 @@ export interface MaskingAlgorithmSetting_Algorithm {/*** Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.* The range of accepted Payload is decided by the category.- * MASKING: FullMaskingPayload, RangePartialMaskingPayload- * HASHING: MD5Payload+ * Mask: FullMask, RangeMask+ * Hash: MD5Mask*/category: string;fullMask?: MaskingAlgorithmSetting_Algorithm_FullMask | undefined;diff --git a/frontend/src/types/proto/v1/setting_service.ts b/frontend/src/types/proto/v1/setting_service.tsindex 12a32706bd..4090f8a940 100644--- a/frontend/src/types/proto/v1/setting_service.ts+++ b/frontend/src/types/proto/v1/setting_service.ts@@ -485,8 +485,8 @@ export interface MaskingAlgorithmSetting_Algorithm {/*** Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.* The range of accepted Payload is decided by the category.- * MASKING: FullMaskingPayload, RangePartialMaskingPayload- * HASHING: MD5Payload+ * Mask: FullMask, RangeMask+ * Hash: MD5Mask*/category: string;fullMask?: MaskingAlgorithmSetting_Algorithm_FullMask | undefined;diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 154cb47f0b..f41c8852b4 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -2417,7 +2417,7 @@ The type of target.| id | [string](#string) | | id is the uuid for masking algorithm. || title | [string](#string) | | title is the title for masking algorithm. || description | [string](#string) | | description is the description for masking algorithm. |-| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING. The range of accepted Payload is decided by the category. MASKING: FullMaskingPayload, RangePartialMaskingPayload HASHING: MD5Payload |+| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING. The range of accepted Payload is decided by the category. Mask: FullMask, RangeMask Hash: MD5Mask || full_mask | [MaskingAlgorithmSetting.Algorithm.FullMask](#bytebase-store-MaskingAlgorithmSetting-Algorithm-FullMask) | | || range_mask | [MaskingAlgorithmSetting.Algorithm.RangeMask](#bytebase-store-MaskingAlgorithmSetting-Algorithm-RangeMask) | | || md5_mask | [MaskingAlgorithmSetting.Algorithm.MD5Mask](#bytebase-store-MaskingAlgorithmSetting-Algorithm-MD5Mask) | | |diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex ebc82fe1f6..7e7724c89d 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -9014,7 +9014,7 @@ When paginating, all other parameters provided to `ListSettings` must match the| id | [string](#string) | | id is the uuid for masking algorithm. || title | [string](#string) | | title is the title for masking algorithm. || description | [string](#string) | | description is the description for masking algorithm. |-| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING. The range of accepted Payload is decided by the category. MASKING: FullMaskingPayload, RangePartialMaskingPayload HASHING: MD5Payload |+| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING. The range of accepted Payload is decided by the category. Mask: FullMask, RangeMask Hash: MD5Mask || full_mask | [MaskingAlgorithmSetting.Algorithm.FullMask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-FullMask) | | || range_mask | [MaskingAlgorithmSetting.Algorithm.RangeMask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-RangeMask) | | || md5_mask | [MaskingAlgorithmSetting.Algorithm.MD5Mask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-MD5Mask) | | |diff --git a/proto/generated-go/store/setting.pb.go b/proto/generated-go/store/setting.pb.goindex 7780b4d91e..1a1b086836 100644--- a/proto/generated-go/store/setting.pb.go+++ b/proto/generated-go/store/setting.pb.go@@ -1503,8 +1503,8 @@ type MaskingAlgorithmSetting_Algorithm struct {Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`// Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.// The range of accepted Payload is decided by the category.- // MASKING: FullMaskingPayload, RangePartialMaskingPayload- // HASHING: MD5Payload+ // Mask: FullMask, RangeMask+ // Hash: MD5MaskCategory string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"`// Types that are assignable to Mask://diff --git a/proto/generated-go/v1/setting_service.pb.go b/proto/generated-go/v1/setting_service.pb.goindex 33147d807c..ec16329af7 100644--- a/proto/generated-go/v1/setting_service.pb.go+++ b/proto/generated-go/v1/setting_service.pb.go@@ -2323,8 +2323,8 @@ type MaskingAlgorithmSetting_Algorithm struct {Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`// Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.// The range of accepted Payload is decided by the category.- // MASKING: FullMaskingPayload, RangePartialMaskingPayload- // HASHING: MD5Payload+ // Mask: FullMask, RangeMask+ // Hash: MD5MaskCategory string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"`// Types that are assignable to Mask://diff --git a/proto/store/setting.proto b/proto/store/setting.protoindex f19996d888..1bfacd6645 100644--- a/proto/store/setting.proto+++ b/proto/store/setting.proto@@ -232,8 +232,8 @@ message MaskingAlgorithmSetting {// Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.// The range of accepted Payload is decided by the category.- // MASKING: FullMaskingPayload, RangePartialMaskingPayload- // HASHING: MD5Payload+ // Mask: FullMask, RangeMask+ // Hash: MD5Maskstring category = 4;message FullMask {diff --git a/proto/v1/setting_service.proto b/proto/v1/setting_service.protoindex dd85234671..d1d1790422 100644--- a/proto/v1/setting_service.proto+++ b/proto/v1/setting_service.proto@@ -361,8 +361,8 @@ message MaskingAlgorithmSetting {// Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.// The range of accepted Payload is decided by the category.- // MASKING: FullMaskingPayload, RangePartialMaskingPayload- // HASHING: MD5Payload+ // Mask: FullMask, RangeMask+ // Hash: MD5Maskstring category = 4;message FullMask {