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 azure iam authentication in data source form (#15415)
h3n4l380e63a1a345
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.goindex 3edc166639..e2ac776ffa 100644--- a/backend/api/v1/instance_service.go+++ b/backend/api/v1/instance_service.go@@ -819,12 +819,25 @@ func (s *InstanceService) UpdateDataSource(ctx context.Context, request *v1pb.Upif v := request.DataSource.IamExtension; v != nil {switch v := v.(type) {case *v1pb.DataSource_ClientSecretCredential_:+ v1ClientSecretCredential := v.ClientSecretCredential+ v1ClientSecretCredential.ClientSecret = common.Obfuscate(v1ClientSecretCredential.ClientSecret, s.secret)dataSource.IamExtension = &storepb.DataSource_ClientSecretCredential_{ClientSecretCredential: convertV1ClientSecretCredential(v.ClientSecretCredential),}default:}}+ // TODO(zp): Remove the hack while frontend use new oneof artifact.+ case "client_secret_credential":+ if request.DataSource.GetClientSecretCredential() == nil {+ dataSource.IamExtension = nil+ } else {+ v1ClientSecretCredential := request.DataSource.GetClientSecretCredential()+ v1ClientSecretCredential.ClientSecret = common.Obfuscate(v1ClientSecretCredential.ClientSecret, s.secret)+ dataSource.IamExtension = &storepb.DataSource_ClientSecretCredential_{+ ClientSecretCredential: convertV1ClientSecretCredential(request.DataSource.GetClientSecretCredential()),+ }+ }default:return nil, status.Errorf(codes.InvalidArgument, `unsupported update_mask "%s"`, path)}@@ -1172,6 +1185,7 @@ func convertDataSources(dataSources []*storepb.DataSource) ([]*v1pb.DataSource,MasterUsername: ds.GetMasterUsername(),}if clientSecretCredential := convertClientSecretCredential(ds.GetClientSecretCredential()); clientSecretCredential != nil {+ clientSecretCredential.ClientSecret = ""dataSource.IamExtension = &v1pb.DataSource_ClientSecretCredential_{ClientSecretCredential: clientSecretCredential,}@@ -1358,9 +1372,8 @@ func (s *InstanceService) convertV1DataSource(dataSource *v1pb.DataSource) (*storeturn nil, err}saslConfig := convertV1DataSourceSaslConfig(dataSource.SaslConfig)- clientSecretCredential := convertV1ClientSecretCredential(dataSource.GetClientSecretCredential())- return &storepb.DataSource{+ storeDataSource := &storepb.DataSource{Id: dataSource.Id,Type: dsType,Username: dataSource.Username,@@ -1394,8 +1407,13 @@ func (s *InstanceService) convertV1DataSource(dataSource *v1pb.DataSource) (*stoMasterName: dataSource.MasterName,MasterUsername: dataSource.MasterUsername,MasterObfuscatedPassword: common.Obfuscate(dataSource.MasterPassword, s.secret),- IamExtension: &storepb.DataSource_ClientSecretCredential_{ClientSecretCredential: clientSecretCredential},- }, nil+ }+ if v := dataSource.GetClientSecretCredential(); v != nil {+ v.ClientSecret = common.Obfuscate(v.ClientSecret, s.secret)+ storeDataSource.IamExtension = &storepb.DataSource_ClientSecretCredential_{ClientSecretCredential: convertV1ClientSecretCredential(v)}+ }++ return storeDataSource, nil}func convertV1ClientSecretCredential(credential *v1pb.DataSource_ClientSecretCredential) *storepb.DataSource_ClientSecretCredential {diff --git a/backend/component/dbfactory/dbfactory.go b/backend/component/dbfactory/dbfactory.goindex 6442f573b7..14d880cd04 100644--- a/backend/component/dbfactory/dbfactory.go+++ b/backend/component/dbfactory/dbfactory.go@@ -132,6 +132,16 @@ func (d *DBFactory) GetDataSourceDriver(ctx context.Context, instance *store.InsconnectionContext.InstanceID = instance.ResourceIDconnectionContext.EngineVersion = instance.Metadata.GetVersion()+ var clientSecretCredential *storepb.DataSource_ClientSecretCredential+ if dataSource.GetClientSecretCredential() != nil {+ clientSecretCredential = dataSource.GetClientSecretCredential()+ updatedClientSecret, err := common.Unobfuscate(clientSecretCredential.GetClientSecret(), d.secret)+ if err != nil {+ return nil, err+ }+ clientSecretCredential.ClientSecret = updatedClientSecret+ }+maximumSQLResultSize := d.store.GetMaximumSQLResultLimit(ctx)driver, err := db.Open(ctx,@@ -173,7 +183,7 @@ func (d *DBFactory) GetDataSourceDriver(ctx context.Context, instance *store.InsMasterPassword: masterPassword,ExtraConnectionParameters: dataSource.GetExtraConnectionParameters(),MaximumSQLResultSize: maximumSQLResultSize,- ClientSecretCredential: dataSource.GetClientSecretCredential(),+ ClientSecretCredential: clientSecretCredential,},)if err != nil {diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vueindex 5b6ad1a55d..0b34475afa 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue@@ -11,25 +11,39 @@<divv-if="basicInfo.engine === Engine.MYSQL ||- basicInfo.engine === Engine.POSTGRES+ basicInfo.engine === Engine.POSTGRES ||+ basicInfo.engine === Engine.COSMOSDB"class="mt-2 sm:col-span-3 sm:col-start-1">- <NRadioGroup- v-model:value="dataSource.authenticationType"- class="textlabel"- :disabled="!allowEdit"- >- <NRadio :value="DataSource_AuthenticationType.PASSWORD">- {{ $t("instance.password-type.password") }}- </NRadio>- <NRadio :value="DataSource_AuthenticationType.GOOGLE_CLOUD_SQL_IAM">- {{ $t("instance.password-type.google-iam") }}- </NRadio>- <NRadio :value="DataSource_AuthenticationType.AWS_RDS_IAM">- {{ $t("instance.password-type.aws-iam") }}- </NRadio>- </NRadioGroup>+ <template v-if="basicInfo.engine === Engine.COSMOSDB">+ <NRadioGroup+ v-model:value="dataSource.authenticationType"+ class="textlabel"+ :disabled="!allowEdit"+ >+ <NRadio :value="DataSource_AuthenticationType.AZURE_IAM">+ {{ $t("instance.password-type.azure-iam") }}+ </NRadio>+ </NRadioGroup>+ </template>+ <template v-else>+ <NRadioGroup+ v-model:value="dataSource.authenticationType"+ class="textlabel"+ :disabled="!allowEdit"+ >+ <NRadio :value="DataSource_AuthenticationType.PASSWORD">+ {{ $t("instance.password-type.password") }}+ </NRadio>+ <NRadio :value="DataSource_AuthenticationType.GOOGLE_CLOUD_SQL_IAM">+ {{ $t("instance.password-type.google-iam") }}+ </NRadio>+ <NRadio :value="DataSource_AuthenticationType.AWS_RDS_IAM">+ {{ $t("instance.password-type.aws-iam") }}+ </NRadio>+ </NRadioGroup>+ </template></div><divv-else-if="basicInfo.engine === Engine.HIVE"@@ -129,7 +143,13 @@</div></div><div v-else class="sm:col-span-3 sm:col-start-1">- <div class="mt-4 sm:col-span-3 sm:col-start-1">+ <div+ v-if="+ dataSource.authenticationType !==+ DataSource_AuthenticationType.AZURE_IAM+ "+ class="mt-4 sm:col-span-3 sm:col-start-1"+ ><label for="username" class="textlabel block">{{ $t("common.username") }}</label>@@ -145,6 +165,60 @@"/></div>+ <div v-else class="mt-4 sm:col-span-3 sm:col-start-1">+ <label for="credential-source" class="textlabel block">+ {{ $t("instance.iam-extension.credential-source") }}+ </label>+ <NRadioGroup+ :value="state.credentialSource"+ class="textlabel"+ :disabled="!allowEdit"+ @update:value="onSelectIAMExtension"+ >+ <template+ v-for="option in getIAMExtensionOptions(+ DataSource_AuthenticationType.AZURE_IAM+ )"+ :key="option.value"+ >+ <NRadio :value="option.value" :label="option.label" />+ </template>+ </NRadioGroup>+ <div+ v-if="state.credentialSource === 'client-secret-credential'"+ class="mt-4 sm:col-span-3 sm:col-start-1"+ >+ <label for="tenant-id" class="textlabel block mt-2">+ {{ $t("instance.iam-extension.tenant-id") }}+ </label>+ <NInput+ v-model:value="dataSource.clientSecretCredential!.tenantId"+ class="mt-2 w-full"+ :disabled="!allowEdit"+ :placeholder="''"+ />+ <label for="client-id" class="textlabel block mt-2">+ {{ $t("instance.iam-extension.client-id") }}+ </label>+ <NInput+ v-model:value="dataSource.clientSecretCredential!.clientId"+ class="mt-2 w-full"+ :disabled="!allowEdit"+ :placeholder="''"+ />+ <label for="client-secret" class="textlabel block mt-2">+ {{ $t("instance.iam-extension.client-secret") }}+ </label>+ <NInput+ type="password"+ show-password-on="click"+ v-model:value="dataSource.clientSecretCredential!.clientSecret"+ class="mt-2 w-full"+ :disabled="!allowEdit"+ :placeholder="$t('instance.type-or-paste-credentials-write-only')"+ />+ </div>+ </div><divv-if="dataSource.authenticationType ===@@ -863,6 +937,7 @@ import {DataSourceExternalSecret_AppRoleAuthOption,DataSourceExternalSecret_AppRoleAuthOption_SecretType,DataSource_AuthenticationType,+ DataSource_ClientSecretCredential,} from "@/types/proto/v1/instance_service";import { DataSource_RedisType } from "@/types/proto/v1/instance_service";import { onlyAllowNumber } from "@/utils";@@ -876,6 +951,12 @@ import SslCertificateFormV1 from "./SslCertificateFormV1.vue";interface LocalState {passwordType: DataSourceExternalSecret_SecretType;+ credentialSource: string;+}++interface IAMExtensionOptions {+ label: string;+ value: string;}const props = defineProps<{@@ -906,6 +987,7 @@ const {const state = reactive<LocalState>({passwordType: DataSourceExternalSecret_SecretType.SAECRET_TYPE_UNSPECIFIED,+ credentialSource: "default-credential",});const { t } = useI18n();@@ -922,6 +1004,18 @@ watch({ immediate: true, deep: true });+watch(+ () => props.dataSource.clientSecretCredential,+ (clientSecretCredential) => {+ if (clientSecretCredential) {+ state.credentialSource = "client-secret-credential";+ } else {+ state.credentialSource = "default-credential";+ }+ },+ { immediate: true, deep: true }+);+const hiveAuthentication = computed(() => {return props.dataSource.saslConfig?.krbConfig ? "KERBEROS" : "PASSWORD";});@@ -1153,4 +1247,36 @@ const handleKeytabUpload = (options: { file: UploadFileInfo }) => {};reader.readAsArrayBuffer(options.file.file as Blob);};++const getIAMExtensionOptions = (+ authenticationType: DataSource_AuthenticationType+): IAMExtensionOptions[] => {+ if (authenticationType == DataSource_AuthenticationType.AZURE_IAM) {+ return [+ {+ label: "Default",+ value: "default-credential",+ },+ {+ label: "Client Secret Credential",+ value: "client-secret-credential",+ },+ ];+ }+ return [];+};++const onSelectIAMExtension = (value: string) => {+ state.credentialSource = value;+ resetIAMExtension();+ if (value === "client-secret-credential") {+ const ds = props.dataSource;+ ds.clientSecretCredential = DataSource_ClientSecretCredential.create();+ }+};++const resetIAMExtension = () => {+ const ds = props.dataSource;+ ds.clientSecretCredential = undefined;+};</script>diff --git a/frontend/src/components/InstanceForm/Form.vue b/frontend/src/components/InstanceForm/Form.vueindex b857f4c520..1f9f6f3ba1 100644--- a/frontend/src/components/InstanceForm/Form.vue+++ b/frontend/src/components/InstanceForm/Form.vue@@ -415,12 +415,7 @@</div><!-- Connection Info -->- <template- v-if="- basicInfo.engine !== Engine.DYNAMODB &&- basicInfo.engine !== Engine.COSMOSDB- "- >+ <template v-if="basicInfo.engine !== Engine.DYNAMODB"><p class="mt-6 pt-4 w-full text-lg leading-6 font-medium text-gray-900">{{ $t("instance.connection-info") }}</p>@@ -643,6 +638,10 @@ const changeInstanceEngine = (engine: Engine) => {) {adminDataSource.value.host = "";}+ } else if (engine === Engine.COSMOSDB) {+ // Cosmos DB supports Azure IAM only.+ adminDataSource.value.authenticationType =+ DataSource_AuthenticationType.AZURE_IAM;} else {if (!adminDataSource.value.host) {adminDataSource.value.host = isDev()diff --git a/frontend/src/components/InstanceForm/common.ts b/frontend/src/components/InstanceForm/common.tsindex 177a18fcd4..ff22d6c42f 100644--- a/frontend/src/components/InstanceForm/common.ts+++ b/frontend/src/components/InstanceForm/common.ts@@ -8,9 +8,7 @@ import {} from "@/types";import { Engine, State } from "@/types/proto/v1/common";import type { DataSource, Instance } from "@/types/proto/v1/instance_service";-import {- DataSourceType,-} from "@/types/proto/v1/instance_service";+import { DataSourceType } from "@/types/proto/v1/instance_service";import { PlanType } from "@/types/proto/v1/subscription_service";import { calcUpdateMask } from "@/utils";diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex c66d089b32..555eccdeb6 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1147,10 +1147,17 @@"password-tip": "You can also specify external secret manage endpoint","google-iam": "Google Cloud SQL IAM","aws-iam": "AWS RDS IAM",+ "azure-iam": "Azure IAM","external-secret-vault": "Vault (KV v2)","external-secret-aws": "AWS Secrets Manager","external-secret-gcp": "GCP Secret Manager"},+ "iam-extension": {+ "credential-source": "Credential Source",+ "tenant-id": "Tenant ID",+ "client-id": "Client ID",+ "client-secret": "Client Secret"+ },"database-region": "Database Region","external-secret-gcp": {"secret-name": "Secret full name",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 27b546638b..d71f9ae205 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1146,11 +1146,18 @@"password": "Contraseña","password-tip": "También puede especificar un punto final de gestión de secreto externo","google-iam": "Google Cloud SQL IAM",+ "azure-iam": "Azure IAM","aws-iam": "AWS RDS IAM","external-secret-vault": "Vault (KV v2)","external-secret-aws": "AWS Secrets Manager","external-secret-gcp": "GCP Secret Manager"},+ "iam-extension": {+ "credential-source": "Credential Source",+ "tenant-id": "Tenant ID",+ "client-id": "Client ID",+ "client-secret": "Client Secret"+ },"database-region": "Región de la base de datos","external-secret-gcp": {"secret-name": "nombre completo secreto",@@ -2612,4 +2619,4 @@"last-visit": "Última visita","changelog-for-version": "Registro de cambios para {version}"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex b648bf58b9..1d26c97954 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1147,10 +1147,17 @@"password-tip": "外部のパスワード管理サービスのエンドポイントを指定することもできます","google-iam": "Google Cloud SQL IAM","aws-iam": "AWS RDS IAM",+ "azure-iam": "Azure IAM","external-secret-vault": "ボールト (KV v2)","external-secret-aws": "AWS シークレットマネージャー","external-secret-gcp": "GCP シークレット マネージャー"},+ "iam-extension": {+ "credential-source": "Credential Source",+ "tenant-id": "Tenant ID",+ "client-id": "Client ID",+ "client-secret": "Client Secret"+ },"database-region": "データベース領域","external-secret-gcp": {"secret-name": "キーのフルパス",@@ -2612,4 +2619,4 @@"last-visit": "最終訪問","changelog-for-version": "{version} の変更履歴"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 09bd2e799b..c1247fbd41 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1147,10 +1147,17 @@"password-tip": "Bạn cũng có thể chỉ định điểm cuối quản lý bí mật bên ngoài","google-iam": "Google Cloud SQL IAM","aws-iam": "AWS RDS IAM",+ "azure-iam": "Azure IAM","external-secret-vault": "Vault (KV v2)","external-secret-aws": "AWS Secrets Manager","external-secret-gcp": "GCP Secret Manager"},+ "iam-extension": {+ "credential-source": "Credential Source",+ "tenant-id": "Tenant ID",+ "client-id": "Client ID",+ "client-secret": "Client Secret"+ },"database-region": "Khu vực cơ sở dữ liệu","external-secret-gcp": {"secret-name": "Tên đầy đủ bí mật",@@ -2612,4 +2619,4 @@"last-visit": "Lần truy cập cuối","changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex fbbada9c5c..341eb42b05 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1147,10 +1147,17 @@"password-tip": "您也可以指定外部的密码管理服务 endpoint","google-iam": "Google Cloud SQL IAM","aws-iam": "AWS RDS IAM",+ "azure-iam": "Azure IAM","external-secret-vault": "Vault (KV v2)","external-secret-aws": "AWS Secrets Manager","external-secret-gcp": "GCP Secret Manager"},+ "iam-extension": {+ "credential-source": "Credential Source",+ "tenant-id": "Tenant ID",+ "client-id": "Client ID",+ "client-secret": "Client Secret"+ },"database-region": "数据库区域","external-secret-gcp": {"secret-name": "密钥完整路径",@@ -2612,4 +2619,4 @@"last-visit": "上次访问","changelog-for-version": "{version} 的更新日志"}-}\ No newline at end of file+}