feat: record client IP and user agent on audit entries (#12673)

* feat: record client IP and user agent on audit entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: trust the compose network's proxy for the audit client IP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: treat undecodable forwarded-for entries as a stop in the client IP walk

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the legacy audit view in step with the new audit columns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: add the audit origin columns to audit_partitioned only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* revert: keep the legacy audit table and view in step with the new columns

Older servers read the legacy audit table in a SELECT * UNION ALL with audit_partitioned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to 8604f6779f08ff2208e85628503877edce8e2343

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

Previous ee-repo-ref: 8c44649a51062cf4f056792c0e2da09b7b7354b5

New ee-repo-ref: 8604f6779f08ff2208e85628503877edce8e2343

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
Ruben Fiszel
2026-11-26 12:54:08 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 windmill-internal-app[bot]
parent 9a7ab54746
commit c689d74505
15 changed files with 400 additions and 5 deletions
+6
View File
@@ -34449,6 +34449,12 @@ components:
type: object
span:
type: string
client_ip:
type: string
description: Address of the client that made the request. Forwarding headers are believed only from the proxies listed in the TRUSTED_PROXIES environment variable (loopback by default, plus the private ranges on Windmill Cloud), so behind a reverse proxy this is the proxy's address until it is listed. Absent on entries no request stands behind.
user_agent:
type: string
description: User-Agent header of the request.
required:
- workspace_id
- id
+25 -1
View File
@@ -323,6 +323,25 @@ async fn set_request_client(
windmill_common::trigger_history::scope_client(client, next.run(req)).await
}
/// Scope the request in its origin (client address and user agent), recorded on the audit
/// entries it writes. A request routed in-process has no connect info and keeps the origin
/// of the request that routed it.
async fn set_request_origin(
req: axum::extract::Request,
next: axum::middleware::Next,
) -> axum::response::Response {
use windmill_common::request_origin::{current, scope, RequestOrigin};
let peer = req
.extensions()
.get::<axum::extract::ConnectInfo<std::net::SocketAddr>>()
.map(|c| c.0.ip());
let origin = match (peer, current()) {
(None, Some(outer)) => (*outer).clone(),
(peer, _) => RequestOrigin::from_request(peer, req.headers()),
};
scope(origin, next.run(req)).await
}
#[cfg(not(feature = "tantivy"))]
type IndexReader = ();
@@ -1292,6 +1311,8 @@ pub async fn run_server(
let app = app.layer(axum::middleware::from_fn(set_request_client));
let app = app.layer(axum::middleware::from_fn(set_request_origin));
let app = app.layer(CatchPanicLayer::custom(|err| {
tracing::error!("panic in handler, returning 500: {:?}", err);
Response::builder()
@@ -1308,7 +1329,10 @@ pub async fn run_server(
let listener = listener.tap_io(move |tcp_stream| {
let _ = tcp_stream.set_nodelay(!server_mode);
});
let server = axum::serve(listener, app.into_make_service());
let server = axum::serve(
listener,
app.into_make_service_with_connect_info::<std::net::SocketAddr>(),
);
tracing::info!(
instance = %*INSTANCE_NAME,
+5 -2
View File
@@ -367,8 +367,11 @@ async fn retire_legacy_audit_table(conn: &mut PgConnection) -> Result<(), Error>
.await?;
tx.execute("DROP TABLE audit").await?;
tx.execute(
format!("CREATE VIEW audit AS SELECT {AUDIT_COLUMNS} FROM audit_partitioned WHERE false")
.as_str(),
format!(
"CREATE VIEW audit AS SELECT {AUDIT_COLUMNS}, client_ip, user_agent \
FROM audit_partitioned WHERE false"
)
.as_str(),
)
.await?;
tx.execute("GRANT ALL ON audit TO windmill_user, windmill_admin")