Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: check workspace id in claims (#10911)
ecmadao7b34cb6d48b3
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.goindex c3b95430bd..2bcb33c50e 100644--- a/backend/api/v1/setting_service.go+++ b/backend/api/v1/setting_service.go@@ -57,6 +57,7 @@ func NewSettingService(// Some settings contain secret info so we only return settings that are needed by the client.var whitelistSettings = []api.SettingName{api.SettingBrandingLogo,+ api.SettingWorkspaceID,api.SettingAppIM,api.SettingWatermark,api.SettingPluginOpenAIKey,diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.goindex c590cbfe96..e4b3830972 100644--- a/backend/enterprise/plugin/hub/hub.go+++ b/backend/enterprise/plugin/hub/hub.go@@ -34,6 +34,7 @@ type claims struct {Trialing bool `json:"trialing"`Plan string `json:"plan"`OrgName string `json:"orgName"`+ WorkspaceID string `json:"workspaceId"`jwt.RegisteredClaims}@@ -54,7 +55,7 @@ func NewProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider,// StoreLicense will store the hub license.func (p *Provider) StoreLicense(ctx context.Context, patch *enterprise.SubscriptionPatch) error {if patch.License != "" {- if _, err := p.parseLicense(patch.License); err != nil {+ if _, err := p.parseLicense(ctx, patch.License); err != nil {return err}}@@ -100,7 +101,7 @@ func (p *Provider) fetchLicense(ctx context.Context) (*enterprise.License, errorif license == "" {return nil, nil}- result, err := p.parseLicense(license)+ result, err := p.parseLicense(ctx, license)if err != nil {return nil, err}@@ -139,13 +140,13 @@ func (p *Provider) loadLicense(ctx context.Context) *enterprise.License {return license}-func (p *Provider) parseLicense(license string) (*enterprise.License, error) {+func (p *Provider) parseLicense(ctx context.Context, license string) (*enterprise.License, error) {claim := &claims{}if err := parseJWTToken(license, p.config.Version, p.config.PublicKey, claim); err != nil {return nil, common.Wrap(err, common.Invalid)}- return p.parseClaims(claim)+ return p.parseClaims(ctx, claim)}func (p *Provider) findEnterpriseLicense(ctx context.Context) (*enterprise.License, error) {@@ -158,7 +159,7 @@ func (p *Provider) findEnterpriseLicense(ctx context.Context) (*enterprise.Licenreturn nil, errors.Wrapf(err, "failed to load enterprise license from settings")}if setting != nil && setting.Value != "" {- license, err := p.parseLicense(setting.Value)+ license, err := p.parseLicense(ctx, setting.Value)if err != nil {return nil, errors.Wrapf(err, "failed to parse enterprise license")}@@ -177,7 +178,7 @@ func (p *Provider) findEnterpriseLicense(ctx context.Context) (*enterprise.Licen}// parseClaims will valid and parse JWT claims to license instance.-func (p *Provider) parseClaims(claim *claims) (*enterprise.License, error) {+func (p *Provider) parseClaims(ctx context.Context, claim *claims) (*enterprise.License, error) {if p.config.Issuer != claim.Issuer {return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", p.config.Issuer, claim.Issuer)}@@ -190,6 +191,16 @@ func (p *Provider) parseClaims(claim *claims) (*enterprise.License, error) {return nil, common.Errorf(common.Invalid, "plan type %q is not valid", planType)}+ if claim.WorkspaceID != "" && planType == api.ENTERPRISE {+ workspaceID, err := p.store.GetWorkspaceID(ctx)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to get workspace id from setting")+ }+ if workspaceID != claim.WorkspaceID {+ return nil, common.Errorf(common.Invalid, "the workspace id not match")+ }+ }+license := &enterprise.License{InstanceCount: claim.InstanceCount,ExpiresTs: claim.ExpiresAt.Unix(),diff --git a/frontend/src/components/GeneralSetting/BrandingSetting.vue b/frontend/src/components/GeneralSetting/BrandingSetting.vueindex 6d659a2bba..c37d6e2b46 100644--- a/frontend/src/components/GeneralSetting/BrandingSetting.vue+++ b/frontend/src/components/GeneralSetting/BrandingSetting.vue@@ -13,9 +13,32 @@</div><div class="flex-1 lg:px-4"><div class="mb-4 mt-4 lg:mt-0">- <p>+ <label class="flex items-center gap-x-2">+ <span class="font-medium">+ {{ $t("settings.general.workspace.id") }}+ </span>+ </label>+ <div class="mb-3 text-sm text-gray-400">+ {{ $t("settings.general.workspace.id-description") }}+ </div>+ <div class="mb-4 flex space-x-2">+ <NInput+ ref="workspaceIdField"+ :value="workspaceId"+ class="mb-4 w-full"+ @click="selectWorkspaceId"+ />+ <NButton+ v-if="isSupported"+ :disabled="!workspaceId"+ @click="handleCopyId"+ >+ <heroicons-outline:clipboard-document class="w-4 h-4" />+ </NButton>+ </div>+ <span class="font-medium">{{ $t("settings.general.workspace.logo") }}- </p>+ </span><p class="mb-3 text-sm text-gray-400">{{ $t("settings.general.workspace.logo-aspect") }}</p>@@ -115,8 +138,9 @@</template><script lang="ts" setup>+import { useClipboard } from "@vueuse/core";import { NPopconfirm } from "naive-ui";-import { computed, reactive, watchEffect } from "vue";+import { computed, reactive, watchEffect, ref } from "vue";import { useI18n } from "vue-i18n";import { featureToRef, pushNotification } from "@/store";import { useActuatorV1Store } from "@/store/modules/v1/actuator";@@ -148,6 +172,7 @@ const convertFileToBase64 = (file: File) =>const settingV1Store = useSettingV1Store();const { t } = useI18n();+const workspaceIdField = ref<HTMLInputElement | null>(null);const state = reactive<LocalState>({displayName: "",@@ -165,6 +190,31 @@ const valid = computed((): boolean => {return !!state.displayName || !!state.logoFile;});+const workspaceId = computed(() => {+ return (+ settingV1Store.getSettingByName("bb.workspace.id")?.value?.stringValue ?? ""+ );+});++const selectWorkspaceId = () => {+ workspaceIdField.value?.select();+};++const { copy: copyTextToClipboard, isSupported } = useClipboard({+ legacy: true,+});++const handleCopyId = () => {+ selectWorkspaceId();+ copyTextToClipboard(workspaceId.value).then(() => {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.copied"),+ });+ });+};+const allowDelete = computed(() => {return settingV1Store.brandingLogo !== "";});diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vueindex 01b326cd00..4d9af75936 100644--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue@@ -160,6 +160,9 @@ const { isSaaSMode } = storeToRefs(actuatorStore);const hasWatermarkFeature = featureToRef("bb.feature.branding");const has2FAFeature = featureToRef("bb.feature.2fa");const hasDisallowSignupFeature = featureToRef("bb.feature.disallow-signup");+const hasRestrictIssueCreationFeature = featureToRef(+ "bb.feature.access-control"+);const watermarkEnabled = computed((): boolean => {return (@@ -242,6 +245,10 @@ const handleWatermarkToggle = async (on: boolean) => {};const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {+ if (!hasRestrictIssueCreationFeature.value && on) {+ state.featureNameForModal = "bb.feature.access-control";+ return;+ }await policyV1Store.createPolicy("", {type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,resourceType: PolicyResourceType.WORKSPACE,diff --git a/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue b/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vueindex 3330df2743..8c7bca5378 100644--- a/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue+++ b/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue@@ -9,6 +9,7 @@><div class="my-4 rounded-sm p-4 bg-gray-100 relative"><div+ v-if="isSupported"class="absolute top-2 right-2 p-2 rounded bg-gray-200 text-gray-500 hover:text-gray-700 hover:bg-gray-300 cursor-pointer"@click="handleCopy">@@ -100,20 +101,12 @@ const { copy: copyTextToClipboard, isSupported } = useClipboard({const { t } = useI18n();const handleCopy = () => {- if (!isSupported.value) {+ copyTextToClipboard(JSON.stringify(example, null, 2)).then(() => {pushNotification({module: "bytebase",- style: "CRITICAL",- title: "Copy to clipboard is not enabled in your browser.",+ style: "SUCCESS",+ title: t("settings.sensitive-data.classification.copy-succeed"),});- return;- }-- copyTextToClipboard(JSON.stringify(example, null, 2));- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("settings.sensitive-data.classification.copy-succeed"),});};</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 4e702ed97e..43ef38b76f 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -591,6 +591,8 @@},"general": {"workspace": {+ "id": "Workspace ID",+ "id-description": "The unique, read-only workspace id.","branding": "Branding","only-admin-can-edit": "Only workspace admin can update the settings.","logo": "Logo",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex cbabb3db50..316f8fd68d 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -591,6 +591,8 @@},"general": {"workspace": {+ "id": "ID del espacio de trabajo",+ "id-description": "La identificación única del espacio de trabajo de solo lectura.","branding": "Marca","only-admin-can-edit": "Solo el administrador del espacio de trabajo puede actualizar la configuración.","logo": "Logo",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex b1b5670075..1236c74824 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -591,6 +591,8 @@},"general": {"workspace": {+ "id": "ワークスペースID",+ "id-description": "一意の読み取り専用ワークスペース ID。","branding": "ブランディング","only-admin-can-edit": "設定の更新はワークスペース管理者のみが行えます。","logo": "ロゴ",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex de4f749bf2..faa0ae6ee5 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -591,6 +591,8 @@},"general": {"workspace": {+ "id": "ID không gian làm việc",+ "id-description": "Id không gian làm việc duy nhất, chỉ đọc.","branding": "Xây dựng thương hiệu","only-admin-can-edit": "Chỉ quản trị viên không gian làm việc mới có thể cập nhật cài đặt.","logo": "Logo",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex e27d17d0eb..e67036e670 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -591,6 +591,8 @@},"general": {"workspace": {+ "id": "工作空间 ID",+ "id-description": "唯一且只读的工作空间 ID","branding": "品牌","only-admin-can-edit": "仅管理员可以更改此设置","logo": "Logo",diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.tsindex 931470f510..b602ef1c88 100644--- a/frontend/src/types/setting.ts+++ b/frontend/src/types/setting.ts@@ -1,5 +1,6 @@export type SettingName =| "bb.branding.logo"+ | "bb.workspace.id"| "bb.app.im"| "bb.workspace.watermark"| "bb.workspace.profile"