Skip to content

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

feat: iam branch (#9864)

p0ny8d44b864d8d8
diff --git a/backend/api/v1/acl_config.go b/backend/api/v1/acl_config.go
index 196434da82..b5e870710e 100644
--- a/backend/api/v1/acl_config.go
+++ b/backend/api/v1/acl_config.go
@@ -179,6 +179,14 @@ var methodPermissionMap = map[string]iam.Permission{
v1pb.OrgPolicyService_CreatePolicy_FullMethodName: iam.PermissionPoliciesCreate,
v1pb.OrgPolicyService_UpdatePolicy_FullMethodName: iam.PermissionPoliciesUpdate,
v1pb.OrgPolicyService_DeletePolicy_FullMethodName: iam.PermissionPoliciesDelete,
+
+ v1pb.BranchService_GetBranch_FullMethodName: iam.PermissionBranchesGet,
+ v1pb.BranchService_ListBranches_FullMethodName: iam.PermissionBranchesList,
+ v1pb.BranchService_CreateBranch_FullMethodName: iam.PermissionBranchesCreate,
+ v1pb.BranchService_UpdateBranch_FullMethodName: iam.PermissionBranchesUpdate,
+ v1pb.BranchService_DeleteBranch_FullMethodName: iam.PermissionBranchesDelete,
+ v1pb.BranchService_MergeBranch_FullMethodName: iam.PermissionBranchesUpdate,
+ v1pb.BranchService_RebaseBranch_FullMethodName: iam.PermissionBranchesUpdate,
}
func isOwnerAndDBAMethod(methodName string) bool {
diff --git a/backend/api/v1/acl_iam.go b/backend/api/v1/acl_iam.go
index e1be57e98c..b7d1aa78eb 100644
--- a/backend/api/v1/acl_iam.go
+++ b/backend/api/v1/acl_iam.go
@@ -138,6 +138,16 @@ func (in *ACLInterceptor) checkIAMPermission(ctx context.Context, fullMethod str
v1pb.ChangelistService_DeleteChangelist_FullMethodName:
projectIDsGetter = in.getProjectIDsForChangelistService
+ case
+ v1pb.BranchService_ListBranches_FullMethodName,
+ v1pb.BranchService_GetBranch_FullMethodName,
+ v1pb.BranchService_CreateBranch_FullMethodName,
+ v1pb.BranchService_UpdateBranch_FullMethodName,
+ v1pb.BranchService_DeleteBranch_FullMethodName,
+ v1pb.BranchService_MergeBranch_FullMethodName,
+ v1pb.BranchService_RebaseBranch_FullMethodName:
+
+ projectIDsGetter = in.getProjectIDsForBranchService
case
v1pb.RolloutService_GetRollout_FullMethodName,
v1pb.RolloutService_CreateRollout_FullMethodName,
@@ -336,6 +346,43 @@ func (*ACLInterceptor) getProjectIDsForRolloutService(_ context.Context, req any
return uniq(projectIDs), nil
}
+func (*ACLInterceptor) getProjectIDsForBranchService(_ context.Context, req any) ([]string, error) {
+ var projects, branches []string
+ switch r := req.(type) {
+ case *v1pb.GetBranchRequest:
+ branches = append(branches, r.GetName())
+ case *v1pb.ListBranchesRequest:
+ projects = append(projects, r.GetParent())
+ case *v1pb.CreateBranchRequest:
+ projects = append(projects, r.GetParent())
+ case *v1pb.UpdateBranchRequest:
+ branches = append(branches, r.GetBranch().GetName())
+ case *v1pb.DeleteBranchRequest:
+ branches = append(branches, r.GetName())
+ case *v1pb.MergeBranchRequest:
+ branches = append(branches, r.GetName())
+ case *v1pb.RebaseBranchRequest:
+ branches = append(branches, r.GetName())
+ }
+
+ var projectIDs []string
+ for _, branch := range branches {
+ projectID, _, err := common.GetProjectAndBranchID(branch)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse branch %q", branch)
+ }
+ projectIDs = append(projectIDs, projectID)
+ }
+ for _, project := range projects {
+ projectID, err := common.GetProjectID(project)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse project %q", project)
+ }
+ projectIDs = append(projectIDs, projectID)
+ }
+ return uniq(projectIDs), nil
+}
+
func (*ACLInterceptor) getProjectIDsForProjectService(_ context.Context, req any) ([]string, error) {
var projects, projectDeploymentConfigs, projectWebhooks, projectGitopsInfos, databaseGroups, schemaGroups, protectionRules []string
diff --git a/backend/component/iam/acl.yaml b/backend/component/iam/acl.yaml
index 27eb891d2d..407c06b417 100644
--- a/backend/component/iam/acl.yaml
+++ b/backend/component/iam/acl.yaml
@@ -86,6 +86,11 @@ roles:
- bb.policies.create
- bb.policies.update
- bb.policies.delete
+ - bb.branches.get
+ - bb.branches.list
+ - bb.branches.create
+ - bb.branches.update
+ - bb.branches.delete
- name: roles/workspaceDBA
permissions:
- bb.instances.list
@@ -173,6 +178,11 @@ roles:
- bb.policies.create
- bb.policies.update
- bb.policies.delete
+ - bb.branches.get
+ - bb.branches.list
+ - bb.branches.create
+ - bb.branches.update
+ - bb.branches.delete
- name: roles/workspaceMember
permissions:
- bb.environments.list
diff --git a/backend/component/iam/permission.go b/backend/component/iam/permission.go
index 18e18c8822..f11559aced 100644
--- a/backend/component/iam/permission.go
+++ b/backend/component/iam/permission.go
@@ -106,4 +106,10 @@ const (
PermissionPoliciesCreate Permission = "bb.policies.create"
PermissionPoliciesUpdate Permission = "bb.policies.update"
PermissionPoliciesDelete Permission = "bb.policies.delete"
+
+ PermissionBranchesList Permission = "bb.branches.list"
+ PermissionBranchesGet Permission = "bb.branches.get"
+ PermissionBranchesCreate Permission = "bb.branches.create"
+ PermissionBranchesUpdate Permission = "bb.branches.update"
+ PermissionBranchesDelete Permission = "bb.branches.delete"
)
diff --git a/backend/component/iam/permission_test.go b/backend/component/iam/permission_test.go
index 6f777e4091..0d60a86d86 100644
--- a/backend/component/iam/permission_test.go
+++ b/backend/component/iam/permission_test.go
@@ -115,7 +115,12 @@ func permissionExist(p Permission) bool {
PermissionPoliciesGet,
PermissionPoliciesCreate,
PermissionPoliciesUpdate,
- PermissionPoliciesDelete:
+ PermissionPoliciesDelete,
+ PermissionBranchesList,
+ PermissionBranchesGet,
+ PermissionBranchesCreate,
+ PermissionBranchesUpdate,
+ PermissionBranchesDelete:
return true
default:
return false