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: address pre-review findings for DynamoDB AWS credentials
Vincent Huang9b7ece0fbcaa
diff --git a/backend/plugin/db/dynamodb/dynamodb_test.go b/backend/plugin/db/dynamodb/dynamodb_test.goindex 07bb259062..f8533b54dd 100644--- a/backend/plugin/db/dynamodb/dynamodb_test.go+++ b/backend/plugin/db/dynamodb/dynamodb_test.go@@ -2,6 +2,7 @@ package dynamodbimport ("context"+ "path/filepath""strings""testing"@@ -68,6 +69,16 @@ func setHermeticAWSEnv(t *testing.T) {t.Setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")t.Setenv("AWS_SESSION_TOKEN", "")t.Setenv("AWS_ENDPOINT_URL_STS", "http://127.0.0.1:1")+ // Single attempt: the SDK's default retryer would otherwise retry the+ // refused connection with backoff, slowing the failure to several seconds.+ t.Setenv("AWS_MAX_ATTEMPTS", "1")+ // Shield the tests from ambient AWS configuration on the host: a set+ // AWS_PROFILE or shared config file would otherwise leak into+ // config.LoadDefaultConfig.+ t.Setenv("AWS_PROFILE", "")+ missing := filepath.Join(t.TempDir(), "nonexistent")+ t.Setenv("AWS_CONFIG_FILE", missing)+ t.Setenv("AWS_SHARED_CREDENTIALS_FILE", missing)}func TestOpenAssumesRoleWhenRoleArnSet(t *testing.T) {diff --git a/backend/plugin/db/util/aws.go b/backend/plugin/db/util/aws.goindex 49552eef1a..1cac83cb4f 100644--- a/backend/plugin/db/util/aws.go+++ b/backend/plugin/db/util/aws.go@@ -45,8 +45,10 @@ func AssumeRoleIfNeeded(ctx context.Context, awsCfg *aws.Config, connectionCtx d}})- // Update config with assumed role credentials- awsCfg.Credentials = assumeRoleProvider+ // Update config with assumed role credentials. The cache refreshes the+ // temporary credentials before expiry instead of calling STS AssumeRole on+ // every AWS API request.+ awsCfg.Credentials = aws.NewCredentialsCache(assumeRoleProvider)// Test credentials retrieval and provide context-specific error messages_, err := awsCfg.Credentials.Retrieve(ctx)diff --git a/frontend/src/components/instance/DataSourceForm.tsx b/frontend/src/components/instance/DataSourceForm.tsxindex 7cc0cc64a1..3e7d8ce0fd 100644--- a/frontend/src/components/instance/DataSourceForm.tsx+++ b/frontend/src/components/instance/DataSourceForm.tsx@@ -276,6 +276,9 @@ export function DataSourceForm({// before the form exposed credentials still carry PASSWORD. Render those in// the AWS IAM mode and stamp the real authentication type only when a// credential field is edited, so opening an old instance stays pristine.+ // (In SaaS mode the shared CredentialSourceForm instead forces+ // specific-credential mode on open — the policy every IAM engine inherits+ // there, since the default credential chain is the host's own identity.)const dynamoDBDataSource = useMemo(() => ({...dataSource,@@ -2201,7 +2204,7 @@ function AwsRegionField({value={region}className="w-full"disabled={!allowEdit}- placeholder="database region, for example, us-east-1"+ placeholder={t("instance.database-region-placeholder")}onChange={(e) => onChange(e.target.value)}/></FormField>diff --git a/frontend/src/components/instance/DataSourceSection.tsx b/frontend/src/components/instance/DataSourceSection.tsxindex ff2b744c54..56faada0f8 100644--- a/frontend/src/components/instance/DataSourceSection.tsx+++ b/frontend/src/components/instance/DataSourceSection.tsx@@ -106,9 +106,12 @@ export function DataSourceSection({[setDataSourceEditState]);- // DynamoDB has a single admin data source: no read-only tabs or tips.+ // DynamoDB normally has a single admin data source, so the read-only+ // tabs/tips are hidden — unless a read-only data source already exists+ // (creatable via the API), which must stay reachable.const showDataSourceTabs =- !isCreating && basicInfo.engine !== Engine.DYNAMODB;+ !isCreating &&+ (basicInfo.engine !== Engine.DYNAMODB || hasReadOnlyDataSource);// Show RO tips when not creating and no RO data sourceconst showROTips = showDataSourceTabs && !hasReadOnlyDataSource;diff --git a/frontend/src/components/instance/InstanceFormBody.tsx b/frontend/src/components/instance/InstanceFormBody.tsxindex 4d9b1066be..425e9354c3 100644--- a/frontend/src/components/instance/InstanceFormBody.tsx+++ b/frontend/src/components/instance/InstanceFormBody.tsx@@ -696,6 +696,14 @@ interface InstanceFormBodyProps {onOpenInfoPanel?: (section: InfoSection) => void;}+// Engines without a host field (or with a non-local default) drop the local+// development placeholder host when the user switches to them.+const clearLocalPlaceholderHost = (ds: EditDataSource) => {+ if (ds.host === "127.0.0.1" || ds.host === "host.docker.internal") {+ ds.host = "";+ }+};+export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {const { t } = useTranslation();const ctx = useInstanceFormContext();@@ -951,35 +959,20 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {const updated = { ...ds };switch (engine) {case Engine.SNOWFLAKE: {- if (- updated.host === "127.0.0.1" ||- updated.host === "host.docker.internal"- ) {- updated.host = "";- }+ clearLocalPlaceholderHost(updated);break;}case Engine.DYNAMODB: {updated.authenticationType =DataSource_AuthenticationType.AWS_RDS_IAM;- if (- updated.host === "127.0.0.1" ||- updated.host === "host.docker.internal"- ) {- updated.host = "";- }+ clearLocalPlaceholderHost(updated);break;}case Engine.SPANNER:case Engine.BIGQUERY: {updated.authenticationType =DataSource_AuthenticationType.GOOGLE_CLOUD_SQL_IAM;- if (- updated.host === "127.0.0.1" ||- updated.host === "host.docker.internal"- ) {- updated.host = "";- }+ clearLocalPlaceholderHost(updated);break;}case Engine.COSMOSDB: {@@ -1749,21 +1742,17 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {<DataSourceSection hideOptions onOpenInfoPanel={onOpenInfoPanel} />{basicInfo.engine !== Engine.DYNAMODB && (- <>- <div className="mt-6">- <SyncDatabases- isCreating={isCreating}- showLabel- allowEdit={- isCreating ? allowEdit && !!allowCreate : allowEdit- }- projectName={parent}- onOpenInfoPanel={onOpenInfoPanel}- syncDatabases={basicInfo.syncDatabases}- onSyncDatabasesChange={handleChangeSyncDatabases}- />- </div>- </>+ <div className="mt-6">+ <SyncDatabases+ isCreating={isCreating}+ showLabel+ allowEdit={isCreating ? allowEdit && !!allowCreate : allowEdit}+ projectName={parent}+ onOpenInfoPanel={onOpenInfoPanel}+ syncDatabases={basicInfo.syncDatabases}+ onSyncDatabasesChange={handleChangeSyncDatabases}+ />+ </div>)}</div>diff --git a/frontend/src/components/instance/InstanceFormContext.test.tsx b/frontend/src/components/instance/InstanceFormContext.test.tsxindex 7d97a92532..7aab904a03 100644--- a/frontend/src/components/instance/InstanceFormContext.test.tsx+++ b/frontend/src/components/instance/InstanceFormContext.test.tsx@@ -5,6 +5,8 @@ import { createRoot } from "react-dom/client";import { beforeEach, describe, expect, test, vi } from "vitest";import { Engine, State } from "@/types/proto-es/v1/common_pb";import {+ DataSource_AuthenticationType,+ DataSource_AWSCredentialSchema,DataSourceSchema,DataSourceType,InstanceSchema,@@ -12,6 +14,7 @@ import {import { ProjectSchema } from "@/types/proto-es/v1/project_service_pb";import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";import { unknownInstance } from "@/types/v1/instance";+import { wrapEditDataSource } from "./common";import {InstanceFormProvider,useInstanceFormContext,@@ -374,4 +377,86 @@ describe("InstanceFormProvider", () => {harness.unmount();});++ describe("checkDataSource AWS region requirement", () => {+ const awsDataSource = (region: string, withCredential: boolean) => {+ const ds = wrapEditDataSource(+ create(DataSourceSchema, {+ id: "admin",+ type: DataSourceType.ADMIN,+ authenticationType: DataSource_AuthenticationType.AWS_RDS_IAM,+ region,+ })+ );+ if (withCredential) {+ ds.iamExtension = {+ case: "awsCredential",+ value: create(DataSource_AWSCredentialSchema, {}),+ };+ }+ return ds;+ };++ const CheckDataSourceProbe = () => {+ const ctx = useInstanceFormContext();+ return (+ <div+ data-credential-no-region={String(+ ctx.checkDataSource([awsDataSource("", true)])+ )}+ data-credential-with-region={String(+ ctx.checkDataSource([awsDataSource("us-east-1", true)])+ )}+ data-default-chain-no-region={String(+ ctx.checkDataSource([awsDataSource("", false)])+ )}+ />+ );+ };++ const instanceOfEngine = (engine: Engine) =>+ create(InstanceSchema, {+ name: "instances/aws-check",+ title: "AWS check",+ engine,+ environment: "environments/prod",+ dataSources: [+ create(DataSourceSchema, { id: "admin", type: DataSourceType.ADMIN }),+ ],+ });++ test("DynamoDB requires a region only with a specific credential", async () => {+ const harness = renderIntoContainer();++ await harness.render(+ <InstanceFormProvider instance={instanceOfEngine(Engine.DYNAMODB)}>+ <CheckDataSourceProbe />+ </InstanceFormProvider>+ );++ const probe = harness.container.firstElementChild as HTMLElement;+ expect(probe.dataset.credentialNoRegion).toBe("false");+ expect(probe.dataset.credentialWithRegion).toBe("true");+ expect(probe.dataset.defaultChainNoRegion).toBe("true");++ harness.unmount();+ });++ test("other engines require a region for AWS IAM even on the default credential chain", async () => {+ const harness = renderIntoContainer();++ await harness.render(+ <InstanceFormProvider instance={instanceOfEngine(Engine.POSTGRES)}>+ <CheckDataSourceProbe />+ </InstanceFormProvider>+ );++ const probe = harness.container.firstElementChild as HTMLElement;+ expect(probe.dataset.credentialNoRegion).toBe("false");+ expect(probe.dataset.credentialWithRegion).toBe("true");+ expect(probe.dataset.defaultChainNoRegion).toBe("false");++ harness.unmount();+ });+ });});diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex b3bf3a1eff..f86adc9be7 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1037,6 +1037,7 @@},"create-gcp-credentials": "To create credentials, see","database-region": "Database Region",+ "database-region-placeholder": "database region, for example, us-east-1","default-role": "Default role","delete-active-confirmation": "Instance \"{{name}}\" is active. Bytebase will archive it first, then permanently delete it. This action cannot be undone. Type the instance ID \"{{id}}\" to confirm.","delete-confirmation": "This will permanently delete instance \"{{name}}\". This action cannot be undone. Type the instance ID \"{{id}}\" to confirm.",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 139ffc0fe5..21712f55fa 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1037,6 +1037,7 @@},"create-gcp-credentials": "Para crear credenciales, consulte","database-region": "Región de la base de datos",+ "database-region-placeholder": "región de la base de datos, por ejemplo us-east-1","default-role": "Rol predeterminado","delete-active-confirmation": "La instancia \"{{name}}\" está activa. Bytebase la archivará primero y luego la eliminará permanentemente. Esta acción no se puede deshacer. Escribe el ID de la instancia \"{{id}}\" para confirmar.","delete-confirmation": "Esto eliminará permanentemente la instancia \"{{name}}\". Esta acción no se puede deshacer. Escribe el ID de la instancia \"{{id}}\" para confirmar.",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 0f044b5f12..fb9961d751 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1037,6 +1037,7 @@},"create-gcp-credentials": "認証情報の作成方法については、を参照してください","database-region": "データベース領域",+ "database-region-placeholder": "データベースのリージョン(例: us-east-1)","default-role": "デフォルトロール","delete-active-confirmation": "インスタンス「{{name}}」はアクティブです。Bytebase はまずアーカイブしてから完全に削除します。この操作は元に戻せません。確認するにはインスタンス ID「{{id}}」を入力してください。","delete-confirmation": "インスタンス「{{name}}」を完全に削除します。この操作は元に戻せません。確認するにはインスタンス ID「{{id}}」を入力してください。",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex bf5388b4fa..3f3529e755 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1037,6 +1037,7 @@},"create-gcp-credentials": "Để tạo thông tin xác thực, xem","database-region": "Khu vực cơ sở dữ liệu",+ "database-region-placeholder": "khu vực cơ sở dữ liệu, ví dụ us-east-1","default-role": "Vai trò mặc định","delete-active-confirmation": "Instance \"{{name}}\" đang hoạt động. Bytebase sẽ lưu trữ instance này trước, sau đó xóa vĩnh viễn. Không thể hoàn tác hành động này. Nhập ID instance \"{{id}}\" để xác nhận.","delete-confirmation": "Thao tác này sẽ xóa vĩnh viễn instance \"{{name}}\". Không thể hoàn tác hành động này. Nhập ID instance \"{{id}}\" để xác nhận.",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 5756fb2be3..f5c45332e6 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1037,6 +1037,7 @@},"create-gcp-credentials": "创建凭据的方法见","database-region": "数据库区域",+ "database-region-placeholder": "数据库区域,例如 us-east-1","default-role": "默认角色","delete-active-confirmation": "实例“{{name}}”当前处于活动状态。Bytebase 将先归档该实例,然后永久删除它。此操作无法撤销。请输入实例 ID “{{id}}” 以确认。","delete-confirmation": "这将永久删除实例“{{name}}”。此操作无法撤销。请输入实例 ID “{{id}}” 以确认。",