Skip to content

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

chore: task run iam (#13051)

Danny Xuad370b44ee8c
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 10bbe93638..ed9aac0703 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -1123,12 +1123,13 @@ func (s *RolloutService) canUserRunStageTasks(ctx context.Context, user *store.U
return issue.Creator.ID == user.ID, nil
}
- // The workspace owner and DBA roles can always run tasks.
- containsRole, err := s.iamManager.CheckUserContainsWorkspaceRoles(ctx, user, api.WorkspaceAdmin, api.WorkspaceDBA)
+ // Users with bb.taskRuns.create can always create task runs.
+ // The roles should be set on the workspace level, workspace Admin and DBA.
+ ok, err := s.iamManager.CheckPermission(ctx, iam.PermissionTaskRunsCreate, user)
if err != nil {
return false, errors.Wrapf(err, "failed to check workspace role")
}
- if containsRole {
+ if ok {
return true, nil
}
diff --git a/backend/component/iam/acl.yaml b/backend/component/iam/acl.yaml
index b3fbe46bb5..e686fdbd42 100644
--- a/backend/component/iam/acl.yaml
+++ b/backend/component/iam/acl.yaml
@@ -107,6 +107,7 @@ roles:
- bb.settings.list
- bb.settings.set
- bb.slowQueries.list
+ - bb.taskRuns.create
- bb.taskRuns.list
- bb.userGroups.create
- bb.userGroups.delete
@@ -223,6 +224,7 @@ roles:
- bb.settings.list
- bb.settings.set
- bb.slowQueries.list
+ - bb.taskRuns.create
- bb.taskRuns.list
- bb.userGroups.get
- bb.userGroups.list
diff --git a/backend/component/iam/permission.go b/backend/component/iam/permission.go
index 21cbda36f4..2fb8d697cc 100644
--- a/backend/component/iam/permission.go
+++ b/backend/component/iam/permission.go
@@ -119,6 +119,7 @@ const (
PermissionRolloutsGet Permission = "bb.rollouts.get"
PermissionRolloutsPreview Permission = "bb.rollouts.preview"
PermissionSlowQueriesList Permission = "bb.slowQueries.list"
+ PermissionTaskRunsCreate Permission = "bb.taskRuns.create"
PermissionTaskRunsList Permission = "bb.taskRuns.list"
)
@@ -238,6 +239,7 @@ var allProjectPermissions = []Permission{
PermissionRolloutsGet,
PermissionRolloutsPreview,
PermissionSlowQueriesList,
+ PermissionTaskRunsCreate,
PermissionTaskRunsList,
}
diff --git a/backend/component/iam/permission.yaml b/backend/component/iam/permission.yaml
index b16606650b..124ebbf504 100644
--- a/backend/component/iam/permission.yaml
+++ b/backend/component/iam/permission.yaml
@@ -52,6 +52,7 @@ permissions:
- bb.rollouts.get
- bb.rollouts.preview
- bb.slowQueries.list
+ - bb.taskRuns.create
- bb.taskRuns.list
workspacePermissions:
- bb.environments.create
diff --git a/frontend/src/types/proto/v1/rollout_service.ts b/frontend/src/types/proto/v1/rollout_service.ts
index 624a03a100..f7dd945be3 100644
--- a/frontend/src/types/proto/v1/rollout_service.ts
+++ b/frontend/src/types/proto/v1/rollout_service.ts
@@ -5469,6 +5469,12 @@ export const RolloutServiceDefinition = {
},
},
},
+ /**
+ * BatchRunTasks creates task runs for the specified tasks.
+ * DataExport issue only allows the creator to run the task.
+ * Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA.
+ * Follow role-based rollout policy for the environment.
+ */
batchRunTasks: {
name: "BatchRunTasks",
requestType: BatchRunTasksRequest,
@@ -5550,6 +5556,10 @@ export const RolloutServiceDefinition = {
},
},
},
+ /**
+ * BatchSkipTasks skips the specified tasks.
+ * The access is the same as BatchRunTasks().
+ */
batchSkipTasks: {
name: "BatchSkipTasks",
requestType: BatchSkipTasksRequest,
@@ -5632,6 +5642,10 @@ export const RolloutServiceDefinition = {
},
},
},
+ /**
+ * BatchSkipTasks cancels the specified task runs in batch.
+ * The access is the same as BatchRunTasks().
+ */
batchCancelTaskRuns: {
name: "BatchCancelTaskRuns",
requestType: BatchCancelTaskRunsRequest,
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 480840f0ea..23edee3122 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -5776,6 +5776,9 @@ paths:
post:
tags:
- RolloutService
+ description: |-
+ BatchSkipTasks cancels the specified task runs in batch.
+ The access is the same as BatchRunTasks().
operationId: RolloutService_BatchCancelTaskRuns
parameters:
- name: project
@@ -5825,6 +5828,11 @@ paths:
post:
tags:
- RolloutService
+ description: |-
+ BatchRunTasks creates task runs for the specified tasks.
+ DataExport issue only allows the creator to run the task.
+ Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA.
+ Follow role-based rollout policy for the environment.
operationId: RolloutService_BatchRunTasks
parameters:
- name: project
@@ -5868,6 +5876,9 @@ paths:
post:
tags:
- RolloutService
+ description: |-
+ BatchSkipTasks skips the specified tasks.
+ The access is the same as BatchRunTasks().
operationId: RolloutService_BatchSkipTasks
parameters:
- name: project
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 4b92f5bbcf..ae03e8a079 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -8805,9 +8805,9 @@ Read from `pg_stat_activity`
| ListTaskRuns | [ListTaskRunsRequest](#bytebase-v1-ListTaskRunsRequest) | [ListTaskRunsResponse](#bytebase-v1-ListTaskRunsResponse) | |
| GetTaskRunLog | [GetTaskRunLogRequest](#bytebase-v1-GetTaskRunLogRequest) | [TaskRunLog](#bytebase-v1-TaskRunLog) | |
| GetTaskRunSession | [GetTaskRunSessionRequest](#bytebase-v1-GetTaskRunSessionRequest) | [TaskRunSession](#bytebase-v1-TaskRunSession) | |
-| BatchRunTasks | [BatchRunTasksRequest](#bytebase-v1-BatchRunTasksRequest) | [BatchRunTasksResponse](#bytebase-v1-BatchRunTasksResponse) | |
-| BatchSkipTasks | [BatchSkipTasksRequest](#bytebase-v1-BatchSkipTasksRequest) | [BatchSkipTasksResponse](#bytebase-v1-BatchSkipTasksResponse) | |
-| BatchCancelTaskRuns | [BatchCancelTaskRunsRequest](#bytebase-v1-BatchCancelTaskRunsRequest) | [BatchCancelTaskRunsResponse](#bytebase-v1-BatchCancelTaskRunsResponse) | |
+| BatchRunTasks | [BatchRunTasksRequest](#bytebase-v1-BatchRunTasksRequest) | [BatchRunTasksResponse](#bytebase-v1-BatchRunTasksResponse) | BatchRunTasks creates task runs for the specified tasks. DataExport issue only allows the creator to run the task. Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA. Follow role-based rollout policy for the environment. |
+| BatchSkipTasks | [BatchSkipTasksRequest](#bytebase-v1-BatchSkipTasksRequest) | [BatchSkipTasksResponse](#bytebase-v1-BatchSkipTasksResponse) | BatchSkipTasks skips the specified tasks. The access is the same as BatchRunTasks(). |
+| BatchCancelTaskRuns | [BatchCancelTaskRunsRequest](#bytebase-v1-BatchCancelTaskRunsRequest) | [BatchCancelTaskRunsResponse](#bytebase-v1-BatchCancelTaskRunsResponse) | BatchSkipTasks cancels the specified task runs in batch. The access is the same as BatchRunTasks(). |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 205268eb81..c25f2b74f8 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -24379,21 +24379,26 @@ Format: instances/{instance}/databases/{database} </p></td>
<td>BatchRunTasks</td>
<td><a href="#bytebase.v1.BatchRunTasksRequest">BatchRunTasksRequest</a></td>
<td><a href="#bytebase.v1.BatchRunTasksResponse">BatchRunTasksResponse</a></td>
- <td><p></p></td>
+ <td><p>BatchRunTasks creates task runs for the specified tasks.
+DataExport issue only allows the creator to run the task.
+Users with &#34;bb.taskRuns.create&#34; permission can run the task, e.g. Workspace Admin and DBA.
+Follow role-based rollout policy for the environment.</p></td>
</tr>
<tr>
<td>BatchSkipTasks</td>
<td><a href="#bytebase.v1.BatchSkipTasksRequest">BatchSkipTasksRequest</a></td>
<td><a href="#bytebase.v1.BatchSkipTasksResponse">BatchSkipTasksResponse</a></td>
- <td><p></p></td>
+ <td><p>BatchSkipTasks skips the specified tasks.
+The access is the same as BatchRunTasks().</p></td>
</tr>
<tr>
<td>BatchCancelTaskRuns</td>
<td><a href="#bytebase.v1.BatchCancelTaskRunsRequest">BatchCancelTaskRunsRequest</a></td>
<td><a href="#bytebase.v1.BatchCancelTaskRunsResponse">BatchCancelTaskRunsResponse</a></td>
- <td><p></p></td>
+ <td><p>BatchSkipTasks cancels the specified task runs in batch.
+The access is the same as BatchRunTasks().</p></td>
</tr>
</tbody>
diff --git a/proto/generated-go/v1/rollout_service_grpc.pb.go b/proto/generated-go/v1/rollout_service_grpc.pb.go
index 010a84628a..915f36647a 100644
--- a/proto/generated-go/v1/rollout_service_grpc.pb.go
+++ b/proto/generated-go/v1/rollout_service_grpc.pb.go
@@ -40,8 +40,16 @@ type RolloutServiceClient interface {
ListTaskRuns(ctx context.Context, in *ListTaskRunsRequest, opts ...grpc.CallOption) (*ListTaskRunsResponse, error)
GetTaskRunLog(ctx context.Context, in *GetTaskRunLogRequest, opts ...grpc.CallOption) (*TaskRunLog, error)
GetTaskRunSession(ctx context.Context, in *GetTaskRunSessionRequest, opts ...grpc.CallOption) (*TaskRunSession, error)
+ // BatchRunTasks creates task runs for the specified tasks.
+ // DataExport issue only allows the creator to run the task.
+ // Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA.
+ // Follow role-based rollout policy for the environment.
BatchRunTasks(ctx context.Context, in *BatchRunTasksRequest, opts ...grpc.CallOption) (*BatchRunTasksResponse, error)
+ // BatchSkipTasks skips the specified tasks.
+ // The access is the same as BatchRunTasks().
BatchSkipTasks(ctx context.Context, in *BatchSkipTasksRequest, opts ...grpc.CallOption) (*BatchSkipTasksResponse, error)
+ // BatchSkipTasks cancels the specified task runs in batch.
+ // The access is the same as BatchRunTasks().
BatchCancelTaskRuns(ctx context.Context, in *BatchCancelTaskRunsRequest, opts ...grpc.CallOption) (*BatchCancelTaskRunsResponse, error)
}
@@ -153,8 +161,16 @@ type RolloutServiceServer interface {
ListTaskRuns(context.Context, *ListTaskRunsRequest) (*ListTaskRunsResponse, error)
GetTaskRunLog(context.Context, *GetTaskRunLogRequest) (*TaskRunLog, error)
GetTaskRunSession(context.Context, *GetTaskRunSessionRequest) (*TaskRunSession, error)
+ // BatchRunTasks creates task runs for the specified tasks.
+ // DataExport issue only allows the creator to run the task.
+ // Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA.
+ // Follow role-based rollout policy for the environment.
BatchRunTasks(context.Context, *BatchRunTasksRequest) (*BatchRunTasksResponse, error)
+ // BatchSkipTasks skips the specified tasks.
+ // The access is the same as BatchRunTasks().
BatchSkipTasks(context.Context, *BatchSkipTasksRequest) (*BatchSkipTasksResponse, error)
+ // BatchSkipTasks cancels the specified task runs in batch.
+ // The access is the same as BatchRunTasks().
BatchCancelTaskRuns(context.Context, *BatchCancelTaskRunsRequest) (*BatchCancelTaskRunsResponse, error)
mustEmbedUnimplementedRolloutServiceServer()
}
diff --git a/proto/v1/rollout_service.proto b/proto/v1/rollout_service.proto
index cbb4c7d4e2..5e8d48aad8 100644
--- a/proto/v1/rollout_service.proto
+++ b/proto/v1/rollout_service.proto
@@ -62,6 +62,10 @@ service RolloutService {
option (bytebase.v1.auth_method) = IAM;
}
+ // BatchRunTasks creates task runs for the specified tasks.
+ // DataExport issue only allows the creator to run the task.
+ // Users with "bb.taskRuns.create" permission can run the task, e.g. Workspace Admin and DBA.
+ // Follow role-based rollout policy for the environment.
rpc BatchRunTasks(BatchRunTasksRequest) returns (BatchRunTasksResponse) {
option (google.api.http) = {
post: "/v1/{parent=projects/*/rollouts/*/stages/*}/tasks:batchRun"
@@ -69,9 +73,10 @@ service RolloutService {
};
option (google.api.method_signature) = "parent";
option (bytebase.v1.auth_method) = CUSTOM;
- // TODO(d): secure it.
}
+ // BatchSkipTasks skips the specified tasks.
+ // The access is the same as BatchRunTasks().
rpc BatchSkipTasks(BatchSkipTasksRequest) returns (BatchSkipTasksResponse) {
option (google.api.http) = {
post: "/v1/{parent=projects/*/rollouts/*/stages/*}/tasks:batchSkip"
@@ -79,9 +84,10 @@ service RolloutService {
};
option (google.api.method_signature) = "parent";
option (bytebase.v1.auth_method) = CUSTOM;
- // TODO(d): secure it.
}
+ // BatchSkipTasks cancels the specified task runs in batch.
+ // The access is the same as BatchRunTasks().
rpc BatchCancelTaskRuns(BatchCancelTaskRunsRequest) returns (BatchCancelTaskRunsResponse) {
option (google.api.http) = {
post: "/v1/{parent=projects/*/rollouts/*/stages/*/tasks/*}/taskRuns:batchCancel"
@@ -89,7 +95,6 @@ service RolloutService {
};
option (google.api.method_signature) = "parent";
option (bytebase.v1.auth_method) = CUSTOM;
- // TODO(d): secure it.
}
}