-
Notifications
You must be signed in to change notification settings - Fork 231
aureport/ausearch: check for non-input stdin pipes #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Calling aureport or ausearch on a remote host e.g.: # ssh host aureport will make aureport hang on read() because stdin is seen as a pipe (from SSH). This can be worked around with "ssh -t", but the aforementioned behaviour is not expected anyway. Fix this by checking if stdin is a pipe, and, if so, poll it to check for available data to read, which will return false for the reproducer. Following examples now works, or continue to work, successfully: # aureport # cat audit.log | aureport # ssh host aureport # ssh host "cat audit.log | aureport" # cat audit.log | ssh host aureport Signed-off-by: Enzo Matsumiya <[email protected]>
There is the --input-logs option which tells it ignore the pipe and use the logs from auditd.conf |
Then --input-logs can be deprecated? :-P I'm half joking. On the non-joke half part: Not counting the 100% unexpected/undesired behaviour for "ssh host aureport" hanging without warnings/errors. What's wrong with making stdin input a try-read instead of "it's a pipe, read from it"? i.e. what's wrong with having this patch? |
I'll look at this next week. |
Wouldn’t it be possible to resolve the issue with a straightforward is_pipe redesign and not touch main at all, like this:
Of course, this could be refactored into a common function and used by both aureport and ausearch. I tried a few combinations. |
@Cropi The only drawback is that this is based on time. To test this, I used a log file from 2021 and piped that to aureport --log. It reported 2025 time range. I gave it 1000 milliseconds and it reported 2021. Then I remembered when I worked on audit full time. I had audit logging 100MB sized files and 200 of them. This was to simulate the environment where someone really uses auditing so I could make sure the utilities were fast. Even in that case, it sometimes took over a minute before it started finding the records of interest. So, I don't know if there is any good way because it can take some time to start outputting in large environments. One idea is maybe add a new command line option --stdin to tell it don't even test but go directly to stdin for input. Then we can have the automatic detection that works most of the time and manual overrides when it doesn't. If we stay with the automatic method, I like @Cropi patch better. But I'd give it like 250 milliseconds in case the input is a little slow to arrive. |
Sure, but why not touch main? I just took the opportunity to do a small refactoring in that if/else if/else. @stevegrubb adding a --stdin switch would be great and it was indeed my first approach to this, but would require (IMHO) a redesign to "don't ever read stdin, unless --stdin", which would break current behaviour. As for the slow input concern, you're correct. Even though I did test such cases to avoid false negatives, apparently my tests were wrong. Note, however, that current code only works with slow input because it (tries to) just read straight from the pipe, regardless if there's data or not. Which is what causes the bug I originally wanted to fix here. I'll rewrite the patch to yours and @Cropi 's suggestions, but to accomodate the timing issue, may I also suggest something like (pseudocode):
Like this, we have a fast, binary path for stdin pipe (readable data or hangup), and an acceptable delay for slow input cases. (*) unless a new command line argument is added I'll wait for your thoughts to refresh the patch. |
Calling aureport or ausearch on a remote host e.g.:
# ssh host aureport
will make aureport hang on read() because stdin is seen as a pipe (from SSH). This can be worked around with "ssh -t", but the aforementioned behaviour is not expected anyway.
Fix this by checking if stdin is a pipe, and, if so, poll it to check for available data to read, which will return false for the reproducer.
Following examples now works, or continue to work, successfully: