Skip to content

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

fix(frontend): find every actor kind in the audit log actor filter

Vincent Huang0df5eef91125
diff --git a/frontend/src/components/AuditLogTable.test.tsx b/frontend/src/components/AuditLogTable.test.tsx
index 65bcccbb73..52284b8c46 100644
--- a/frontend/src/components/AuditLogTable.test.tsx
+++ b/frontend/src/components/AuditLogTable.test.tsx
@@ -1,10 +1,13 @@
import { create } from "@bufbuild/protobuf";
import { timestampFromMs, anyPack } from "@bufbuild/protobuf/wkt";
+import { fireEvent, within } from "@testing-library/react";
import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import type { ScopeOption } from "@/components/AdvancedSearch";
import { TIMESTAMP_COLUMN_WIDTH } from "@/components/timestampColumn";
+import { DEBOUNCE_SEARCH_DELAY } from "@/types/common";
import { StatusSchema } from "@/types/proto-es/google/rpc/status_pb";
import {
AuditLog_Severity,
@@ -16,6 +19,11 @@ import { PermissionDeniedDetailSchema } from "@/types/proto-es/v1/common_pb";
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
+interface ListActorParams {
+ parent?: string;
+ filter?: { query?: string };
+}
+
const mocks = vi.hoisted(() => ({
searchAuditLogs: vi.fn(),
exportAuditLogs: vi.fn(),
@@ -23,17 +31,23 @@ const mocks = vi.hoisted(() => ({
pushNotification: vi.fn(),
usePlanFeature: vi.fn(() => true),
listUsers: vi.fn(
- async (): Promise<{
+ async (
+ _params?: ListActorParams
+ ): Promise<{
users: Array<{ name: string; email: string; title: string }>;
}> => ({ users: [] })
),
listServiceAccounts: vi.fn(
- async (): Promise<{
+ async (
+ _params?: ListActorParams
+ ): Promise<{
serviceAccounts: Array<{ name: string; email: string; title: string }>;
}> => ({ serviceAccounts: [] })
),
listWorkloadIdentities: vi.fn(
- async (): Promise<{
+ async (
+ _params?: ListActorParams
+ ): Promise<{
workloadIdentities: Array<{ name: string; email: string; title: string }>;
}> => ({ workloadIdentities: [] })
),
@@ -160,6 +174,52 @@ const renderIntoContainer = (element: ReactElement) => {
};
};
+const ACTORS = {
+ user: {
+ name: "users/[email protected]",
+ email: "[email protected]",
+ title: "Alice",
+ },
+ serviceAccount: {
+ name: "serviceAccounts/[email protected]",
+ email: "[email protected]",
+ title: "Deploy",
+ },
+ workloadIdentity: {
+ name: "workloadIdentities/[email protected]",
+ email: "[email protected]",
+ title: "CI",
+ },
+};
+
+// Mirrors the server's filter: a case-insensitive contains match on the
+// display name or the email, never on the resource name.
+const matchesQuery =
+ (params?: ListActorParams) =>
+ ({ email, title }: { email: string; title: string }) => {
+ const query = params?.filter?.query?.toLowerCase() ?? "";
+ return (
+ email.toLowerCase().includes(query) || title.toLowerCase().includes(query)
+ );
+ };
+
+const seedActors = () => {
+ mocks.listUsers.mockImplementation(async (params) => ({
+ users: [ACTORS.user].filter(matchesQuery(params)),
+ }));
+ mocks.listServiceAccounts.mockImplementation(async (params) => ({
+ serviceAccounts: [ACTORS.serviceAccount].filter(matchesQuery(params)),
+ }));
+ mocks.listWorkloadIdentities.mockImplementation(async (params) => ({
+ workloadIdentities: [ACTORS.workloadIdentity].filter(matchesQuery(params)),
+ }));
+};
+
+const getActorScope = () =>
+ (mocks.scopeOptions.value as ScopeOption[]).find(
+ (scope) => scope.id === "actor"
+ );
+
beforeEach(async () => {
vi.clearAllMocks();
({ AuditLogTable } = await import("./AuditLogTable"));
@@ -210,60 +270,117 @@ describe("AuditLogTable", () => {
unmount();
});
- test("searches only the matching special-account kind for a prefixed actor", async () => {
+ test.each([
+ ACTORS.user,
+ ACTORS.serviceAccount,
+ ACTORS.workloadIdentity,
+ ])("finds $name typed into the actor search box", async (actor) => {
+ vi.useFakeTimers();
+ seedActors();
mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
- mocks.listServiceAccounts.mockResolvedValue({
- serviceAccounts: [
- {
- name: "serviceAccounts/[email protected]",
- email: "[email protected]",
- title: "Deploy",
- },
- ],
+ const { AdvancedSearch } = await vi.importActual<
+ typeof import("@/components/AdvancedSearch")
+ >("@/components/AdvancedSearch");
+
+ const table = renderIntoContainer(
+ <AuditLogTable parent="projects/-" canExport={false} />
+ );
+ await table.render();
+ const search = renderIntoContainer(
+ <AdvancedSearch
+ params={{ query: "", scopes: [] }}
+ scopeOptions={mocks.scopeOptions.value as ScopeOption[]}
+ onParamsChange={() => {}}
+ />
+ );
+ await search.render();
+
+ const box = within(search.container);
+ fireEvent.click(box.getByRole("textbox"));
+ fireEvent.click(box.getByText("actor"));
+ fireEvent.change(box.getByRole("textbox"), {
+ target: { value: `actor:${actor.name}` },
});
- mocks.listWorkloadIdentities.mockResolvedValue({
- workloadIdentities: [
- {
- name: "workloadIdentities/[email protected]",
- email: "[email protected]",
- title: "CI",
- },
- ],
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(DEBOUNCE_SEARCH_DELAY);
});
+ expect(box.getByTitle(actor.name)).toBeInstanceOf(HTMLElement);
+ expect(mocks.listUsers).toHaveBeenLastCalledWith(
+ expect.objectContaining({ filter: { query: actor.email } })
+ );
+
+ search.unmount();
+ table.unmount();
+ });
+
+ test("lists every actor kind for an empty keyword", async () => {
+ seedActors();
+ mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
+
const { render, unmount } = renderIntoContainer(
<AuditLogTable parent="projects/project-a" canExport={false} />
);
await render();
+ const options = await getActorScope()?.onSearch?.("");
+
+ // The fake lists the same accounts under the workspace and the project.
+ expect(options?.map((option) => option.value)).toEqual([
+ ACTORS.user.name,
+ ACTORS.serviceAccount.name,
+ ACTORS.workloadIdentity.name,
+ ]);
+ expect(mocks.listServiceAccounts).toHaveBeenCalledTimes(2);
+ expect(mocks.listWorkloadIdentities).toHaveBeenCalledTimes(2);
- const actorScope = (
- mocks.scopeOptions.value as Array<{
- id: string;
- onSearch?: (keyword: string) => Promise<Array<{ value: string }>>;
- }>
- ).find((scope) => scope.id === "actor");
- const serviceAccounts = await actorScope?.onSearch?.(
- "serviceAccounts/deploy"
+ unmount();
+ });
+
+ test("matches a resource prefix in any case", async () => {
+ seedActors();
+ mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
+
+ const { render, unmount } = renderIntoContainer(
+ <AuditLogTable parent="projects/-" canExport={false} />
+ );
+ await render();
+ const options = await getActorScope()?.onSearch?.(
+ "ServiceAccounts/[email protected]"
);
- expect(serviceAccounts).toEqual([
- expect.objectContaining({
- value: "serviceAccounts/[email protected]",
- }),
+ expect(options?.map((option) => option.value)).toEqual([
+ ACTORS.serviceAccount.name,
]);
- expect(mocks.listUsers).not.toHaveBeenCalled();
- expect(mocks.listWorkloadIdentities).not.toHaveBeenCalled();
- const workloadIdentities = await actorScope?.onSearch?.(
- "workloadIdentities/ci"
+ unmount();
+ });
+
+ test("keeps the other actor kinds when one list fails", async () => {
+ seedActors();
+ mocks.listWorkloadIdentities.mockRejectedValueOnce(new Error("denied"));
+ mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
+
+ const { render, unmount } = renderIntoContainer(
+ <AuditLogTable parent="projects/-" canExport={false} />
);
- expect(workloadIdentities).toEqual([
- expect.objectContaining({
- value: "workloadIdentities/[email protected]",
- }),
+ await render();
+ const options = await getActorScope()?.onSearch?.("");
+
+ expect(options?.map((option) => option.value)).toEqual([
+ ACTORS.user.name,
+ ACTORS.serviceAccount.name,
]);
- expect(mocks.listUsers).not.toHaveBeenCalled();
+ unmount();
+ });
+
+ test("filters a service account actor by its name and its legacy user name", async () => {
+ mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
+
+ const { render, unmount } = renderIntoContainer(
+ <AuditLogTable parent="projects/-" canExport={false} />
+ );
+ await render();
await act(async () => {
(
mocks.onSearchParamsChange.value as
@@ -274,15 +391,11 @@ describe("AuditLogTable", () => {
| undefined
)?.({
query: "",
- scopes: [
- {
- id: "actor",
- value: "serviceAccounts/[email protected]",
- },
- ],
+ scopes: [{ id: "actor", value: ACTORS.serviceAccount.name }],
});
await Promise.resolve();
});
+
expect(mocks.searchAuditLogs).toHaveBeenLastCalledWith(
expect.objectContaining({
filter:
@@ -293,40 +406,6 @@ describe("AuditLogTable", () => {
unmount();
});
- test("falls back to users for an unprefixed actor", async () => {
- mocks.searchAuditLogs.mockResolvedValue({ auditLogs: [], nextPageToken: "" });
- mocks.listUsers.mockResolvedValue({
- users: [
- {
- name: "users/[email protected]",
- email: "[email protected]",
- title: "Alice",
- },
- ],
- });
-
- const { render, unmount } = renderIntoContainer(
- <AuditLogTable parent="projects/project-a" canExport={false} />
- );
- await render();
-
- const actorScope = (
- mocks.scopeOptions.value as Array<{
- id: string;
- onSearch?: (keyword: string) => Promise<Array<{ value: string }>>;
- }>
- ).find((scope) => scope.id === "actor");
- const users = await actorScope?.onSearch?.("alice");
-
- expect(users).toEqual([
- expect.objectContaining({ value: "users/[email protected]" }),
- ]);
- expect(mocks.listServiceAccounts).not.toHaveBeenCalled();
- expect(mocks.listWorkloadIdentities).not.toHaveBeenCalled();
-
- unmount();
- });
-
test("renders a special-account actor as its full principal name", async () => {
mocks.searchAuditLogs.mockResolvedValue({
auditLogs: [
diff --git a/frontend/src/components/AuditLogTable.tsx b/frontend/src/components/AuditLogTable.tsx
index 2de125fabc..5ad7fa08cc 100644
--- a/frontend/src/components/AuditLogTable.tsx
+++ b/frontend/src/components/AuditLogTable.tsx
@@ -94,6 +94,22 @@ function uniqueValueOptions(options: ValueOption[]): ValueOption[] {
return [...new Map(options.map((option) => [option.value, option])).values()];
}
+// Strips an actor name's resource prefix, since the account lists match on
+// email. Ignores case because AdvancedSearch lowercases the keyword.
+const ACTOR_NAME_PREFIX = new RegExp(
+ `^(?:${userNamePrefix}|${serviceAccountNamePrefix}|${workloadIdentityNamePrefix})`,
+ "i"
+);
+
+function toActorOptions(
+ accounts: Array<{ name: string; email: string; title: string }>
+): ValueOption[] {
+ return accounts.map((account) => ({
+ value: account.name,
+ keywords: [account.email, account.title],
+ }));
+}
+
function buildFilterString(filter: AuditLogFilter): string {
const parts: string[] = [];
if (filter.method) parts.push(`method == ${celString(filter.method)}`);
@@ -811,80 +827,54 @@ export function AuditLogTable({
);
const searchActors = useCallback(
async (keyword: string): Promise<ValueOption[]> => {
- const query = keyword.trim();
+ const query = keyword.trim().replace(ACTOR_NAME_PREFIX, "");
const pageSize = getDefaultPagination();
- const accountParams = (parent: string, filter: string) => ({
+ const accountParams = (parent: string) => ({
parent,
pageSize,
showDeleted: false,
- filter: { query: filter },
+ filter: { query },
skipCache: true,
});
+ const accountParents = (
+ canListInWorkspace: boolean,
+ canListInProject: boolean
+ ) => [
+ ...(workspaceResourceName && canListInWorkspace
+ ? [workspaceResourceName]
+ : []),
+ ...(projectAccountParent && canListInProject
+ ? [projectAccountParent]
+ : []),
+ ];
- if (query.startsWith(serviceAccountNamePrefix)) {
- const accountQuery = query.slice(serviceAccountNamePrefix.length);
- const serviceAccounts = await Promise.all([
- ...(workspaceResourceName && canListWorkspaceServiceAccounts
- ? [
- listServiceAccounts(
- accountParams(workspaceResourceName, accountQuery)
- ),
- ]
- : []),
- ...(projectAccountParent && canListProjectServiceAccounts
- ? [
- listServiceAccounts(
- accountParams(projectAccountParent, accountQuery)
- ),
- ]
- : []),
- ]);
- return uniqueValueOptions(
- serviceAccounts.flatMap((result) =>
- result.serviceAccounts.map((account) => ({
- value: account.name,
- keywords: [account.email, account.title],
- }))
+ const results = await Promise.allSettled([
+ listUsers({
+ pageSize,
+ filter: query ? { query } : undefined,
+ }).then(({ users }) => toActorOptions(users)),
+ ...accountParents(
+ canListWorkspaceServiceAccounts,
+ canListProjectServiceAccounts
+ ).map((parent) =>
+ listServiceAccounts(accountParams(parent)).then(
+ ({ serviceAccounts }) => toActorOptions(serviceAccounts)
)
- );
- }
-
- if (query.startsWith(workloadIdentityNamePrefix)) {
- const identityQuery = query.slice(workloadIdentityNamePrefix.length);
- const workloadIdentities = await Promise.all([
- ...(workspaceResourceName && canListWorkspaceWorkloadIdentities
- ? [
- listWorkloadIdentities(
- accountParams(workspaceResourceName, identityQuery)
- ),
- ]
- : []),
- ...(projectAccountParent && canListProjectWorkloadIdentities
- ? [
- listWorkloadIdentities(
- accountParams(projectAccountParent, identityQuery)
- ),
- ]
- : []),
- ]);
- return uniqueValueOptions(
- workloadIdentities.flatMap((result) =>
- result.workloadIdentities.map((identity) => ({
- value: identity.name,
- keywords: [identity.email, identity.title],
- }))
+ ),
+ ...accountParents(
+ canListWorkspaceWorkloadIdentities,
+ canListProjectWorkloadIdentities
+ ).map((parent) =>
+ listWorkloadIdentities(accountParams(parent)).then(
+ ({ workloadIdentities }) => toActorOptions(workloadIdentities)
)
- );
- }
-
- const { users } = await listUsers({
- pageSize,
- filter: query ? { query } : undefined,
- });
- return users.map((user) => ({
- value: user.name,
- keywords: [user.email, user.title],
- }));
+ ),
+ ]);
+ return uniqueValueOptions(
+ results.flatMap((result) =>
+ result.status === "fulfilled" ? result.value : []
+ )
+ );
},
[
listUsers,
diff --git a/frontend/src/components/ui/column-resize-handle.tsx b/frontend/src/components/ui/column-resize-handle.tsx
index 1bcc1e6d94..4711620165 100644
--- a/frontend/src/components/ui/column-resize-handle.tsx
+++ b/frontend/src/components/ui/column-resize-handle.tsx
@@ -7,7 +7,9 @@ interface ColumnResizeHandleProps {
/**
* Drag affordance for resizing a table column. Designed to be absolutely
- * positioned inside a `relative` `<th>`.
+ * positioned inside a `relative` `<th>`. Its z-index only lifts it above the
+ * cell's own content: inline popups such as the AdvancedSearch menu share the
+ * page's stacking context at `LAYER_SURFACE_CLASS` and must cover it.
*/
export function ColumnResizeHandle({
onMouseDown,
@@ -16,7 +18,7 @@ export function ColumnResizeHandle({
return (
<div
className={cn(
- "group absolute right-0 top-0 z-10 h-full w-3 cursor-col-resize",
+ "group absolute right-0 top-0 z-1 h-full w-3 cursor-col-resize",
className
)}
onMouseDown={onMouseDown}
diff --git a/frontend/src/components/ui/table.test.tsx b/frontend/src/components/ui/table.test.tsx
index d631cca54c..ba66a238c7 100644
--- a/frontend/src/components/ui/table.test.tsx
+++ b/frontend/src/components/ui/table.test.tsx
@@ -1,5 +1,6 @@
import { describe, expect, test } from "vitest";
import { ColumnResizeHandle } from "./column-resize-handle";
+import { LAYER_SURFACE_CLASS } from "./layer";
import { TableBody, TableEmptyView, TableRow } from "./table";
describe("table primitives", () => {
@@ -57,8 +58,17 @@ describe("table primitives", () => {
expect(element.props.className).toContain("right-0");
expect(element.props.className).not.toContain("right-[-6px]");
expect(element.props.className).toContain("w-3");
- expect(element.props.className).toContain("z-10");
expect(element.props.children.props.className).toContain("right-0");
expect(element.props.children.props.className).toContain("w-0.5");
});
+
+ test("ColumnResizeHandle stacks below popup surfaces", () => {
+ const zIndexOf = (className: string) =>
+ Number(/\bz-(\d+)\b/.exec(className)?.[1]);
+ const element = ColumnResizeHandle({ onMouseDown: () => {} });
+
+ expect(zIndexOf(element.props.className)).toBeLessThan(
+ zIndexOf(LAYER_SURFACE_CLASS)
+ );
+ });
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 8c9c648402..8a133fa328 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -79,7 +79,7 @@
"advanced-search": {
"scope": {
"actor": {
- "description": "Search users by email. Prefix with serviceAccounts/ or workloadIdentities/ to search those actors.",
+ "description": "Search users, service accounts, and workload identities by name or email",
"title": "Actor"
},
"level": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index eacd30aa51..f827005433 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -79,7 +79,7 @@
"advanced-search": {
"scope": {
"actor": {
- "description": "Busca usuarios por correo electrónico. Usa el prefijo serviceAccounts/ o workloadIdentities/ para buscar esos actores.",
+ "description": "Buscar usuarios, cuentas de servicio e identidades de carga de trabajo por nombre o correo electrónico",
"title": "Actor"
},
"level": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 795e674d0b..98dba6345a 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -79,7 +79,7 @@
"advanced-search": {
"scope": {
"actor": {
- "description": "メールアドレスでユーザーを検索します。サービスアカウントまたはワークロード ID を検索するには、serviceAccounts/ または workloadIdentities/ を付けます。",
+ "description": "名前またはメールアドレスでユーザー、サービスアカウント、ワークロードIDを検索",
"title": "操作者"
},
"level": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 0a8d72e01d..1969147d2e 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -79,7 +79,7 @@
"advanced-search": {
"scope": {
"actor": {
- "description": "Tìm người dùng theo email. Thêm tiền tố serviceAccounts/ hoặc workloadIdentities/ để tìm các tác nhân đó.",
+ "description": "Tìm kiếm người dùng, tài khoản dịch vụ và danh tính workload theo tên hoặc email",
"title": "Người thực hiện"
},
"level": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 7a2e0a9ef4..1e737743c8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -79,7 +79,7 @@
"advanced-search": {
"scope": {
"actor": {
- "description": "按邮箱搜索用户。使用 serviceAccounts/ 或 workloadIdentities/ 前缀搜索这些操作者。",
+ "description": "按名称或邮箱搜索用户、服务账号和工作负载身份",
"title": "操作者"
},
"level": {