Files
windmill/backend/tests/audit_rls.rs
T
Ruben Fiszelandwindmill-internal-app[bot] 5ef19a88a9 fix: stop audit inserts from silently rolling back saves (#11938)
* fix: let non-admins write audit rows for jobs run as another user

* fix: keep logging audit failures on pool connections

* chore: point ee-repo-ref at the import fix

* chore: update ee-repo-ref to 06b2eb32cd7d40fd93078285d8b6150648384602

This commit updates the EE repository reference after PR #910 was merged in windmill-ee-private.

Previous ee-repo-ref: da546d93c846192ed599b02a5aa3edd5d1ecdcfd

New ee-repo-ref: 06b2eb32cd7d40fd93078285d8b6150648384602

Automated by sync-ee-ref workflow.

---------

Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-10-22 17:15:05 +02:00

38 lines
1.4 KiB
Rust

//! A non-admin's transaction must accept an audit row recorded under another username, as a
//! job pushed to run as someone else writes one. A rejected insert aborts the transaction and
//! takes the caller's own write down with it.
use sqlx::{Pool, Postgres};
use windmill_test_utils::ensure_today_audit_partition;
#[sqlx::test]
async fn non_admin_writes_an_audit_row_for_another_user(db: Pool<Postgres>) -> anyhow::Result<()> {
ensure_today_audit_partition(&db).await;
let mut tx = db.begin().await?;
sqlx::query("SET LOCAL ROLE windmill_user")
.execute(&mut *tx)
.await?;
sqlx::query("SELECT set_config('session.user', 'bob', true)")
.execute(&mut *tx)
.await?;
// The shape a schedule run as alice records without an Enterprise license: parameters
// redacted, so no `end_user` names the schedule.
sqlx::query(
"INSERT INTO audit_partitioned
(workspace_id, username, operation, action_kind, resource, parameters, email)
VALUES ('admins', 'alice', 'redacted', 'execute', 'EE only', '{\"redacted\": \"-\"}', 'alice@windmill.dev')",
)
.execute(&mut *tx)
.await?;
tx.commit().await?;
let count: i64 =
sqlx::query_scalar("SELECT count(*) FROM audit_partitioned WHERE username = 'alice'")
.fetch_one(&db)
.await?;
assert_eq!(count, 1);
Ok(())
}