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

Implement a way to run external scripts #18323

Closed
exekias opened this issue May 6, 2020 · 6 comments
Closed

Implement a way to run external scripts #18323

exekias opened this issue May 6, 2020 · 6 comments
Labels
enhancement libbeat Team:Integrations Label for the Integrations team

Comments

@exekias
Copy link
Contributor

exekias commented May 6, 2020

We want to run external processes in some parts of Beats. A few cases we want to support are:

  • Running a java jar to collect JMX metrics as a Metricbeat module
  • Running Nagios scripts to collect metrics or health status

This issue is minded to implement a common mechanism that we can reuse in several places, with a simple API.

  • Communication with the process (when needed) will be done through stdin/stdout
  • We foresee using several models of running processes, so we should be able to: start/stop/kill, also be notified if they stop (including exit code)

Security model:

Running external stuff can represent an attack vector so we should put some measures in place to avoid issues, for anything that we run we should require:

  • Script/binary must be owned by the same user that is running beats
  • Permissions must also be strict: only be writable by the owner (we do the same check for config files)
  • We should only run scripts that are located in paths that the user has configured
  • We won't allow for this paths config to happen remotely (ie with fleet)
  • We should explore dropping privileges when they are not needed, for instance, the code requesting to run the script must communicate the needed capabilities, the rest will be disabled
  • In the same sense, it should be allowed to set a different user if beats is running as root
@exekias exekias added enhancement libbeat Team:Integrations Label for the Integrations team labels May 6, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@exekias exekias mentioned this issue May 6, 2020
11 tasks
@andrewvc
Copy link
Contributor

andrewvc commented May 6, 2020

Regarding the last point about dropping privileges. We definitely need to do this for heartbeat, which runs as root by default. Perhaps we could just switch users? Another thought is we could do a check to see if we're running as root by default.

A final thought is that heartbeat no longer really needs to run as root now that we support rootless ping. Maybe it's time to change that.

@jsoriano
Copy link
Member

jsoriano commented May 7, 2020

Big +1 to this feature, I think this will be great, specially for heartbeat.

Script/binary must be owned by the same user that is running beats

The idea is to allow to run commands installed explicitly for beats? If not, I think it'd be good if binaries installed by root are also allowed, so Beats can use any command installed on the machine, without the need of being executed as root for that (though this opens the pandora's box of running shells and interpreters). Mentioned privileges dropping could still be used to limit some things in any case.

@exekias
Copy link
Contributor Author

exekias commented Jun 4, 2020

Perhaps we could just switch users? Another thought is we could do a check to see if we're running as root by default.

Yes, actually I think this was in our initial discussions, I've added that option to the description

The idea is to allow to run commands installed explicitly for beats?

We will probably want both commands installed by beats (ie a JMX converter), and installed by the user. For the later, seems that a good security measure is that the folder where they are located must be included in the config before (ie, having a scripts folder)

@botelastic
Copy link

botelastic bot commented Jan 27, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ruflin
Copy link
Contributor

ruflin commented Feb 1, 2022

Closing this issue in favor of elastic/elastic-agent#1237 as this makes more sense in the context of Elastic Agent then beats itself. All the technical discussion here still makes sense and should be taken into account for elastic/elastic-agent#1237

@botelastic botelastic bot removed the Stalled label Feb 1, 2022
@ruflin ruflin closed this as completed Feb 1, 2022
@zube zube bot removed the [zube]: Done label May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement libbeat Team:Integrations Label for the Integrations team
Projects
None yet
Development

No branches or pull requests

6 participants