Skip to content

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

chore: handle legacy service account (#19272)

ecmadaoe522ad63c60a
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 9d15b2c980..d913c2929d 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -128,7 +128,9 @@ func (s *Store) GetPrincipalByEmail(ctx context.Context, email string) (*UserMes
return user, nil
}
- // Default to end user
+ // Default to end user lookup, which loads and caches all principals
+ // (regardless of type) so legacy service accounts/workload identities
+ // with non-standard email formats are also found.
return s.GetUserByEmail(ctx, email)
}
diff --git a/frontend/src/components/IssueV1/components/CurrentApproverV1.vue b/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
index 393c6769a9..b805cd81d3 100644
--- a/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
+++ b/frontend/src/components/IssueV1/components/CurrentApproverV1.vue
@@ -92,7 +92,9 @@ const rejectedApprover = computedAsync(() => {
(ap) => ap.status === Issue_Approver_Status.REJECTED
);
if (!rejectedApproval?.principal) return undefined;
- return userStore.getOrFetchUserByIdentifier(rejectedApproval.principal);
+ return userStore.getOrFetchUserByIdentifier({
+ identifier: rejectedApproval.principal,
+ });
});
const currentApprover = computedAsync(() => {
@@ -116,6 +118,8 @@ const currentApprover = computedAsync(() => {
// Show the first approver candidate otherwise.
if (candidates.length === 0) return undefined;
- return userStore.getOrFetchUserByIdentifier(candidates[0]);
+ return userStore.getOrFetchUserByIdentifier({
+ identifier: candidates[0],
+ });
});
</script>
diff --git a/frontend/src/components/Member/EditMemberRoleDrawer.vue b/frontend/src/components/Member/EditMemberRoleDrawer.vue
index 31b462a146..20125c06cd 100644
--- a/frontend/src/components/Member/EditMemberRoleDrawer.vue
+++ b/frontend/src/components/Member/EditMemberRoleDrawer.vue
@@ -12,6 +12,8 @@
v-model:value="state.memberList"
:required="true"
:include-all-users="true"
+ :include-service-account="true"
+ :include-workload-identity="true"
/>
<div v-else class="w-full flex flex-col gap-y-2">
<div class="flex items-center gap-x-1">
diff --git a/frontend/src/components/Member/MembersBindingSelect.vue b/frontend/src/components/Member/MembersBindingSelect.vue
index 3d14801c3f..78c3ffef6f 100644
--- a/frontend/src/components/Member/MembersBindingSelect.vue
+++ b/frontend/src/components/Member/MembersBindingSelect.vue
@@ -32,6 +32,8 @@
:disabled="disabled"
:project-name="projectName"
:include-all-users="includeAllUsers"
+ :include-service-account="includeServiceAccount"
+ :include-workload-identity="includeWorkloadIdentity"
@update:value="onMemberListUpdate($event as string[])"
/>
</div>
@@ -69,19 +71,16 @@ const props = withDefaults(
// - group:{email}
// - serviceAccount:{email}
// - workloadIdentity:{email}
- // We don't support mix group with other data.
value: string[];
required: boolean;
projectName?: string;
disabled?: boolean;
- allowChangeType?: boolean;
- includeAllUsers?: boolean;
+ includeAllUsers: boolean;
+ includeServiceAccount: boolean;
+ includeWorkloadIdentity: boolean;
}>(),
{
- disabled: false,
projectName: undefined,
- allowChangeType: true,
- includeAllUsers: false,
}
);
diff --git a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionCreator.vue b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionCreator.vue
index 4de7f78b79..e05e741818 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionCreator.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionCreator.vue
@@ -17,6 +17,8 @@ const props = defineProps<{
const userStore = useUserStore();
const user = computedAsync(() => {
- return userStore.getOrFetchUserByIdentifier(props.creator);
+ return userStore.getOrFetchUserByIdentifier({
+ identifier: props.creator,
+ });
});
</script>
diff --git a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionIcon.vue b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionIcon.vue
index bc2a359f6c..9702f6206e 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionIcon.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentView/ActionIcon.vue
@@ -151,7 +151,9 @@ const props = defineProps<{
const userStore = useUserStore();
const user = computedAsync(() => {
- return userStore.getOrFetchUserByIdentifier(props.issueComment.creator);
+ return userStore.getOrFetchUserByIdentifier({
+ identifier: props.issueComment.creator,
+ });
});
const iconType = computed((): ActionIconType => {
diff --git a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalUserView.vue b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalUserView.vue
index c21a64dcfb..aeb774e93d 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalUserView.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalUserView.vue
@@ -25,7 +25,9 @@ const props = defineProps<{
const userStore = useUserStore();
const candidateUser = computedAsync(async () => {
- const user = await userStore.getOrFetchUserByIdentifier(props.candidate);
+ const user = await userStore.getOrFetchUserByIdentifier({
+ identifier: props.candidate,
+ });
if (!user) {
return;
}
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index cf0c79bcbe..e46696446f 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -5,6 +5,8 @@
:required="true"
:include-all-users="true"
:disabled="disableMemberChange"
+ :include-service-account="true"
+ :include-workload-identity="true"
/>
<div class="w-full flex flex-col gap-y-2">
diff --git a/frontend/src/components/SensitiveData/GrantAccessForm.vue b/frontend/src/components/SensitiveData/GrantAccessForm.vue
index 0a0a770f40..a35e557c5d 100644
--- a/frontend/src/components/SensitiveData/GrantAccessForm.vue
+++ b/frontend/src/components/SensitiveData/GrantAccessForm.vue
@@ -50,6 +50,8 @@
v-model:value="state.memberList"
:required="true"
:include-all-users="false"
+ :include-service-account="true"
+ :include-workload-identity="true"
/>
</div>
</template>
diff --git a/frontend/src/components/v2/Model/User/UserByEmail.vue b/frontend/src/components/v2/Model/User/UserByEmail.vue
deleted file mode 100644
index 8d7e6422f4..0000000000
--- a/frontend/src/components/v2/Model/User/UserByEmail.vue
+++ /dev/null
@@ -1,50 +0,0 @@
-<template>
- <component
- :is="link ? 'router-link' : tag"
- v-bind="bindings"
- :class="link && !plain && 'normal-link'"
- >
- {{ email }}
- </component>
-</template>
-
-<script setup lang="ts">
-import { computedAsync } from "@vueuse/core";
-import { computed } from "vue";
-import { useUserStore } from "@/store";
-
-const props = withDefaults(
- defineProps<{
- email: string;
- tag?: string;
- link?: boolean;
- plain?: boolean;
- }>(),
- {
- tag: "span",
- link: true,
- plain: false,
- }
-);
-
-const store = useUserStore();
-
-const user = computedAsync(() => {
- return store.getOrFetchUserByIdentifier(props.email);
-});
-
-const bindings = computed(() => {
- if (props.link) {
- const to = user.value ? `/users/${user.value.email}` : "/404";
- return {
- to,
- activeClass: "",
- exactActiveClass: "",
- onClick: (e: MouseEvent) => {
- e.stopPropagation();
- },
- };
- }
- return {};
-});
-</script>
diff --git a/frontend/src/components/v2/Model/User/index.ts b/frontend/src/components/v2/Model/User/index.ts
deleted file mode 100644
index 540fdc5933..0000000000
--- a/frontend/src/components/v2/Model/User/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import UserByEmail from "./UserByEmail.vue";
-
-export { UserByEmail };
diff --git a/frontend/src/components/v2/Model/cells/UserNameCell.vue b/frontend/src/components/v2/Model/cells/UserNameCell.vue
index 3beb8d1e19..5203242d0d 100644
--- a/frontend/src/components/v2/Model/cells/UserNameCell.vue
+++ b/frontend/src/components/v2/Model/cells/UserNameCell.vue
@@ -18,7 +18,7 @@
:keyword="keyword"
:title="user.title"
:email="user.email"
- :link="link"
+ :link="link && user.userType === UserType.USER"
/>
</div>
<slot name="suffix">
diff --git a/frontend/src/components/v2/Model/index.ts b/frontend/src/components/v2/Model/index.ts
index ca8dd34bc6..6d088822ed 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -11,7 +11,6 @@ import RichDatabaseName from "./RichDatabaseName.vue";
export * from "./Instance";
export * from "./Plan";
-export * from "./User";
export * from "./DatabaseV1Table";
export * from "./Project";
export {
diff --git a/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts b/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts
index 61c2b24a6f..2e4d6387a7 100644
--- a/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts
+++ b/frontend/src/components/v2/ResourceOccupiedModal/useResourceByName.ts
@@ -93,7 +93,9 @@ export const useResourceByName = ({
}
return;
case "user":
- await userStore.getOrFetchUserByIdentifier(resource.value, true);
+ await userStore.getOrFetchUserByIdentifier({
+ identifier: resource.value,
+ });
return;
}
});
diff --git a/frontend/src/components/v2/Select/AccountSelect.vue b/frontend/src/components/v2/Select/AccountSelect.vue
index 6bfd07bb40..8846671d80 100644
--- a/frontend/src/components/v2/Select/AccountSelect.vue
+++ b/frontend/src/components/v2/Select/AccountSelect.vue
@@ -47,6 +47,7 @@ import {
import {
allUsersUser,
getUserTypeByEmail,
+ getUserTypeByFullname,
unknownGroup,
unknownUser,
} from "@/types";
@@ -79,7 +80,9 @@ const props = defineProps<{
value?: string | string[] | undefined; // fullname
projectName?: string;
// allUsers is a special user that represents all users in the project.
- includeAllUsers?: boolean;
+ includeAllUsers: boolean;
+ includeServiceAccount: boolean;
+ includeWorkloadIdentity: boolean;
}>();
defineEmits<{
@@ -159,7 +162,7 @@ const additionalOptions = computedAsync(async () => {
groupNames.push(fullname);
continue;
}
- const userType = getUserTypeByEmail(fullname);
+ const userType = getUserTypeByFullname(fullname);
switch (userType) {
case UserType.SERVICE_ACCOUNT:
if (!hasGetServiceAccountPermission.value) {
@@ -244,9 +247,20 @@ const fetchAccounts = async (params: {
nextPageToken: string;
options: ResourceSelectOption<AccountResource>[];
}> => {
- const userType = getUserTypeByEmail(params.search);
+ let userType = getUserTypeByFullname(params.search);
+ if (userType === UserType.USER) {
+ // If the params.search doesn't have the prefix,
+ // we will try to guess the type by email suffix.
+ userType = getUserTypeByEmail(params.search);
+ }
switch (userType) {
case UserType.SERVICE_ACCOUNT:
+ if (!props.includeServiceAccount) {
+ return {
+ nextPageToken: "",
+ options: [],
+ };
+ }
if (!hasGetServiceAccountPermission.value) {
const email = extractServiceAccountId(params.search);
return {
@@ -274,6 +288,12 @@ const fetchAccounts = async (params: {
options: [getUserOption(serviceAccountToUser(sa))],
};
case UserType.WORKLOAD_IDENTITY:
+ if (!props.includeWorkloadIdentity) {
+ return {
+ nextPageToken: "",
+ options: [],
+ };
+ }
if (!hasGetWorkloadIdentityPermission.value) {
const email = extractWorkloadIdentityId(params.search);
return {
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index 5cfab8992b..ea47671a11 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -63,7 +63,6 @@ const getListUserFilter = (params: UserFilter) => {
export const useUserStore = defineStore("user", () => {
const actuatorStore = useActuatorV1Store();
const allUser = computed(() => allUsersUser());
- const userRequestCache = new Map<string, Promise<User>>();
const userMapByName = ref<Map<string, User>>(
new Map([[allUser.value.name, allUser.value]])
@@ -142,8 +141,11 @@ export const useUserStore = defineStore("user", () => {
const updateUser = async (updateUserRequest: UpdateUserRequest) => {
const name = updateUserRequest.user?.name || "";
- const originData = await getOrFetchUserByIdentifier(name);
- if (!originData) {
+ const originData = await getOrFetchUserByIdentifier({
+ identifier: name,
+ fallback: false,
+ });
+ if (!isValidUserName(originData.name)) {
throw new Error(`user with name ${name} not found`);
}
@@ -160,8 +162,11 @@ export const useUserStore = defineStore("user", () => {
};
const updateEmail = async (oldEmail: string, newEmail: string) => {
- const originData = await getOrFetchUserByIdentifier(oldEmail);
- if (!originData) {
+ const originData = await getOrFetchUserByIdentifier({
+ identifier: oldEmail,
+ fallback: false,
+ });
+ if (!isValidUserName(originData.name)) {
throw new Error(`user with email ${oldEmail} not found`);
}
const oldName = originData.name;
@@ -172,7 +177,6 @@ export const useUserStore = defineStore("user", () => {
// Remove old cache entry since the user's name changes with email
if (oldName !== response.name) {
userMapByName.value.delete(oldName);
- userRequestCache.delete(oldName);
}
return setUser(response);
};
@@ -258,10 +262,15 @@ export const useUserStore = defineStore("user", () => {
}
};
- const getOrFetchUserByIdentifier = async (
- identifier: string,
- silent = true
- ) => {
+ const getOrFetchUserByIdentifier = async ({
+ identifier,
+ silent = true,
+ fallback = true,
+ }: {
+ identifier: string;
+ silent?: boolean;
+ fallback?: boolean;
+ }) => {
const user = getUserByIdentifier(identifier);
if (user) {
return user;
@@ -271,12 +280,9 @@ export const useUserStore = defineStore("user", () => {
if (!isValidUserName(fullname)) {
return unknownUser();
}
- const cached = userRequestCache.get(fullname);
- if (cached) return cached;
const request = fetchUser(fullname, silent)
.then((user) => setUser(user))
- .catch(() => unknownUser(fullname));
- userRequestCache.set(fullname, request);
+ .catch(() => unknownUser(fallback ? fullname : ""));
return request;
};
diff --git a/frontend/src/store/modules/v1/worksheet.ts b/frontend/src/store/modules/v1/worksheet.ts
index bcb532a473..1080aaeed8 100644
--- a/frontend/src/store/modules/v1/worksheet.ts
+++ b/frontend/src/store/modules/v1/worksheet.ts
@@ -80,7 +80,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
await Promise.all([
projectStore.getOrFetchProjectByName(worksheet.project),
databaseStore.getOrFetchDatabaseByName(worksheet.database),
- userStore.getOrFetchUserByIdentifier(worksheet.creator),
+ userStore.getOrFetchUserByIdentifier({ identifier: worksheet.creator }),
]);
} catch {
// ignore error
diff --git a/frontend/src/types/v1/user.ts b/frontend/src/types/v1/user.ts
index c96336da42..26221d0939 100644
--- a/frontend/src/types/v1/user.ts
+++ b/frontend/src/types/v1/user.ts
@@ -1,6 +1,10 @@
import { create } from "@bufbuild/protobuf";
import { t } from "@/plugins/i18n";
-import { extractUserEmail } from "@/store/modules/v1/common";
+import {
+ extractUserEmail,
+ serviceAccountNamePrefix,
+ workloadIdentityNamePrefix,
+} from "@/store/modules/v1/common";
import { UNKNOWN_ID } from "../const";
import { State } from "../proto-es/v1/common_pb";
import type { User } from "../proto-es/v1/user_service_pb";
@@ -97,3 +101,17 @@ export const getUserTypeByEmail = (email: string): UserType => {
}
return UserType.USER;
};
+
+// getUserTypeByFullname determines the user type by the fullname prefix.
+// This is more reliable than checking email suffix, as it works for
+// legacy service accounts/workload identities with non-standard email formats.
+// Supported formats: serviceAccounts/{email}, workloadIdentities/{email}, users/{email}
+export const getUserTypeByFullname = (fullname: string): UserType => {
+ if (fullname.startsWith(serviceAccountNamePrefix)) {
+ return UserType.SERVICE_ACCOUNT;
+ }
+ if (fullname.startsWith(workloadIdentityNamePrefix)) {
+ return UserType.WORKLOAD_IDENTITY;
+ }
+ return UserType.USER;
+};
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index ff58697ecc..55b2784a8d 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -213,7 +213,7 @@
import { create } from "@bufbuild/protobuf";
import { FieldMaskSchema } from "@bufbuild/protobuf/wkt";
import type { ConnectError } from "@connectrpc/connect";
-import { computedAsync, useTitle } from "@vueuse/core";
+import { useTitle } from "@vueuse/core";
import { cloneDeep, isEqual } from "lodash-es";
import { EllipsisIcon } from "lucide-vue-next";
import type { DropdownOption } from "naive-ui";
@@ -258,7 +258,12 @@ import {
useUserStore,
useWorkspaceV1Store,
} from "@/store";
-import { ALL_USERS_USER_EMAIL, getUserTypeByEmail, unknownUser } from "@/types";
+import {
+ ALL_USERS_USER_EMAIL,
+ getUserTypeByEmail,
+ isValidUserName,
+ unknownUser,
+} from "@/types";
import { State } from "@/types/proto-es/v1/common_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
import type { User } from "@/types/proto-es/v1/user_service_pb";
@@ -332,6 +337,17 @@ const keyboardHandler = (e: KeyboardEvent) => {
onMounted(async () => {
document.addEventListener("keydown", keyboardHandler);
+ if (props.principalEmail) {
+ const user = await userStore.getOrFetchUserByIdentifier({
+ identifier: props.principalEmail,
+ fallback: false,
+ });
+ if (!isValidUserName(user.name)) {
+ router.replace({
+ name: WORKSPACE_ROUTE_404,
+ });
+ }
+ }
});
onUnmounted(() => {
@@ -349,12 +365,12 @@ const showRegenerateRecoveryCodes = computed(() => {
return user.value.mfaEnabled && user.value.name === currentUser.value.name;
});
-const user = computedAsync(() => {
+const user = computed(() => {
if (props.principalEmail) {
- return userStore.getOrFetchUserByIdentifier(props.principalEmail);
+ return userStore.getUserByIdentifier(props.principalEmail) ?? unknownUser();
}
return currentUser.value;
-}, unknownUser());
+});
const userRoles = computed(() => {
return [...workspaceStore.getWorkspaceRolesByName(user.value.name)];