Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(audit): redact batch instance updates and the IAM credential oneof (#21174)
Vincent Huangd039b23a3395
diff --git a/backend/api/v1/audit.go b/backend/api/v1/audit.goindex f3c5c5418a..9ad653532b 100644--- a/backend/api/v1/audit.go+++ b/backend/api/v1/audit.go@@ -596,6 +596,12 @@ func getRequestString(request any) (string, error) {r = proto.CloneOf(r)r.Instance = redactInstance(r.Instance)return r+ case *v1pb.BatchUpdateInstancesRequest:+ r = proto.CloneOf(r)+ for _, ur := range r.Requests {+ ur.Instance = redactInstance(ur.Instance)+ }+ return rcase *v1pb.AddDataSourceRequest:r = proto.CloneOf(r)r.DataSource = redactDataSource(r.DataSource)@@ -702,6 +708,12 @@ func getResponseString(response any) (string, error) {n.Sheets = append(n.Sheets, redactSheet(sheet))}return n+ case *v1pb.BatchUpdateInstancesResponse:+ n := &v1pb.BatchUpdateInstancesResponse{}+ for _, instance := range r.Instances {+ n.Instances = append(n.Instances, redactInstance(instance))+ }+ return ndefault:if p, ok := r.(protoreflect.ProtoMessage); ok {return p@@ -1051,11 +1063,11 @@ func redactInstance(i *v1pb.Instance) *v1pb.Instance {}func redactDataSource(d *v1pb.DataSource) *v1pb.DataSource {- // Clone the datasource to avoid modifying the original- cloned, ok := proto.Clone(d).(*v1pb.DataSource)- if !ok {- return d+ if d == nil {+ return nil}+ // Clone the datasource to avoid modifying the original+ cloned := proto.CloneOf(d)if cloned.Password != "" {cloned.Password = maskedString}@@ -1086,6 +1098,10 @@ func redactDataSource(d *v1pb.DataSource) *v1pb.DataSource {if cloned.AuthenticationPrivateKey != "" {cloned.AuthenticationPrivateKey = maskedString}+ if cloned.AuthenticationPrivateKeyPassphrase != "" {+ cloned.AuthenticationPrivateKeyPassphrase = maskedString+ }+ redactIAMExtension(cloned)if cloned.ExternalSecret != nil {cloned.ExternalSecret = new(v1pb.DataSourceExternalSecret)}@@ -1101,6 +1117,46 @@ func redactDataSource(d *v1pb.DataSource) *v1pb.DataSource {return cloned}+// redactIAMExtension strips the IAM credential while keeping the variant that+// was set, so the row still records which credential type the caller supplied.+// It keys off the oneof rather than authentication_type, which a request is+// free to leave unset or contradict.+//+// What survives mirrors the read path (instance_service_converter.go): the+// Azure tenant and client IDs name the principal and are not INPUT_ONLY, so+// they stay; every AWSCredential field is, including the role ARN, so none+// does; and the GCP content is a whole service-account key.+//+// Keeping the ARN was considered — it names a principal rather than+// authenticating as one, and the row could then answer which role a data+// source was pointed at. It is dropped anyway, because "no INPUT_ONLY field+// survives redaction" is an invariant a descriptor walk can check forever+// (TestAuditRedactsEveryInputOnlyDataSourceField), and a hand-kept exception+// list is the drift this function exists to stop.+func redactIAMExtension(d *v1pb.DataSource) {+ switch extension := d.GetIamExtension().(type) {+ case *v1pb.DataSource_AzureCredential_:+ d.IamExtension = &v1pb.DataSource_AzureCredential_{+ AzureCredential: &v1pb.DataSource_AzureCredential{+ TenantId: extension.AzureCredential.GetTenantId(),+ ClientId: extension.AzureCredential.GetClientId(),+ },+ }+ case *v1pb.DataSource_AwsCredential:+ d.IamExtension = &v1pb.DataSource_AwsCredential{+ AwsCredential: &v1pb.DataSource_AWSCredential{},+ }+ case *v1pb.DataSource_GcpCredential:+ d.IamExtension = &v1pb.DataSource_GcpCredential{+ GcpCredential: &v1pb.DataSource_GCPCredential{},+ }+ default:+ // A variant added to the oneof after this function was written is+ // dropped whole rather than logged. Unset lands here too and stays nil.+ d.IamExtension = nil+ }+}+func redactAdminExecuteResponse(r *v1pb.AdminExecuteResponse) *v1pb.AdminExecuteResponse {if r == nil {return nildiff --git a/backend/api/v1/audit_redaction_test.go b/backend/api/v1/audit_redaction_test.goindex f3ead2a2eb..56b2d541af 100644--- a/backend/api/v1/audit_redaction_test.go+++ b/backend/api/v1/audit_redaction_test.go@@ -2,9 +2,15 @@ package v1import ("encoding/base64"+ "fmt"+ "slices""testing""github.com/stretchr/testify/require"+ "google.golang.org/genproto/googleapis/api/annotations"+ "google.golang.org/protobuf/proto"+ "google.golang.org/protobuf/reflect/protoreflect"+ "google.golang.org/protobuf/types/descriptorpb"v1pb "github.com/bytebase/bytebase/backend/generated-go/v1")@@ -86,6 +92,16 @@ func TestAuditResponseRedactsCredentials(t *testing.T) {NextPageToken: "next-page-token",},},+ {+ // The single-instance response is redacted as defense in depth even+ // though the converter blanks these on reads; its batch twin gets+ // the same treatment rather than the default arm.+ name: "batch instance update response",+ response: &v1pb.BatchUpdateInstancesResponse{Instances: []*v1pb.Instance{{+ Name: "instances/instance-a",+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }}},+ },} {t.Run(tt.name, func(t *testing.T) {got, err := getResponseString(tt.response)@@ -96,7 +112,329 @@ func TestAuditResponseRedactsCredentials(t *testing.T) {}}+// dataSourceWithEverySecret is the readable fixture: every secret redactDataSource+// masks today, on one data source, so a case reads as the request a caller sends.+// It is a hand-kept list and cannot see a field added later —+// TestAuditRedactsEveryInputOnlyDataSourceField is the net that can.+func dataSourceWithEverySecret() *v1pb.DataSource {+ return &v1pb.DataSource{+ Id: "admin",+ Type: v1pb.DataSourceType_ADMIN,+ Username: "bytebase",+ Host: "db.example.com",+ Password: secretSentinel,+ SslCa: secretSentinel,+ SslCaPath: secretSentinel,+ SslCert: secretSentinel,+ SslCertPath: secretSentinel,+ SslKey: secretSentinel,+ SslKeyPath: secretSentinel,+ SshPassword: secretSentinel,+ SshPrivateKey: secretSentinel,+ AuthenticationPrivateKey: secretSentinel,+ AuthenticationPrivateKeyPassphrase: secretSentinel,+ MasterPassword: secretSentinel,+ ExternalSecret: &v1pb.DataSourceExternalSecret{+ AuthOption: &v1pb.DataSourceExternalSecret_Token{Token: secretSentinel},+ },+ SaslConfig: &v1pb.SASLConfig{Mechanism: &v1pb.SASLConfig_KrbConfig{+ KrbConfig: &v1pb.KerberosConfig{Keytab: []byte(secretSentinel)},+ }},+ IamExtension: &v1pb.DataSource_GcpCredential{+ GcpCredential: &v1pb.DataSource_GCPCredential{Content: secretSentinel},+ },+ }+}++// assertDataSourceIntact checks the fields a redactor rewrites rather than+// clears, then returns the password for the caller's own comparison.+func assertDataSourceIntact(t *testing.T, d *v1pb.DataSource) string {+ t.Helper()+ require.Equal(t, secretSentinel, d.GetAuthenticationPrivateKeyPassphrase(), "redaction mutated the passphrase")+ require.Equal(t, secretSentinel, d.GetGcpCredential().GetContent(), "redaction mutated the IAM credential")+ require.Equal(t, secretSentinel, string(d.GetSaslConfig().GetKrbConfig().GetKeytab()), "redaction mutated the keytab")+ return d.GetPassword()+}++// fillInputOnlyFields sets every INPUT_ONLY string and bytes field reachable+// from m to the sentinel, singular or repeated. Each oneof takes its arm-th+// variant, so calling this for every arm up to maxOneofArms covers every branch+// of every oneof declared alongside its siblings.+//+// This reads the same annotation the read path is pinned against+// (assertNoInputOnlyValues), so a credential added to the proto lands in the+// fixture without anyone remembering to add it here. Two shapes it cannot build:+// a map, and a oneof nested inside another oneof's arm, which one global arm+// counter only ever constructs on one value. Neither is silent — inputOnlyLeaves+// counts both, so a fill that cannot reach one fails the test rather than+// quietly asking less of the redactor.+func fillInputOnlyFields(m protoreflect.Message, arm int, onPath map[protoreflect.FullName]bool) {+ descriptor := m.Descriptor()+ if onPath[descriptor.FullName()] {+ return+ }+ onPath[descriptor.FullName()] = true+ defer delete(onPath, descriptor.FullName())++ skip := map[protoreflect.FieldNumber]bool{}+ for i := 0; i < descriptor.Oneofs().Len(); i++ {+ oneof := descriptor.Oneofs().Get(i)+ if oneof.IsSynthetic() {+ continue+ }+ for j := 0; j < oneof.Fields().Len(); j++ {+ skip[oneof.Fields().Get(j).Number()] = true+ }+ fillOneField(m, oneof.Fields().Get(arm%oneof.Fields().Len()), arm, onPath)+ }+ for i := 0; i < descriptor.Fields().Len(); i++ {+ if field := descriptor.Fields().Get(i); !skip[field.Number()] {+ fillOneField(m, field, arm, onPath)+ }+ }+}++func fillOneField(m protoreflect.Message, field protoreflect.FieldDescriptor, arm int, onPath map[protoreflect.FullName]bool) {+ if field.IsMap() {+ return+ }+ if field.Kind() == protoreflect.MessageKind {+ if field.IsList() {+ list := m.Mutable(field).List()+ element := list.NewElement()+ fillInputOnlyFields(element.Message(), arm, onPath)+ list.Append(element)+ return+ }+ fillInputOnlyFields(m.Mutable(field).Message(), arm, onPath)+ return+ }+ if !isInputOnly(field) {+ return+ }+ var value protoreflect.Value+ switch field.Kind() {+ case protoreflect.StringKind:+ value = protoreflect.ValueOfString(secretSentinel)+ case protoreflect.BytesKind:+ value = protoreflect.ValueOfBytes([]byte(secretSentinel))+ default:+ return+ }+ if field.IsList() {+ m.Mutable(field).List().Append(value)+ return+ }+ m.Set(field, value)+}++// maxOneofArms returns the widest non-synthetic oneof reachable from the+// descriptor. Driving the arm loop off this rather than off a literal is the+// point: a fourth iam_extension variant raises the bound by declaring itself.+func maxOneofArms(descriptor protoreflect.MessageDescriptor, onPath map[protoreflect.FullName]bool) int {+ if onPath[descriptor.FullName()] {+ return 0+ }+ onPath[descriptor.FullName()] = true+ defer delete(onPath, descriptor.FullName())++ widest := 1+ for i := 0; i < descriptor.Oneofs().Len(); i++ {+ if oneof := descriptor.Oneofs().Get(i); !oneof.IsSynthetic() {+ widest = max(widest, oneof.Fields().Len())+ }+ }+ for i := 0; i < descriptor.Fields().Len(); i++ {+ if field := descriptor.Fields().Get(i); field.Kind() == protoreflect.MessageKind && !field.IsMap() {+ widest = max(widest, maxOneofArms(field.Message(), onPath))+ }+ }+ return widest+}++// inputOnlyLeaves is the yardstick: every INPUT_ONLY scalar reachable from the+// descriptor, down every arm of every oneof at once and through map values. The+// fill can only take one arm per pass and cannot build a map at all, so the+// union over passes has to equal this — which is what makes a fill that quietly+// reaches less than it claims fail instead of pass. Every other assertion in the+// test is negative, and a field nobody populated passes them all.+//+// Counting what the fill cannot yet build is deliberate. DataSource already+// carries a map (extra_connection_parameters); the day one like it is declared+// INPUT_ONLY, this fails and names it, rather than the gap staying a comment.+func inputOnlyLeaves(descriptor protoreflect.MessageDescriptor, prefix string, onPath map[protoreflect.FullName]bool) []string {+ if onPath[descriptor.FullName()] {+ return nil+ }+ onPath[descriptor.FullName()] = true+ defer delete(onPath, descriptor.FullName())++ var paths []string+ for i := 0; i < descriptor.Fields().Len(); i++ {+ field := descriptor.Fields().Get(i)+ path := fmt.Sprintf("%s.%s", prefix, field.Name())+ switch {+ case field.IsMap():+ if isInputOnly(field) {+ paths = append(paths, path)+ }+ if field.MapValue().Kind() == protoreflect.MessageKind {+ paths = append(paths, inputOnlyLeaves(field.MapValue().Message(), path, onPath)...)+ }+ case field.Kind() == protoreflect.MessageKind:+ paths = append(paths, inputOnlyLeaves(field.Message(), path, onPath)...)+ case isInputOnly(field):+ paths = append(paths, path)+ default:+ }+ }+ return paths+}++// sentinelPaths reports which fields the fill actually reached.+func sentinelPaths(m protoreflect.Message, prefix string) []string {+ var paths []string+ m.Range(func(field protoreflect.FieldDescriptor, value protoreflect.Value) bool {+ path := fmt.Sprintf("%s.%s", prefix, field.Name())+ switch {+ case field.IsMap():+ case field.Kind() == protoreflect.MessageKind && field.IsList():+ for i := range value.List().Len() {+ paths = append(paths, sentinelPaths(value.List().Get(i).Message(), path)...)+ }+ case field.Kind() == protoreflect.MessageKind:+ paths = append(paths, sentinelPaths(value.Message(), path)...)+ case field.IsList():+ for i := range value.List().Len() {+ if isSentinel(field, value.List().Get(i)) {+ paths = append(paths, path)+ break+ }+ }+ default:+ if isSentinel(field, value) {+ paths = append(paths, path)+ }+ }+ return true+ })+ return paths+}++func isSentinel(field protoreflect.FieldDescriptor, value protoreflect.Value) bool {+ switch field.Kind() {+ case protoreflect.StringKind:+ return value.String() == secretSentinel+ case protoreflect.BytesKind:+ return string(value.Bytes()) == secretSentinel+ default:+ return false+ }+}++func isInputOnly(field protoreflect.FieldDescriptor) bool {+ options, ok := field.Options().(*descriptorpb.FieldOptions)+ if !ok || options == nil {+ return false+ }+ behaviors, ok := proto.GetExtension(options, annotations.E_FieldBehavior).([]annotations.FieldBehavior)+ return ok && slices.Contains(behaviors, annotations.FieldBehavior_INPUT_ONLY)+}++// A hand-kept fixture cannot fail for a credential nobody added to it. This one+// is derived from the proto instead: every INPUT_ONLY field on a DataSource,+// every arm of every oneof under it, on each request that carries one. A new+// credential field, or a fourth iam_extension variant, is covered on the day it+// is declared rather than on the day someone notices the audit row.+func TestAuditRedactsEveryInputOnlyDataSourceField(t *testing.T) {+ dataSource := (&v1pb.DataSource{}).ProtoReflect().Descriptor()+ reached := map[string]bool{}+ for arm := range maxOneofArms(dataSource, map[protoreflect.FullName]bool{}) {+ filled := &v1pb.DataSource{}+ fillInputOnlyFields(filled.ProtoReflect(), arm, map[protoreflect.FullName]bool{})+ for _, path := range sentinelPaths(filled.ProtoReflect(), "dataSource") {+ reached[path] = true+ }++ for _, tt := range []struct {+ name string+ request any+ }{+ {"create instance", &v1pb.CreateInstanceRequest{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{filled},+ }}},+ {"update instance", &v1pb.UpdateInstanceRequest{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{filled},+ }}},+ {"batch update instances", &v1pb.BatchUpdateInstancesRequest{+ Requests: []*v1pb.UpdateInstanceRequest{{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{filled},+ }}},+ }},+ {"add data source", &v1pb.AddDataSourceRequest{DataSource: filled}},+ {"update data source", &v1pb.UpdateDataSourceRequest{DataSource: filled}},+ {"remove data source", &v1pb.RemoveDataSourceRequest{DataSource: filled}},+ } {+ t.Run(fmt.Sprintf("%s/oneof arm %d", tt.name, arm), func(t *testing.T) {+ got, err := getRequestString(tt.request)+ require.NoError(t, err)+ require.NotContains(t, got, secretSentinel, "credential written to the audit log")+ require.NotContains(t, got, encodedSecretSentinel, "encoded credential written to the audit log")+ })+ }++ t.Run(fmt.Sprintf("redacted message/oneof arm %d", arm), func(t *testing.T) {+ // The string check above only catches what the fixture happened to+ // populate. This one holds the whole annotation: nothing declared+ // INPUT_ONLY may carry a value after redaction.+ assertNoInputOnlyValues(t, redactDataSource(filled).ProtoReflect(), "dataSource")+ })+ }++ // The positive half. Everything above is an assertion that something is+ // absent, which a field the fill never populated passes for free — so under-+ // coverage would read as success. This one fails instead.+ t.Run("the fill reaches every INPUT_ONLY field", func(t *testing.T) {+ var missed []string+ for _, path := range inputOnlyLeaves(dataSource, "dataSource", map[protoreflect.FullName]bool{}) {+ if !reached[path] {+ missed = append(missed, path)+ }+ }+ require.Empty(t, missed, "never populated, so the redaction assertions above say nothing about them")+ })+}++// A rejected request is audited too, so every redactor runs on messages the+// handler was about to refuse. redactDataSource used to read through the nil+// data source in one of these and panic the interceptor.+func TestAuditRedactionSurvivesAnIncompleteRequest(t *testing.T) {+ for _, tt := range []struct {+ name string+ request any+ }{+ {"add data source without one", &v1pb.AddDataSourceRequest{Name: "instances/instance-a"}},+ {"update data source without one", &v1pb.UpdateDataSourceRequest{Name: "instances/instance-a"}},+ {"remove data source without one", &v1pb.RemoveDataSourceRequest{Name: "instances/instance-a"}},+ {"create instance without one", &v1pb.CreateInstanceRequest{InstanceId: "instance-a"}},+ {"update instance without one", &v1pb.UpdateInstanceRequest{}},+ {"batch update instances without any", &v1pb.BatchUpdateInstancesRequest{+ Requests: []*v1pb.UpdateInstanceRequest{{}},+ }},+ {"instance carrying an empty data source", &v1pb.UpdateInstanceRequest{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{{}},+ }}},+ } {+ t.Run(tt.name, func(t *testing.T) {+ got, err := getRequestString(tt.request)+ require.NoError(t, err)+ require.NotEmpty(t, got, "a rejected request still gets a row")+ })+ }+}+func TestAuditRequestRedactsCredentials(t *testing.T) {+ batchParent := "projects/project-a"settingRequest := func(v *v1pb.SettingValue) *v1pb.UpdateSettingRequest {return &v1pb.UpdateSettingRequest{Setting: &v1pb.Setting{Value: v}}}@@ -155,6 +493,46 @@ func TestAuditRequestRedactsCredentials(t *testing.T) {{"saved query SQL", &v1pb.CreateSavedQueryRequest{SavedQuery: &v1pb.SavedQuery{Content: []byte(secretSentinel),}}},+ // The data-source secrets are INPUT_ONLY, so a write request is the only+ // place they appear — which is exactly what an audit row records.+ {"instance data source secrets", &v1pb.UpdateInstanceRequest{Instance: &v1pb.Instance{+ Name: "instances/instance-a",+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }}},+ {"batch instance data source secrets", &v1pb.BatchUpdateInstancesRequest{+ Parent: &batchParent,+ Requests: []*v1pb.UpdateInstanceRequest{nil, {Instance: &v1pb.Instance{+ Name: "instances/instance-a",+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }}},+ }},+ {"created instance data source secrets", &v1pb.CreateInstanceRequest{+ InstanceId: "instance-a",+ Instance: &v1pb.Instance{DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()}},+ }},+ {"added data source secrets", &v1pb.AddDataSourceRequest{+ Name: "instances/instance-a",+ DataSource: dataSourceWithEverySecret(),+ }},+ {"updated data source secrets", &v1pb.UpdateDataSourceRequest{+ Name: "instances/instance-a",+ DataSource: dataSourceWithEverySecret(),+ }},+ {"removed data source secrets", &v1pb.RemoveDataSourceRequest{+ Name: "instances/instance-a",+ DataSource: dataSourceWithEverySecret(),+ }},+ {"azure iam client secret", &v1pb.AddDataSourceRequest{DataSource: &v1pb.DataSource{+ IamExtension: &v1pb.DataSource_AzureCredential_{AzureCredential: &v1pb.DataSource_AzureCredential{+ TenantId: "tenant-a", ClientId: "client-a", ClientSecret: secretSentinel,+ }},+ }}},+ {"aws iam access keys", &v1pb.AddDataSourceRequest{DataSource: &v1pb.DataSource{+ IamExtension: &v1pb.DataSource_AwsCredential{AwsCredential: &v1pb.DataSource_AWSCredential{+ AccessKeyId: secretSentinel, SecretAccessKey: secretSentinel, SessionToken: secretSentinel,+ RoleArn: secretSentinel, ExternalId: secretSentinel,+ }},+ }}},{"password reset code and password", &v1pb.ResetPasswordRequest{Email: "[email protected]",Code: secretSentinel,@@ -185,6 +563,7 @@ func TestAuditRequestRedactsCredentials(t *testing.T) {}func TestSensitiveOutboundAuditMetadata(t *testing.T) {+ batchParent := "projects/project-a"for _, tt := range []struct {name stringvalue any@@ -196,6 +575,37 @@ func TestSensitiveOutboundAuditMetadata(t *testing.T) {value: &v1pb.AddWebhookRequest{Project: "projects/project-a", Webhook: &v1pb.Webhook{Name: "projects/project-a/webhooks/webhook-a", Title: "Webhook A", Url: secretSentinel}},want: []string{"projects/project-a", "projects/project-a/webhooks/webhook-a", "Webhook A"},},+ {+ // The row has to stay useful: which instances were retargeted, and+ // which kind of IAM credential was supplied.+ name: "batch instance update retains targets and credential type",+ value: &v1pb.BatchUpdateInstancesRequest{+ Parent: &batchParent,+ Requests: []*v1pb.UpdateInstanceRequest{{Instance: &v1pb.Instance{+ Name: "instances/instance-a",+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }}},+ },+ want: []string{"projects/project-a", "instances/instance-a", "db.example.com", "gcpCredential"},+ },+ {+ name: "azure iam credential retains the principal it names",+ value: &v1pb.AddDataSourceRequest{DataSource: &v1pb.DataSource{+ IamExtension: &v1pb.DataSource_AzureCredential_{AzureCredential: &v1pb.DataSource_AzureCredential{+ TenantId: "tenant-a", ClientId: "client-a", ClientSecret: secretSentinel,+ }},+ }},+ want: []string{"azureCredential", "tenant-a", "client-a"},+ },+ {+ name: "aws iam credential records that one was supplied",+ value: &v1pb.AddDataSourceRequest{DataSource: &v1pb.DataSource{+ IamExtension: &v1pb.DataSource_AwsCredential{AwsCredential: &v1pb.DataSource_AWSCredential{+ AccessKeyId: secretSentinel, SecretAccessKey: secretSentinel,+ }},+ }},+ want: []string{"awsCredential"},+ },{name: "audit export retains page token",value: &v1pb.ExportAuditLogsResponse{Content: []byte(secretSentinel), NextPageToken: "next-page-token"},@@ -264,19 +674,25 @@ func TestAuditRedactionDoesNotMutateInput(t *testing.T) {}{{name: "create instance request",- request: &v1pb.CreateInstanceRequest{Instance: &v1pb.Instance{DataSources: []*v1pb.DataSource{{- Password: secretSentinel,- }}}},+ request: &v1pb.CreateInstanceRequest{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }},},{name: "update instance request",- request: &v1pb.UpdateInstanceRequest{Instance: &v1pb.Instance{DataSources: []*v1pb.DataSource{{- Password: secretSentinel,- }}}},+ request: &v1pb.UpdateInstanceRequest{Instance: &v1pb.Instance{+ DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()},+ }},+ },+ {+ name: "batch update instances request",+ request: &v1pb.BatchUpdateInstancesRequest{Requests: []*v1pb.UpdateInstanceRequest{{+ Instance: &v1pb.Instance{DataSources: []*v1pb.DataSource{dataSourceWithEverySecret()}},+ }}},},- {name: "add data source request", request: &v1pb.AddDataSourceRequest{DataSource: &v1pb.DataSource{Password: secretSentinel}}},- {name: "update data source request", request: &v1pb.UpdateDataSourceRequest{DataSource: &v1pb.DataSource{Password: secretSentinel}}},- {name: "remove data source request", request: &v1pb.RemoveDataSourceRequest{DataSource: &v1pb.DataSource{Password: secretSentinel}}},+ {name: "add data source request", request: &v1pb.AddDataSourceRequest{DataSource: dataSourceWithEverySecret()}},+ {name: "update data source request", request: &v1pb.UpdateDataSourceRequest{DataSource: dataSourceWithEverySecret()}},+ {name: "remove data source request", request: &v1pb.RemoveDataSourceRequest{DataSource: dataSourceWithEverySecret()}},{name: "create release request", request: &v1pb.CreateReleaseRequest{Release: &v1pb.Release{Files: []*v1pb.Release_File{{Statement: []byte(secretSentinel)}}}}},{name: "update release request", request: &v1pb.UpdateReleaseRequest{Release: &v1pb.Release{Files: []*v1pb.Release_File{{Statement: []byte(secretSentinel)}}}}},{name: "create saved query request", request: &v1pb.CreateSavedQueryRequest{SavedQuery: &v1pb.SavedQuery{Content: []byte(secretSentinel)}}},@@ -288,15 +704,17 @@ func TestAuditRedactionDoesNotMutateInput(t *testing.T) {var sensitiveValue stringswitch request := tt.request.(type) {case *v1pb.CreateInstanceRequest:- sensitiveValue = request.GetInstance().GetDataSources()[0].GetPassword()+ sensitiveValue = assertDataSourceIntact(t, request.GetInstance().GetDataSources()[0])case *v1pb.UpdateInstanceRequest:- sensitiveValue = request.GetInstance().GetDataSources()[0].GetPassword()+ sensitiveValue = assertDataSourceIntact(t, request.GetInstance().GetDataSources()[0])+ case *v1pb.BatchUpdateInstancesRequest:+ sensitiveValue = assertDataSourceIntact(t, request.GetRequests()[0].GetInstance().GetDataSources()[0])case *v1pb.AddDataSourceRequest:- sensitiveValue = request.GetDataSource().GetPassword()+ sensitiveValue = assertDataSourceIntact(t, request.GetDataSource())case *v1pb.UpdateDataSourceRequest:- sensitiveValue = request.GetDataSource().GetPassword()+ sensitiveValue = assertDataSourceIntact(t, request.GetDataSource())case *v1pb.RemoveDataSourceRequest:- sensitiveValue = request.GetDataSource().GetPassword()+ sensitiveValue = assertDataSourceIntact(t, request.GetDataSource())case *v1pb.CreateReleaseRequest:sensitiveValue = string(request.GetRelease().GetFiles()[0].GetStatement())case *v1pb.UpdateReleaseRequest:diff --git a/backend/api/v1/mcp_forbidden.go b/backend/api/v1/mcp_forbidden.goindex 3456040347..efa36a292d 100644--- a/backend/api/v1/mcp_forbidden.go+++ b/backend/api/v1/mcp_forbidden.go@@ -116,17 +116,24 @@ var mcpForbiddenReasons = map[v1pb.MCPForbiddenReason]string{v1pb.MCPForbiddenReason_MINTS_CREDENTIAL_FOR_OTHERS: "it hands someone control of a principal other than the caller, which revoking this session would not take back",// SettingService/UpdateSetting, refused for the boundary it rewrites- // rather than for any credential it hands out. Two mask paths carry it:+ // rather than for any credential it hands out. Three mask paths carry it:// value.workspace_profile.mcp_capability IS the MCP ceiling, so a session- // that reaches it is not bounded by it; and value.email.smtp keeps the+ // that reaches it is not bounded by it; value.email.smtp keeps the// stored password when the request omits it while accepting a new host,// which hands over the relay resolvePreLoginEmailSetting reads to mail- // password resets and login codes. TestEmailSetting is the one-shot- // version of the second; this is the persisting one. The same method also- // writes the SSO domain allowlist and the sign-in switches.+ // password resets and login codes; and value.ai.endpoint does the same to+ // the AI key it never names — the stored api_key survives the mask, and the+ // next AIService/Chat puts it in an auth header to the host just written+ // (ai_service.go). SaaS refuses AI writes outright (setting_service.go), so+ // that third one is a self-hosted vector, and the key it carries out is+ // whatever the operator configured — GEMINI_API_KEY, where it is set, seeds+ // one key into every workspace created after it (getAdditionalWorkspaceSettings).+ // TestEmailSetting is the one-shot version of the second; this is the+ // persisting one. The same method also writes the SSO domain allowlist and+ // the sign-in switches.//// Classification is per method, so this refuses the whole RPC — including- // the settings that have nothing to do with either path. Splitting the+ // the settings that have nothing to do with any of them. Splitting the// handler so ordinary configuration stays reachable to an agent is the// follow-up (BOT-53); disallowing first is the deliberate order.v1pb.MCPForbiddenReason_REWRITES_SESSION_BOUNDARY: "it rewrites the workspace settings that bound this session, including the switch meant to contain it",diff --git a/backend/generated-go/v1/annotation.pb.go b/backend/generated-go/v1/annotation.pb.goindex 6e861c8bcd..250070956d 100644--- a/backend/generated-go/v1/annotation.pb.go+++ b/backend/generated-go/v1/annotation.pb.go@@ -170,9 +170,10 @@ const (// gets delivered.MCPForbiddenReason_MINTS_CREDENTIAL_FOR_OTHERS MCPForbiddenReason = 6// Rewrites the workspace configuration that governs the session making the- // call — the MCP switch itself, the sign-in and SSO settings, and the mail- // relay that carries credential resets. A session that can widen its own- // ceiling is not bounded by it.+ // call — the MCP switch itself, the sign-in and SSO settings, the mail+ // relay that carries credential resets, and the AI endpoint the stored API+ // key is sent to. A session that can widen its own ceiling is not bounded+ // by it.MCPForbiddenReason_REWRITES_SESSION_BOUNDARY MCPForbiddenReason = 7)diff --git a/frontend/src/types/proto-es/v1/annotation_pb.d.ts b/frontend/src/types/proto-es/v1/annotation_pb.d.tsindex 910f3072b9..aa0e42e307 100644--- a/frontend/src/types/proto-es/v1/annotation_pb.d.ts+++ b/frontend/src/types/proto-es/v1/annotation_pb.d.ts@@ -159,9 +159,10 @@ export enum MCPForbiddenReason {/*** Rewrites the workspace configuration that governs the session making the- * call — the MCP switch itself, the sign-in and SSO settings, and the mail- * relay that carries credential resets. A session that can widen its own- * ceiling is not bounded by it.+ * call — the MCP switch itself, the sign-in and SSO settings, the mail+ * relay that carries credential resets, and the AI endpoint the stored API+ * key is sent to. A session that can widen its own ceiling is not bounded+ * by it.** @generated from enum value: REWRITES_SESSION_BOUNDARY = 7;*/diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex a2162db619..6cd6971258 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -826,7 +826,7 @@ reader trusts — so a method changing what it does changes its reason here.| ENDS_SESSION | 4 | Destroys the human's own login session. || ENDS_MEMBERSHIP | 5 | Destroys the caller's own workspace membership and mints a plain workspace token on the way out. || MINTS_CREDENTIAL_FOR_OTHERS | 6 | Leaves someone holding a principal the caller is not — by issuing its credential, carrying an existing one out to a host the caller named, choosing what will later be trusted to mint one, or redirecting where one gets delivered. |-| REWRITES_SESSION_BOUNDARY | 7 | Rewrites the workspace configuration that governs the session making the call — the MCP switch itself, the sign-in and SSO settings, and the mail relay that carries credential resets. A session that can widen its own ceiling is not bounded by it. |+| REWRITES_SESSION_BOUNDARY | 7 | Rewrites the workspace configuration that governs the session making the call — the MCP switch itself, the sign-in and SSO settings, the mail relay that carries credential resets, and the AI endpoint the stored API key is sent to. A session that can widen its own ceiling is not bounded by it. |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex c6dce8a5af..25c66eb2e4 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -3257,9 +3257,10 @@ gets delivered.</p></td><td>REWRITES_SESSION_BOUNDARY</td><td>7</td><td><p>Rewrites the workspace configuration that governs the session making the-call — the MCP switch itself, the sign-in and SSO settings, and the mail-relay that carries credential resets. A session that can widen its own-ceiling is not bounded by it.</p></td>+call — the MCP switch itself, the sign-in and SSO settings, the mail+relay that carries credential resets, and the AI endpoint the stored API+key is sent to. A session that can widen its own ceiling is not bounded+by it.</p></td></tr></tbody>diff --git a/proto/v1/v1/annotation.proto b/proto/v1/v1/annotation.protoindex 428914664e..85f5daf2ac 100644--- a/proto/v1/v1/annotation.proto+++ b/proto/v1/v1/annotation.proto@@ -83,8 +83,9 @@ enum MCPForbiddenReason {// gets delivered.MINTS_CREDENTIAL_FOR_OTHERS = 6;// Rewrites the workspace configuration that governs the session making the- // call — the MCP switch itself, the sign-in and SSO settings, and the mail- // relay that carries credential resets. A session that can widen its own- // ceiling is not bounded by it.+ // call — the MCP switch itself, the sign-in and SSO settings, the mail+ // relay that carries credential resets, and the AI endpoint the stored API+ // key is sent to. A session that can widen its own ceiling is not bounded+ // by it.REWRITES_SESSION_BOUNDARY = 7;}