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

libbeat/processors/add_process_metada: add capabilities to process me… #38252

Merged
merged 16 commits into from
Apr 12, 2024

Conversation

haesbaert
Copy link
Contributor

@haesbaert haesbaert commented Mar 11, 2024

Proposed commit message

Extends process metadata with effective and permitted capabilities.

Errors from capabilities.FromPid() are ignored since it returns a nil slice, which results in len() == 0 which supresses any output. A possible common error is getting ESRCH as the process might have already exited.

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.

How to test this PR locally

processors:
  - add_process_metadata:
      overwrite_keys: true
      match_pids: ["process.pid"]

auditbeat.modules:
- module: system
  datasets:
    - socket
  period: 10s # The frequency at which the datasets check for changes
  state.period: 20s

output.console:
  pretty: true

Related issues

Part of https://github.com/elastic/security-team/issues/4375
Related to #37453

Screenshots

Screenshot from 2024-03-11 12-07-56

output.txt

…tadata

Extends process metadata with effective and permitted capabilities.
@haesbaert haesbaert requested a review from a team as a code owner March 11, 2024 12:22
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 11, 2024
@haesbaert haesbaert added the Team:Security-Linux Platform Linux Platform Team in Security Solution label Mar 11, 2024
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 11, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@haesbaert haesbaert marked this pull request as draft March 11, 2024 12:22
Copy link
Contributor

mergify bot commented Mar 11, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @haesbaert? 🙏.
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-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

while here zap the extra newline
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 11, 2024

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Duration: 133 min 9 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@haesbaert haesbaert marked this pull request as ready for review March 11, 2024 15:19
@haesbaert
Copy link
Contributor Author

The Windows errors seem to be unrelated, apparently the CI can't find the go binary and whatnot

@pierrehilbert pierrehilbert added the Team:Elastic-Agent Label for the Agent team label Mar 11, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@belimawr
Copy link
Contributor

BuildKite should not prevent the PR from be merged yet. Once you get the approvals and Jenkins is green you should be able to merge it.

…est.go

Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
@haesbaert
Copy link
Contributor Author

BuildKite should not prevent the PR from be merged yet. Once you get the approvals and Jenkins is green you should be able to merge it.

Awesome, thanks :)

Copy link

@stanek-michal stanek-michal left a comment

Choose a reason for hiding this comment

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

LGTM

@haesbaert
Copy link
Contributor Author

Merging is blocked as waiting a review from @fearful-symmetry , is this because we need a reviewer from each team?

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @haesbaert

@@ -52,17 +53,22 @@ func (p gosysinfoProvider) GetProcessMetadata(pid int) (result *processMetadata,
}
}

capPermitted, _ := capabilities.FromPid(capabilities.Permitted, pid)
capEffective, _ := capabilities.FromPid(capabilities.Effective, pid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we're not checking the errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it fails, we don't include the capabilities, same outcome if the capabilities were empty. There are valid/normal reasons for it to fail, like the process being gone by the time we try to fetch it. Also on Windows/OS X i fails with ErrUnsupported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a quick comment to that effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@haesbaert haesbaert requested a review from a team as a code owner April 3, 2024 09:13
@haesbaert
Copy link
Contributor Author

/test

@haesbaert haesbaert merged commit 9153275 into main Apr 12, 2024
193 of 201 checks passed
@haesbaert haesbaert deleted the cap-processor branch April 12, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Team:Elastic-Agent Label for the Agent team Team:Security-Linux Platform Linux Platform Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants