Skip to content

[Fleet] Make API routes public by default#163345

Merged
juliaElastic merged 4 commits intoelastic:mainfrom
nchaulet:feature-default-public-access-fleet
Aug 8, 2023
Merged

[Fleet] Make API routes public by default#163345
juliaElastic merged 4 commits intoelastic:mainfrom
nchaulet:feature-default-public-access-fleet

Conversation

@nchaulet
Copy link
Copy Markdown
Member

@nchaulet nchaulet commented Aug 7, 2023

Summary

Kibana API will not be public by default in serverless, this mean Fleet API will not be accessible.

That PR fix that by changing the Fleet router to make Fleet API routes public unless they specify options.access in their config, the only route that I found that should be internal is the /internal/fleet/reset_preconfiguration`

Test

  • Added unit test to our router

manual test run Kibana in serverless and check Fleet API are still publicly available

Before that change

Screenshot 2023-08-07 at 1 36 29 PM

After that change

Screenshot 2023-08-07 at 1 36 55 PM

@nchaulet nchaulet added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team labels Aug 7, 2023
@nchaulet nchaulet self-assigned this Aug 7, 2023
@nchaulet nchaulet requested a review from a team as a code owner August 7, 2023 17:32
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

@ghost
Copy link
Copy Markdown

ghost commented Aug 7, 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!)

@nchaulet
Copy link
Copy Markdown
Member Author

nchaulet commented Aug 8, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @nchaulet

Copy link
Copy Markdown
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

LGTM, I think we should review though if anything else can be made internal e.g. deprecated APIs.

@juliaElastic juliaElastic merged commit 5a6c5fb into elastic:main Aug 8, 2023
@kibanamachine kibanamachine added v8.10.0 backport:skip This PR does not require backporting labels Aug 8, 2023
@nchaulet nchaulet deleted the feature-default-public-access-fleet branch August 8, 2023 13:59
bryce-b pushed a commit to bryce-b/kibana that referenced this pull request Aug 9, 2023
## Summary

Kibana API will not be public by default in serverless, this mean Fleet
API will not be accessible.

That PR fix that by changing the Fleet router to make Fleet API routes
public unless they specify `options.access` in their config, the only
route that I found that should be internal is the
/internal/fleet/reset_preconfiguration`

## Test

- [x] Added unit test to our router

manual test run Kibana in serverless and check Fleet API are still
publicly available

Before that change 

<img width="1003" alt="Screenshot 2023-08-07 at 1 36 29 PM"
src="https://github.com/elastic/kibana/assets/1336873/8e2fb113-f5e8-45e8-9892-f25bd9e722ad">


After that change 

<img width="679" alt="Screenshot 2023-08-07 at 1 36 55 PM"
src="https://github.com/elastic/kibana/assets/1336873/3cade239-5b13-4caf-bd1a-1bc8e2495c31">

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
criamico added a commit that referenced this pull request Sep 5, 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.

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

3. 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
- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
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 release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.10.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants