Skip to content

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

fix: export request project id (#11882)

p0ny20a60cc40665
diff --git a/backend/api/v1/ctx.go b/backend/api/v1/ctx.go
index 3478c9b2b3..6502cca906 100644
--- a/backend/api/v1/ctx.go
+++ b/backend/api/v1/ctx.go
@@ -2,6 +2,7 @@ package v1
import (
"context"
+ "strings"
"github.com/pkg/errors"
"google.golang.org/grpc"
@@ -442,7 +443,16 @@ func (p *ContextProvider) getProjectIDsForDatabase(ctx context.Context, req any)
case *v1pb.QueryRequest:
databaseNames = append(databaseNames, r.GetName())
case *v1pb.ExportRequest:
- databaseNames = append(databaseNames, r.GetName())
+ if strings.HasPrefix(r.GetName(), common.ProjectNamePrefix) {
+ projectID, _, err := common.GetProjectIDIssueUID(r.GetName())
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get projectID from %q", r.GetName())
+ }
+ projectIDs = append(projectIDs, projectID)
+ }
+ if strings.HasPrefix(r.GetName(), common.InstanceNamePrefix) {
+ databaseNames = append(databaseNames, r.GetName())
+ }
case *v1pb.GetDatabaseRequest:
databaseNames = append(databaseNames, r.GetName())
case *v1pb.SyncDatabaseRequest:
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index aa7fade927..56741a4cb6 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -314,7 +314,7 @@ func (s *SQLService) doExecute(ctx context.Context, instance *store.InstanceMess
// Export exports the SQL query result.
func (s *SQLService) Export(ctx context.Context, request *v1pb.ExportRequest) (*v1pb.ExportResponse, error) {
// Prehandle export from issue.
- if strings.Contains(request.Name, common.IssueNamePrefix) {
+ if strings.HasPrefix(request.Name, common.ProjectNamePrefix) {
return s.doExportFromIssue(ctx, request.Name)
}
// Prepare related message.
@@ -399,6 +399,13 @@ func (s *SQLService) doExportFromIssue(ctx context.Context, issueName string) (*
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get issue: %v", err)
}
+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
+ if !ok {
+ return nil, status.Errorf(codes.Internal, "user not found")
+ }
+ if user.ID != issue.Creator.ID {
+ return nil, status.Errorf(codes.PermissionDenied, "only the issue creator can download")
+ }
if issue.PipelineUID == nil {
return nil, status.Errorf(codes.InvalidArgument, "issue %s has no pipeline", issueName)
}
diff --git a/frontend/src/types/proto/v1/sql_service.ts b/frontend/src/types/proto/v1/sql_service.ts
index abcd9070e9..22bb130bb3 100644
--- a/frontend/src/types/proto/v1/sql_service.ts
+++ b/frontend/src/types/proto/v1/sql_service.ts
@@ -222,6 +222,7 @@ export interface ExportRequest {
/**
* The name is the instance name to execute the query against.
* Format: instances/{instance}/databases/{databaseName}
+ * Format: projects/{project}/issues/{issue} for data export issue.
*/
name: string;
/** @deprecated */
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 83c3784b00..05231d6a82 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -9712,6 +9712,7 @@ components:
description: |-
The name is the instance name to execute the query against.
Format: instances/{instance}/databases/{databaseName}
+ Format: projects/{project}/issues/{issue} for data export issue.
connectionDatabase:
type: string
statement:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 66d9d63735..f8ccc131a1 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -9436,7 +9436,7 @@ Type of the SheetPayload.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| name | [string](#string) | | The name is the instance name to execute the query against. Format: instances/{instance}/databases/{databaseName} |
+| name | [string](#string) | | The name is the instance name to execute the query against. Format: instances/{instance}/databases/{databaseName} Format: projects/{project}/issues/{issue} for data export issue. |
| connection_database | [string](#string) | | **Deprecated.** |
| statement | [string](#string) | | The SQL statement to execute. |
| limit | [int32](#int32) | | The maximum number of rows to return. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 9c1f4315e8..943cd03da2 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -26008,7 +26008,8 @@ Format: instances/{instance}/databases/{databaseName} </p></td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>The name is the instance name to execute the query against.
-Format: instances/{instance}/databases/{databaseName} </p></td>
+Format: instances/{instance}/databases/{databaseName}
+Format: projects/{project}/issues/{issue} for data export issue. </p></td>
</tr>
<tr>
diff --git a/proto/generated-go/v1/sql_service.pb.go b/proto/generated-go/v1/sql_service.pb.go
index 8cae5bb15d..67fd945ffd 100644
--- a/proto/generated-go/v1/sql_service.pb.go
+++ b/proto/generated-go/v1/sql_service.pb.go
@@ -1085,6 +1085,7 @@ type ExportRequest struct {
// The name is the instance name to execute the query against.
// Format: instances/{instance}/databases/{databaseName}
+ // Format: projects/{project}/issues/{issue} for data export issue.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// Deprecated: Marked as deprecated in v1/sql_service.proto.
ConnectionDatabase string `protobuf:"bytes,2,opt,name=connection_database,json=connectionDatabase,proto3" json:"connection_database,omitempty"`
diff --git a/proto/v1/sql_service.proto b/proto/v1/sql_service.proto
index 2bac40ae93..f29009a555 100644
--- a/proto/v1/sql_service.proto
+++ b/proto/v1/sql_service.proto
@@ -257,6 +257,7 @@ message Advice {
message ExportRequest {
// The name is the instance name to execute the query against.
// Format: instances/{instance}/databases/{databaseName}
+ // Format: projects/{project}/issues/{issue} for data export issue.
string name = 1 [(google.api.field_behavior) = REQUIRED];
string connection_database = 2 [deprecated = true];