* [pmg-devel] [PATCH v2 log-tracker] close #2106: show outgoing TLS connection in tracking center
@ 2021-03-22 12:23 Mira Limbeck
2021-03-22 14:10 ` Stoiko Ivanov
0 siblings, 1 reply; 3+ messages in thread
From: Mira Limbeck @ 2021-03-22 12:23 UTC (permalink / raw)
To: pmg-devel
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>
---
v2:
- added 'Untrusted' line match as well
src/main.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/main.rs b/src/main.rs
index 5069252..a186620 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -378,6 +378,18 @@ 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")
+ || msg.starts_with(b"Untrusted TLS connection established to")
+ {
+ // 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 +405,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 +1688,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 +1727,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,
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pmg-devel] [PATCH v2 log-tracker] close #2106: show outgoing TLS connection in tracking center
2021-03-22 12:23 [pmg-devel] [PATCH v2 log-tracker] close #2106: show outgoing TLS connection in tracking center Mira Limbeck
@ 2021-03-22 14:10 ` Stoiko Ivanov
2021-03-22 15:33 ` Stoiko Ivanov
0 siblings, 1 reply; 3+ messages in thread
From: Stoiko Ivanov @ 2021-03-22 14:10 UTC (permalink / raw)
To: Mira Limbeck; +Cc: pmg-devel
LGTM now!
Tested-By: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-By: Stoiko Ivanov <s.ivanov@proxmox.com>
On Mon, 22 Mar 2021 13:23:27 +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>
> ---
> v2:
> - added 'Untrusted' line match as well
>
> src/main.rs | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/src/main.rs b/src/main.rs
> index 5069252..a186620 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -378,6 +378,18 @@ 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")
> + || msg.starts_with(b"Untrusted TLS connection established to")
> + {
> + // 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 +405,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 +1688,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 +1727,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,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pmg-devel] [PATCH v2 log-tracker] close #2106: show outgoing TLS connection in tracking center
2021-03-22 14:10 ` Stoiko Ivanov
@ 2021-03-22 15:33 ` Stoiko Ivanov
0 siblings, 0 replies; 3+ messages in thread
From: Stoiko Ivanov @ 2021-03-22 15:33 UTC (permalink / raw)
To: Mira Limbeck; +Cc: pmg-devel
On Mon, 22 Mar 2021 15:10:19 +0100
Stoiko Ivanov <s.ivanov@proxmox.com> wrote:
> LGTM now!
>
> Tested-By: Stoiko Ivanov <s.ivanov@proxmox.com>
> Reviewed-By: Stoiko Ivanov <s.ivanov@proxmox.com>
re-building and re-running the tests with faketime in place - the run now
fails (since the output of our old tests now needs to include the line
with the TLS-connect)
could I ask you to resent the patch, with the updated test-outputs (in one
commit) - this should keep everything build and bisectable nicely
>
> On Mon, 22 Mar 2021 13:23:27 +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>
> > ---
> > v2:
> > - added 'Untrusted' line match as well
> >
> > src/main.rs | 23 +++++++++++++++++++++++
> > 1 file changed, 23 insertions(+)
> >
> > diff --git a/src/main.rs b/src/main.rs
> > index 5069252..a186620 100644
> > --- a/src/main.rs
> > +++ b/src/main.rs
> > @@ -378,6 +378,18 @@ 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")
> > + || msg.starts_with(b"Untrusted TLS connection established to")
> > + {
> > + // 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 +405,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 +1688,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 +1727,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,
>
>
>
> _______________________________________________
> pmg-devel mailing list
> pmg-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-22 15:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 12:23 [pmg-devel] [PATCH v2 log-tracker] close #2106: show outgoing TLS connection in tracking center Mira Limbeck
2021-03-22 14:10 ` Stoiko Ivanov
2021-03-22 15:33 ` Stoiko Ivanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox