From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 02239601E8 for ; Fri, 16 Oct 2020 11:06:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E713A19180 for ; Fri, 16 Oct 2020 11:06:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 8262919155 for ; Fri, 16 Oct 2020 11:06:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4B7E345C70 for ; Fri, 16 Oct 2020 11:06:54 +0200 (CEST) From: Thomas Lamprecht To: pbs-devel@lists.proxmox.com Date: Fri, 16 Oct 2020 11:06:48 +0200 Message-Id: <20201016090648.23887-3-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201016090648.23887-1-t.lamprecht@proxmox.com> References: <20201016090648.23887-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.133 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [access.rs] Subject: [pbs-devel] [PATCH backup 3/3] api: access: log to separate file, reduce syslog to errors X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 09:06:56 -0000 for now log auth errors also to the syslog, on a protected (LAN and/or firewalled) setup this should normally happen due to missconfiguration, not tries to break in. This reduces syslog noise *a lot*. A current full journal output from the current boot here has 72066 lines, of which 71444 (>99% !!) are "successful auth for user ..." messages Signed-off-by: Thomas Lamprecht --- src/api2/access.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/api2/access.rs b/src/api2/access.rs index 19b128b1..c302e0c7 100644 --- a/src/api2/access.rs +++ b/src/api2/access.rs @@ -10,6 +10,7 @@ use proxmox::{http_err, list_subdirs_api_method}; use crate::tools::ticket::{self, Empty, Ticket}; use crate::auth_helpers::*; use crate::api2::types::*; +use crate::tools::{FileLogOptions, FileLogger}; use crate::config::cached_user_info::CachedUserInfo; use crate::config::acl::{PRIVILEGES, PRIV_PERMISSIONS_MODIFY}; @@ -140,13 +141,20 @@ fn create_ticket( port: Option, rpcenv: &mut dyn RpcEnvironment, ) -> Result { + let logger_options = FileLogOptions { + append: true, + prefix_time: true, + ..Default::default() + }; + let mut auth_log = FileLogger::new("/var/log/proxmox-backup/api/auth.log", logger_options)?; + match authenticate_user(&username, &password, path, privs, port) { Ok(true) => { let ticket = Ticket::new("PBS", &username)?.sign(private_auth_key(), None)?; let token = assemble_csrf_prevention_token(csrf_secret(), &username); - log::info!("successful auth for user '{}'", username); + auth_log.log(format!("successful auth for user '{}'", username)); Ok(json!({ "username": username, @@ -163,7 +171,15 @@ fn create_ticket( None => "unknown".into(), }; - log::error!("authentication failure; rhost={} user={} msg={}", client_ip, username, err.to_string()); + let msg = format!( + "authentication failure; rhost={} user={} msg={}", + client_ip, + username, + err.to_string() + ); + auth_log.log(&msg); + log::error!("{}", msg); + Err(http_err!(UNAUTHORIZED, "permission check failed.")) } } -- 2.27.0