Skip to content

[Fleet] Add instructions and generation of a service token for Fleet Server onboarding#97585

Merged
jen-huang merged 9 commits intoelastic:masterfrom
jen-huang:fix/onboarding-service-tokens
Apr 20, 2021
Merged

[Fleet] Add instructions and generation of a service token for Fleet Server onboarding#97585
jen-huang merged 9 commits intoelastic:masterfrom
jen-huang:fix/onboarding-service-tokens

Conversation

@jen-huang
Copy link
Copy Markdown
Contributor

@jen-huang jen-huang commented Apr 20, 2021

Summary

Relates to #96295. This PR adds a routes for generating (and regenerating, via sending delete + re-create requests to ES) a service token for Fleet Server. The name of this token is default-fleet-server-token. Since we don't have designs yet, I also took a stab try at a fully-fledged set of instructions for on prem Fleet Server onboarding that includes the service token step. Copy edits are much appreciated.

Remaining tasks:

  • Add tests
  • Update OpenAPI spec

Screenshots

What the user sees initially on empty state. They will also see this if they leave the page without finishing enrolling a Fleet server. In the latter case, Generate token will regenerate the default-fleet-server-token:

image

After they click Generate token, we display the token and install commands, the user can choose from Linux / macOS, Windows, or RPM / DEB for the platform. I took the commands from my own testing, our existing agent enrollment UI, and docs, please let me know if anything needs to be adjusted. The token and ES URL are dynamic:

Linux / macOS:

sudo ./elastic-agent install -f --fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL2RlZmF1bHQtZmxlZXQtc2VydmVyLXRva2VuOnlXN0tGYXVmVGFDNkczeExEUmpqOWc --fleet-server-es=http://localhost:9200

Windows:

.\elastic-agent.exe install --fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL2RlZmF1bHQtZmxlZXQtc2VydmVyLXRva2VuOnlXN0tGYXVmVGFDNkczeExEUmpqOWc --fleet-server-es=http://localhost:9200

RPM / DEB:

sudo elastic-agent install -f --fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL2RlZmF1bHQtZmxlZXQtc2VydmVyLXRva2VuOnlXN0tGYXVmVGFDNkczeExEUmpqOWc --fleet-server-es=http://localhost:9200
sudo systemctl enable elastic-agent 
sudo systemctl start elastic-agent

image

@jen-huang jen-huang added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 labels Apr 20, 2021
@jen-huang jen-huang requested a review from nchaulet April 20, 2021 05:18
@jen-huang jen-huang self-assigned this Apr 20, 2021
@jen-huang jen-huang requested a review from a team as a code owner April 20, 2021 05:18
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

<EuiFlyoutBody
banner={
fleetServerHosts.length === 0 ? (
fleetServerHosts.length === 0 && mode === 'managed' ? (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I also updated the Add agent flyout so that the Run standalone tab can be viewed without Fleet Server being setup. I thought this was appropriate since, well, those are standalone agents! @nchaulet maybe you can help me double check if this makes sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes it make sense 👍

}
switch (platform) {
case 'linux-mac':
return `./elastic-agent install -f --fleet-server-service-token=${serviceToken} --fleet-server-es=${esHost}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think with fleet-server always sudo is required as a part will be exposed.

@ruflin
Copy link
Copy Markdown
Contributor

ruflin commented Apr 20, 2021

Did a quick run locally and works as expected 🎉

}
};

export const regenerateServiceTokenHandler: RequestHandler = async (context, request, response) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is regenerate really what we want? It means if this API endpoint is called, all existing fleet-servers will stop working. Instead I more thinking of it as "add token".

Copy link
Copy Markdown
Member

@nchaulet nchaulet Apr 20, 2021

Choose a reason for hiding this comment

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

Yes I think we probably want to generate a new token here each time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My concern with adding a new token every time is that maybe some of them will get generated and then never used. Is that okay?

Also, since this is a new set of ES APIs, I couldn't find documentation for "retrieve all token names for this service account", which would let me generate incremental token names. Should we just generate the token names based on timestamp? token-{timestamp}?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There will be token that are generated and never used, that is why we will need some management. But it is also the reason I want to the user to "click" a button to generate it to not have too many just because a user reloaded.

++ on timestamp for now. More APIs are still under development and we can get better here.

import type { CheckPermissionsResponse, RegenerateServiceTokenResponse } from '../../../common';
import { defaultIngestErrorHandler, RegenerateServiceTokenError } from '../../errors';

const DEFAULT_FLEET_SERVER_SERVICE_TOKEN_NAME = 'default-fleet-server-token';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The service account is already called fleet-server and it is tokens for it, so not sure we need to include it all in the name. Thinking of a future where there are multiple tokens, how will the user differentiate between these. Should we call it token-{number} for token-{timestamp} for now and later let the user specify a name if they want?


const getServiceToken = useCallback(async () => {
setIsLoadingServiceToken(true);
const { data } = await sendRegenerateServiceToken();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we add some error handling around that? and use a toast notification if there is an error?

@nchaulet
Copy link
Copy Markdown
Member

@elasticmachine merge upstream

Copy link
Copy Markdown
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

🚀

}
switch (platform) {
case 'linux-mac':
return `sudo ./elastic-agent install -f --fleet-server-service-token=${serviceToken} --fleet-server-es=${esHost}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we flip this and place the --fleet-server-es first?

case 'linux-mac':
return `sudo ./elastic-agent install -f --fleet-server-service-token=${serviceToken} --fleet-server-es=${esHost}`;
case 'windows':
return `.\\elastic-agent.exe install --fleet-server-service-token=${serviceToken} --fleet-server-es=${esHost}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On windows you will want to run that either in a cmd.exe or a Powershell that is started with Run as Administrator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the copy above the commands we tell user administrator privileges are needed

case 'deb-rpm':
return `sudo elastic-agent install -f --fleet-server-service-token=${serviceToken} --fleet-server-es=${esHost}
sudo systemctl enable elastic-agent
sudo systemctl start elastic-agent`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

None of this is correct on the DEB/RPM. You only need a single command, that command will automatically handle the restart of the Elastic Agent. You also need to use the enroll command on DEB/RPM.

So just change it to one-line:

elastic-agent enroll -f --fleet-server-es=${esHost} --fleet-server-service-token=${serviceToken}

Copy link
Copy Markdown
Contributor Author

@jen-huang jen-huang Apr 20, 2021

Choose a reason for hiding this comment

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

is sudo needed in this case? yes it is

@EricDavisX
Copy link
Copy Markdown
Contributor

we had previously not exposed the rpm/deb commands as we were slightly downplaying them (relying on docs support) since their usage inherently prevents being able to 'upgrade' the agent later on. We could pull them out of this as well, but it is fine to list it, and folks may use and desire it even though it isn't our recommended usage on linux to deploy. @jen-huang

@jen-huang jen-huang added the auto-backport Deprecated - use backport:version if exact versions are needed label Apr 20, 2021
@jen-huang jen-huang enabled auto-merge (squash) April 20, 2021 17:13
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
fleet 475 454 -21

Async chunks

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

id before after diff
fleet 787.1KB 719.6KB -67.6KB

Page load bundle

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

id before after diff
fleet 346.1KB 346.3KB +135.0B
Unknown metric groups

API count

id before after diff
fleet 1076 1081 +5

API count missing comments

id before after diff
fleet 986 991 +5

History

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

cc @jen-huang

@jen-huang jen-huang merged commit 10e52bb into elastic:master Apr 20, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Apr 20, 2021
…Server onboarding (elastic#97585)

* Don't block standalone agent instructions when not using Fleet server yet

* Add service token instructions - UI only

* Add route for regenerating fleet server service token

* generate tokens instead of regenerate and add error catching and tests

* fix i18n typo

* i18n fix, add sudo, copy edits

* Fix commands

* Add missing test file

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

@jen-huang jen-huang deleted the fix/onboarding-service-tokens branch April 20, 2021 17:59
kibanamachine added a commit that referenced this pull request Apr 20, 2021
…Server onboarding (#97585) (#97696)

* Don't block standalone agent instructions when not using Fleet server yet

* Add service token instructions - UI only

* Add route for regenerating fleet server service token

* generate tokens instead of regenerate and add error catching and tests

* fix i18n typo

* i18n fix, add sudo, copy edits

* Fix commands

* Add missing test file

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Jen Huang <its.jenetic@gmail.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

auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants