Skip to content

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

chore: disallow SSO user to change email (#4424)

boojack67a1de8a4e6e
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 1ba06a08b0..2ac1a8a49a 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -174,6 +174,9 @@ func (s *AuthService) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRe
for _, path := range request.UpdateMask.Paths {
switch path {
case "user.email":
+ if user.IdentityProviderResourceID != nil {
+ return nil, status.Errorf(codes.PermissionDenied, "SSO user cannot modify email address")
+ }
if _, err := mail.ParseAddress(request.User.Email); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid email address %q", request.User.Email)
}
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 9ec0b6c83a..e39765f99b 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -44,3 +44,4 @@ export * from "./onboardingGuide";
export * from "./schemaEditor";
export * from "./dbSchema";
export * from "./idp";
+export * from "./user";
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
new file mode 100644
index 0000000000..480eb5a506
--- /dev/null
+++ b/frontend/src/store/modules/user.ts
@@ -0,0 +1,27 @@
+import { defineStore } from "pinia";
+import { authServiceClient } from "@/grpcweb";
+import { User } from "@/types/proto/v1/auth_service";
+
+interface UserState {
+ userMapByName: Map<string, User>;
+}
+
+export const useUserStore = defineStore("user", {
+ state: (): UserState => ({
+ userMapByName: new Map(),
+ }),
+ getters: {
+ userList(state) {
+ return Array.from(state.userMapByName.values());
+ },
+ },
+ actions: {
+ async fetchUser(name: string) {
+ const user = await authServiceClient().getUser({
+ name,
+ });
+ this.userMapByName.set(user.name, user);
+ return user;
+ },
+ },
+});
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 699a01eafb..a0b32d6c80 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -116,7 +116,7 @@
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-control-light">
- {{ $t("settings.profile.email") }}
+ {{ $t("settings.profile.email") }} {{ isSSOUser }}
</dt>
<dd class="mt-1 text-sm text-main">
<input
@@ -127,6 +127,7 @@
name="email"
type="text"
class="textfield"
+ :disabled="isSSOUser"
:value="state.editingPrincipal?.email"
@input="(e: any)=>updatePrincipal('email', e.target.value)"
/>
@@ -184,7 +185,7 @@
</main>
</template>
-<script lang="ts">
+<script lang="ts" setup>
import {
nextTick,
computed,
@@ -192,15 +193,18 @@ import {
onUnmounted,
reactive,
ref,
- defineComponent,
+ watch,
} from "vue";
-import cloneDeep from "lodash-es/cloneDeep";
-import isEmpty from "lodash-es/isEmpty";
-import isEqual from "lodash-es/isEqual";
-import PrincipalAvatar from "../components/PrincipalAvatar.vue";
+import { cloneDeep, isEmpty, isEqual } from "lodash-es";
import { PrincipalPatch } from "../types";
import { hasWorkspacePermission } from "../utils";
-import { featureToRef, useCurrentUser, usePrincipalStore } from "@/store";
+import {
+ featureToRef,
+ useCurrentUser,
+ usePrincipalStore,
+ useUserStore,
+} from "@/store";
+import PrincipalAvatar from "../components/PrincipalAvatar.vue";
interface LocalState {
editing: boolean;
@@ -208,128 +212,118 @@ interface LocalState {
passwordConfirm?: string;
}
-export default defineComponent({
- name: "ProfileDashboard",
- components: { PrincipalAvatar },
- props: {
- principalId: {
- type: String,
- default: undefined,
- },
- },
- setup(props) {
- const editNameTextField = ref();
+const props = defineProps<{
+ principalId?: string;
+}>();
- const principalStore = usePrincipalStore();
+const currentUser = useCurrentUser();
+const principalStore = usePrincipalStore();
+const userStore = useUserStore();
+const state = reactive<LocalState>({
+ editing: false,
+});
- const state = reactive<LocalState>({
- editing: false,
- });
+const editNameTextField = ref();
- const keyboardHandler = (e: KeyboardEvent) => {
- if (state.editing) {
- if (e.code == "Escape") {
- cancelEdit();
- } else if (e.code == "Enter" && e.metaKey) {
- if (allowSaveEdit.value) {
- saveEdit();
- }
- }
+const keyboardHandler = (e: KeyboardEvent) => {
+ if (state.editing) {
+ if (e.code == "Escape") {
+ cancelEdit();
+ } else if (e.code == "Enter" && e.metaKey) {
+ if (allowSaveEdit.value) {
+ saveEdit();
}
- };
+ }
+ }
+};
- onMounted(() => {
- document.addEventListener("keydown", keyboardHandler);
- });
+onMounted(async () => {
+ document.addEventListener("keydown", keyboardHandler);
+});
- onUnmounted(() => {
- document.removeEventListener("keydown", keyboardHandler);
- });
+onUnmounted(() => {
+ document.removeEventListener("keydown", keyboardHandler);
+});
- const currentUser = useCurrentUser();
+const hasRBACFeature = featureToRef("bb.feature.rbac");
- const hasRBACFeature = featureToRef("bb.feature.rbac");
+const principal = computed(() => {
+ if (props.principalId) {
+ return principalStore.principalById(parseInt(props.principalId));
+ }
+ return currentUser.value;
+});
- const principal = computed(() => {
- if (props.principalId) {
- return principalStore.principalById(parseInt(props.principalId));
- }
- return currentUser.value;
- });
+const passwordMismatch = computed(() => {
+ return (
+ !isEmpty(state.editingPrincipal?.password) &&
+ state.editingPrincipal?.password != state.passwordConfirm
+ );
+});
- const passwordMismatch = computed(() => {
- return (
- !isEmpty(state.editingPrincipal?.password) &&
- state.editingPrincipal?.password != state.passwordConfirm
- );
- });
+const isSSOUser = computed(() => {
+ const name = `users/${principal.value.id}`;
+ return userStore.userMapByName.get(name)?.identityProvider !== "";
+});
- // User can change her own info.
- // Besides, owner can also change anyone's info. This is for resetting password in case user forgets.
- const allowEdit = computed(() => {
- return (
- currentUser.value.id == principal.value.id ||
- hasWorkspacePermission(
- "bb.permission.workspace.manage-member",
- currentUser.value.role
- )
- );
- });
+// User can change her own info.
+// Besides, owner can also change anyone's info. This is for resetting password in case user forgets.
+const allowEdit = computed(() => {
+ return (
+ currentUser.value.id == principal.value.id ||
+ hasWorkspacePermission(
+ "bb.permission.workspace.manage-member",
+ currentUser.value.role
+ )
+ );
+});
- const allowSaveEdit = computed(() => {
- return (
- !isEqual(principal.value, state.editingPrincipal) &&
- (state.passwordConfirm == "" ||
- state.passwordConfirm == state.editingPrincipal?.password)
- );
- });
+const allowSaveEdit = computed(() => {
+ return (
+ !isEqual(principal.value, state.editingPrincipal) &&
+ (state.passwordConfirm == "" ||
+ state.passwordConfirm == state.editingPrincipal?.password)
+ );
+});
+
+const updatePrincipal = (field: string, value: string) => {
+ (state.editingPrincipal as any)[field] = value;
+};
- const updatePrincipal = (field: string, value: string) => {
- (state.editingPrincipal as any)[field] = value;
- };
+const editUser = () => {
+ const clone = cloneDeep(principal.value);
+ state.editingPrincipal = {
+ name: clone.name,
+ email: clone.email,
+ type: clone.type,
+ };
+ state.editing = true;
- const editUser = () => {
- const clone = cloneDeep(principal.value);
- state.editingPrincipal = {
- name: clone.name,
- email: clone.email,
- type: clone.type,
- };
- state.editing = true;
+ nextTick(() => editNameTextField.value.focus());
+};
- nextTick(() => editNameTextField.value.focus());
- };
+const cancelEdit = () => {
+ state.editingPrincipal = undefined;
+ state.editing = false;
+};
- const cancelEdit = () => {
+const saveEdit = () => {
+ principalStore
+ .patchPrincipal({
+ principalId: principal.value.id,
+ principalPatch: state.editingPrincipal!,
+ })
+ .then(() => {
state.editingPrincipal = undefined;
state.editing = false;
- };
-
- const saveEdit = () => {
- principalStore
- .patchPrincipal({
- principalId: principal.value.id,
- principalPatch: state.editingPrincipal!,
- })
- .then(() => {
- state.editingPrincipal = undefined;
- state.editing = false;
- });
- };
+ });
+};
- return {
- editNameTextField,
- state,
- hasRBACFeature,
- principal,
- allowEdit,
- allowSaveEdit,
- passwordMismatch,
- updatePrincipal,
- editUser,
- cancelEdit,
- saveEdit,
- };
+watch(
+ principal,
+ async () => {
+ await userStore.fetchUser(`users/${principal.value.id}`);
},
-});
+ { immediate: true }
+);
</script>