Skip to content

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

fix: retain keytabs in UpdateInstance data_sources; prune fixed audit findings

Danny29e05447b07f
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 51dc096ef7..bf84e0b01a 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -839,6 +839,7 @@ func (s *InstanceService) UpdateInstance(ctx context.Context, req *connect.Reque
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, err)
}
+ retainStoredKeytabs(dataSources, instance.Metadata.GetDataSources())
normalizeGCPDataSources(instance.Metadata.GetEngine(), dataSources)
for _, ds := range dataSources {
if err := validateAndSanitizeDataSourceTLS(ds); err != nil {
diff --git a/backend/api/v1/instance_service_converter.go b/backend/api/v1/instance_service_converter.go
index e17ff5a578..72d02ca288 100644
--- a/backend/api/v1/instance_service_converter.go
+++ b/backend/api/v1/instance_service_converter.go
@@ -464,6 +464,21 @@ func retainStoredKeytabOnEmptyUpdate(updated, stored *storepb.SASLConfig) {
}
}
+// retainStoredKeytabs applies retainStoredKeytabOnEmptyUpdate across a full
+// data source replacement (UpdateInstance with update_mask=data_sources),
+// matching stored data sources by ID.
+func retainStoredKeytabs(updated, stored []*storepb.DataSource) {
+ storedByID := make(map[string]*storepb.DataSource, len(stored))
+ for _, ds := range stored {
+ storedByID[ds.GetId()] = ds
+ }
+ for _, ds := range updated {
+ if existing, ok := storedByID[ds.GetId()]; ok {
+ retainStoredKeytabOnEmptyUpdate(ds.GetSaslConfig(), existing.GetSaslConfig())
+ }
+ }
+}
+
func convertDataSourceAddresses(addresses []*storepb.DataSource_Address) []*v1pb.DataSource_Address {
res := make([]*v1pb.DataSource_Address, 0, len(addresses))
for _, address := range addresses {
diff --git a/backend/api/v1/instance_service_converter_test.go b/backend/api/v1/instance_service_converter_test.go
index f6afa9ec17..f3c601d208 100644
--- a/backend/api/v1/instance_service_converter_test.go
+++ b/backend/api/v1/instance_service_converter_test.go
@@ -220,6 +220,36 @@ func TestRetainStoredKeytabOnEmptyUpdate(t *testing.T) {
retainStoredKeytabOnEmptyUpdate(nil, stored)
}
+func TestRetainStoredKeytabs(t *testing.T) {
+ krbDS := func(id string, keytab []byte) *storepb.DataSource {
+ return &storepb.DataSource{
+ Id: id,
+ SaslConfig: &storepb.SASLConfig{
+ Mechanism: &storepb.SASLConfig_KrbConfig{
+ KrbConfig: &storepb.KerberosConfig{Keytab: keytab},
+ },
+ },
+ }
+ }
+ stored := []*storepb.DataSource{
+ krbDS("admin", []byte("admin-keytab")),
+ krbDS("ro", []byte("ro-keytab")),
+ }
+
+ updated := []*storepb.DataSource{
+ krbDS("admin", nil), // unchanged on read-modify-write
+ krbDS("ro", []byte("new-ro-keytab")), // freshly uploaded
+ krbDS("added", nil), // new data source, nothing stored
+ {Id: "plain"}, // no SASL config at all
+ }
+ retainStoredKeytabs(updated, stored)
+
+ require.Equal(t, []byte("admin-keytab"), updated[0].GetSaslConfig().GetKrbConfig().Keytab)
+ require.Equal(t, []byte("new-ro-keytab"), updated[1].GetSaslConfig().GetKrbConfig().Keytab)
+ require.Empty(t, updated[2].GetSaslConfig().GetKrbConfig().Keytab)
+ require.Nil(t, updated[3].GetSaslConfig())
+}
+
// assertNoInputOnlyValues walks every populated message field and requires
// that fields annotated INPUT_ONLY carry no value. It pins the read-path
// contract: whatever the proto declares write-only must be blanked by the
diff --git a/docs/design/v1-api-audit-2026-08.md b/docs/design/v1-api-audit-2026-08.md
index 21efaa4a1c..89375002bf 100644
--- a/docs/design/v1-api-audit-2026-08.md
+++ b/docs/design/v1-api-audit-2026-08.md
@@ -13,33 +13,6 @@ backend actually does**, which is where everything serious lives.
---
-# TIER 1 — Credential disclosure
-
-### T2 ✅ HIGH — Kerberos keytab returned to the lowest project role — **FIXED on this branch**
-
-- Returned verbatim: `backend/api/v1/instance_service_converter.go:442` (`Keytab: m.KrbConfig.Keytab`)
-- Sibling credentials are all blanked in the same file, with the comment *"We don't return the password and SSLs on reads."* (`:248-286`)
-- The audit redactor **masks this exact field** — `backend/api/v1/audit.go:711` — proving it is classified sensitive; the read path simply doesn't.
-- Reachable via `Database.instance_resource` (`proto/v1/v1/database_service.proto:528`, populated at `database_service.go:1192`), which needs only `bb.databases.get` — held by `ProjectViewerRole` (`predefined_roles.go:589`).
-
-Any project viewer calls `GetDatabase` and extracts the keytab, then authenticates straight to
-the database, bypassing Bytebase entirely.
-
-Same read path, lower severity: AWS `role_arn` and `external_id` are marked `INPUT_ONLY` but
-returned anyway (`instance_service.proto:756,759` → `instance_service_converter.go:302-303`).
-The external ID is the confused-deputy guard shared with the customer's AWS account.
-
-**Fix (this branch):** keytab blanked on read and annotated `INPUT_ONLY`; `UpdateDataSource`
-retains the stored keytab when the update carries an empty one (read-modify-write safe);
-AWS `role_arn`/`external_id` blanked on read (presence-only credential struct);
-`master_password` annotated `INPUT_ONLY` (was already blanked); frontend requires the keytab
-only on create. A reflection test (`TestConvertDataSourcesBlanksEveryInputOnlyField`) now pins
-every `INPUT_ONLY`-annotated field to stay blank through the read converters. Bonus sweep:
-dead `DataSource.cluster` field removed (never persisted, rejected on update), and every
-field-number gap across both proto trees is now `reserved` (64 messages/enums).
-
----
-
# TIER 2 — Cross-project authorization gaps
**Shared root cause.** The ACL authorizes exactly ONE resource per request — `parent`, else
@@ -255,23 +228,22 @@ List RPCs, the same 7 `state` fields missing `OUTPUT_ONLY`, the same enum zero-v
HTTP patterns in `database_service` that match no declared resource pattern. It adds a cleaner
framing for 30 `name` fields: they want `IDENTIFIER`.
-Still open from the first pass: only 4 files use `reserved` (7 enums and 13 messages carry
-unreserved gaps — SQLite's `Engine = 5` is the proven case); 28 of 205 RPCs lack the mandated
-`// Permissions required:` comment; 22 files have string fields and zero protovalidate constraints
-despite `VALIDATION_STANDARDS.md`.
+Still open from the first pass: 28 of 205 RPCs lack the mandated `// Permissions required:`
+comment; 22 files have string fields and zero protovalidate constraints despite
+`VALIDATION_STANDARDS.md`.
---
# What I'd do, in order
1. **Runtime-confirm T9.** Eleven bad logins. If the eleventh is accepted, there is no lockout and that outranks everything else here.
-2. ~~**Blank the keytab** (T2), and stop returning AWS `role_arn`/`external_id`.~~ **Done on this branch.**
-3. **Close the multi-resource ACL class, not the instances** (T4–T7 + the pending `DiffSchema` patch): teach `getResourceFromRequest` to collect *every* `resource_reference`d field including oneof and repeated members, then annotate `DiffSchemaRequest.changelog`, `CheckReleaseRequest.targets`, `Revision.release/file/task_run`. `UpdateDatabase`'s project-transfer case (`acl.go:604-624`) is the in-repo precedent.
-4. **Give sheets an ownership model** (T5), or at minimum scope the blob fetch by the owning project/workspace. Until then the sheet namespace is workspace-global by design, and should be documented as such.
-5. **Fail closed**: reject `AUTH_METHOD_UNSPECIFIED` at startup; make `permission` on a CUSTOM RPC either enforced or a build error, since 20 of them are currently decorative.
-6. **Wire api-linter into CI** at the 474-finding baseline. None of Tier 5 was visible to `buf lint`'s `BASIC` profile, which is why it accumulated.
-
-**Note on scope.** Tier 1–3 are security issues in a shipped product. T2 is fixed on this
-branch; everything else is still a report — untouched. The three patches from earlier in the
-session (`SearchProjects` proto comment, `SearchProjects` pagination, `DiffSchema` ACL) remain
-parked and still apply cleanly.
+2. **Close the multi-resource ACL class, not the instances** (T4–T7 + the pending `DiffSchema` patch): teach `getResourceFromRequest` to collect *every* `resource_reference`d field including oneof and repeated members, then annotate `DiffSchemaRequest.changelog`, `CheckReleaseRequest.targets`, `Revision.release/file/task_run`. `UpdateDatabase`'s project-transfer case (`acl.go:604-624`) is the in-repo precedent.
+3. **Give sheets an ownership model** (T5), or at minimum scope the blob fetch by the owning project/workspace. Until then the sheet namespace is workspace-global by design, and should be documented as such.
+4. **Fail closed**: reject `AUTH_METHOD_UNSPECIFIED` at startup; make `permission` on a CUSTOM RPC either enforced or a build error, since 20 of them are currently decorative.
+5. **Wire api-linter into CI** at the 474-finding baseline. None of Tier 5 was visible to `buf lint`'s `BASIC` profile, which is why it accumulated.
+
+**Note on scope.** Tier 2–3 are security issues in a shipped product, and everything here is
+still a report — untouched. Resolved findings are removed from this document (T1/T3 earlier;
+T2 via the INPUT_ONLY read-path fix). The three patches from earlier in the session
+(`SearchProjects` proto comment, `SearchProjects` pagination, `DiffSchema` ACL) remain parked
+and still apply cleanly.