elastic / kibana

Your window into the Elastic Stack

Home Page:https://www.elastic.co/products/kibana

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Fleet] Allow uploading zip packages in integrations UI

jen-huang opened this issue · comments

Supersedes #70582

Today we have the endpoint POST /api/fleet/epm/packages which accepts a zip package archive and uploads it to Fleet in the same way that a regular package install would. This feature is important to reduce the total delivery time for package developers. While much of the functionality is complete through enabling bundled packages with Kibana, there are still some outstanding tasks before this API is ready for documentation and wider use:

  • The package policy editor doesn't use the streams from the uploaded package if another version of the package also exists in the registry (original report)
  • Ensure uploaded package can be fully uninstalled
  • Ensure uploaded package can be fully overwritten (similar to a re-install)
  • Ensure uploaded package does not conflict with bundled or registry packages (whether they are installed or not)
  • Robust unit tests around the code path (installPackageByUpload, parseAndVerifyArchive)
  • Improved integration tests
  • OpenAPI documentation

Sample test instructions can be found at elastic/integrations#4597:

  1. Download elasticsearch-1.1.0-preview1.zip
  2. Upload the package to Kibana:
curl -XPOST -H 'content-type: application/zip' -H 'kbn-xsrf: true' http://my-kibana:5601/api/fleet/epm/packages -u elastic:changeme --data-binary @elasticsearch-1.1.0-preview1.zip

Related enhancements that can be done once the API is finished:

  • Support gzip in addition to zip (as of last testing, seems gzip has some issues)
  • UI for upload package
  • CLI integration with elastic-package: elastic/elastic-package#1084

Pinging @elastic/fleet (Team:Fleet)

After reviewing the issue, the linked improvements in #70582 are still needed. Started working on them.

  • [Fleet] Use epm-packages saved object as main source of truth for installed packages #81995
  • [Fleet] Refactor package installation / upgrade / downgrade and error recovery / rollback #82007

Can't reproduce this issue:

  • [Fleet] Add error handling: uploaded package missing from in-memory cache #82010

This one I'll hold off on, as it is a change in package-spec repo.

@jen-huang @kpollich @jsoriano Do we have an example package that is not yet in the registry? The elasticsearch package mentioned in the description is already there. I would need one to test some scenarios where the package is not in registry.

@juliaElastic you could use elastic-package build --zip -v to build one of our test packages in x-pack/test/fleet_api_integration/apis/fixtures if that works? I know alot of them are not 100% valid per the package spec but they should be good enough

@hop-dev it worked, thanks.

@jen-huang @kpollich I am wondering if this issue is still relevant: #82010 Not sure how to reproduce a cache miss. Do any of you know? I'm looking at the uploaded packages after kibana restart in local, and don't see any issues.
I think this code was refactored since the issue was raised, and we fetch the info from source if missing in cache. If you agree, we can close this one.

image

I think the above is likely no longer relevant. From what I remember, all installation paths add packages to the in-memory cache as expected. I'm going to close that issue as I don't think it's relevant to the current state of the EPM codebase.

Tested the Uninstall of uploaded packages and seems to work fine.

@kpollich What is the expected behavior of the Reinstall button on the UI for uploaded packages?
Now the button calls the POST /epm/packages API that calls the installPackageFromRegistry function.

We could potentially add a drag and drop feature to upload the zip file again on the UI, though this is out of scope for this issue I think. Should we make the button disabled with a tooltip for uploaded packages?

image

We could potentially add a drag and drop feature to upload the zip file again on the UI, though this is out of scope for this issue I think. Should we make the button disabled with a tooltip for uploaded packages?

Agreed on a both. A dropzone implementation could be nice, but seems needless for the corner case of reinstalling an uploaded package. Let's go forward with the disabled button + tooltip stating

This integration was installed by upload and cannot be automatically reinstalled. Please upload it again to reinstall.

@joshdover I tried to reproduce the issue reported here on 8.7 but couldn't:

The package policy editor doesn't use the streams from the uploaded package if another version of the package also exists in the registry

I uploaded the elasticsearch-1.3.0-preview1 package from the linked pr and I'm seeing the new data stream on the Package Policy Create UI. Tested the Edit and Upgrade package policy forms as well, looks good.
Did you see the issue in a different scenario?

image

@juliaElastic it must be fixed, I was testing this against 8.5 at the time which I think was before some of the changes we did for input packages were in place that may have fixed this.

Tested uploads with elasticsearch package, that has latest 1.2.0 GA version in registry, initially the package was not installed.

  • uploaded version 1.3.0-preview1
  • uploaded an older 1.0.0 version (downgrade)
  • upgraded uploaded package to latest 1.2.0 registry version
  • uploaded again version 1.3.0-preview1

image

image

image

The API work is done, so closing the issue.
Planning to investigate gzip support separately.

I tried uploading a tar.gz file (compressed an extracted zip package) and it was successful. There is also an integration test with application/gzip content type.

tar -czf verified-1.0.0.tar.gz verified-1.0.0/
curl -XPOST -H 'content-type: application/gzip' -H 'kbn-xsrf: true' http://localhost:5601/julia/api/fleet/epm/packages -u elastic:changeme --data-binary @verified-1.0.0.tar.gz

// response:
{"items":[{"id":"logs-verified.log-1.0.0","type":"ingest_pipeline"},{"id":"logs-verified.log","type":"index_template"},{"id":"logs-verified.log@package","type":"component_template"},{"id":"logs-verified.log@custom","type":"component_template"}],"response":[{"id":"logs-verified.log-1.0.0","type":"ingest_pipeline"},{"id":"logs-verified.log","type":"index_template"},{"id":"logs-verified.log@package","type":"component_template"},{"id":"logs-verified.log@custom","type":"component_template"}],"_meta":{"install_source":"upload"}}%  

Support gzip in addition to zip (as of last testing, seems gzip has some issues)

@kpollich Could you let me know how to reproduce the issues mentioned in the description?

Another thing, I noticed that the upload package logic skips verification. Is this something we want to support in the future? If so, might be worth creating a follow up issue.

@kpollich Could you let me know how to reproduce the issues mentioned in the description?

It's been a very long time, so I'm not sure. If gzip functionality is working in recent tests, then I'd expect work we've done to archive parsing logic in recent sprints/releases has resolved whatever issues we had initially.

Another thing, I noticed that the upload package logic skips verification. Is this something we want to support in the future? If so, might be worth creating a follow up issue.

Yes, it'd be great to support verification of uploaded packages if possible. I agree that a follow up issue would be appropriate here. I suppose we'll have to think about how to provide a signature file along with an uploaded package, right?

Yes, it'd be great to support verification of uploaded packages if possible. I agree that a follow up issue would be appropriate here. I suppose we'll have to think about how to provide a signature file along with an uploaded package, right?

Yes, we might have to change the API to support multiple files or create another API endpoint to verify an uploaded package. If we eventually add the elastic-package support for this, it would be easier for users to send the signature as well, even if there are more than one underlying API calls.

I think having the upload API support multiple files would be ideal, but not sure on how much work that'd actually be. A separate API for uploading signatures would be a fallback.

Another option could be to allow for a different archive directory structure that includes signature files at the root of the archive. We'd have to have some conditional logic that determines whether this is the case, though, because the current validation logic expects only a single top-level directory I believe.

Another option could be to allow for a different archive directory structure that includes signature files at the root of the archive. We'd have to have some conditional logic that determines whether this is the case, though, because the current validation logic expects only a single top-level directory I believe.

I don't think this would be feasible since the content of the signature itself depends on the content of the zip.

+1 to supporting multiple files on the same API call. This is supported by multipart content-type I believe

commented

@kpollich & @juliaElastic is there a docs issue for this feature?

@nimarezainia Not yet, perhaps we could add a section in the docs about how to upload packages around here: https://www.elastic.co/guide/en/fleet/master/air-gapped.html#air-gapped-diy-epr
@kpollich WDYT?

commented

Thanks @juliaElastic. if there was a docs issue with enough details for the documentation to follow that would be great. Regarding the location where that content resides I would leave it to their expertise.

(fyi @dedemorton & @karenzone )

@juliaElastic If this is an alternative to users hosting their own package registry, then, yes, it should be documented in the topic about air gapped environments. To get this in quickly, I would suggest opening a PR with the doc changes and tagging @elastic/ingest-docs for review and technical edits.