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

Create Elastic Agent enrolment tokens in the operator #5846

Merged
merged 28 commits into from
Jul 19, 2022

Conversation

pebrc
Copy link
Collaborator

@pebrc pebrc commented Jun 29, 2022

Fixes #5779

See issue for detail on the approach taken. But to repeat the gist: do not expose highly privileged Kibana credentials to Elastic Agent Pods. Instead make the operator do all the Kibana API interactions with the more limited user (possible as of 8.1) and expose only the enrolment token to the Elastic Agent as it would be also the case on a typical bare metal installation.

Tradeoffs:

  • Agent rollout needs to wait until Kibana is available (but in the old system the Agents would just crash loop until that was the case so I consider this actually an improvement)
  • Operator needs to stay up to date with Fleet API development. So far the relevant APIs have been fairly stable with one API being renamed for consistency.
  • Each Kibana association creates a Kibana user. Technically we could use a single user to do all the API interactions with Kibana but that would have broken out of the association mechanism and it seemed convenient and correct to keep using that.

Some additional choices I made that are maybe of interest to reviewers: I am not reusing the default enrolment token but creating a new one. No particular strong reason for that. It allows us to clean the tokens up if something goes wrong and also allows us to run without explicitly calling /api/fleet/setup (which creates the default tokens). In practice I ended up calling the setup API anyway because we cannot rely on users configuring Kibana with pre-defined policies in kibana.yml (as do all our recipes). So if there are strong feelings against creating our own tokens we can revisit this choice.

I hope I did not miss anything fundamental. I did manual tests with 7.14 (first version of Fleet we support), 7.17 and a recent 8.x.

@botelastic botelastic bot added the triage label Jun 29, 2022
@pebrc pebrc added the >enhancement Enhancement of existing functionality label Jun 29, 2022
@botelastic botelastic bot removed the triage label Jun 29, 2022
@pebrc
Copy link
Collaborator Author

pebrc commented Jun 29, 2022

run/e2e-tests tags=agent

1 similar comment
@pebrc
Copy link
Collaborator Author

pebrc commented Jun 30, 2022

run/e2e-tests tags=agent

@pebrc pebrc marked this pull request as ready for review July 3, 2022 18:58
@pebrc
Copy link
Collaborator Author

pebrc commented Jul 4, 2022

Jenkins test this please

@pebrc pebrc requested a review from david-kow July 4, 2022 05:19
@pebrc pebrc added the v2.4.0 label Jul 4, 2022
Copy link
Contributor

@david-kow david-kow left a comment

Choose a reason for hiding this comment

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

LGTM! One thing I'd like to clarify is what happens if the user sets FLEET_SERVER_POLICY_ID env var separately from policyID. Should we document the precedence?

pkg/controller/agent/config.go Outdated Show resolved Hide resolved
pkg/controller/agent/config.go Outdated Show resolved Hide resolved
pkg/controller/agent/driver.go Outdated Show resolved Hide resolved
pkg/controller/agent/fleet.go Outdated Show resolved Hide resolved
if kb.Status.Health != commonv1.GreenHealth {
return false, nil // requeue
}
return true, nil
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I realise this does not work well with external KibanaRefs. I will look into making an actuall HTTP request instead here.

Copy link
Collaborator Author

@pebrc pebrc Jul 14, 2022

Choose a reason for hiding this comment

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

It turns out this is a rabbit hole. Making external refs work is more complicated. Other things required: communication between Fleet Server and Elasticsearch needs to use a service token otherwise Agent will try to talk to Kibana to generate one. Also I ran into some weird connectivity issues where Agent seemed to connect to an IP directly without host header and failed to connect through the ESS proxy. Still looking into that, but I might punt the external ref support to another PR if it makes sense at all.

@pebrc
Copy link
Collaborator Author

pebrc commented Jul 18, 2022

run/e2e-tests tags=agent

@pebrc
Copy link
Collaborator Author

pebrc commented Jul 18, 2022

@elasticmachine, run elasticsearch-ci/docs

@pebrc pebrc merged commit 2d0f7fe into elastic:main Jul 19, 2022
@david-kow david-kow changed the title Create agent enrollment tokens in the operator Create Elastic Agent enrolment tokens in the operator Aug 3, 2022
fantapsody pushed a commit to fantapsody/cloud-on-k8s that referenced this pull request Feb 7, 2023
Do not expose highly privileged Kibana credentials to Elastic Agent Pods. Instead make the operator do all the Kibana API interactions with the more limited user (possible as of 8.1) and expose only the enrolment token to the Elastic Agent as it would be also the case on a typical bare metal installation.

Tradeoffs:
- Agent rollout needs to wait until Kibana is available (but in the old system the Agents would just crash loop until that was the case so I consider this actually an improvement)
- Operator needs to stay up to date with Fleet API development. So far the relevant APIs have been fairly stable with one API being renamed for consistency.
- Each Kibana association creates a Kibana user. Technically we could use a single user to do all the API interactions with Kibana but that would have broken out of the association mechanism and it seemed convenient and correct to keep using that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement Enhancement of existing functionality v2.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should the operator create enrolment tokens instead of configuring Agents to talk to Kibana
2 participants