Skip to content

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

Introduce a dedicated ADMIN data source type.

天舟8acbd5ae66bc
diff --git a/frontend/src/directives/data-source-type.ts b/frontend/src/directives/data-source-type.ts
index b130c7fa25..491b854447 100644
--- a/frontend/src/directives/data-source-type.ts
+++ b/frontend/src/directives/data-source-type.ts
@@ -4,12 +4,15 @@ const directive = {
beforeMount(el: HTMLElement) {
const dataSourceType = el.innerText as DataSourceType;
switch (dataSourceType) {
- case "RO":
- el.innerText = "Read Only";
+ case "ADMIN":
+ el.innerText = "ADMIN";
return;
case "RW":
el.innerText = "Read & Write";
return;
+ case "RO":
+ el.innerText = "Read Only";
+ return;
}
},
};
diff --git a/frontend/src/miragejs/routes/dataSource.js b/frontend/src/miragejs/routes/dataSource.js
index 032bc50d45..8ea33e978c 100644
--- a/frontend/src/miragejs/routes/dataSource.js
+++ b/frontend/src/miragejs/routes/dataSource.js
@@ -5,7 +5,9 @@ export default function configureDataSource(route) {
const database = schema.databases.find(request.params.databaseId);
if (database) {
return schema.dataSources.where((dataSource) => {
- return dataSource.databaseId == database.id;
+ return (
+ dataSource.databaseId == database.id && dataSource.type != "ADMIN"
+ );
});
}
return new Response(
diff --git a/frontend/src/miragejs/routes/instance.js b/frontend/src/miragejs/routes/instance.js
index c4fb0dd50f..6a2f53f79a 100644
--- a/frontend/src/miragejs/routes/instance.js
+++ b/frontend/src/miragejs/routes/instance.js
@@ -75,7 +75,7 @@ export default function configurInstance(route) {
instance: createdInstance,
database: allDatabase,
name: createdInstance.name + " admin data source",
- type: "RW",
+ type: "ADMIN",
username: attrs.username,
password: attrs.password,
});
@@ -112,7 +112,7 @@ export default function configurInstance(route) {
const dataSource = schema.dataSources.findBy({
instanceId: instance.id,
- type: "RW",
+ type: "ADMIN",
});
if (!dataSource) {
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index 180c95be4e..19c7f043c7 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -632,7 +632,7 @@ const createInstanceList = (
instance,
database: allDatabase,
name: instance.name + " admin data source",
- type: "RW",
+ type: "ADMIN",
username: "adminRW",
password: "pwdadminRW",
});
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 67bc0f9e14..4725612fcd 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -40,7 +40,7 @@ function convert(
for (const item of includedList || []) {
if (
item.type == "data-source" &&
- item.attributes.type == "RW" &&
+ item.attributes.type == "ADMIN" &&
(item.relationships!.instance.data as ResourceIdentifier).id ==
instance.id
) {
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 25f6a9ed24..56f80c13ba 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -807,7 +807,10 @@ export type InstancePatch = {
password?: string;
};
-export type DataSourceType = "RW" | "RO";
+// For now the ADMIN requires the same database privilege as RW.
+// The seperation is to make it explicit which one serves as the ADMIN data source,
+// which from the ops perspective, having different meaning from the normal RW data source.
+export type DataSourceType = "ADMIN" | "RW" | "RO";
// Data Source
export type DataSource = {
id: DataSourceId;
diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.ts
index 0bc9e0a87e..e3fe46bbff 100644
--- a/frontend/src/utils/database.ts
+++ b/frontend/src/utils/database.ts
@@ -6,12 +6,27 @@ import {
Principal,
} from "../types";
import { isDBAOrOwner } from "./role";
+import { isDev } from "./util";
export function allowDatabaseAccess(
database: Database,
principal: Principal,
type: DataSourceType
): boolean {
+ // "ADMIN" data source should only be used by the system, thus it shouldn't
+ // touch this method at all. If it touches somehow, we will reject it and
+ // log a warning
+ if (type == "ADMIN") {
+ if (isDev()) {
+ console.trace(
+ "Should not check database access against ADMIN connection"
+ );
+ } else {
+ console.warn("Should not check database access against ADMIN connection");
+ }
+ return false;
+ }
+
if (isDBAOrOwner(principal.role)) {
return true;
}