Skip to content
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

error checks when reading /proc/[pid]/exe don't account for kernel processes or docker permissions shenanigans #135

Closed
fearful-symmetry opened this issue Mar 20, 2024 · 1 comment · Fixed by #148
Assignees
Labels
bug Something isn't working Team:Elastic-Agent Label for the Agent team

Comments

@fearful-symmetry
Copy link
Contributor

Right now, under Linux we check to see if we have a permission denied error when we resolve the symlink for exe:

if errors.Is(err, os.ErrPermission) { // pass through permission errors

We do this so we can skip any errors related to permissions issues. However, this doesn't work under two cases:

  1. For kernel processes, the exe symlink is non-existent
  2. Under docker, we'll get either Permission deined or file not found depending on the permissions docker is running with.

The permissions check in process_linux_common.go should check for both permission errors, and file not found errors.

@fearful-symmetry fearful-symmetry self-assigned this Mar 20, 2024
@pierrehilbert pierrehilbert added Team:Elastic-Agent Label for the Agent team bug Something isn't working labels Mar 25, 2024
@pierrehilbert
Copy link

Blocked as required elastic/beats#38241 first

fearful-symmetry added a commit that referenced this issue Apr 18, 2024
…tainer (#140)

## What does this PR do?
Closes elastic/beats#38241

This adds a lightweight test framework that runs a set of system tests
under a container with the goal of monitoring the host system. The goal
with these tests is to catch the numerous edge cases that happen when
the system metrics function from a `/hostfs` path inside a container.

The tests have a fairly large matrix of configurations, as we need to
test both a wide variety of container permission settings, as well as
differences in how linux distros will configure cgroups.

The framework here was designed with the goal of being relatively
idiomatic; you can just run the framework with `go test` as you would
normally.

You can run the tests yourself with `go test -v ./tests`

As you may have noticed, there's a non-zero amount of TODO statements
here, since these tests were built to aggravate a bunch of existing
bugs, so certain parts of the tests will remain un-implemented until
those bugs are fixed.

## Why is it important?

See elastic/beats#38241, we really need test
for this particular case.

## List of bugs that are responsible for TODO statements in the tests:

- #141
- #135
- #139
- #132
- elastic/go-sysinfo#12

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added an entry in `CHANGELOG.md`
fearful-symmetry added a commit that referenced this issue May 1, 2024
## What does this PR do?

Closes
#135

This fixes an issue where our permissions checks for fetching
`/proc/pid/exe` could fail for kernel procs and certain docker configs.

Also re-enables one of the tests.

## Why is it important?

This is a bug that causes data loss.

## Checklist


- [x] My code follows the style guidelines of this project
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added an entry in `CHANGELOG.md`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants