Bug 2208963

Summary: ausearch fails when called from cron script
Product: [Fedora] Fedora Reporter: John Dodson <jwadodson>
Component: auditAssignee: Steve Grubb <sgrubb>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 37CC: scorreia, sgrubb
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-23 15:07:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description John Dodson 2023-05-22 08:16:36 UTC
/usr/sbin/ausearch -ts yesterday -i |grep denied
returns "<no matches>" since audit-3.1.1-1.fc37.x86_64 installed & log rotated.
Is this version keeping the wrong log file open? lsof says not.


Reproducible: Always

Steps to Reproduce:
1. Try /usr/sbin/ausearch -ts yesterday -i |grep denied within a cron script (FAILS!)
2. Try /usr/sbin/ausearch -ts yesterday -i |grep denied as root succeeds
3. There are selinux denied events.
Actual Results:  
<no matches>

Expected Results:  
Same as I get running as root.

Comment 1 Steve Grubb 2023-05-22 16:48:18 UTC
ausearch prefers input from pipes if stdin is a pipe. In cron scripts stdin/out/err are pipes. So, it mistakenly waits for something on stdin. The fix is to use --input-logs so that it overrides the normal behavior. This behavior has been in place for at least the last 15 years.

Comment 2 John Dodson 2023-05-23 13:35:57 UTC
How is stdin suddenly a pipe? (A change to cron?)

"This behaviour has been in place for at least the last 15 years."
      ^^^^^^^^^
Sadly that is not true.
This happened with audit-3.1.1-1.fc37.x86_64

So someone obviously fixed the bug that had it broken (from the way you thought it worked) for
the last 15 years.

Otherwise why has it worked for me for the last 15 years? (in cron scripts?)

Maybe it's another of the things that has affected cron recently (selinux limits).

In any case --input-logs does now allow it to work again as it did last week
in a cron script without that option!

Comment 3 Steve Grubb 2023-05-23 13:44:32 UTC
Glad it's working for you now. No idea why it worked for you. The --input-logs is specifically to be used for cron jobs. You can see here people were asking questions about this 15 years ago:

https://listman.redhat.com/archives/linux-audit/2008-May/005276.html

I think we can close this.

Comment 4 John Dodson 2023-05-23 14:18:45 UTC
This is not in "redhat" it's in fedora.

Maybe it coincided with moving it from cron.daily to a discrete cron job?

Ok please close...

Comment 5 Steve Grubb 2023-05-23 15:07:41 UTC
It might be the result of switching from cron.daily to something else. I also have no idea if running it from a systemd timer would change things either. In any event, it is working so I'll close this report. If you run into other problems with ausearch/cron, feel free to re-open.