From e85b7c7128cd88ec46bc82cafcfdf1933173c08a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 25 May 2023 08:56:38 +0200 Subject: [PATCH] audit log redacted in CE (#1645) * auditLogOnEE * audit logs --- backend/windmill-api/src/lib.rs | 4 +-- backend/windmill-audit/src/lib.rs | 13 ++++++++-- frontend/src/lib/components/CliHelpBox.svelte | 7 ++--- frontend/src/lib/stores.ts | 3 ++- .../(root)/(logged)/audit_logs/+page.svelte | 9 ++++++- frontend/src/routes/(root)/+layout.svelte | 26 ++++++++++++++++--- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/backend/windmill-api/src/lib.rs b/backend/windmill-api/src/lib.rs index 7e87fdf8c7..a216695951 100644 --- a/backend/windmill-api/src/lib.rs +++ b/backend/windmill-api/src/lib.rs @@ -220,12 +220,12 @@ async fn git_v() -> String { format!("CE {GIT_VERSION}") } -#[cfg(feature = "enterprise")] +#[cfg(not(feature = "enterprise"))] async fn ee_license() -> &'static str { "" } -#[cfg(not(feature = "enterprise"))] +#[cfg(feature = "enterprise")] async fn ee_license() -> String { LICENSE_KEY .as_ref() diff --git a/backend/windmill-audit/src/lib.rs b/backend/windmill-audit/src/lib.rs index 9f18ad03ed..34308d3ccb 100644 --- a/backend/windmill-audit/src/lib.rs +++ b/backend/windmill-audit/src/lib.rs @@ -50,8 +50,15 @@ pub async fn audit_log<'c, E: sqlx::Executor<'c, Database = Postgres>>( resource: Option<&str>, parameters: Option>, ) -> Result<()> { + #[cfg(feature = "enterprise")] let p_json: serde_json::Value = serde_json::to_value(¶meters).unwrap(); + #[cfg(not(feature = "enterprise"))] + let p_json: serde_json::Value = serde_json::json!({"redacted": "-"}); + + #[cfg(not(feature = "enterprise"))] + let resource: Option<&str> = Some("EE only"); + tracing::info!( operation = operation, action_kind = ?action_kind, @@ -60,10 +67,11 @@ pub async fn audit_log<'c, E: sqlx::Executor<'c, Database = Postgres>>( workspace_id = w_id, username = username, ); + sqlx::query( "INSERT INTO audit - (workspace_id, username, operation, action_kind, resource, parameters) - VALUES ($1, $2, $3, $4, $5, $6)", + (workspace_id, username, operation, action_kind, resource, parameters) + VALUES ($1, $2, $3, $4, $5, $6)", ) .bind(w_id) .bind(username) @@ -73,6 +81,7 @@ pub async fn audit_log<'c, E: sqlx::Executor<'c, Database = Postgres>>( .bind(p_json) .execute(db) .await?; + Ok(()) } diff --git a/frontend/src/lib/components/CliHelpBox.svelte b/frontend/src/lib/components/CliHelpBox.svelte index bb74675e5e..d03a800a03 100644 --- a/frontend/src/lib/components/CliHelpBox.svelte +++ b/frontend/src/lib/components/CliHelpBox.svelte @@ -1,15 +1,12 @@ @@ -41,7 +38,7 @@ >
  • Setup the wmill cli for this workspace & remote:
  • Follow the prompts in your terminal
  • diff --git a/frontend/src/lib/stores.ts b/frontend/src/lib/stores.ts index a3e1e7ac60..1036b261bb 100644 --- a/frontend/src/lib/stores.ts +++ b/frontend/src/lib/stores.ts @@ -18,6 +18,7 @@ export interface UserExt { let persistedWorkspace = BROWSER && localStorage.getItem('workspace') +export const enterpriseLicense = writable(undefined) export const workerTags = writable(undefined) export const usageStore = writable(0) export const runFormStore = writable() @@ -40,7 +41,7 @@ export const userWorkspaces: Readable< const originalWorkspaces = store?.workspaces ?? [] if (superadmin) { return [ - ...originalWorkspaces.filter((x) => x.id != 'starter' && x.id != 'admins'), + ...originalWorkspaces.filter((x) => x.id != 'admins'), { id: 'admins', name: 'Admins', diff --git a/frontend/src/routes/(root)/(logged)/audit_logs/+page.svelte b/frontend/src/routes/(root)/(logged)/audit_logs/+page.svelte index c67ca1bae8..b2b55bbdd5 100644 --- a/frontend/src/routes/(root)/(logged)/audit_logs/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/audit_logs/+page.svelte @@ -5,8 +5,9 @@ import CenteredPage from '$lib/components/CenteredPage.svelte' import PageHeader from '$lib/components/PageHeader.svelte' import TableCustom from '$lib/components/TableCustom.svelte' + import { Alert } from '$lib/components/common' import { AuditLog, AuditService, UserService } from '$lib/gen' - import { userStore, workspaceStore } from '$lib/stores' + import { enterpriseLicense, userStore, workspaceStore } from '$lib/stores' import { displayDate } from '$lib/utils' import { faCross, faEdit, faPlay, faPlus, faQuestion } from '@fortawesome/free-solid-svg-icons' import Icon from 'svelte-awesome' @@ -85,6 +86,12 @@ tooltip="You can only see your own audit logs unless you are an admin." /> + {#if !$enterpriseLicense} + You need an enterprise license to see unredacted audit logs. +
    + {/if}