Skip to content

[Fleet] Introduce API versioning for serverless#163570

Merged
criamico merged 43 commits intoelastic:mainfrom
criamico:1921_API_versioning
Sep 5, 2023
Merged

[Fleet] Introduce API versioning for serverless#163570
criamico merged 43 commits intoelastic:mainfrom
criamico:1921_API_versioning

Conversation

@criamico
Copy link
Copy Markdown
Contributor

@criamico criamico commented Aug 10, 2023

Summary

Add versioning to Fleet APIs in preparation for serverless.
All the Fleet endpoints were made public by default in #163345.

  • Modify the fleet router to use the new Router.versioned provided by Kibana core. Our router is a wrapper around it so I had to do some modifications to use the new APIs.
  • Modify all the endpoints to use the new API. They'll now follow this format:
router.versioned.
    .post({
      access: 'internal', // Specified only if the access is internal, otherwise all the endpoints are public
      path: '/api/my-app/foo/{id?}',
      fleetAuthz: {
        fleet: { all: true },
      },
      options: { timeout: { payload: 60000 } }, // optional
    })
    // introduces first version
    .addVersion(
      {
        version: '2023-10-31', // The public version of this API
        validate: {
          request: endpointValidationSchema
          },
      },
      endpointHandler,
    )

If a new version will be released, a new addVersion block can be added to the previous.

  • Introduce constants for the versions. These versions will be replaced in the future when new versions of the apis will be released:

    • Public endpoints will use version API_VERSIONS.public.v1 = 2023-10-31
    • Private endpoints will use version API_VERSIONS.internal.v1 = 1
  • Mark deprecated endpoints as private. List:

    • GET /api/fleet/agent-status
    • GET /api/fleet/enrollment-api-keys
    • POST /api/fleet/enrollment-api-keys
    • GET /api/fleet/enrollment-api-keys/{keyId}
    • DELETE /api/fleet/enrollment-api-keys/{keyId}
    • POST /api/fleet/service-tokens
    • PUT /api/fleet/epm/packages/{pkgkey}
    • DELETE /api/fleet/epm/packages/{pkgkey}
  • Pass these versions through the headers wherever the fleet apis are called (UI, other plugins, tests, etc). These headers have this format:

{ Elastic-Api-Version: '2023-10-31' }
  • All the browsers calls now specify the headers with the versions

Notes

  1. In dev the request of passing the headers is always enforced, to avoid it it's needed the following flag when starting the env:
server.versioned.versionResolution: oldest

This prevents the router to enforce the headers presence for all the public endpoints; internal endpoints however will need it regardless of this flag.

  1. The kibana dev tools still don't accept the new headers, the api calls can be only tested through curl or equivalent for now

  2. These deprecated endpoints are still marked as public because if we mark them as internal the router would always choose them over the correspondent public routes.

  - `POST /api/fleet/epm/packages/{pkgkey}`
  - `GET /api/fleet/epm/packages/{pkgkey}`

Testing

  • Load Fleet in dev
  • The UI should work as normal and you should be able to see the new headers in the dev tools
  • API calls (via curl) should work as normal, with and without headers for public endpoints

Checklist

@criamico criamico added the Team:Fleet Team label for Observability Data Collection Fleet team label Aug 10, 2023
@ghost
Copy link
Copy Markdown

ghost commented Aug 10, 2023

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@criamico criamico self-assigned this Aug 10, 2023
@criamico
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@criamico criamico added the ci:cloud-deploy Create or update a Cloud deployment label Aug 21, 2023
@criamico
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

merge conflict between base and head

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 4, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 4, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 4, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 4, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 5, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 5, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 5, 2023

@elasticmachine merge upstream

@criamico
Copy link
Copy Markdown
Contributor Author

criamico commented Sep 5, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Copy Markdown

kibana-ci commented Sep 5, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Serverless Security Cypress Tests #8 / Add endpoint exception from rule details edits an endpoint exception item edits an endpoint exception item

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
fleet 937 939 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
fleet 1.2MB 1.2MB +146.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fleet 140.1KB 142.3KB +2.2KB

History

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

cc @criamico

@criamico criamico merged commit 8ca63ad into elastic:main Sep 5, 2023
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Sep 5, 2023
ashokaditya added a commit to ashokaditya/kibana that referenced this pull request Sep 6, 2023
security_solution data loader scripts using fleet APIs
need to move to versioned fleet APIs after changes in elastic/pull/163570

refs elastic/security-team/issues/7547
criamico added a commit that referenced this pull request Sep 6, 2023
## Summary

Related to #163570

Add a section to Readme about option to provide a default version for
API headers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting ci:cloud-deploy Create or update a Cloud deployment release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.11.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants