Skip to content

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

chore: masking exception policy uid (#12066)

Danny Xufe1d264b4540
diff --git a/backend/api/v1/masking_evaluator_test.go b/backend/api/v1/masking_evaluator_test.go
index 154bbd4d82..728d2ea634 100644
--- a/backend/api/v1/masking_evaluator_test.go
+++ b/backend/api/v1/masking_evaluator_test.go
@@ -108,7 +108,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Condition: &expr.Expr{
Expression: `(resource.instance_id == "neon-host") && (resource.database_name == "bb") && (resource.schema_name == "hiring") && (resource.table_name == "employees") && (resource.column_name == "salary")`,
},
- Member: "[email protected]",
+ Member: "users/1234",
MaskingLevel: storepb.MaskingLevel_PARTIAL,
},
},
@@ -141,7 +141,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Condition: &expr.Expr{
Expression: `(resource.instance_id == "neon-host") && (resource.database_name == "bb") && (resource.schema_name == "hiring") && (resource.table_name == "employees") && (resource.column_name == "salary")`,
},
- Member: "[email protected]",
+ Member: "users/1234",
MaskingLevel: storepb.MaskingLevel_FULL,
},
},
@@ -177,7 +177,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Condition: &expr.Expr{
Expression: `(resource.instance_id == "neon-host") && (resource.database_name == "bb") && (resource.schema_name == "hiring") && (resource.table_name == "employees") && (resource.column_name == "salary")`,
},
- Member: "[email protected]",
+ Member: "users/1234",
MaskingLevel: storepb.MaskingLevel_PARTIAL,
},
},
diff --git a/backend/api/v1/org_policy_service.go b/backend/api/v1/org_policy_service.go
index 389d60517a..77f79c8e5a 100644
--- a/backend/api/v1/org_policy_service.go
+++ b/backend/api/v1/org_policy_service.go
@@ -48,7 +48,7 @@ func (s *OrgPolicyService) GetPolicy(ctx context.Context, request *v1pb.GetPolic
return nil, err
}
- response, err := convertToPolicy(parent, policy)
+ response, err := s.convertToPolicy(ctx, parent, policy)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
@@ -93,7 +93,7 @@ func (s *OrgPolicyService) ListPolicies(ctx context.Context, request *v1pb.ListP
}
return nil, err
}
- p, err := convertToPolicy(parentPath, policy)
+ p, err := s.convertToPolicy(ctx, parentPath, policy)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
@@ -157,7 +157,7 @@ func (s *OrgPolicyService) UpdatePolicy(ctx context.Context, request *v1pb.Updat
if err := validatePolicyPayload(policy.Type, request.Policy); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid policy: %v", err)
}
- payloadStr, err := s.convertPolicyPayloadToString(request.Policy)
+ payloadStr, err := s.convertPolicyPayloadToString(ctx, request.Policy)
if err != nil {
return nil, err
}
@@ -172,7 +172,7 @@ func (s *OrgPolicyService) UpdatePolicy(ctx context.Context, request *v1pb.Updat
return nil, status.Errorf(codes.Internal, err.Error())
}
- response, err := convertToPolicy(parent, p)
+ response, err := s.convertToPolicy(ctx, parent, p)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
@@ -402,7 +402,7 @@ func (s *OrgPolicyService) createPolicyMessage(ctx context.Context, creatorID in
return nil, status.Errorf(codes.InvalidArgument, "invalid policy: %v", err)
}
- payloadStr, err := s.convertPolicyPayloadToString(policy)
+ payloadStr, err := s.convertPolicyPayloadToString(ctx, policy)
if err != nil {
return nil, err
}
@@ -420,7 +420,7 @@ func (s *OrgPolicyService) createPolicyMessage(ctx context.Context, creatorID in
return nil, status.Errorf(codes.Internal, err.Error())
}
- response, err := convertToPolicy(parent, p)
+ response, err := s.convertToPolicy(ctx, parent, p)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
@@ -537,7 +537,7 @@ func validatePolicyPayload(policyType api.PolicyType, policy *v1pb.Policy) error
return nil
}
-func (s *OrgPolicyService) convertPolicyPayloadToString(policy *v1pb.Policy) (string, error) {
+func (s *OrgPolicyService) convertPolicyPayloadToString(ctx context.Context, policy *v1pb.Policy) (string, error) {
switch policy.Type {
case v1pb.PolicyType_ROLLOUT_POLICY:
rolloutPolicy := convertToStorePBRolloutPolicy(policy.GetRolloutPolicy())
@@ -608,7 +608,7 @@ func (s *OrgPolicyService) convertPolicyPayloadToString(policy *v1pb.Policy) (st
if err := s.licenseService.IsFeatureEnabled(api.FeatureSensitiveData); err != nil {
return "", status.Errorf(codes.PermissionDenied, err.Error())
}
- payload, err := convertToStorePBMaskingExceptionPolicyPayload(policy.GetMaskingExceptionPolicy())
+ payload, err := s.convertToStorePBMaskingExceptionPolicyPayload(ctx, policy.GetMaskingExceptionPolicy())
if err != nil {
return "", status.Errorf(codes.InvalidArgument, err.Error())
}
@@ -631,7 +631,7 @@ func (s *OrgPolicyService) convertPolicyPayloadToString(policy *v1pb.Policy) (st
return "", status.Errorf(codes.InvalidArgument, "invalid policy %v", policy.Type)
}
-func convertToPolicy(parentPath string, policyMessage *store.PolicyMessage) (*v1pb.Policy, error) {
+func (s *OrgPolicyService) convertToPolicy(ctx context.Context, parentPath string, policyMessage *store.PolicyMessage) (*v1pb.Policy, error) {
resourceType := v1pb.PolicyResourceType_RESOURCE_TYPE_UNSPECIFIED
switch policyMessage.ResourceType {
case api.PolicyResourceTypeWorkspace:
@@ -709,7 +709,7 @@ func convertToPolicy(parentPath string, policyMessage *store.PolicyMessage) (*v1
if err := protojson.Unmarshal([]byte(policyMessage.Payload), maskingRulePolicy); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal masking exception policy")
}
- payload, err := convertToV1PBMaskingExceptionPolicyPayload(maskingRulePolicy)
+ payload, err := s.convertToV1PBMaskingExceptionPolicyPayload(ctx, maskingRulePolicy)
if err != nil {
return nil, errors.Wrap(err, "failed to convert masking exception policy")
}
@@ -990,13 +990,18 @@ func convertToV1PBMaskingRulePolicy(policy *storepb.MaskingRulePolicy) (*v1pb.Ma
}, nil
}
-func convertToStorePBMaskingExceptionPolicyPayload(policy *v1pb.MaskingExceptionPolicy) (*storepb.MaskingExceptionPolicy, error) {
+func (s *OrgPolicyService) convertToStorePBMaskingExceptionPolicyPayload(ctx context.Context, policy *v1pb.MaskingExceptionPolicy) (*storepb.MaskingExceptionPolicy, error) {
var exceptions []*storepb.MaskingExceptionPolicy_MaskingException
for _, exception := range policy.MaskingExceptions {
+ memberEmail := strings.TrimPrefix(exception.Member, "user:")
+ user, err := s.store.GetUser(ctx, &store.FindUserMessage{Email: &memberEmail})
+ if err != nil {
+ return nil, err
+ }
exceptions = append(exceptions, &storepb.MaskingExceptionPolicy_MaskingException{
Action: convertToStorePBAction(exception.Action),
MaskingLevel: convertToStorePBMaskingLevel(exception.MaskingLevel),
- Member: strings.TrimPrefix(exception.Member, "user:"),
+ Member: common.FormatUserUID(user.ID),
Condition: &expr.Expr{
Title: exception.Condition.Title,
Expression: exception.Condition.Expression,
@@ -1011,13 +1016,21 @@ func convertToStorePBMaskingExceptionPolicyPayload(policy *v1pb.MaskingException
}, nil
}
-func convertToV1PBMaskingExceptionPolicyPayload(policy *storepb.MaskingExceptionPolicy) (*v1pb.MaskingExceptionPolicy, error) {
+func (s *OrgPolicyService) convertToV1PBMaskingExceptionPolicyPayload(ctx context.Context, policy *storepb.MaskingExceptionPolicy) (*v1pb.MaskingExceptionPolicy, error) {
var exceptions []*v1pb.MaskingExceptionPolicy_MaskingException
for _, exception := range policy.MaskingExceptions {
+ uid, err := common.GetUserID(exception.Member)
+ if err != nil {
+ return nil, err
+ }
+ user, err := s.store.GetUserByID(ctx, uid)
+ if err != nil {
+ return nil, err
+ }
exceptions = append(exceptions, &v1pb.MaskingExceptionPolicy_MaskingException{
Action: convertToV1PBAction(exception.Action),
MaskingLevel: convertToV1PBMaskingLevel(exception.MaskingLevel),
- Member: fmt.Sprintf("user:%s", exception.Member),
+ Member: fmt.Sprintf("user:%s", user.Email),
Condition: &expr.Expr{
Title: exception.Condition.Title,
Expression: exception.Condition.Expression,
diff --git a/backend/api/v1/query_result_masker.go b/backend/api/v1/query_result_masker.go
index a66a3e71ac..bc335f8ed5 100644
--- a/backend/api/v1/query_result_masker.go
+++ b/backend/api/v1/query_result_masker.go
@@ -206,7 +206,11 @@ func (s *QueryResultMasker) getMaskerForColumnResource(
if maskingException.Action != action {
continue
}
- if maskingException.Member == currentPrincipal.Email {
+ uid, err := common.GetUserID(maskingException.Member)
+ if err != nil {
+ continue
+ }
+ if uid == currentPrincipal.ID {
maskingExceptionContainsCurrentPrincipal = append(maskingExceptionContainsCurrentPrincipal, maskingException)
}
}
diff --git a/frontend/src/types/proto/store/policy.ts b/frontend/src/types/proto/store/policy.ts
index 85f36faa35..fcc194d953 100644
--- a/frontend/src/types/proto/store/policy.ts
+++ b/frontend/src/types/proto/store/policy.ts
@@ -113,7 +113,7 @@ export interface MaskingExceptionPolicy_MaskingException {
/**
* Member is the principal who bind to this exception policy instance.
*
- * * `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`.
+ * Format: users/{userUID}.
*/
member: string;
/** The condition that is associated with this exception policy instance. */
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index c1ed77e8af..0cec12e190 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -11128,7 +11128,7 @@ components:
description: |-
Member is the principal who bind to this exception policy instance.
- * `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`.
+ Format: users/{userUID}.
condition:
allOf:
- $ref: '#/components/schemas/Expr'
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 44e1ae5b09..6867dd3a3a 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -2728,7 +2728,7 @@ MaskingExceptionPolicy is the allowlist of users who can access sensitive data.
| masking_level | [MaskingLevel](#bytebase-store-MaskingLevel) | | Level is the masking level that the user can access sensitive data. |
| member | [string](#string) | | Member is the principal who bind to this exception policy instance.
-* `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`. |
+Format: users/{userUID}. |
| condition | [google.type.Expr](#google-type-Expr) | | The condition that is associated with this exception policy instance. |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index 9ca6d36422..1746fba8ec 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -7086,7 +7086,7 @@ Format: instances/{instance}/databases/{database} </p></td>
<td></td>
<td><p>Member is the principal who bind to this exception policy instance.
-* `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`. </p></td>
+Format: users/{userUID}. </p></td>
</tr>
<tr>
diff --git a/proto/generated-go/store/policy.pb.go b/proto/generated-go/store/policy.pb.go
index d0e1fb4169..101a8e7930 100644
--- a/proto/generated-go/store/policy.pb.go
+++ b/proto/generated-go/store/policy.pb.go
@@ -569,7 +569,7 @@ type MaskingExceptionPolicy_MaskingException struct {
MaskingLevel MaskingLevel `protobuf:"varint,2,opt,name=masking_level,json=maskingLevel,proto3,enum=bytebase.store.MaskingLevel" json:"masking_level,omitempty"`
// Member is the principal who bind to this exception policy instance.
//
- // * `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`.
+ // Format: users/{userUID}.
Member string `protobuf:"bytes,4,opt,name=member,proto3" json:"member,omitempty"`
// The condition that is associated with this exception policy instance.
Condition *expr.Expr `protobuf:"bytes,5,opt,name=condition,proto3" json:"condition,omitempty"`
diff --git a/proto/store/policy.proto b/proto/store/policy.proto
index 08cc7ecc9d..618886553e 100644
--- a/proto/store/policy.proto
+++ b/proto/store/policy.proto
@@ -45,7 +45,7 @@ message MaskingExceptionPolicy {
// Member is the principal who bind to this exception policy instance.
//
- // * `user:{emailid}`: An email address that represents a specific Bytebase account. For example, `[email protected]`.
+ // Format: users/{userUID}.
string member = 4;
// The condition that is associated with this exception policy instance.