Skip to content

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

chore: refactor default algorithm (#14859)

Danny Xuedb7003bacc5
diff --git a/backend/api/v1/common.go b/backend/api/v1/common.go
index e5bfe27b6a..61b773c680 100644
--- a/backend/api/v1/common.go
+++ b/backend/api/v1/common.go
@@ -31,10 +31,8 @@ const (
var (
resourceIDMatcher = regexp.MustCompile("^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$")
- // https://datatracker.ietf.org/doc/html/rfc4122#section-4.1
- uuidMatcher = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
- deletePatch = true
- undeletePatch = false
+ deletePatch = true
+ undeletePatch = false
)
func convertDeletedToState(deleted bool) v1pb.State {
@@ -471,12 +469,6 @@ func parseLimitAndOffset(size *pageSize) (*pageOffset, error) {
return offset, nil
}
-// isValidUUID validates that the id is the valid UUID format.
-// https://datatracker.ietf.org/doc/html/rfc4122#section-4.1
-func isValidUUID(id string) bool {
- return uuidMatcher.MatchString(id)
-}
-
func convertExportFormat(format storepb.ExportFormat) v1pb.ExportFormat {
switch format {
case storepb.ExportFormat_CSV:
diff --git a/backend/api/v1/masking_evaluator.go b/backend/api/v1/masking_evaluator.go
index 4dfdc438e3..ff3349e9b9 100644
--- a/backend/api/v1/masking_evaluator.go
+++ b/backend/api/v1/masking_evaluator.go
@@ -63,15 +63,6 @@ func (m *maskingLevelEvaluator) getDataClassificationConfig(classificationID str
return m.dataClassificationIDMap[classificationID]
}
-var (
- defaultFullAlgorithm = &storepb.Algorithm{
- Id: "default",
- }
- defaultPartialAlgorithm = &storepb.Algorithm{
- Id: "default-partial",
- }
-)
-
// nolint
func (m *maskingLevelEvaluator) evaluateMaskingAlgorithmOfColumn(
databaseMessage *store.DatabaseMessage,
@@ -97,13 +88,6 @@ func (m *maskingLevelEvaluator) evaluateMaskingAlgorithmOfColumn(
}
}
- switch semanticTypeID {
- case "default":
- return defaultFullAlgorithm, nil
- case "default-partial":
- return defaultPartialAlgorithm, nil
- }
-
semanticType, ok := m.semanticTypesMap[semanticTypeID]
if ok {
return semanticType.GetAlgorithm(), nil
diff --git a/backend/api/v1/masking_evaluator_test.go b/backend/api/v1/masking_evaluator_test.go
index 9fc2a95ae8..768b88b107 100644
--- a/backend/api/v1/masking_evaluator_test.go
+++ b/backend/api/v1/masking_evaluator_test.go
@@ -46,17 +46,23 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
},
},
}
- defaultAlgorithm := &storepb.Algorithm{
- Id: "hash",
+ fullAlgorithm := &storepb.Algorithm{
+ Mask: &storepb.Algorithm_FullMask_{FullMask: &storepb.Algorithm_FullMask{Substitution: "******"}},
+ }
+ hashAlgorithm := &storepb.Algorithm{
Mask: &storepb.Algorithm_Md5Mask{
Md5Mask: &storepb.Algorithm_MD5Mask{Salt: "123"},
},
}
defaultSemanticType := &storepb.SemanticTypeSetting{
Types: []*storepb.SemanticTypeSetting_SemanticType{
+ {
+ Id: "default",
+ Algorithm: fullAlgorithm,
+ },
{
Id: "salary-amount",
- Algorithm: defaultAlgorithm,
+ Algorithm: hashAlgorithm,
},
},
}
@@ -97,7 +103,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
dataClassification: defaultClassification,
databaseProjectDatabaseClassificationID: defaultProjectDatabaseDataClassificationID,
- want: defaultFullAlgorithm,
+ want: fullAlgorithm,
},
{
description: "Respect The Exception",
@@ -144,7 +150,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
dataClassification: defaultClassification,
databaseProjectDatabaseClassificationID: defaultProjectDatabaseDataClassificationID,
- want: defaultAlgorithm,
+ want: hashAlgorithm,
},
}
diff --git a/backend/api/v1/query_result_masker.go b/backend/api/v1/query_result_masker.go
index f097d176a5..3feef32760 100644
--- a/backend/api/v1/query_result_masker.go
+++ b/backend/api/v1/query_result_masker.go
@@ -272,10 +272,8 @@ func getMaskerByMaskingAlgorithmAndLevel(algorithm *storepb.Algorithm) masker.Ma
if algorithm == nil {
return masker.NewNoneMasker()
}
- switch algorithm.GetId() {
- case "default":
- return masker.NewDefaultFullMasker()
- case "default-partial":
+ // TODO(d): hack about existing default-partial algorithm.
+ if algorithm.GetId() == "default-partial" {
return masker.NewDefaultRangeMasker()
}
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index ccfe42bae1..c3a9720fc7 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -556,9 +556,6 @@ func (s *SettingService) UpdateSetting(ctx context.Context, request *v1pb.Update
}
idMap := make(map[string]struct{})
for _, tp := range storeSemanticTypeSetting.Types {
- if !isValidUUID(tp.Id) {
- return nil, status.Errorf(codes.InvalidArgument, "invalid semantic type id format: %s", tp.Id)
- }
if tp.Title == "" {
return nil, status.Errorf(codes.InvalidArgument, "category title cannot be empty: %s", tp.Id)
}
@@ -1342,9 +1339,6 @@ func convertV1SchemaTemplateSetting(template *v1pb.SchemaTemplateSetting) (*stor
}
func validateMaskingAlgorithm(algorithm *v1pb.Algorithm) error {
- if !isValidUUID(algorithm.Id) {
- return status.Errorf(codes.InvalidArgument, "invalid masking algorithm id format: %s", algorithm.Id)
- }
if preservedMaskingAlgorithmIDMatcher.MatchString(algorithm.Id) {
return status.Errorf(codes.InvalidArgument, "masking algorithm id cannot be preserved id: %s", algorithm.Id)
}
diff --git a/backend/tests/sensitive_data_test.go b/backend/tests/sensitive_data_test.go
index c228d5b4e3..99e1d0763d 100644
--- a/backend/tests/sensitive_data_test.go
+++ b/backend/tests/sensitive_data_test.go
@@ -111,6 +111,29 @@ func TestSensitiveData(t *testing.T) {
a.NoError(err)
defer ctl.Close(ctx)
+ _, err = ctl.settingServiceClient.UpdateSetting(ctx, &v1pb.UpdateSettingRequest{
+ Setting: &v1pb.Setting{
+ Name: "settings/bb.workspace.semantic-types",
+ Value: &v1pb.Value{
+ Value: &v1pb.Value_SemanticTypeSettingValue{
+ SemanticTypeSettingValue: &v1pb.SemanticTypeSetting{
+ Types: []*v1pb.SemanticTypeSetting_SemanticType{
+ {
+ Id: "default",
+ Title: "Default",
+ Algorithm: &v1pb.Algorithm{
+ Mask: &v1pb.Algorithm_FullMask_{FullMask: &v1pb.Algorithm_FullMask{Substitution: "******"}},
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ AllowMissing: true,
+ })
+ a.NoError(err)
+
// Create a MySQL instance.
mysqlPort := getTestPort()
stopInstance := mysql.SetupTestInstance(t, mysqlPort, mysqlBinDir)