From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: Mira Limbeck <m.limbeck@proxmox.com>
Cc: pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-log-tracker] close #2106: show outgoing TLS connection in tracking center
Date: Mon, 15 Mar 2021 15:10:36 +0100 [thread overview]
Message-ID: <20210315151036.69be7ffc@rosa.proxmox.com> (raw)
In-Reply-To: <20210303150506.10282-1-m.limbeck@proxmox.com>
Thanks for taking a look at the issue and providing this patch!
The general approach seems viable to me (since we simply have no other
point of information to go on but the pid)!
One issue inline:
On Wed, 3 Mar 2021 16:05:06 +0100
Mira Limbeck <m.limbeck@proxmox.com> wrote:
> This is a best effort try to add the outgoing TLS connection information
> to the output of pmg-log-tracker. The only thing we can match on is the
> PID of the 'smtp' process. In the code we asumme that the TLS log entry
> always happens before the actual smtp send entry that has a QID. This means
> we save the TLS log entry in a map with the PID as key and then, once the
> send entry happens, we look it up and add the log entry to the QEntry's
> logs.
>
> Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
> ---
> src/main.rs | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/src/main.rs b/src/main.rs
> index 5069252..eaaf00e 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -378,6 +378,16 @@ fn handle_qmgr_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) {
>
> // handle log entries for 'lmtp', 'smtp', 'error' and 'local'
> fn handle_lmtp_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) {
> + if msg.starts_with(b"Trusted TLS connection established to") {
Not all TLS connections are trusted - e.g. in my test-environment with
self-signed certificates:
`Mar 15 14:58:45 pmg6 postfix/smtp[17051]: Untrusted TLS connection ...`
Adding this match as well - shows the desired behavior in my tracking
center (some tests probably need adaptation)
> + // the only way to match outgoing TLS connections is by smtp pid
> + // this message has to appear before the 'qmgr: <QID>: removed' entry in the log
> + parser.smtp_tls_log_by_pid.insert(
> + parser.current_record_state.pid,
> + (complete_line.into(), parser.lines),
> + );
> + return;
> + }
> +
> let (qid, data) = match parse_qid(msg, 15) {
> Some((q, t)) => (q, t),
> None => return,
> @@ -393,6 +403,14 @@ fn handle_lmtp_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) {
> .log
> .push((complete_line.into(), parser.lines));
>
> + // assume the TLS log entry always appears before as it is the same process
> + if let Some(log_line) = parser
> + .smtp_tls_log_by_pid
> + .remove(&parser.current_record_state.pid)
> + {
> + qe.borrow_mut().log.push(log_line);
> + }
> +
> let data = &data[2..];
> if !data.starts_with(b"to=<") {
> return;
> @@ -1668,6 +1686,8 @@ struct Parser {
> fentries: HashMap<Box<[u8]>, Rc<RefCell<FEntry>>>,
> qentries: HashMap<Box<[u8]>, Rc<RefCell<QEntry>>>,
>
> + smtp_tls_log_by_pid: HashMap<u64, (Box<[u8]>, u64)>,
> +
> current_record_state: RecordState,
> rel_line_nr: u64,
>
> @@ -1705,6 +1725,7 @@ impl Parser {
> sentries: HashMap::new(),
> fentries: HashMap::new(),
> qentries: HashMap::new(),
> + smtp_tls_log_by_pid: HashMap::new(),
> current_record_state: Default::default(),
> rel_line_nr: 0,
> current_year: years,
prev parent reply other threads:[~2021-03-15 14:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-03 15:05 Mira Limbeck
2021-03-15 14:10 ` Stoiko Ivanov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210315151036.69be7ffc@rosa.proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=m.limbeck@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox