Skip to content

Install systemd on Filebeat Docker images#44056

Merged
belimawr merged 3 commits intoelastic:mainfrom
belimawr:44040-add-journalctl-to-containers
Apr 25, 2025
Merged

Install systemd on Filebeat Docker images#44056
belimawr merged 3 commits intoelastic:mainfrom
belimawr:44040-add-journalctl-to-containers

Conversation

@belimawr
Copy link
Copy Markdown
Contributor

@belimawr belimawr commented Apr 24, 2025

Proposed commit message

The journald input from Filebeat requires the journalctl binary to ingest journal logs, this commit adds it by installing systemd in all Filebeat Docker container images

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

## Disruptive User Impact
## Author's Checklist

How to test this PR locally

  1. Package Filebeat

    DEV=true SNAPSHOT=true PACKAGES="docker" PLATFORMS=linux/amd64 mage -v package
  2. Ensure journalctl is present in the containers (adjust the image name/tag according to the version you built, oss or not)

    docker run --rm -it --user root --entrypoint "journalctl" docker.elastic.co/beats/filebeat-wolfi:9.1.0-SNAPSHOT --version
    docker run --rm -it --user root --entrypoint "journalctl" docker.elastic.co/beats/filebeat-ubi:9.1.0-SNAPSHOT --version
    # Only for x-pack
    docker run --rm -it --user root --entrypoint "journalctl" docker.elastic.co/beats/filebeat:9.1.0-SNAPSHOT --version
  3. Start a stack. E.g: using elastic-package: elastic-package stack up --version=9.1.0-SNAPSHOT -v -d

  4. Create the following filebeat.yml (adjust the IP address/ES host as needed)

    filebeat.yml

    filebeat.inputs:
      - type: journald
        id: foo-bar
        paths:
          - /var/log/journal/*/*.journal
    
    output.elasticsearch:
      hosts:
        - https://192.168.42.42:9200
      username: elastic
      password: changeme
      ssl.verification_mode: none

  5. Then run Filebeat from the docker image (adjust the journald folder if needed)

    docker run --rm \
      --name=filebeat \
      --user=root \
      --volume="/var/log/journal:/var/log/journal:ro" \
      --volume="$(pwd)/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro" \
      --volume="registry:/usr/share/filebeat/data:rw" \
      docker.elastic.co/beats/filebeat-wolfi:9.1.0-SNAPSHOT filebeat -e --strict.perms=false setup
  6. Ensure there are no errors and data is ingested

Related issues

## Use cases
## Screenshots
## Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 24, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images
@belimawr belimawr force-pushed the 44040-add-journalctl-to-containers branch from ff2a227 to 1317cd2 Compare April 24, 2025 16:42
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 24, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @belimawr? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@belimawr belimawr added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team bugfix backport-active-all Automated backport with mergify to all the active branches labels Apr 24, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 24, 2025
@belimawr belimawr marked this pull request as ready for review April 24, 2025 18:49
@belimawr belimawr requested review from a team as code owners April 24, 2025 18:49
@belimawr belimawr requested review from faec and leehinman April 24, 2025 18:49
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Copy link
Copy Markdown
Contributor

@leehinman leehinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI opened #44062 for us to improve updating of packages.

Copy link
Copy Markdown
Member

@kilfoyle kilfoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the docs! 🏎️
(I added just a small suggestion.)

Comment on lines +18 to +20
```sh
docker run --rm -it --entrypoint "journalctl" docker.elastic.co/beats/filebeat-wolfi:<VERSION> --version
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very helpful, thanks!

@rdner
Copy link
Copy Markdown
Member

rdner commented Apr 25, 2025

@belimawr I see this PR is marked to close #44040 I don't think it's correct.

This PR only addresses the standalone Filebeat container, not running integrations under Elastic Agent, right?

@belimawr
Copy link
Copy Markdown
Contributor Author

@belimawr I see this PR is marked to close #44040 I don't think it's correct.

This PR only addresses the standalone Filebeat container, not running integrations under Elastic Agent, right?

Yes, you're correct. Thanks for catching this. I updated the PR description.

@belimawr
Copy link
Copy Markdown
Contributor Author

FYI opened #44062 for us to improve updating of packages.

Thanks Lee!

@belimawr belimawr merged commit 32ecb7c into elastic:main Apr 25, 2025
196 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@Mergifyio backport 8.17 8.18 8.19 9.0

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 25, 2025

backport 8.17 8.18 8.19 9.0

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Apr 25, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md
mergify bot pushed a commit that referenced this pull request Apr 25, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md
mergify bot pushed a commit that referenced this pull request Apr 25, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md
mergify bot pushed a commit that referenced this pull request Apr 25, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)
belimawr added a commit that referenced this pull request Apr 25, 2025
…4085)

The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md

* Convert the docs and changelog to markdown

---------

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
belimawr added a commit that referenced this pull request Apr 25, 2025
…4086)

The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md

* Convert the docs and changelog to markdown

---------

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
belimawr added a commit that referenced this pull request Apr 25, 2025
…4087)

The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

# Conflicts:
#	docs/reference/filebeat/filebeat-input-journald.md
#	docs/release-notes/index.md

* Convert the docs and changelog to markdown

---------

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
belimawr added a commit that referenced this pull request Apr 25, 2025
The journald input from Filebeat requires the `journalctl` binary to
ingest journal logs, this commit adds it by installing systemd in all
Filebeat Docker container images

(cherry picked from commit 32ecb7c)

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
@rdner
Copy link
Copy Markdown
Member

rdner commented Apr 28, 2025

@belimawr could you document the image size increase in the description of this PR?

{{- if (contains .from "ubi") }}
RUN for iter in {1..10}; do \
microdnf -y update && \
microdnf -y install systemd && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What systemd version does this install and how compatible is it with debian?

I ask because I expect users will frequently use this to read journald logs from debian or ubuntu based k8s nodes so if it isn't compatible we need to clearly document that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UBI at least already exposes us to CVEs in the rest of the OS packages so it doesn't have the same concerns as Wolfi for that problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What systemd version does this install and how compatible is it with debian?

I ask because I expect users will frequently use this to read journald logs from debian or ubuntu based k8s nodes so if it isn't compatible we need to clearly document that.

Is not it sufficiently documented here? https://github.com/elastic/beats/pull/44056/files#diff-7a8b715909f505c1dc033e00d9fb48d50576d9c128e1c50538fe697218b97ff7R11-R21

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think almost, that doesn't explain why this is important or what the compatibility rules are. It just says users should check.

What is journactl's version compatibility policy? Backwards compatibility (new versions can read old versions) I assume, but does it also provide forward compatibility (old versions can read new versions of journal files)?

If the Filebeat version is 255 but the host system is 257 what does that mean for users?

{{- if (contains .from "wolfi") }}
RUN for iter in {1..10}; do \
apk update && \
apk add --no-interactive --no-progress --no-cache systemd && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to have the side effect of exposing us to CVEs in the entirety of systemd which might turn out to be a significant problem. We probably want to keep this out of the wolfi image whose point is to minimize exposure to OS based CVEs.

In general it would actually be better to build only what we need or find a way to include just journalctl and nothing else but I'm not sure how possible that is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdner
Copy link
Copy Markdown
Member

rdner commented Apr 29, 2025

PR to remove systemd from Wolfi #44108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bugfix Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Filebeat] Journald input doesn't work in container

6 participants