[Filebeat/Journald] allow to use a chroot when calling journalctl#48008
[Filebeat/Journald] allow to use a chroot when calling journalctl#48008belimawr merged 37 commits intoelastic:mainfrom
journalctl#48008Conversation
🤖 GitHub commentsJust comment with:
|
|
The failing test on Windows is unrelated to this PR. The flaky test issue: #48009 |
🔍 Preview links for changed docs |
|
This pull request is now in conflicts. Could you fix it? 🙏 |
|
This looks like it will work if you are root, have you found what the least privilege way to execute journalctl is yet? Can you for example be a non-root user with The wolfi images do not have root as the running container user for example, so ideally we can keep that and add the minimum capabilities rather than being root if possible. |
I've been trying different variations of privileges and doing some research, the only way I can get the chroot to work is when setting the user to root. Even without adding
I'll update the docs to reflect it. |
|
The CI failure is unrelated to this PR, here is the flaky test isuse: #48187 |
cmacknz
left a comment
There was a problem hiding this comment.
Thanks, I'm fine with this (and backport to 9.3).
We can work out the minimum privileges separately.
colleenmcginnis
left a comment
There was a problem hiding this comment.
I left a couple minor non-blocking suggestions below.
…48008) Add support in the journald inpur for using chroot when calling `journalctl`. In a container environment this allows to mount the host file system into the container and use its `journalctl`, which prevents any sort of incompatibility between the `journalctl` in the container image and the host Journald. --------- Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co> (cherry picked from commit b5e52fa)
…48008) (#48197) Add support in the journald inpur for using chroot when calling `journalctl`. In a container environment this allows to mount the host file system into the container and use its `journalctl`, which prevents any sort of incompatibility between the `journalctl` in the container image and the host Journald. --------- (cherry picked from commit b5e52fa) Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co> Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
Proposed commit message
Checklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.## Disruptive User ImpactAuthor's Checklist
How to test this PR locally
Run the tests
Manual testing
1. Create a
filebeat.ymlfilebeat.yml
2. Build a staicaly linked Filebeat binary
3. Create a Dockerfile and build a test image
Dockerfile
4. Run the container
You should see in the logs the
journalctlstarting:{ "@timestamp": "2025-12-17T17:14:29.446Z", "ecs.version": "1.6.0", "id": "journald-input-id", "input_id": "journald-input-id", "input_source": "LOCAL_SYSTEM_JOURNAL", "log.level": "info", "log.logger": "input.journald.reader.journalctl-runner", "log.origin": { "file.line": 153, "file.name": "journalctl/journalctl.go", "function": "github.com/elastic/beats/v7/filebeat/input/journald.(*journald).Run.NewFactory.func1" }, "message": "Journalctl command. Paths relative to chroot (if set)", "path": "LOCAL_SYSTEM_JOURNAL", "process.chroot": "/host", "process.command_line": "/usr/bin/journalctl --utc --output=json --no-pager --all --follow --no-tail --boot all", "service.name": "filebeat" } { "@timestamp": "2025-12-17T17:14:29.447Z", "ecs.version": "1.6.0", "id": "journald-input-id", "input_id": "journald-input-id", "input_source": "LOCAL_SYSTEM_JOURNAL", "log.level": "info", "log.logger": "input.journald.reader.journalctl-runner", "log.origin": { "file.line": 163, "file.name": "journalctl/journalctl.go", "function": "github.com/elastic/beats/v7/filebeat/input/journald.(*journald).Run.NewFactory.func1" }, "message": "journalctl started", "path": "LOCAL_SYSTEM_JOURNAL", "process.pid": 23, "service.name": "filebeat" }You can also see the number events published in the metrics that are logged every 5s.
If you want to see the events, remove the discard output and uncomment
the console output in
filebeat.yml, then rebuild the docker imageand run it again.
Related issues
journalctlfrom the host, thus eliminating version issues #47323## Use cases## Screenshots## Logs