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

[Agent] Enable post install hooks #17241

Merged
merged 17 commits into from
Apr 1, 2020

Conversation

michalpristas
Copy link
Contributor

@michalpristas michalpristas commented Mar 25, 2020

What does this PR do?

This PR introduces new collection of steps just like we have with rules.
This collection is part of baked in spec file and is called post_install
When installation needs to be run it executed Install method of respective installer and after that it runs collection of these hooks.

At the moment two steps were introduced, rename and remove;

Example of the config:

name: Metricbeat
cmd: metricbeat
args: ["-E", "setup.ilm.enabled=false"]
configurable: grpc
post_install:
  - move_file:
      path: "modules.d/system.yml"
      target: "modules.d/system.yml.disabled"

Why is it important?

Metricbeat is collecting system metrics by default and is sending them to default ES index. We want to avoid this default behavior as default behavior is specified by configuration coming from fleet.

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.

Fixes: #17197
Related: elastic/kibana#60319

@elasticmachine
Copy link
Collaborator

Pinging @elastic/ingest-management (Project:fleet)

// NOTE(ph): this is a bit of a hack because I want to make sure
// the unpack strategy stay in the struct implementation and yaml
// doesn't have a RawMessage similar to the JSON package, so partial unpack
// is not possible.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I this is what I hate the most about the yaml package, there is a way to work around that go-yaml/yaml#13 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove my name next to NOTE :)

// Execute executes delete file step.
func (r *DeleteFileStep) Execute(rootDir string) error {
path := filepath.Join(rootDir, filepath.FromSlash(r.Path))
err := os.Remove(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to add some defensive programming here, even if we control the spec, we never know when this will not be the case. I think we should convert the Filepath.Join() into an absolute path and make sure we are in the "rootdir" and not somewhere else.

I believe this is the case, we want to sandbox every command into a specific directly. I assume all our commands operate in the extracted directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is something i was thinking about but did not want to sound too paraniod

Copy link
Contributor

Choose a reason for hiding this comment

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

Better to be paranoid than sorry :)

@ph
Copy link
Contributor

ph commented Mar 26, 2020

I think this works, I need to think a bit more in the context of endpoint and the driver/endpoint installation because I assume this will be also a post install hook that will trigger the installation with a custom installation script.

Maybe we will need to have different hooks defined per platforms? No need to do it now. but this is something we have in mind.

@michalpristas
Copy link
Contributor Author

Jenkins test this

@michalpristas
Copy link
Contributor Author

@ph i think we can introduce constraints here as well at some later point

@michalpristas
Copy link
Contributor Author

needs update on tests, failures are related to change

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

Minors changes, but the looks good to me.

if runtime.GOOS == "windows" {
absRoot = strings.ToLower(absRoot)
absPath = strings.ToLower(absPath)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also true on macOS, by default HFS+ is case insensitive. So the following will work.

mkdir hello
cd HelLO

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been bitten so many times on weird git issues with case insensitive filesystem, the things is if you turn on the case sensitivity on HFS+ it will make many things fails.

// NOTE(ph): this is a bit of a hack because I want to make sure
// the unpack strategy stay in the struct implementation and yaml
// doesn't have a RawMessage similar to the JSON package, so partial unpack
// is not possible.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove my name next to NOTE :)

{"/a/b", "/a/b/../c", "\\a\\c", false},
{"/a/b", "../c", "\\a\\c", false},
},
}
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 tests for the case sensitivity on windows/darwin?

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

LGTM

@michalpristas michalpristas merged commit 5c2eb42 into elastic:master Apr 1, 2020
@ph ph added the needs_backport PR is waiting to be backported to other branches. label Apr 7, 2020
@ph ph added v7.8.0 and removed needs_backport PR is waiting to be backported to other branches. labels Apr 7, 2020
ph pushed a commit to ph/beats that referenced this pull request Apr 7, 2020
[Agent] Enable post install hooks (elastic#17241)

(cherry picked from commit 5c2eb42)
ph added a commit that referenced this pull request Apr 7, 2020
[Agent] Enable post install hooks (#17241)

(cherry picked from commit 5c2eb42)

Co-authored-by: Michal Pristas <michal.pristas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agent] Enable post install hooks
3 participants