-
Notifications
You must be signed in to change notification settings - Fork 102
feat(k8saudit): file watching #1167
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: main
Are you sure you want to change the base?
feat(k8saudit): file watching #1167
Conversation
Add continuous file watching capability for audit logs using the tail:// URL scheme. This allows monitoring files for new entries and handles log rotation via inode detection and file truncation. Closes falcosecurity#191 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
Add documentation for the new tail:// URL scheme and watchPollIntervalMs configuration option. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: RichardoC The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Rules files suggestionsrulesComparing No changes detected |
irozzo-1A
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @RichardoC, thanks for your contribution. I suggest using file instead of tail to have a more standard URI, and using an event based approach instead of polling.
| return k.OpenWebServer(u.Host, u.Path, false) | ||
| case "https": | ||
| return k.OpenWebServer(u.Host, u.Path, true) | ||
| case "tail": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| case "tail": | |
| case "file": |
plugins/k8saudit/README.md
Outdated
| This plugin supports consuming Kubernetes Audit Events coming from the [Webhook backend](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/#webhook-backend) or from a file. For webhooks, the plugin embeds a web server that listens on a configurable port and accepts POST requests. The posted JSON object comprises one or more events. The web server of the plugin can be configured as part of the plugin's init configuration and open parameters. For files, the plugin expects content to be in [JSONL format](https://jsonlines.org/), where each line represents a JSON object, containing one or more audit events. | ||
|
|
||
| The expected way of using the plugin with Falco is through a Webhook. File reading support can be used with Stratoshark or testing and development. | ||
| The expected way of using the plugin with Falco is through a Webhook. File reading support can be used with Stratoshark or testing and development. The `tail://` scheme enables continuous file watching with log rotation support, useful for reading audit logs written to disk by the API server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The expected way of using the plugin with Falco is through a Webhook. File reading support can be used with Stratoshark or testing and development. The `tail://` scheme enables continuous file watching with log rotation support, useful for reading audit logs written to disk by the API server. | |
| The expected way of using the plugin with Falco is through a Webhook. File reading support can be used with Stratoshark or testing and development. The `file://` scheme enables continuous file watching with log rotation support, useful for reading audit logs written to disk by the API server. |
plugins/k8saudit/README.md
Outdated
| **Open Parameters**: | ||
| - `http://<host>:<port>/<endpoint>`: Opens an event stream by listening on an HTTP web server | ||
| - `https://<host>:<port>/<endpoint>`: Opens an event stream by listening on an HTTPS web server | ||
| - `tail://<filepath>`: Opens an event stream by continuously watching a file for new audit events, similar to `tail -f`. Handles log rotation (inode changes) and file truncation automatically. Example: `tail:///var/log/kube-apiserver/audit.log` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - `tail://<filepath>`: Opens an event stream by continuously watching a file for new audit events, similar to `tail -f`. Handles log rotation (inode changes) and file truncation automatically. Example: `tail:///var/log/kube-apiserver/audit.log` | |
| - `file://<filepath>`: Opens an event stream by continuously watching a file for new audit events, similar to `tail -f`. Handles log rotation (inode changes) and file truncation automatically. Example: `file:///var/log/kube-apiserver/audit.log` |
| UseAsync bool `json:"useAsync" jsonschema:"title=Use async extraction,description=If true then async extraction optimization is enabled (Default: true),default=true"` | ||
| MaxEventSize uint64 `json:"maxEventSize" jsonschema:"title=Maximum event size,description=Maximum size of single audit event (Default: 262144),default=262144"` | ||
| WebhookMaxBatchSize uint64 `json:"webhookMaxBatchSize" jsonschema:"title=Maximum webhook request size,description=Maximum size of incoming webhook POST request bodies (Default: 12582912),default=12582912"` | ||
| WatchPollIntervalMs uint64 `json:"watchPollIntervalMs" jsonschema:"title=Watch poll interval,description=Polling interval in milliseconds when watching a file with tail:// scheme (Default: 250),default=250"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid this if we use an event based approach e.g. inotify
Co-authored-by: Iacopo Rozzo <iacopo@sysdig.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
Thank you for the thorough review @irozzo-1A , making those changes now |
|
Claude log for the changes |
Replace polling-based file watching with fsnotify for better efficiency. - Use fsnotify to watch parent directory (per maintainer recommendation) - Rename scheme from tail:// to file:// - Remove watchPollIntervalMs config (no longer needed) - Rename test package from tail to filewatch Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
0613d65 to
c12e1e0
Compare
|
The cargo install issue in ci seems unrelated to my changes |
Move tests from orphaned filewatch/ package into k8saudit alongside the code they test, and restore truncation detection that was lost in the fsnotify refactor. - Detect file truncation via size check before seeking (copytruncate) - Move filewatch/filewatch_test.go to watch_test.go in k8saudit package - Restore TestOpenFileWatch_HandlesTruncation test - Remove empty filewatch/ directory - Mark fsnotify as direct dependency in go.mod Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
Rules files suggestionsrulesComparing No changes detected |
…tcher - Align scanner buffer with MaxEventSize to avoid silently dropping large events - Log scanner errors instead of swallowing them - Log fsnotify watcher errors instead of discarding them - Add real assertions to watch tests using sentinel-based content verification Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Richard Tweed <RichardoC@users.noreply.github.com>
Rules files suggestionsrulesComparing No changes detected |
What type of PR is this?
/kind feature
Any specific area of the project related to this PR?
/area plugins
What this PR does / why we need it:
Add continuous file watching capability for audit logs using the
tail:// URL scheme. This allows monitoring files for new entries
and handles log rotation via inode detection and file truncation.
Which issue(s) this PR fixes:
Fixes #191
Special notes for your reviewer: Generated with Claude Code. Full transcript attached
claude-log.txt