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

[Security solution] [Endpoint] Fix bad artifact migration #111294

Conversation

dasansol92
Copy link
Contributor

@dasansol92 dasansol92 commented Sep 6, 2021

Summary

Zip compression was removed during artifacts generation as it was done on the fleet side.
We need to keep this behaviour for the migration script as it is taking the old ones already zip compressed.

fixes #111210

For maintainers

@dasansol92
Copy link
Contributor Author

@elasticmachine merge upstream

@dasansol92 dasansol92 marked this pull request as ready for review September 7, 2021 12:26
@dasansol92 dasansol92 requested review from a team as code owners September 7, 2021 12:26
@dasansol92 dasansol92 added auto-backport Deprecated - use backport:version if exact versions are needed release_note:fix Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.0.0 labels Sep 7, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

@dasansol92 dasansol92 requested review from a team, academo and paul-tavares and removed request for a team September 7, 2021 12:27
@@ -77,10 +82,12 @@ export const generateEsRequestErrorApiResponseMock = (
);
};

export const generateArtifactEsGetSingleHitMock = (): SearchHit<ArtifactElasticsearchProperties> => {
export const generateArtifactEsGetSingleHitMock = (
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: Just making this mock provider a bit more robust by accepting on input an optional artifact

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Sep 7, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

🔥 🔥

artifact.attributes.body = (
await inflateAsync(Buffer.from(artifact.attributes.body, 'base64'))
).toString('base64');
}
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 case where is not compressed? if so, do we have tests to cover it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paul-tavares correct me if I'm wrong, but if this script is executed just one time it shouldn't be non compressed artifacts right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@academo no, there is no case where an Artifact would be stored in the Saved Object with out being compressed. I think this check is just to be safe, but agree is not technically needed.

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

Changes to Fleet mock LGTM

expect.objectContaining({
...soArtifactEntry,
compressionAlgorithm: 'zlib',
body: 'eJyrVkrNKynKTC1WsoqOrQUAJxkFKQ==',
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this (thanks for pointing it out.
Can you remove this and instead changing the migration change to not mutate the body prop? like:

if (isCompressed(artifact.attributes)) {
  artifact.attributes = {
    ...artifact.attributes,
    body: (
      await inflateAsync(Buffer.from(artifact.attributes.body, 'base64'))
    ).toString('base64'),
  };
}

Or - capture a copy of the soArtifatEntry here in the test prior to calling migration (above like 115) and then use that to check again on like 119 (and remove body from here)

@@ -57,6 +65,15 @@ export const migrateArtifactsToFleet = async (
}

for (const artifact of artifactList) {
if (isCompressed(artifact.attributes)) {
artifact.attributes = {
...artifact.attributes,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

🚢

@paul-tavares paul-tavares self-assigned this Sep 7, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @paul-tavares

@paul-tavares paul-tavares merged commit 855a338 into elastic:master Sep 7, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 7, 2021
…1294)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 7, 2021
…1294)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 7, 2021
…1294)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.15
7.x
7.14

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Sep 7, 2021
…111432)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: David Sánchez <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>
kibanamachine added a commit that referenced this pull request Sep 7, 2021
…111430)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: David Sánchez <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>
kibanamachine added a commit that referenced this pull request Sep 7, 2021
…111431)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: David Sánchez <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 8, 2021
…-link-to-kibana-app

* 'master' of github.com:elastic/kibana: (61 commits)
  [Logs UI] Fix alert previews for thresholds of `0` (elastic#111150)
  [Archive Migration][Partial] discover apps-discover (elastic#110437)
  [APM] Set start date of APM ML job to -4 weeks (elastic#111375)
  [ML] APM Latency Correlations: Code consolidation. (elastic#110790)
  [Discover] Fix indices permission for multiline test (elastic#111284)
  [Detection Rules] Add 7.15 rules (elastic#111464)
  [Security Solution][Endpoint][Host Isolation] Hide isolate host option in alert details rather than disabling (elastic#111064)
  React version of angular license view (elastic#111317)
  [APM] Fix link in readme (elastic#111362)
  [Security Solution] add agent field to generator (elastic#111428)
  [Dashboard] Retain Tags on Quicksave (elastic#111015)
  Reorder App Search ingestion methods (elastic#111361)
  Port performance docs to new docs system. (elastic#111063)
  [Security Solution][RAC] Fixes updatedAt loading bug (elastic#111010)
  [sample data] update web log geo.src field to match country code of geo.coordinates (elastic#110885)
  [Security solution] [Endpoint] Fix bad artifact migration (elastic#111294)
  Fix copy typo. (elastic#111203)
  [build] Remove empty optimize directory (elastic#111393)
  [Maps] fix term join not updating when editing right field (elastic#111030)
  [Fleet] Set default settings in component template instead of the index template (elastic#111197)
  ...

# Conflicts:
#	x-pack/plugins/reporting/public/management/__snapshots__/report_listing.test.tsx.snap
#	x-pack/plugins/reporting/public/management/report_listing.test.tsx
chrisronline pushed a commit to chrisronline/kibana that referenced this pull request Sep 8, 2021
…1294)

* Working test that validate migrated artifact has same properties as SO artifact
* Checks if artifact is compressed and uncompress it if necessary before creating the new one from fleet

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:fix Team:Defend Workflows “EDR Workflows” sub-team of Security Solution Team:Fleet Team label for Observability Data Collection Fleet team v7.14.2 v7.15.0 v7.16.0 v8.0.0
Projects
None yet
6 participants