From ce7795a67d8d25658221511bfd9d6f232e942096 Mon Sep 17 00:00:00 2001 From: Anastasia Lubennikova Date: Fri, 18 Apr 2025 00:32:38 +0100 Subject: [PATCH] compute: use project_id, endpoint_id as tag (#11556) for compute audit logs part of https://github.com/neondatabase/cloud/issues/21955 --- compute_tools/src/compute.rs | 21 ++++++++++++++++++++- compute_tools/src/rsyslog.rs | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/compute_tools/src/compute.rs b/compute_tools/src/compute.rs index c7b4bdd240..8834f0d63d 100644 --- a/compute_tools/src/compute.rs +++ b/compute_tools/src/compute.rs @@ -641,7 +641,26 @@ impl ComputeNode { let log_directory_path = Path::new(&self.params.pgdata).join("log"); let log_directory_path = log_directory_path.to_string_lossy().to_string(); - configure_audit_rsyslog(log_directory_path.clone(), "hipaa", &remote_endpoint)?; + + // Add project_id,endpoint_id tag to identify the logs. + // + // These ids are passed from cplane, + // for backwards compatibility (old computes that don't have them), + // we set them to None. + // TODO: Clean up this code when all computes have them. + let tag: Option = match ( + pspec.spec.project_id.as_deref(), + pspec.spec.endpoint_id.as_deref(), + ) { + (Some(project_id), Some(endpoint_id)) => { + Some(format!("{project_id}/{endpoint_id}")) + } + (Some(project_id), None) => Some(format!("{project_id}/None")), + (None, Some(endpoint_id)) => Some(format!("None,{endpoint_id}")), + (None, None) => None, + }; + + configure_audit_rsyslog(log_directory_path.clone(), tag, &remote_endpoint)?; // Launch a background task to clean up the audit logs launch_pgaudit_gc(log_directory_path); diff --git a/compute_tools/src/rsyslog.rs b/compute_tools/src/rsyslog.rs index ba08302df2..7be97046a0 100644 --- a/compute_tools/src/rsyslog.rs +++ b/compute_tools/src/rsyslog.rs @@ -50,13 +50,13 @@ fn restart_rsyslog() -> Result<()> { pub fn configure_audit_rsyslog( log_directory: String, - tag: &str, + tag: Option, remote_endpoint: &str, ) -> Result<()> { let config_content: String = format!( include_str!("config_template/compute_audit_rsyslog_template.conf"), log_directory = log_directory, - tag = tag, + tag = tag.unwrap_or("".to_string()), remote_endpoint = remote_endpoint );