Skip to content

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

fix: export audit logs (#14328)

ecmadao760623addbd3
diff --git a/backend/api/v1/audit_log_service.go b/backend/api/v1/audit_log_service.go
index 36feefa769..1a39179391 100644
--- a/backend/api/v1/audit_log_service.go
+++ b/backend/api/v1/audit_log_service.go
@@ -55,7 +55,7 @@ func (s *AuditLogService) SearchAuditLogs(ctx context.Context, request *v1pb.Sea
offset, err := parseLimitAndOffset(&pageSize{
token: request.PageToken,
limit: int(request.PageSize),
- maximum: 1000,
+ maximum: 10000,
})
if err != nil {
return nil, err
@@ -100,6 +100,9 @@ func (s *AuditLogService) ExportAuditLogs(ctx context.Context, request *v1pb.Exp
if err := s.licenseService.IsFeatureEnabled(api.FeatureAuditLog); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
+ if request.Filter == "" {
+ return nil, status.Error(codes.InvalidArgument, "filter is required to export audit logs")
+ }
searchAuditLogsResult, err := s.SearchAuditLogs(ctx, &v1pb.SearchAuditLogsRequest{
Filter: request.Filter,
OrderBy: request.OrderBy,
diff --git a/frontend/src/components/DataExportButton.vue b/frontend/src/components/DataExportButton.vue
index 45186a1975..d76136b9aa 100644
--- a/frontend/src/components/DataExportButton.vue
+++ b/frontend/src/components/DataExportButton.vue
@@ -2,23 +2,28 @@
<NDropdown
trigger="hover"
:options="exportDropdownOptions"
- :disabled="viewMode === 'DRAWER'"
+ :disabled="viewMode === 'DRAWER' || disabled"
@select="tryExportViaDropdown"
>
- <NButton
- :quaternary="size === 'tiny'"
- :size="size"
- :loading="state.isRequesting"
- :disabled="state.isRequesting || disabled"
- @click="handleClickExportButton"
- >
- <template #icon>
- <heroicons-outline:download class="h-5 w-5" />
+ <NTooltip :disabled="!tooltip">
+ <template #trigger>
+ <NButton
+ :quaternary="size === 'tiny'"
+ :size="size"
+ :loading="state.isRequesting"
+ :disabled="state.isRequesting || disabled"
+ @click="handleClickExportButton"
+ >
+ <template #icon>
+ <heroicons-outline:download class="h-5 w-5" />
+ </template>
+ <span v-if="size !== 'tiny'">
+ {{ t("common.export") }}
+ </span>
+ </NButton>
</template>
- <span v-if="size !== 'tiny'">
- {{ t("common.export") }}
- </span>
- </NButton>
+ <span class="text-sm"> {{ tooltip }} </span>
+ </NTooltip>
</NDropdown>
<Drawer v-if="viewMode === 'DRAWER'" v-model:show="state.showDrawer">
@@ -115,6 +120,7 @@ import {
NFormItem,
NRadio,
NRadioGroup,
+ NTooltip,
} from "naive-ui";
import type { BinaryLike } from "node:crypto";
import { computed, reactive, ref, watch } from "vue";
@@ -145,11 +151,13 @@ const props = withDefaults(
supportFormats: ExportFormat[];
allowSpecifyRowCount?: boolean;
fileType: "zip" | "raw";
+ tooltip?: string;
}>(),
{
size: "small",
disabled: false,
allowSpecifyRowCount: false,
+ tooltip: undefined,
}
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index ad084bdceb..58d4fb7a89 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3053,6 +3053,7 @@
"no-logs": "No audit logs",
"audit-log-detail": "Audit Log Details",
"export-finished": "Export finished",
+ "export-tooltip": "Must select start time and end time within 30 days",
"table": {
"created-ts": "Time",
"created-time": "Created Time",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 0a0b2c1d9d..6ccca528d4 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3053,6 +3053,7 @@
"no-logs": "Sin registros de auditoría",
"audit-log-detail": "Detalles del registro de auditoría",
"export-finished": "Exportación finalizada",
+ "export-tooltip": "Debe seleccionar la hora de inicio y la hora de finalización dentro de los 30 días",
"table": {
"created-ts": "Hora",
"created-time": "Hora de creación",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 26aa9a9be9..99659ed15e 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3053,6 +3053,7 @@
"no-logs": "監査ログはまだありません",
"audit-log-detail": "監査の詳細",
"export-finished": "エクスポートが完了しました",
+ "export-tooltip": "30日以内に開始時間と終了時間を選択する必要があります",
"table": {
"created-ts": "時間",
"created-time": "作成時間",
@@ -3846,4 +3847,4 @@
"setup": {
"self": "設定"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 1e60639f50..f0c4f721b5 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2216,7 +2216,7 @@
"delete-success": "GitOps 连接已删除"
},
"masking-access": {
- "self": "数据访问",
+ "self": "数据管控",
"grant-access": "授予访问权限",
"revoke-access-title": "是否删除 {member} 的导出和查询访问权限?"
}
@@ -3053,6 +3053,7 @@
"no-logs": "暂无审计日志",
"audit-log-detail": "审计详情",
"export-finished": "导出完成",
+ "export-tooltip": "必须选择 30 天范围内的开始和结束日期",
"table": {
"created-ts": "时间",
"created-time": "创建时间",
diff --git a/frontend/src/store/modules/v1/auditLog.ts b/frontend/src/store/modules/v1/auditLog.ts
index 43c10df19e..76c59d0a0d 100644
--- a/frontend/src/store/modules/v1/auditLog.ts
+++ b/frontend/src/store/modules/v1/auditLog.ts
@@ -54,10 +54,15 @@ export const useAuditLogStore = defineStore("audit_log", () => {
return resp;
};
- const exportAuditLogs = async (
- search: SearchAuditLogsParams,
- format: ExportFormat
- ): Promise<{
+ const exportAuditLogs = async ({
+ search,
+ format,
+ pageSize,
+ }: {
+ search: SearchAuditLogsParams;
+ format: ExportFormat;
+ pageSize: number;
+ }): Promise<{
content: BinaryLike | Blob;
nextPageToken: string;
}> => {
@@ -66,7 +71,7 @@ export const useAuditLogStore = defineStore("audit_log", () => {
filter: buildFilter(search),
orderBy: search.order ? `create_time ${search.order}` : undefined,
format,
- pageSize: 1000,
+ pageSize,
});
};
diff --git a/frontend/src/types/proto/v1/audit_log_service.ts b/frontend/src/types/proto/v1/audit_log_service.ts
index 9102c764e4..b5578889b5 100644
--- a/frontend/src/types/proto/v1/audit_log_service.ts
+++ b/frontend/src/types/proto/v1/audit_log_service.ts
@@ -38,7 +38,7 @@ export interface SearchAuditLogsRequest {
* The maximum number of logs to return.
* The service may return fewer than this value.
* If unspecified, at most 100 log entries will be returned.
- * The maximum value is 1000; values above 1000 will be coerced to 1000.
+ * The maximum value is 10000; values above 10000 will be coerced to 10000.
*/
pageSize: number;
/**
@@ -83,7 +83,7 @@ export interface ExportAuditLogsRequest {
* The maximum number of logs to return.
* The service may return fewer than this value.
* If unspecified, at most 100 log entries will be returned.
- * The maximum value is 1000; values above 1000 will be coerced to 1000.
+ * The maximum value is 10000; values above 10000 will be coerced to 10000.
*/
pageSize: number;
/**
diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vue
index 333a162e0d..c1726b27d3 100644
--- a/frontend/src/views/SettingWorkspaceAuditLog.vue
+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue
@@ -1,5 +1,5 @@
<template>
- <div class="w-full space-y-4">
+ <div class="w-full space-y-4 pb-6">
<FeatureAttention feature="bb.feature.audit-log" />
<AuditLogSearch v-model:params="state.params">
<template #searchbox-suffix>
@@ -11,7 +11,8 @@
ExportFormat.JSON,
ExportFormat.XLSX,
]"
- :disabled="!hasAuditLogFeature"
+ :tooltip="disableExportTip"
+ :disabled="!hasAuditLogFeature || !!disableExportTip"
@export="handleExport"
/>
</template>
@@ -20,7 +21,7 @@
v-if="hasAuditLogFeature"
:search-audit-logs="searchAuditLogs"
session-key="bb.page-audit-log-table.settings-audit-log-v1-table"
- :page-size="10"
+ :page-size="1000"
>
<template #table="{ list }">
<AuditLogDataTable key="audit-log-table" :audit-log-list="list" />
@@ -76,6 +77,23 @@ const searchAuditLogs = computed((): SearchAuditLogsParams => {
};
});
+const disableExportTip = computed(() => {
+ if (
+ !searchAuditLogs.value.createdTsAfter ||
+ !searchAuditLogs.value.createdTsBefore
+ ) {
+ return t("audit-log.export-tooltip");
+ }
+ if (
+ searchAuditLogs.value.createdTsBefore -
+ searchAuditLogs.value.createdTsAfter >
+ 30 * 24 * 60 * 60 * 1000
+ ) {
+ return t("audit-log.export-tooltip");
+ }
+ return "";
+});
+
const handleExport = async (
options: ExportOption,
callback: (content: BinaryLike | Blob, filename: string) => void
@@ -85,10 +103,11 @@ const handleExport = async (
while (i === 0 || pageToken !== "") {
i++;
- const { content, nextPageToken } = await auditLogStore.exportAuditLogs(
- searchAuditLogs.value,
- options.format
- );
+ const { content, nextPageToken } = await auditLogStore.exportAuditLogs({
+ search: searchAuditLogs.value,
+ format: options.format,
+ pageSize: 10000,
+ });
pageToken = nextPageToken;
callback(
content,
diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vue
index 5f8e849f7e..1cc4155d39 100644
--- a/frontend/src/views/project/ProjectAuditLogDashboard.vue
+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue
@@ -14,7 +14,8 @@
ExportFormat.JSON,
ExportFormat.XLSX,
]"
- :disabled="!hasAuditLogFeature"
+ :tooltip="disableExportTip"
+ :disabled="!hasAuditLogFeature || !!disableExportTip"
@export="handleExport"
/>
</template>
@@ -24,7 +25,7 @@
v-if="hasAuditLogFeature"
:search-audit-logs="searchAuditLogs"
:session-key="`bb.page-audit-log-table.settings-audit-log-v1-table.${projectId}`"
- :page-size="10"
+ :page-size="1000"
>
<template #table="{ list }">
<AuditLogDataTable
@@ -96,6 +97,23 @@ const searchAuditLogs = computed((): SearchAuditLogsParams => {
};
});
+const disableExportTip = computed(() => {
+ if (
+ !searchAuditLogs.value.createdTsAfter ||
+ !searchAuditLogs.value.createdTsBefore
+ ) {
+ return t("audit-log.export-tooltip");
+ }
+ if (
+ searchAuditLogs.value.createdTsBefore -
+ searchAuditLogs.value.createdTsAfter >
+ 30 * 24 * 60 * 60 * 1000
+ ) {
+ return t("audit-log.export-tooltip");
+ }
+ return "";
+});
+
const handleExport = async (
options: ExportOption,
callback: (content: BinaryLike | Blob, filename: string) => void
@@ -105,10 +123,11 @@ const handleExport = async (
while (i === 0 || pageToken !== "") {
i++;
- const { content, nextPageToken } = await auditLogStore.exportAuditLogs(
- searchAuditLogs.value,
- options.format
- );
+ const { content, nextPageToken } = await auditLogStore.exportAuditLogs({
+ search: searchAuditLogs.value,
+ format: options.format,
+ pageSize: 10000,
+ });
pageToken = nextPageToken;
callback(
content,
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index ad833f4986..832ed491f0 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -10204,7 +10204,7 @@ components:
The maximum number of logs to return.
The service may return fewer than this value.
If unspecified, at most 100 log entries will be returned.
- The maximum value is 1000; values above 1000 will be coerced to 1000.
+ The maximum value is 10000; values above 10000 will be coerced to 10000.
format: int32
pageToken:
type: string
@@ -13497,7 +13497,7 @@ components:
The maximum number of logs to return.
The service may return fewer than this value.
If unspecified, at most 100 log entries will be returned.
- The maximum value is 1000; values above 1000 will be coerced to 1000.
+ The maximum value is 10000; values above 10000 will be coerced to 10000.
format: int32
pageToken:
type: string
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index afab881e6a..d2db48bfe1 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -5434,7 +5434,7 @@ The type of action performed on a Binding in a policy.
| filter | [string](#string) | | The filter of the log. It should be a valid CEL expression. For example: - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39; &amp;&amp; user == &#39;users/[email protected]&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39; &amp;&amp; create_time &lt;= &#39;2021-01-01T00:00:00Z&#39; &amp;&amp; create_time &gt;= &#39;2020-01-01T00:00:00Z&#39;&#34; |
| order_by | [string](#string) | | The order by of the log. Only support order by create_time. For example: - order_by = &#34;create_time asc&#34; - order_by = &#34;create_time desc&#34; |
| format | [ExportFormat](#bytebase-v1-ExportFormat) | | The export format. |
-| page_size | [int32](#int32) | | The maximum number of logs to return. The service may return fewer than this value. If unspecified, at most 100 log entries will be returned. The maximum value is 1000; values above 1000 will be coerced to 1000. |
+| page_size | [int32](#int32) | | The maximum number of logs to return. The service may return fewer than this value. If unspecified, at most 100 log entries will be returned. The maximum value is 10000; values above 10000 will be coerced to 10000. |
| page_token | [string](#string) | | A page token, received from a previous `ExportAuditLogs` call. Provide this to retrieve the subsequent page. |
@@ -5485,7 +5485,7 @@ Metadata about the request.
| parent | [string](#string) | | |
| filter | [string](#string) | | The filter of the log. It should be a valid CEL expression. For example: - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39; &amp;&amp; user == &#39;users/[email protected]&#39;&#34; - filter = &#34;method == &#39;/bytebase.v1.SQLService/Query&#39; &amp;&amp; severity == &#39;ERROR&#39; &amp;&amp; create_time &lt;= &#39;2021-01-01T00:00:00Z&#39; &amp;&amp; create_time &gt;= &#39;2020-01-01T00:00:00Z&#39;&#34; |
| order_by | [string](#string) | | The order by of the log. Only support order by create_time. For example: - order_by = &#34;create_time asc&#34; - order_by = &#34;create_time desc&#34; |
-| page_size | [int32](#int32) | | The maximum number of logs to return. The service may return fewer than this value. If unspecified, at most 100 log entries will be returned. The maximum value is 1000; values above 1000 will be coerced to 1000. |
+| page_size | [int32](#int32) | | The maximum number of logs to return. The service may return fewer than this value. If unspecified, at most 100 log entries will be returned. The maximum value is 10000; values above 10000 will be coerced to 10000. |
| page_token | [string](#string) | | A page token, received from a previous `SearchLogs` call. Provide this to retrieve the subsequent page. |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index a7057e759f..40c0168c67 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -15577,7 +15577,7 @@ For example:
<td><p>The maximum number of logs to return.
The service may return fewer than this value.
If unspecified, at most 100 log entries will be returned.
-The maximum value is 1000; values above 1000 will be coerced to 1000. </p></td>
+The maximum value is 10000; values above 10000 will be coerced to 10000. </p></td>
</tr>
<tr>
@@ -15707,7 +15707,7 @@ For example:
<td><p>The maximum number of logs to return.
The service may return fewer than this value.
If unspecified, at most 100 log entries will be returned.
-The maximum value is 1000; values above 1000 will be coerced to 1000. </p></td>
+The maximum value is 10000; values above 10000 will be coerced to 10000. </p></td>
</tr>
<tr>
diff --git a/proto/generated-go/v1/audit_log_service.pb.go b/proto/generated-go/v1/audit_log_service.pb.go
index b556436850..b4a0381cff 100644
--- a/proto/generated-go/v1/audit_log_service.pb.go
+++ b/proto/generated-go/v1/audit_log_service.pb.go
@@ -113,7 +113,7 @@ type SearchAuditLogsRequest struct {
// The maximum number of logs to return.
// The service may return fewer than this value.
// If unspecified, at most 100 log entries will be returned.
- // The maximum value is 1000; values above 1000 will be coerced to 1000.
+ // The maximum value is 10000; values above 10000 will be coerced to 10000.
PageSize int32 `protobuf:"varint,3,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
// A page token, received from a previous `SearchLogs` call.
// Provide this to retrieve the subsequent page.
@@ -265,7 +265,7 @@ type ExportAuditLogsRequest struct {
// The maximum number of logs to return.
// The service may return fewer than this value.
// If unspecified, at most 100 log entries will be returned.
- // The maximum value is 1000; values above 1000 will be coerced to 1000.
+ // The maximum value is 10000; values above 10000 will be coerced to 10000.
PageSize int32 `protobuf:"varint,5,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
// A page token, received from a previous `ExportAuditLogs` call.
// Provide this to retrieve the subsequent page.
diff --git a/proto/v1/audit_log_service.proto b/proto/v1/audit_log_service.proto
index 5c7db1de1b..459ea9e282 100644
--- a/proto/v1/audit_log_service.proto
+++ b/proto/v1/audit_log_service.proto
@@ -65,7 +65,7 @@ message SearchAuditLogsRequest {
// The maximum number of logs to return.
// The service may return fewer than this value.
// If unspecified, at most 100 log entries will be returned.
- // The maximum value is 1000; values above 1000 will be coerced to 1000.
+ // The maximum value is 10000; values above 10000 will be coerced to 10000.
int32 page_size = 3;
// A page token, received from a previous `SearchLogs` call.
@@ -109,7 +109,7 @@ message ExportAuditLogsRequest {
// The maximum number of logs to return.
// The service may return fewer than this value.
// If unspecified, at most 100 log entries will be returned.
- // The maximum value is 1000; values above 1000 will be coerced to 1000.
+ // The maximum value is 10000; values above 10000 will be coerced to 10000.
int32 page_size = 5;
// A page token, received from a previous `ExportAuditLogs` call.