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

[Fleet] Use fleet server indices for enrollment keys and to list agents with a feature flag #86179

Merged

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented Dec 16, 2020

Summary

Part of #87372

Introduce a feature flag to start using fleet server indice xpack.fleet.agents.fleetServerEnabled: true

If this flag is enabled we will use a different service that read and write for .fleet-enrollment-key instead of saved object.

This is a draft PR to explore what a feature flag for the development of Kibana with Fleet Server will look like

How to test that PR?

With the feature flag off

if the feature flag is off xpack.fleet.agents.fleetServerEnabled: false you should be able to create a policy, enroll agents, unenroll, all the actions as before, (this PR should not have any impact)

With the feature flag on

with the feature flag on xpack.fleet.agents.fleetServerEnabled: true you should be able to enroll agent, and rollup a policy via fleet-server, (turning the flag off again is not supported)

You should respect the following order (for now):

  • Start fleet-server
  • Create a custom kibana system user with the right permissions (see below)
  • start kibana with flag and the custom kibana user
  • Setup fleet and agent in Kibana set the kibana url to the fleet server url (by default http://localhost:8000)
  • enroll an agent to fleet server, you can trigger a policy change the other actions are not yet working.

Migration

During the plugin start we will transform all of the existing saved object to .fleet-* document, I discussed this kibana platform and it should work for us.

Indices creation

In this PR we rely on fleet server creating the indice, (in the future the indice should be created by an ES plugin)

So the first step is to run fleet server.

Kibana system user

The kibana_system will need to have access to .fleet* indices.

In this PR I used a custom user as the kibana system user created like

POST /_security/role/kibana_fleet_system
{
   "cluster" : [
      "all"
    ],
    "indices" : [
      {
        "names" : [
          ".fleet*"
        ],
        "privileges" : [
          "all"
        ]
      }
    ]
}



POST /_security/user/kibana_fleet_system
{
  "password" : "changeme",
  "roles" : [ "kibana_system", "kibana_fleet_system" ]
}

then in kibana.dev.yml

elasticsearch.username: 'kibana_fleet_system'
elasticsearch.password: 'changeme'

@nchaulet nchaulet added the Team:Fleet Team label for Observability Data Collection Fleet team label Dec 16, 2020
@nchaulet nchaulet force-pushed the feature-poc-kibana-fleet-server-feature-flag branch from 75b2a6a to 4a8791b Compare December 16, 2020 21:12
@nchaulet nchaulet self-assigned this Dec 17, 2020
@nchaulet nchaulet marked this pull request as ready for review January 6, 2021 14:11
@nchaulet nchaulet requested a review from a team as a code owner January 6, 2021 14:11
@nchaulet nchaulet requested a review from a team January 6, 2021 14:11
@nchaulet nchaulet requested a review from a team as a code owner January 6, 2021 14:11
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

Didn't review test files or security_solution files. Left questions and comments mostly regarding the ES agents CRUD service.

@nchaulet
Copy link
Member Author

Yes it's normal you cannot enroll an agent to kibana for now, you need to enroll the agent to fleet server. I will add the support for the new indices and Kibana enroll in a future PR the whole migration plan is here #87372

@jen-huang
Copy link
Contributor

@nchaulet How can I enroll into Fleet server? Can you update the PR description with more testing steps around what is expected behavior?

@nchaulet
Copy link
Member Author

nchaulet commented Jan 19, 2021

@jen-huang thanks for taking some time on that PR, and sorry for the missing expectations, I udpated the PR description and created a small video on what to expect when testing with the flag set to on.

What to test on that PR:

  • nothing break when the flag is off
  • you can enroll and agent via Fleet server when the flag is on.
fleet-server.mp4

@jen-huang
Copy link
Contributor

Thanks for the updated instructions and video. I ran through the Fleet server enabled scenario again today and am seeing all of the behavior described. My agent has logs and I see data streams come in too. The only issue I see is that the status bar doesn't reflect the status of the agents, but I think that might be due to the current limitation of "can trigger a policy change the other actions are not yet working"?

image

Tomorrow I will run another test with Fleet server disabled and give the code another look too.

@nchaulet
Copy link
Member Author

@jen-huang yes the agent status with Fleet server are not yet working if it's okay with you I will fix it in a following PR as there is already a lot of change here

@nchaulet
Copy link
Member Author

@kevinlog I would love a review from endpoint here, mostly checking if the flag set to false it's not breaking anything

@jen-huang
Copy link
Contributor

@nchaulet Yeah no worries, just wanted to confirm that it's a known limitation right now.

@kevinlog
Copy link
Contributor

kevinlog commented Jan 20, 2021

@nchaulet

I checked it out and tested with some basic Endpoint flows with xpack.fleet.agents.fleetServerEnabled: false, Endpoints deploy correctly and I'm still able to change policies, etc.

From that perspective, the change looks good from our end - I'll leave the review of the actual code to Fleet devs.

image

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

Tested locally with and without Fleet server enabled. With Fleet server, ran into known limitations but overall things work as described. Without Fleet server, things worked normally and I confirmed that .fleet indices were not created.

Left some code comments but not blocking. Thanks for your patience during my reviews of this and good work on getting this first major piece completed!

return appContextService.getInternalUserSOClient(fakeRequest);
}

async function migrateEnrollmentApiKeys() {
Copy link
Contributor

Choose a reason for hiding this comment

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

not a blocker but would be good to have tests for this

would agent documents need to be migrated too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes agents would need to be migrated too, I am probably going to address that and add tests for that in a following PR as this PR is already complex

@@ -291,6 +295,12 @@ export class FleetPlugin
licenseService.start(this.licensing$);
agentCheckinState.start();

const fleetServerEnabled = appContextService.getConfig()?.agents?.fleetServerEnabled;
if (fleetServerEnabled) {
await this.licensing$.pipe(first()).toPromise();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we wait for licensing before starting migration?

Copy link
Member Author

@nchaulet nchaulet Jan 20, 2021

Choose a reason for hiding this comment

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

we need licensing to be available so the SO client is correctly initialized. it probably need a comment here

@nchaulet nchaulet requested a review from paul-tavares January 20, 2021 19:20
@nchaulet nchaulet removed the request for review from paul-tavares January 20, 2021 19:44
@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

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

id before after diff
fleet 377.0KB 377.9KB +860.0B

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants