Skip to content

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

fix: `isDatabaseAccessible` in SQL editor (#6202)

boojack02d8e395718a
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index acf9dd2bc3..96b2310ed2 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -191,7 +191,7 @@ export const useCurrentUserIamPolicy = () => {
if (!policy) {
return false;
}
- for (const binding of policy.bindings) {
+ const iamPolicyCheckResult = policy.bindings.map((binding) => {
if (
binding.role === PresetRoleType.OWNER &&
binding.members.find(
@@ -206,34 +206,23 @@ export const useCurrentUserIamPolicy = () => {
(member) => member === `user:${currentUser.value.email}`
)
) {
- const expressionList = binding.condition?.expression.split(" && ");
- if (expressionList && expressionList.length > 0) {
- let hasDatabaseField = false;
- for (const expression of expressionList) {
- const fields = expression.split(" ");
- if (fields[0] === "resource.database") {
- hasDatabaseField = true;
- for (const url of JSON.parse(fields[2])) {
- const value = url.split("/");
- const instanceName = value[1] || "";
- const databaseName = value[3] || "";
- if (
- database.instance.resourceId === instanceName &&
- database.name === databaseName
- ) {
- return true;
- }
- }
- }
- }
- if (!hasDatabaseField) {
- return true;
- }
+ const conditionExpression = parseConditionExpressionString(
+ binding.condition?.expression || ""
+ );
+ if (conditionExpression.databases) {
+ const databaseResourceName = getDatabaseNameById(database.id);
+ return conditionExpression.databases.includes(databaseResourceName);
} else {
return true;
}
}
+ return false;
+ });
+ // If one of the binding is true, then the user is allowed to query the database.
+ if (iamPolicyCheckResult.includes(true)) {
+ return true;
}
+
return false;
};
@@ -248,7 +237,7 @@ export const useCurrentUserIamPolicy = () => {
if (!policy) {
return false;
}
- for (const binding of policy.bindings) {
+ const iamPolicyCheckResult = policy.bindings.map((binding) => {
if (
binding.role === PresetRoleType.OWNER &&
binding.members.find(
@@ -273,7 +262,12 @@ export const useCurrentUserIamPolicy = () => {
return true;
}
}
+ });
+ // If one of the binding is true, then the user is allowed to export the database.
+ if (iamPolicyCheckResult.includes(true)) {
+ return true;
}
+
return false;
};
diff --git a/frontend/src/utils/policy.ts b/frontend/src/utils/policy.ts
index 67471148d9..0693d42e84 100644
--- a/frontend/src/utils/policy.ts
+++ b/frontend/src/utils/policy.ts
@@ -54,22 +54,21 @@ export const isDatabaseAccessible = (
}
const { environment } = database.instance;
- if (environment.tier === "UNPROTECTED") {
- return true;
+ if (environment.tier === "PROTECTED") {
+ const policy = policyList.find((policy) => {
+ const { type, resourceUid, enforce } = policy;
+ return (
+ type === PolicyType.ACCESS_CONTROL &&
+ resourceUid === `${database.id}` &&
+ enforce
+ );
+ });
+ if (policy) {
+ // The database is in the allowed list
+ return true;
+ }
}
- const policy = policyList.find((policy) => {
- const { type, resourceUid, enforce } = policy;
- return (
- type === PolicyType.ACCESS_CONTROL &&
- resourceUid === `${database.id}` &&
- enforce
- );
- });
- if (policy) {
- // The database is in the allowed list
- return true;
- }
const currentUserIamPolicy = useCurrentUserIamPolicy();
if (currentUserIamPolicy.allowToQueryDatabase(database)) {
return true;
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index ac28951bfc..02e713017d 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -97,9 +97,7 @@ const shouldShowSyncSchemaEntry = computed(() => {
const currentUserIamPolicy = useCurrentUserIamPolicy();
return projectList.value
.map((project) => {
- return currentUserIamPolicy.allowToChangeDatabaseOfProject(
- `projects/${project.name}`
- );
+ return currentUserIamPolicy.allowToChangeDatabaseOfProject(project.name);
})
.includes(true);
});