Skip to content

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

fix: should not check cel for workspace iam binding (#19435)

ecmadaoa5340b8c1c4e
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index c327991796..61f85f9646 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -578,7 +578,7 @@ func (s *ProjectService) SetIamPolicy(ctx context.Context, req *connect.Request[
return nil, connect.NewError(connect.CodeAborted, errors.Errorf("there is concurrent update to the project iam policy, please refresh and try again"))
}
- if err := validateIAMPolicy(ctx, s.store, req.Msg.Policy, oldIamPolicyMsg); err != nil {
+ if err := validateIAMPolicy(ctx, s.store, req.Msg, oldIamPolicyMsg); err != nil {
return nil, err
}
@@ -1038,13 +1038,13 @@ func getBindingIdentifier(role string, condition *expr.Expr) string {
func validateIAMPolicy(
ctx context.Context,
stores *store.Store,
- policy *v1pb.IamPolicy,
+ msg *v1pb.SetIamPolicyRequest,
oldPolicyMessage *store.IamPolicyMessage,
) error {
- if policy == nil {
+ if msg.Policy == nil {
return connect.NewError(connect.CodeInvalidArgument, errors.New("IAM Policy is required"))
}
- if len(policy.Bindings) == 0 {
+ if len(msg.Policy.Bindings) == 0 {
return connect.NewError(connect.CodeInvalidArgument, errors.New("IAM Binding is empty"))
}
@@ -1069,7 +1069,7 @@ func validateIAMPolicy(
}
bindings := []*v1pb.Binding{}
- for _, binding := range policy.Bindings {
+ for _, binding := range msg.Policy.Bindings {
if len(binding.Members) == 0 {
continue
}
@@ -1080,10 +1080,15 @@ func validateIAMPolicy(
}
}
- return validateBindings(bindings, roleMessages, maximumRoleExpiration)
+ return validateBindings(msg.Resource, bindings, roleMessages, maximumRoleExpiration)
}
-func validateBindings(bindings []*v1pb.Binding, roles []*store.RoleMessage, maximumRoleExpiration *durationpb.Duration) error {
+func validateBindings(
+ parent string,
+ bindings []*v1pb.Binding,
+ roles []*store.RoleMessage,
+ maximumRoleExpiration *durationpb.Duration,
+) error {
existingRoles := make(map[string]bool)
for _, role := range roles {
existingRoles[common.FormatRole(role.ResourceID)] = true
@@ -1097,6 +1102,10 @@ func validateBindings(bindings []*v1pb.Binding, roles []*store.RoleMessage, maxi
return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("IAM Binding role %s does not exist", binding.Role))
}
+ if !strings.HasPrefix(parent, common.ProjectNamePrefix) {
+ continue
+ }
+
if _, err := common.ValidateProjectMemberCELExpr(binding.Condition); err != nil {
return err
}
diff --git a/backend/api/v1/project_service_test.go b/backend/api/v1/project_service_test.go
index 1ca66cc321..646ef5dddc 100644
--- a/backend/api/v1/project_service_test.go
+++ b/backend/api/v1/project_service_test.go
@@ -245,7 +245,7 @@ func TestValidateBindings(t *testing.T) {
a := require.New(t)
for _, tt := range tests {
- err := validateBindings(tt.bindings, tt.roles, nil)
+ err := validateBindings("projects/sample", tt.bindings, tt.roles, nil)
if tt.wantErr {
a.Error(err)
} else {
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 670d07fba4..06fdae7157 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -56,7 +56,7 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, req *connect.Reques
return nil, connect.NewError(connect.CodeAborted, errors.New("there is concurrent update to the workspace iam policy, please refresh and try again"))
}
- if err := validateIAMPolicy(ctx, s.store, request.Policy, policyMessage); err != nil {
+ if err := validateIAMPolicy(ctx, s.store, request, policyMessage); err != nil {
return nil, err
}