Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: add AccessGrantService backend implementation (#19323)
rebelicef897ca3b71e8
diff --git a/backend/api/mcp/gen/openapi.yaml b/backend/api/mcp/gen/openapi.yamlindex 2e74df39cf..2e3ec9dbcd 100644--- a/backend/api/mcp/gen/openapi.yaml+++ b/backend/api/mcp/gen/openapi.yaml@@ -11892,7 +11892,7 @@ components:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: creator, status, issue, expire_time, create_time+ Supported fields: name, creator, status, issue, expire_time, create_timeExamples:- 'creator = "users/[email protected]"'- 'status = "ACTIVE"'@@ -15864,8 +15864,9 @@ components:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: status, expire_time, create_time+ Supported fields: name, status, expire_time, create_timeExamples:+ - 'name = "projects/x/accessGrants/uuid"'- 'status = "ACTIVE"'- 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'title: SearchMyAccessGrantsRequestdiff --git a/backend/api/v1/access_grant_service.go b/backend/api/v1/access_grant_service.gonew file mode 100644index 0000000000..42bf6d279c--- /dev/null+++ b/backend/api/v1/access_grant_service.go@@ -0,0 +1,322 @@+package v1++import (+ "context"+ "time"++ "connectrpc.com/connect"+ "github.com/pkg/errors"+ "google.golang.org/protobuf/types/known/timestamppb"++ "github.com/bytebase/bytebase/backend/common"+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"+ v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"+ "github.com/bytebase/bytebase/backend/generated-go/v1/v1connect"+ "github.com/bytebase/bytebase/backend/store"+)++// AccessGrantService implements the access grant service.+type AccessGrantService struct {+ v1connect.UnimplementedAccessGrantServiceHandler+ store *store.Store+}++// NewAccessGrantService returns a new access grant service instance.+func NewAccessGrantService(store *store.Store) *AccessGrantService {+ return &AccessGrantService{+ store: store,+ }+}++// GetAccessGrant gets an access grant by name.+func (s *AccessGrantService) GetAccessGrant(ctx context.Context, request *connect.Request[v1pb.GetAccessGrantRequest]) (*connect.Response[v1pb.AccessGrant], error) {+ req := request.Msg+ projectID, accessGrantID, err := common.GetProjectIDAccessGrantID(req.Name)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ grant, err := s.store.GetAccessGrant(ctx, &store.FindAccessGrantMessage{+ ID: &accessGrantID,+ ProjectID: &projectID,+ })+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get access grant"))+ }+ if grant == nil {+ return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("access grant %q not found", req.Name))+ }++ return connect.NewResponse(convertToAccessGrant(grant)), nil+}++// ListAccessGrants lists access grants in a project.+func (s *AccessGrantService) ListAccessGrants(ctx context.Context, request *connect.Request[v1pb.ListAccessGrantsRequest]) (*connect.Response[v1pb.ListAccessGrantsResponse], error) {+ req := request.Msg+ projectID, err := common.GetProjectID(req.Parent)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ offset, err := parseLimitAndOffset(&pageSize{+ token: req.PageToken,+ limit: int(req.PageSize),+ maximum: 1000,+ })+ if err != nil {+ return nil, err+ }+ limitPlusOne := offset.limit + 1++ find := &store.FindAccessGrantMessage{+ ProjectID: &projectID,+ Limit: &limitPlusOne,+ Offset: &offset.offset,+ }++ if req.Filter != "" {+ filterQ, err := store.GetListAccessGrantFilter(req.Filter)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Wrapf(err, "failed to parse filter"))+ }+ find.FilterQ = filterQ+ }++ grants, err := s.store.ListAccessGrants(ctx, find)+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to list access grants"))+ }++ resp := &v1pb.ListAccessGrantsResponse{}+ if len(grants) == limitPlusOne {+ nextPageToken, err := offset.getNextPageToken()+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get next page token"))+ }+ resp.NextPageToken = nextPageToken+ grants = grants[:offset.limit]+ }+ for _, grant := range grants {+ resp.AccessGrants = append(resp.AccessGrants, convertToAccessGrant(grant))+ }++ return connect.NewResponse(resp), nil+}++// CreateAccessGrant creates an access grant.+func (s *AccessGrantService) CreateAccessGrant(ctx context.Context, request *connect.Request[v1pb.CreateAccessGrantRequest]) (*connect.Response[v1pb.AccessGrant], error) {+ req := request.Msg+ projectID, err := common.GetProjectID(req.Parent)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ ag := req.AccessGrant+ if ag == nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("access_grant is required"))+ }+ if ag.Creator == "" {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("creator is required"))+ }+ if len(ag.Targets) == 0 {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("targets is required"))+ }++ creatorEmail, err := common.GetUserEmail(ag.Creator)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Wrapf(err, "invalid creator"))+ }++ var expireTime time.Time+ switch exp := ag.Expiration.(type) {+ case *v1pb.AccessGrant_ExpireTime:+ if exp.ExpireTime == nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("expire_time is required"))+ }+ expireTime = exp.ExpireTime.AsTime()+ case *v1pb.AccessGrant_Ttl:+ if exp.Ttl == nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("ttl is required"))+ }+ expireTime = time.Now().Add(exp.Ttl.AsDuration())+ default:+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("expiration (expire_time or ttl) is required"))+ }++ create := &store.AccessGrantMessage{+ ProjectID: projectID,+ Creator: creatorEmail,+ Status: storepb.AccessGrant_PENDING,+ ExpireTime: expireTime,+ Payload: &storepb.AccessGrantPayload{+ Targets: ag.Targets,+ Query: ag.Query,+ Unmask: ag.Unmask,+ },+ }++ grant, err := s.store.CreateAccessGrant(ctx, create)+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to create access grant"))+ }++ return connect.NewResponse(convertToAccessGrant(grant)), nil+}++// ActivateAccessGrant activates a pending access grant.+func (s *AccessGrantService) ActivateAccessGrant(ctx context.Context, request *connect.Request[v1pb.ActivateAccessGrantRequest]) (*connect.Response[v1pb.AccessGrant], error) {+ req := request.Msg+ projectID, accessGrantID, err := common.GetProjectIDAccessGrantID(req.Name)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ grant, err := s.store.GetAccessGrant(ctx, &store.FindAccessGrantMessage{+ ID: &accessGrantID,+ ProjectID: &projectID,+ })+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get access grant"))+ }+ if grant == nil {+ return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("access grant %q not found", req.Name))+ }+ if grant.Status != storepb.AccessGrant_PENDING {+ return nil, connect.NewError(connect.CodeFailedPrecondition, errors.Errorf("access grant %q is not in PENDING status", req.Name))+ }++ status := storepb.AccessGrant_ACTIVE+ updated, err := s.store.UpdateAccessGrant(ctx, accessGrantID, &store.UpdateAccessGrantMessage{+ Status: &status,+ })+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to activate access grant"))+ }++ return connect.NewResponse(convertToAccessGrant(updated)), nil+}++// RevokeAccessGrant revokes an active access grant.+func (s *AccessGrantService) RevokeAccessGrant(ctx context.Context, request *connect.Request[v1pb.RevokeAccessGrantRequest]) (*connect.Response[v1pb.AccessGrant], error) {+ req := request.Msg+ projectID, accessGrantID, err := common.GetProjectIDAccessGrantID(req.Name)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ grant, err := s.store.GetAccessGrant(ctx, &store.FindAccessGrantMessage{+ ID: &accessGrantID,+ ProjectID: &projectID,+ })+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get access grant"))+ }+ if grant == nil {+ return nil, connect.NewError(connect.CodeNotFound, errors.Errorf("access grant %q not found", req.Name))+ }+ if grant.Status != storepb.AccessGrant_ACTIVE {+ return nil, connect.NewError(connect.CodeFailedPrecondition, errors.Errorf("access grant %q is not in ACTIVE status", req.Name))+ }++ status := storepb.AccessGrant_REVOKED+ updated, err := s.store.UpdateAccessGrant(ctx, accessGrantID, &store.UpdateAccessGrantMessage{+ Status: &status,+ })+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to revoke access grant"))+ }++ return connect.NewResponse(convertToAccessGrant(updated)), nil+}++// SearchMyAccessGrants searches access grants created by the caller.+func (s *AccessGrantService) SearchMyAccessGrants(ctx context.Context, request *connect.Request[v1pb.SearchMyAccessGrantsRequest]) (*connect.Response[v1pb.SearchMyAccessGrantsResponse], error) {+ req := request.Msg+ projectID, err := common.GetProjectID(req.Parent)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, err)+ }++ user, ok := GetUserFromContext(ctx)+ if !ok || user == nil {+ return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("user not found"))+ }++ offset, err := parseLimitAndOffset(&pageSize{+ token: req.PageToken,+ limit: int(req.PageSize),+ maximum: 1000,+ })+ if err != nil {+ return nil, err+ }+ limitPlusOne := offset.limit + 1++ find := &store.FindAccessGrantMessage{+ ProjectID: &projectID,+ Creator: &user.Email,+ Limit: &limitPlusOne,+ Offset: &offset.offset,+ }++ if req.Filter != "" {+ filterQ, err := store.GetListAccessGrantFilter(req.Filter)+ if err != nil {+ return nil, connect.NewError(connect.CodeInvalidArgument, errors.Wrapf(err, "failed to parse filter"))+ }+ find.FilterQ = filterQ+ }++ grants, err := s.store.ListAccessGrants(ctx, find)+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to search access grants"))+ }++ resp := &v1pb.SearchMyAccessGrantsResponse{}+ if len(grants) == limitPlusOne {+ nextPageToken, err := offset.getNextPageToken()+ if err != nil {+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to get next page token"))+ }+ resp.NextPageToken = nextPageToken+ grants = grants[:offset.limit]+ }+ for _, grant := range grants {+ resp.AccessGrants = append(resp.AccessGrants, convertToAccessGrant(grant))+ }++ return connect.NewResponse(resp), nil+}++func convertToAccessGrant(msg *store.AccessGrantMessage) *v1pb.AccessGrant {+ ag := &v1pb.AccessGrant{+ Name: common.FormatAccessGrant(msg.ProjectID, msg.ID),+ Creator: common.FormatUserEmail(msg.Creator),+ Status: convertToAccessGrantStatus(msg.Status),+ Expiration: &v1pb.AccessGrant_ExpireTime{ExpireTime: timestamppb.New(msg.ExpireTime)},+ CreateTime: timestamppb.New(msg.CreatedAt),+ UpdateTime: timestamppb.New(msg.UpdatedAt),+ }+ if p := msg.Payload; p != nil {+ ag.Targets = p.Targets+ ag.Query = p.Query+ ag.Unmask = p.Unmask+ if p.IssueId != 0 {+ ag.Issue = common.FormatIssue(msg.ProjectID, int(p.IssueId))+ }+ }+ return ag+}++func convertToAccessGrantStatus(status storepb.AccessGrant_Status) v1pb.AccessGrant_Status {+ switch status {+ case storepb.AccessGrant_PENDING:+ return v1pb.AccessGrant_PENDING+ case storepb.AccessGrant_ACTIVE:+ return v1pb.AccessGrant_ACTIVE+ case storepb.AccessGrant_REVOKED:+ return v1pb.AccessGrant_REVOKED+ default:+ return v1pb.AccessGrant_STATUS_UNSPECIFIED+ }+}diff --git a/backend/common/permission/permission.go b/backend/common/permission/permission.goindex 7ff246a163..6dca516568 100644--- a/backend/common/permission/permission.go+++ b/backend/common/permission/permission.go@@ -12,6 +12,11 @@ var permissionYAML []bytetype Permission = stringconst (+ AccessGrantsActivate Permission = "bb.accessGrants.activate"+ AccessGrantsCreate Permission = "bb.accessGrants.create"+ AccessGrantsGet Permission = "bb.accessGrants.get"+ AccessGrantsList Permission = "bb.accessGrants.list"+ AccessGrantsRevoke Permission = "bb.accessGrants.revoke"AuditLogsExport Permission = "bb.auditLogs.export"AuditLogsSearch Permission = "bb.auditLogs.search"ChangelogsGet Permission = "bb.changelogs.get"diff --git a/backend/common/permission/permission.yaml b/backend/common/permission/permission.yamlindex ee12a2d8ff..5aabcc5146 100644--- a/backend/common/permission/permission.yaml+++ b/backend/common/permission/permission.yaml@@ -1,4 +1,9 @@permissions:+ - bb.accessGrants.activate+ - bb.accessGrants.create+ - bb.accessGrants.get+ - bb.accessGrants.list+ - bb.accessGrants.revoke- bb.auditLogs.export- bb.auditLogs.search- bb.changelogs.getdiff --git a/backend/common/resource_name.go b/backend/common/resource_name.goindex cbc660c5c8..c16de4acfb 100644--- a/backend/common/resource_name.go+++ b/backend/common/resource_name.go@@ -50,6 +50,7 @@ const (ReleaseNamePrefix = "releases/"FileNamePrefix = "files/"RevisionNamePrefix = "revisions/"+ AccessGrantNamePrefix = "accessGrants/"ServiceAccountNamePrefix = "serviceAccounts/"WorkloadIdentityNamePrefix = "workloadIdentities/"@@ -91,6 +92,20 @@ func GetProjectIDWebhookID(name string) (string, string, error) {return tokens[0], tokens[1], nil}+// GetProjectIDAccessGrantID returns the project ID and access grant ID from a resource name.+func GetProjectIDAccessGrantID(name string) (string, string, error) {+ tokens, err := GetNameParentTokens(name, ProjectNamePrefix, AccessGrantNamePrefix)+ if err != nil {+ return "", "", err+ }+ return tokens[0], tokens[1], nil+}++// FormatAccessGrant returns the resource name for an access grant.+func FormatAccessGrant(projectID string, id string) string {+ return fmt.Sprintf("%s/%s%s", FormatProject(projectID), AccessGrantNamePrefix, id)+}+// TrimSuffixAndGetInstanceDatabaseID trims the suffix from the name and returns the instance ID and database ID.func TrimSuffixAndGetInstanceDatabaseID(name string, suffix string) (string, string, error) {trimmed, err := TrimSuffix(name, suffix)diff --git a/backend/generated-go/store/access_grant.pb.go b/backend/generated-go/store/access_grant.pb.gonew file mode 100644index 0000000000..6be42d300f--- /dev/null+++ b/backend/generated-go/store/access_grant.pb.go@@ -0,0 +1,254 @@+// Code generated by protoc-gen-go. DO NOT EDIT.+// versions:+// protoc-gen-go v1.36.11+// protoc (unknown)+// source: store/access_grant.proto++package store++import (+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"+ reflect "reflect"+ sync "sync"+ unsafe "unsafe"+)++const (+ // Verify that this generated code is sufficiently up-to-date.+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)+ // Verify that runtime/protoimpl is sufficiently up-to-date.+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)+)++type AccessGrant_Status int32++const (+ AccessGrant_STATUS_UNSPECIFIED AccessGrant_Status = 0+ AccessGrant_PENDING AccessGrant_Status = 1+ AccessGrant_ACTIVE AccessGrant_Status = 2+ AccessGrant_REVOKED AccessGrant_Status = 3+)++// Enum value maps for AccessGrant_Status.+var (+ AccessGrant_Status_name = map[int32]string{+ 0: "STATUS_UNSPECIFIED",+ 1: "PENDING",+ 2: "ACTIVE",+ 3: "REVOKED",+ }+ AccessGrant_Status_value = map[string]int32{+ "STATUS_UNSPECIFIED": 0,+ "PENDING": 1,+ "ACTIVE": 2,+ "REVOKED": 3,+ }+)++func (x AccessGrant_Status) Enum() *AccessGrant_Status {+ p := new(AccessGrant_Status)+ *p = x+ return p+}++func (x AccessGrant_Status) String() string {+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))+}++func (AccessGrant_Status) Descriptor() protoreflect.EnumDescriptor {+ return file_store_access_grant_proto_enumTypes[0].Descriptor()+}++func (AccessGrant_Status) Type() protoreflect.EnumType {+ return &file_store_access_grant_proto_enumTypes[0]+}++func (x AccessGrant_Status) Number() protoreflect.EnumNumber {+ return protoreflect.EnumNumber(x)+}++// Deprecated: Use AccessGrant_Status.Descriptor instead.+func (AccessGrant_Status) EnumDescriptor() ([]byte, []int) {+ return file_store_access_grant_proto_rawDescGZIP(), []int{0, 0}+}++type AccessGrant struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *AccessGrant) Reset() {+ *x = AccessGrant{}+ mi := &file_store_access_grant_proto_msgTypes[0]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *AccessGrant) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*AccessGrant) ProtoMessage() {}++func (x *AccessGrant) ProtoReflect() protoreflect.Message {+ mi := &file_store_access_grant_proto_msgTypes[0]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use AccessGrant.ProtoReflect.Descriptor instead.+func (*AccessGrant) Descriptor() ([]byte, []int) {+ return file_store_access_grant_proto_rawDescGZIP(), []int{0}+}++type AccessGrantPayload struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ // The issue associated with the access grant.+ IssueId int64 `protobuf:"varint,1,opt,name=issue_id,json=issueId,proto3" json:"issue_id,omitempty"`+ // The target databases for this access grant.+ // Format: instances/{instance}/databases/{database}+ Targets []string `protobuf:"bytes,2,rep,name=targets,proto3" json:"targets,omitempty"`+ // The query permission granted.+ Query string `protobuf:"bytes,3,opt,name=query,proto3" json:"query,omitempty"`+ // Whether the grant allows unmasking sensitive data.+ Unmask bool `protobuf:"varint,4,opt,name=unmask,proto3" json:"unmask,omitempty"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *AccessGrantPayload) Reset() {+ *x = AccessGrantPayload{}+ mi := &file_store_access_grant_proto_msgTypes[1]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *AccessGrantPayload) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*AccessGrantPayload) ProtoMessage() {}++func (x *AccessGrantPayload) ProtoReflect() protoreflect.Message {+ mi := &file_store_access_grant_proto_msgTypes[1]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use AccessGrantPayload.ProtoReflect.Descriptor instead.+func (*AccessGrantPayload) Descriptor() ([]byte, []int) {+ return file_store_access_grant_proto_rawDescGZIP(), []int{1}+}++func (x *AccessGrantPayload) GetIssueId() int64 {+ if x != nil {+ return x.IssueId+ }+ return 0+}++func (x *AccessGrantPayload) GetTargets() []string {+ if x != nil {+ return x.Targets+ }+ return nil+}++func (x *AccessGrantPayload) GetQuery() string {+ if x != nil {+ return x.Query+ }+ return ""+}++func (x *AccessGrantPayload) GetUnmask() bool {+ if x != nil {+ return x.Unmask+ }+ return false+}++var File_store_access_grant_proto protoreflect.FileDescriptor++const file_store_access_grant_proto_rawDesc = "" ++ "\n" ++ "\x18store/access_grant.proto\x12\x0ebytebase.store\"U\n" ++ "\vAccessGrant\"F\n" ++ "\x06Status\x12\x16\n" ++ "\x12STATUS_UNSPECIFIED\x10\x00\x12\v\n" ++ "\aPENDING\x10\x01\x12\n" ++ "\n" ++ "\x06ACTIVE\x10\x02\x12\v\n" ++ "\aREVOKED\x10\x03\"w\n" ++ "\x12AccessGrantPayload\x12\x19\n" ++ "\bissue_id\x18\x01 \x01(\x03R\aissueId\x12\x18\n" ++ "\atargets\x18\x02 \x03(\tR\atargets\x12\x14\n" ++ "\x05query\x18\x03 \x01(\tR\x05query\x12\x16\n" ++ "\x06unmask\x18\x04 \x01(\bR\x06unmaskB\x93\x01\n" ++ "\x12com.bytebase.storeB\x10AccessGrantProtoP\x01Z\x12generated-go/store\xa2\x02\x03BSX\xaa\x02\x0eBytebase.Store\xca\x02\x0eBytebase\\Store\xe2\x02\x1aBytebase\\Store\\GPBMetadata\xea\x02\x0fBytebase::Storeb\x06proto3"++var (+ file_store_access_grant_proto_rawDescOnce sync.Once+ file_store_access_grant_proto_rawDescData []byte+)++func file_store_access_grant_proto_rawDescGZIP() []byte {+ file_store_access_grant_proto_rawDescOnce.Do(func() {+ file_store_access_grant_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_store_access_grant_proto_rawDesc), len(file_store_access_grant_proto_rawDesc)))+ })+ return file_store_access_grant_proto_rawDescData+}++var file_store_access_grant_proto_enumTypes = make([]protoimpl.EnumInfo, 1)+var file_store_access_grant_proto_msgTypes = make([]protoimpl.MessageInfo, 2)+var file_store_access_grant_proto_goTypes = []any{+ (AccessGrant_Status)(0), // 0: bytebase.store.AccessGrant.Status+ (*AccessGrant)(nil), // 1: bytebase.store.AccessGrant+ (*AccessGrantPayload)(nil), // 2: bytebase.store.AccessGrantPayload+}+var file_store_access_grant_proto_depIdxs = []int32{+ 0, // [0:0] is the sub-list for method output_type+ 0, // [0:0] is the sub-list for method input_type+ 0, // [0:0] is the sub-list for extension type_name+ 0, // [0:0] is the sub-list for extension extendee+ 0, // [0:0] is the sub-list for field type_name+}++func init() { file_store_access_grant_proto_init() }+func file_store_access_grant_proto_init() {+ if File_store_access_grant_proto != nil {+ return+ }+ type x struct{}+ out := protoimpl.TypeBuilder{+ File: protoimpl.DescBuilder{+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),+ RawDescriptor: unsafe.Slice(unsafe.StringData(file_store_access_grant_proto_rawDesc), len(file_store_access_grant_proto_rawDesc)),+ NumEnums: 1,+ NumMessages: 2,+ NumExtensions: 0,+ NumServices: 0,+ },+ GoTypes: file_store_access_grant_proto_goTypes,+ DependencyIndexes: file_store_access_grant_proto_depIdxs,+ EnumInfos: file_store_access_grant_proto_enumTypes,+ MessageInfos: file_store_access_grant_proto_msgTypes,+ }.Build()+ File_store_access_grant_proto = out.File+ file_store_access_grant_proto_goTypes = nil+ file_store_access_grant_proto_depIdxs = nil+}diff --git a/backend/generated-go/store/access_grant_equal.pb.go b/backend/generated-go/store/access_grant_equal.pb.gonew file mode 100644index 0000000000..76f2cb8ffa--- /dev/null+++ b/backend/generated-go/store/access_grant_equal.pb.go@@ -0,0 +1,41 @@+// Code generated by protoc-gen-equal-go. DO NOT EDIT.+// source: store/access_grant.proto++package store++func (x *AccessGrant) Equal(y *AccessGrant) bool {+ if x == y {+ return true+ }+ if x == nil || y == nil {+ return x == nil && y == nil+ }+ return true+}++func (x *AccessGrantPayload) Equal(y *AccessGrantPayload) bool {+ if x == y {+ return true+ }+ if x == nil || y == nil {+ return x == nil && y == nil+ }+ if x.IssueId != y.IssueId {+ return false+ }+ if len(x.Targets) != len(y.Targets) {+ return false+ }+ for i := 0; i < len(x.Targets); i++ {+ if x.Targets[i] != y.Targets[i] {+ return false+ }+ }+ if x.Query != y.Query {+ return false+ }+ if x.Unmask != y.Unmask {+ return false+ }+ return true+}diff --git a/backend/generated-go/v1/access_grant_service.pb.go b/backend/generated-go/v1/access_grant_service.pb.goindex f1fd7931fc..05f2347b38 100644--- a/backend/generated-go/v1/access_grant_service.pb.go+++ b/backend/generated-go/v1/access_grant_service.pb.go@@ -314,7 +314,7 @@ type ListAccessGrantsRequest struct {// A page token from a previous ListAccessGrants call.PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`// Filter expression using AIP-160 syntax.- // Supported fields: creator, status, issue, expire_time, create_time+ // Supported fields: name, creator, status, issue, expire_time, create_time// Examples:// - 'creator = "users/[email protected]"'// - 'status = "ACTIVE"'@@ -596,8 +596,9 @@ type SearchMyAccessGrantsRequest struct {// A page token from a previous SearchMyAccessGrants call.PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`// Filter expression using AIP-160 syntax.- // Supported fields: status, expire_time, create_time+ // Supported fields: name, status, expire_time, create_time// Examples:+ // - 'name = "projects/x/accessGrants/uuid"'// - 'status = "ACTIVE"'// - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'Filter string `protobuf:"bytes,4,opt,name=filter,proto3" json:"filter,omitempty"`diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.goindex 4e4b253953..a670fb7dda 100644--- a/backend/server/grpc_routes.go+++ b/backend/server/grpc_routes.go@@ -87,6 +87,7 @@ func configureGrpcRouters(grpcruntime.DefaultHTTPErrorHandler(ctx, sm, m, w, r, err)}),)+ accessGrantService := apiv1.NewAccessGrantService(stores)actuatorService := apiv1.NewActuatorService(stores, profile, schemaSyncer, licenseService, sampleInstanceManager)auditLogService := apiv1.NewAuditLogService(stores, licenseService)authService := apiv1.NewAuthService(stores, secret, licenseService, profile, iamManager)@@ -139,6 +140,9 @@ func configureGrpcRouters(connectHandlers := make(map[string]http.Handler)+ accessGrantPath, accessGrantHandler := v1connect.NewAccessGrantServiceHandler(accessGrantService, handlerOpts)+ connectHandlers[accessGrantPath] = accessGrantHandler+actuatorPath, actuatorHandler := v1connect.NewActuatorServiceHandler(actuatorService, handlerOpts)connectHandlers[actuatorPath] = actuatorHandler@@ -228,6 +232,7 @@ func configureGrpcRouters(// grpc reflection handlers.reflector := grpcreflect.NewStaticReflector(+ v1connect.AccessGrantServiceName,v1connect.ActuatorServiceName,v1connect.AuditLogServiceName,v1connect.AuthServiceName,@@ -277,6 +282,9 @@ func configureGrpcRouters(return err}+ if err := v1pb.RegisterAccessGrantServiceHandler(ctx, mux, grpcConn); err != nil {+ return err+ }if err := v1pb.RegisterActuatorServiceHandler(ctx, mux, grpcConn); err != nil {return err}diff --git a/backend/store/access_grant.go b/backend/store/access_grant.gonew file mode 100644index 0000000000..d4b7bbc566--- /dev/null+++ b/backend/store/access_grant.go@@ -0,0 +1,339 @@+package store++import (+ "context"+ "strings"+ "time"++ "github.com/google/cel-go/cel"+ celast "github.com/google/cel-go/common/ast"+ celoperators "github.com/google/cel-go/common/operators"+ "github.com/google/uuid"+ "github.com/pkg/errors"+ "google.golang.org/protobuf/encoding/protojson"++ "github.com/bytebase/bytebase/backend/common"+ "github.com/bytebase/bytebase/backend/common/qb"+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"+)++// AccessGrantMessage is the message for access_grant.+type AccessGrantMessage struct {+ ProjectID string+ Creator string+ Status storepb.AccessGrant_Status+ ExpireTime time.Time+ Payload *storepb.AccessGrantPayload+ // Output only.+ ID string+ CreatedAt time.Time+ UpdatedAt time.Time+}++// FindAccessGrantMessage is the message for finding access grants.+type FindAccessGrantMessage struct {+ ID *string+ ProjectID *string+ Creator *string+ Limit *int+ Offset *int++ FilterQ *qb.Query+}++// UpdateAccessGrantMessage is the message for updating an access grant.+type UpdateAccessGrantMessage struct {+ Status *storepb.AccessGrant_Status+}++// CreateAccessGrant creates a new access grant.+func (s *Store) CreateAccessGrant(ctx context.Context, create *AccessGrantMessage) (*AccessGrantMessage, error) {+ payload, err := protojson.Marshal(create.Payload)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to marshal payload")+ }++ create.ID = uuid.NewString()++ q := qb.Q().Space(`+ INSERT INTO access_grant (+ id,+ project,+ creator,+ status,+ expire_time,+ payload+ ) VALUES (+ ?, ?, ?, ?, ?, ?+ ) RETURNING created_at, updated_at+ `, create.ID, create.ProjectID, create.Creator, create.Status.String(), create.ExpireTime, payload)++ query, args, err := q.ToSQL()+ if err != nil {+ return nil, errors.Wrapf(err, "failed to build sql")+ }++ if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&create.CreatedAt, &create.UpdatedAt); err != nil {+ return nil, errors.Wrapf(err, "failed to insert access grant")+ }++ return create, nil+}++// GetAccessGrant gets an access grant.+func (s *Store) GetAccessGrant(ctx context.Context, find *FindAccessGrantMessage) (*AccessGrantMessage, error) {+ grants, err := s.ListAccessGrants(ctx, find)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to list access grants")+ }+ if len(grants) == 0 {+ return nil, nil+ }+ if len(grants) > 1 {+ return nil, errors.Errorf("expect to find one access grant, found %d", len(grants))+ }+ return grants[0], nil+}++// ListAccessGrants retrieves a list of access grants.+func (s *Store) ListAccessGrants(ctx context.Context, find *FindAccessGrantMessage) ([]*AccessGrantMessage, error) {+ q := qb.Q().Space(`+ SELECT+ id,+ project,+ creator,+ status,+ expire_time,+ payload,+ created_at,+ updated_at+ FROM access_grant+ WHERE TRUE+ `)++ if filterQ := find.FilterQ; filterQ != nil {+ q.And("?", filterQ)+ }+ if v := find.ID; v != nil {+ q.And("id = ?", *v)+ }+ if v := find.ProjectID; v != nil {+ q.And("project = ?", *v)+ }+ if v := find.Creator; v != nil {+ q.And("creator = ?", *v)+ }++ q.Space("ORDER BY created_at DESC")+ if v := find.Limit; v != nil {+ q.Space("LIMIT ?", *v)+ }+ if v := find.Offset; v != nil {+ q.Space("OFFSET ?", *v)+ }++ query, args, err := q.ToSQL()+ if err != nil {+ return nil, errors.Wrapf(err, "failed to build sql")+ }++ rows, err := s.GetDB().QueryContext(ctx, query, args...)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to select access grants")+ }+ defer rows.Close()++ var grants []*AccessGrantMessage+ for rows.Next() {+ grant := AccessGrantMessage{+ Payload: &storepb.AccessGrantPayload{},+ }+ var payload []byte+ var statusString string+ if err := rows.Scan(+ &grant.ID,+ &grant.ProjectID,+ &grant.Creator,+ &statusString,+ &grant.ExpireTime,+ &payload,+ &grant.CreatedAt,+ &grant.UpdatedAt,+ ); err != nil {+ return nil, errors.Wrapf(err, "failed to scan access grant")+ }+ statusValue, ok := storepb.AccessGrant_Status_value[statusString]+ if !ok {+ return nil, errors.Errorf("invalid access grant status %q", statusString)+ }+ grant.Status = storepb.AccessGrant_Status(statusValue)+ if err := common.ProtojsonUnmarshaler.Unmarshal(payload, grant.Payload); err != nil {+ return nil, errors.Wrapf(err, "failed to unmarshal payload")+ }+ grants = append(grants, &grant)+ }+ if err := rows.Err(); err != nil {+ return nil, errors.Wrapf(err, "failed to iterate access grants")+ }++ return grants, nil+}++// UpdateAccessGrant updates an existing access grant.+func (s *Store) UpdateAccessGrant(ctx context.Context, id string, update *UpdateAccessGrantMessage) (*AccessGrantMessage, error) {+ set := qb.Q()++ if v := update.Status; v != nil {+ set.Comma("status = ?", v.String())+ }+ if set.Len() == 0 {+ return nil, errors.New("no update field provided")+ }+ set.Comma("updated_at = ?", time.Now())++ q := qb.Q().Space("UPDATE access_grant SET ?", set).Space(`WHERE id = ?+ RETURNING id, project, creator, status, expire_time, payload, created_at, updated_at`, id)++ query, args, err := q.ToSQL()+ if err != nil {+ return nil, errors.Wrapf(err, "failed to build sql")+ }++ grant := AccessGrantMessage{+ Payload: &storepb.AccessGrantPayload{},+ }+ var payload []byte+ var statusString string+ if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(+ &grant.ID,+ &grant.ProjectID,+ &grant.Creator,+ &statusString,+ &grant.ExpireTime,+ &payload,+ &grant.CreatedAt,+ &grant.UpdatedAt,+ ); err != nil {+ return nil, errors.Wrapf(err, "failed to update access grant")+ }+ statusValue, ok := storepb.AccessGrant_Status_value[statusString]+ if !ok {+ return nil, errors.Errorf("invalid access grant status %q", statusString)+ }+ grant.Status = storepb.AccessGrant_Status(statusValue)+ if err := common.ProtojsonUnmarshaler.Unmarshal(payload, grant.Payload); err != nil {+ return nil, errors.Wrapf(err, "failed to unmarshal payload")+ }++ return &grant, nil+}++// GetListAccessGrantFilter parses a CEL filter expression into a query builder query for listing access grants.+func GetListAccessGrantFilter(filter string) (*qb.Query, error) {+ if filter == "" {+ return nil, nil+ }++ e, err := cel.NewEnv()+ if err != nil {+ return nil, errors.Errorf("failed to create cel env")+ }+ ast, iss := e.Parse(filter)+ if iss != nil {+ return nil, errors.Errorf("failed to parse filter %v, error: %v", filter, iss.String())+ }++ var getFilter func(expr celast.Expr) (*qb.Query, error)++ getFilter = func(expr celast.Expr) (*qb.Query, error) {+ q := qb.Q()+ switch expr.Kind() {+ case celast.CallKind:+ functionName := expr.AsCall().FunctionName()+ switch functionName {+ case celoperators.LogicalAnd:+ for _, arg := range expr.AsCall().Args() {+ qq, err := getFilter(arg)+ if err != nil {+ return nil, err+ }+ q.And("?", qq)+ }+ return qb.Q().Space("(?)", q), nil+ case celoperators.Equals:+ variable, value := getVariableAndValueFromExpr(expr)+ switch variable {+ case "name":+ nameStr, ok := value.(string)+ if !ok {+ return nil, errors.Errorf("name value must be a string")+ }+ _, accessGrantID, err := common.GetProjectIDAccessGrantID(nameStr)+ if err != nil {+ return nil, errors.Wrapf(err, "invalid access grant name %q", nameStr)+ }+ return qb.Q().Space("access_grant.id = ?", accessGrantID), nil+ case "creator":+ creatorStr, ok := value.(string)+ if !ok {+ return nil, errors.Errorf("creator value must be a string")+ }+ if !strings.HasPrefix(creatorStr, "users/") {+ return nil, errors.Errorf("creator must have format \"users/{email}\", got %q", creatorStr)+ }+ creatorEmail := strings.TrimPrefix(creatorStr, "users/")+ return qb.Q().Space("access_grant.creator = ?", creatorEmail), nil+ case "status":+ statusStr, ok := value.(string)+ if !ok {+ return nil, errors.Errorf("status value must be a string")+ }+ return qb.Q().Space("access_grant.status = ?", statusStr), nil+ case "issue":+ return nil, errors.Errorf("filtering by issue is not supported yet")+ default:+ return nil, errors.Errorf("unsupported variable %q", variable)+ }+ case celoperators.GreaterEquals, celoperators.LessEquals, celoperators.Greater, celoperators.Less:+ variable, rawValue := getVariableAndValueFromExpr(expr)+ value, ok := rawValue.(string)+ if !ok {+ return nil, errors.Errorf("expect string, got %T, hint: filter literals should be string", rawValue)+ }+ var column string+ switch variable {+ case "expire_time":+ column = "access_grant.expire_time"+ case "create_time":+ column = "access_grant.created_at"+ default:+ return nil, errors.Errorf("unsupported variable %q for comparison operator", variable)+ }+ t, err := time.Parse(time.RFC3339, value)+ if err != nil {+ return nil, errors.Errorf("failed to parse time %v, error: %v", value, err)+ }+ switch functionName {+ case celoperators.GreaterEquals:+ return qb.Q().Space(column+" >= ?", t), nil+ case celoperators.LessEquals:+ return qb.Q().Space(column+" <= ?", t), nil+ case celoperators.Greater:+ return qb.Q().Space(column+" > ?", t), nil+ default:+ return qb.Q().Space(column+" < ?", t), nil+ }+ default:+ return nil, errors.Errorf("unsupported function %v", functionName)+ }+ default:+ return nil, errors.Errorf("unexpected expr kind %v", expr.Kind())+ }+ }++ q, err := getFilter(ast.NativeRep().Expr())+ if err != nil {+ return nil, err+ }+ return qb.Q().Space("(?)", q), nil+}diff --git a/backend/store/predefined_roles.go b/backend/store/predefined_roles.goindex 051b79247d..c54803c594 100644--- a/backend/store/predefined_roles.go+++ b/backend/store/predefined_roles.go@@ -30,6 +30,11 @@ var PredefinedRoles = []*RoleMessage{Name: "Workspace admin",Predefined: true,Permissions: permissionSet(+ permission.AccessGrantsActivate,+ permission.AccessGrantsCreate,+ permission.AccessGrantsGet,+ permission.AccessGrantsList,+ permission.AccessGrantsRevoke,permission.AuditLogsExport,permission.AuditLogsSearch,permission.ChangelogsGet,@@ -171,6 +176,11 @@ var PredefinedRoles = []*RoleMessage{Name: "Workspace DBA",Predefined: true,Permissions: permissionSet(+ permission.AccessGrantsActivate,+ permission.AccessGrantsCreate,+ permission.AccessGrantsGet,+ permission.AccessGrantsList,+ permission.AccessGrantsRevoke,permission.AuditLogsExport,permission.AuditLogsSearch,permission.ChangelogsGet,@@ -317,6 +327,11 @@ var PredefinedRoles = []*RoleMessage{Name: "Project owner",Predefined: true,Permissions: permissionSet(+ permission.AccessGrantsActivate,+ permission.AccessGrantsCreate,+ permission.AccessGrantsGet,+ permission.AccessGrantsList,+ permission.AccessGrantsRevoke,permission.AuditLogsExport,permission.AuditLogsSearch,permission.ChangelogsGet,@@ -410,6 +425,8 @@ var PredefinedRoles = []*RoleMessage{Name: "Project developer",Predefined: true,Permissions: permissionSet(+ permission.AccessGrantsCreate,+ permission.AccessGrantsGet,permission.AuditLogsSearch,permission.ChangelogsGet,permission.ChangelogsList,@@ -529,6 +546,7 @@ var PredefinedRoles = []*RoleMessage{Name: "Project viewer",Predefined: true,Permissions: permissionSet(+ permission.AccessGrantsCreate,permission.DatabaseCatalogsGet,permission.DatabaseGroupsGet,permission.DatabaseGroupsList,diff --git a/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts b/frontend/src/types/proto-es/v1/access_grant_service_pb.d.tsindex add152de6b..535140948f 100644--- a/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts+++ b/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts@@ -202,7 +202,7 @@ export declare type ListAccessGrantsRequest = Message<"bytebase.v1.ListAccessGra/*** Filter expression using AIP-160 syntax.- * Supported fields: creator, status, issue, expire_time, create_time+ * Supported fields: name, creator, status, issue, expire_time, create_time* Examples:* - 'creator = "users/[email protected]"'* - 'status = "ACTIVE"'@@ -339,8 +339,9 @@ export declare type SearchMyAccessGrantsRequest = Message<"bytebase.v1.SearchMyA/*** Filter expression using AIP-160 syntax.- * Supported fields: status, expire_time, create_time+ * Supported fields: name, status, expire_time, create_time* Examples:+ * - 'name = "projects/x/accessGrants/uuid"'* - 'status = "ACTIVE"'* - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'*diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex 7eb79077b4..0a2066e754 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -7204,7 +7204,7 @@ paths:in: querydescription: |-Filter expression using AIP-160 syntax.- Supported fields: creator, status, issue, expire_time, create_time+ Supported fields: name, creator, status, issue, expire_time, create_timeExamples:- 'creator = "users/[email protected]"'- 'status = "ACTIVE"'@@ -7216,7 +7216,7 @@ paths:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: creator, status, issue, expire_time, create_time+ Supported fields: name, creator, status, issue, expire_time, create_timeExamples:- 'creator = "users/[email protected]"'- 'status = "ACTIVE"'@@ -7373,8 +7373,9 @@ paths:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: status, expire_time, create_time+ Supported fields: name, status, expire_time, create_timeExamples:+ - 'name = "projects/x/accessGrants/uuid"'- 'status = "ACTIVE"'- 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'title: SearchMyAccessGrantsRequest@@ -21086,7 +21087,7 @@ components:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: creator, status, issue, expire_time, create_time+ Supported fields: name, creator, status, issue, expire_time, create_timeExamples:- 'creator = "users/[email protected]"'- 'status = "ACTIVE"'@@ -25148,8 +25149,9 @@ components:title: filterdescription: |-Filter expression using AIP-160 syntax.- Supported fields: status, expire_time, create_time+ Supported fields: name, status, expire_time, create_timeExamples:+ - 'name = "projects/x/accessGrants/uuid"'- 'status = "ACTIVE"'- 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'title: SearchMyAccessGrantsRequestdiff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 4d3baf1baa..55b7159543 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -3,6 +3,12 @@## Table of Contents+- [store/access_grant.proto](#store_access_grant-proto)+ - [AccessGrant](#bytebase-store-AccessGrant)+ - [AccessGrantPayload](#bytebase-store-AccessGrantPayload)++ - [AccessGrant.Status](#bytebase-store-AccessGrant-Status)+- [store/common.proto](#store_common-proto)- [PageToken](#bytebase-store-PageToken)- [Position](#bytebase-store-Position)@@ -326,6 +332,64 @@+<a name="store_access_grant-proto"></a>+<p align="right"><a href="#top">Top</a></p>++## store/access_grant.proto++++<a name="bytebase-store-AccessGrant"></a>++### AccessGrant++++++++<a name="bytebase-store-AccessGrantPayload"></a>++### AccessGrantPayload++++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| issue_id | [int64](#int64) | | The issue associated with the access grant. |+| targets | [string](#string) | repeated | The target databases for this access grant. Format: instances/{instance}/databases/{database} |+| query | [string](#string) | | The query permission granted. |+| unmask | [bool](#bool) | | Whether the grant allows unmasking sensitive data. |+++++++++<a name="bytebase-store-AccessGrant-Status"></a>++### AccessGrant.Status+++| Name | Number | Description |+| ---- | ------ | ----------- |+| STATUS_UNSPECIFIED | 0 | |+| PENDING | 1 | |+| ACTIVE | 2 | |+| REVOKED | 3 | |++++++++++<a name="store_common-proto"></a><p align="right"><a href="#top">Top</a></p>diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex 9488001994..b51e415e5d 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -174,6 +174,29 @@<ul id="toc">+ <li>+ <a href="#store%2faccess_grant.proto">store/access_grant.proto</a>+ <ul>++ <li>+ <a href="#bytebase.store.AccessGrant"><span class="badge">M</span>AccessGrant</a>+ </li>++ <li>+ <a href="#bytebase.store.AccessGrantPayload"><span class="badge">M</span>AccessGrantPayload</a>+ </li>+++ <li>+ <a href="#bytebase.store.AccessGrant.Status"><span class="badge">E</span>AccessGrant.Status</a>+ </li>++++ </ul>+ </li>++<li><a href="#store%2fcommon.proto">store/common.proto</a><ul>@@ -1469,6 +1492,108 @@+ <div class="file-heading">+ <h2 id="store/access_grant.proto">store/access_grant.proto</h2><a href="#title">Top</a>+ </div>+ <p></p>+++ <h3 id="bytebase.store.AccessGrant">AccessGrant</h3>+ <p></p>++++++ <h3 id="bytebase.store.AccessGrantPayload">AccessGrantPayload</h3>+ <p></p>+++ <table class="field-table">+ <thead>+ <tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>+ </thead>+ <tbody>++ <tr>+ <td>issue_id</td>+ <td><a href="#int64">int64</a></td>+ <td></td>+ <td><p>The issue associated with the access grant. </p></td>+ </tr>++ <tr>+ <td>targets</td>+ <td><a href="#string">string</a></td>+ <td>repeated</td>+ <td><p>The target databases for this access grant.+Format: instances/{instance}/databases/{database} </p></td>+ </tr>++ <tr>+ <td>query</td>+ <td><a href="#string">string</a></td>+ <td></td>+ <td><p>The query permission granted. </p></td>+ </tr>++ <tr>+ <td>unmask</td>+ <td><a href="#bool">bool</a></td>+ <td></td>+ <td><p>Whether the grant allows unmasking sensitive data. </p></td>+ </tr>++ </tbody>+ </table>++++++++ <h3 id="bytebase.store.AccessGrant.Status">AccessGrant.Status</h3>+ <p></p>+ <table class="enum-table">+ <thead>+ <tr><td>Name</td><td>Number</td><td>Description</td></tr>+ </thead>+ <tbody>++ <tr>+ <td>STATUS_UNSPECIFIED</td>+ <td>0</td>+ <td><p></p></td>+ </tr>++ <tr>+ <td>PENDING</td>+ <td>1</td>+ <td><p></p></td>+ </tr>++ <tr>+ <td>ACTIVE</td>+ <td>2</td>+ <td><p></p></td>+ </tr>++ <tr>+ <td>REVOKED</td>+ <td>3</td>+ <td><p></p></td>+ </tr>++ </tbody>+ </table>+++++++<div class="file-heading"><h2 id="store/common.proto">store/common.proto</h2><a href="#title">Top</a></div>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 883a10ddf6..a4335b49da 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -836,7 +836,7 @@ Authorization method for RPC calls.| parent | [string](#string) | | The parent project of the access grants. Format: projects/{project} || page_size | [int32](#int32) | | The maximum number of access grants to return. || page_token | [string](#string) | | A page token from a previous ListAccessGrants call. |-| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: creator, status, issue, expire_time, create_time Examples: - 'creator = "users/[email protected]"' - 'status = "ACTIVE"' - 'creator = "users/[email protected]" AND status = "ACTIVE"' - 'issue = "projects/x/issues/123"' - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"' |+| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: name, creator, status, issue, expire_time, create_time Examples: - 'creator = "users/[email protected]"' - 'status = "ACTIVE"' - 'creator = "users/[email protected]" AND status = "ACTIVE"' - 'issue = "projects/x/issues/123"' - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"' |@@ -885,7 +885,7 @@ Authorization method for RPC calls.| parent | [string](#string) | | The parent project to search in. Format: projects/{project} || page_size | [int32](#int32) | | The maximum number of access grants to return. || page_token | [string](#string) | | A page token from a previous SearchMyAccessGrants call. |-| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: status, expire_time, create_time Examples: - 'status = "ACTIVE"' - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"' |+| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: name, status, expire_time, create_time Examples: - 'name = "projects/x/accessGrants/uuid"' - 'status = "ACTIVE"' - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"' |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex 54e68c8a36..109cedfc52 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -3176,7 +3176,7 @@ Format: projects/{project} </p></td><td><a href="#string">string</a></td><td></td><td><p>Filter expression using AIP-160 syntax.-Supported fields: creator, status, issue, expire_time, create_time+Supported fields: name, creator, status, issue, expire_time, create_timeExamples:- 'creator = "users/[email protected]"'- 'status = "ACTIVE"'@@ -3286,8 +3286,9 @@ Format: projects/{project} </p></td><td><a href="#string">string</a></td><td></td><td><p>Filter expression using AIP-160 syntax.-Supported fields: status, expire_time, create_time+Supported fields: name, status, expire_time, create_timeExamples:+ - 'name = "projects/x/accessGrants/uuid"'- 'status = "ACTIVE"'- 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"' </p></td></tr>diff --git a/proto/store/store/access_grant.proto b/proto/store/store/access_grant.protonew file mode 100644index 0000000000..6629176608--- /dev/null+++ b/proto/store/store/access_grant.proto@@ -0,0 +1,29 @@+syntax = "proto3";++package bytebase.store;++option go_package = "generated-go/store";++message AccessGrant {+ enum Status {+ STATUS_UNSPECIFIED = 0;+ PENDING = 1;+ ACTIVE = 2;+ REVOKED = 3;+ }+}++message AccessGrantPayload {+ // The issue associated with the access grant.+ int64 issue_id = 1;++ // The target databases for this access grant.+ // Format: instances/{instance}/databases/{database}+ repeated string targets = 2;++ // The query permission granted.+ string query = 3;++ // Whether the grant allows unmasking sensitive data.+ bool unmask = 4;+}diff --git a/proto/v1/v1/access_grant_service.proto b/proto/v1/v1/access_grant_service.protoindex e24c862cb3..f55ce2bc75 100644--- a/proto/v1/v1/access_grant_service.proto+++ b/proto/v1/v1/access_grant_service.proto@@ -166,7 +166,7 @@ message ListAccessGrantsRequest {string page_token = 3;// Filter expression using AIP-160 syntax.- // Supported fields: creator, status, issue, expire_time, create_time+ // Supported fields: name, creator, status, issue, expire_time, create_time// Examples:// - 'creator = "users/[email protected]"'// - 'status = "ACTIVE"'@@ -230,8 +230,9 @@ message SearchMyAccessGrantsRequest {string page_token = 3;// Filter expression using AIP-160 syntax.- // Supported fields: status, expire_time, create_time+ // Supported fields: name, status, expire_time, create_time// Examples:+ // - 'name = "projects/x/accessGrants/uuid"'// - 'status = "ACTIVE"'// - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'string filter = 4;