Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: allow plan creator to update plan (#10419)
p0nyeeebb879fcf9
diff --git a/backend/api/v1/acl_iam.go b/backend/api/v1/acl_iam.goindex 5ea8615689..5a1ecfd9e8 100644--- a/backend/api/v1/acl_iam.go+++ b/backend/api/v1/acl_iam.go@@ -146,7 +146,6 @@ func (in *ACLInterceptor) checkIAMPermission(ctx context.Context, fullMethod strv1pb.RolloutService_PreviewRollout_FullMethodName,v1pb.RolloutService_GetPlan_FullMethodName,v1pb.RolloutService_CreatePlan_FullMethodName,- v1pb.RolloutService_UpdatePlan_FullMethodName,v1pb.RolloutService_ListTaskRuns_FullMethodName,v1pb.RolloutService_ListPlanCheckRuns_FullMethodName,v1pb.RolloutService_RunPlanChecks_FullMethodName,@@ -262,6 +261,10 @@ func isSkippedMethod(fullMethod string) bool {v1pb.ChangelistService_UpdateChangelist_FullMethodName,v1pb.ChangelistService_DeleteChangelist_FullMethodName:return true+ // handled in the method because we need to consider plan.Creator.+ case+ v1pb.RolloutService_UpdatePlan_FullMethodName:+ return true// handled in the method because we need to consider issue.Creator and issue type.// additional bb.plans.action and bb.rollouts.action permissions are required if the issue type is change database.case@@ -372,8 +375,6 @@ func (*ACLInterceptor) getProjectIDsForRolloutService(_ context.Context, req anyplans = append(plans, r.GetName())case *v1pb.CreatePlanRequest:projects = append(projects, r.GetParent())- case *v1pb.UpdatePlanRequest:- plans = append(plans, r.GetPlan().GetName())case *v1pb.ListTaskRunsRequest:tasks = append(tasks, r.GetParent())case *v1pb.ListPlanCheckRunsRequest:diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.goindex 9224a586fd..791727e65a 100644--- a/backend/api/v1/rollout_service.go+++ b/backend/api/v1/rollout_service.go@@ -779,6 +779,10 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlaif request.UpdateMask == nil {return nil, status.Errorf(codes.InvalidArgument, "update_mask must be set")}+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)+ if !ok {+ return nil, status.Errorf(codes.Internal, "user not found")+ }for _, path := range request.UpdateMask.Paths {switch path {case "steps":@@ -797,6 +801,22 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlaif oldPlan == nil {return nil, status.Errorf(codes.NotFound, "plan %q not found", request.Plan.Name)}++ if s.profile.DevelopmentIAM {+ ok, err := func() (bool, error) {+ if oldPlan.CreatorUID == user.ID {+ return true, nil+ }+ return s.iamManager.CheckPermission(ctx, iam.PermissionPlansUpdate, user, oldPlan.ProjectID)+ }()+ if err != nil {+ return nil, status.Errorf(codes.Internal, "failed to check permission, error: %v", err)+ }+ if !ok {+ return nil, status.Errorf(codes.PermissionDenied, "permission denied to update plan")+ }+ }+oldSteps := convertToPlanSteps(oldPlan.Config.Steps)issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{PlanUID: &oldPlan.UID})@@ -824,10 +844,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlavar taskPatchList []*api.TaskPatchvar statementUpdates []api.ActivityPipelineTaskStatementUpdatePayloadvar earliestUpdates []api.ActivityPipelineTaskEarliestAllowedTimeUpdatePayload- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)- if !ok {- return nil, status.Errorf(codes.Internal, "principal ID not found")- }+if oldPlan.PipelineUID != nil {tasks, err := s.store.ListTasks(ctx, &api.TaskFind{PipelineID: oldPlan.PipelineUID})if err != nil {@@ -837,7 +854,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePladoUpdate := falsetaskPatch := &api.TaskPatch{ID: task.ID,- UpdaterID: principalID,+ UpdaterID: user.ID,}tasksMap[task.ID] = task@@ -1015,7 +1032,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlaif err := s.store.UpdatePlan(ctx, &store.UpdatePlanMessage{UID: oldPlan.UID,- UpdaterID: principalID,+ UpdaterID: user.ID,Config: &storepb.PlanConfig{Steps: convertPlanSteps(request.Plan.Steps),},@@ -1049,7 +1066,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlareturn errors.Wrapf(err, "failed to marshal payload")}_, err = s.activityManager.CreateActivity(ctx, &store.ActivityMessage{- CreatorUID: principalID,+ CreatorUID: user.ID,ContainerUID: task.PipelineID,Type: api.ActivityPipelineTaskStatementUpdate,Payload: string(payload),@@ -1070,7 +1087,7 @@ func (s *RolloutService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlareturn errors.Wrapf(err, "failed to marshal payload")}_, err = s.activityManager.CreateActivity(ctx, &store.ActivityMessage{- CreatorUID: principalID,+ CreatorUID: user.ID,ContainerUID: task.PipelineID,Type: api.ActivityPipelineTaskEarliestAllowedTimeUpdate,Payload: string(payload),