-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[Fleet] Implement secrets in APM package policy editor #225956
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
base: main
Are you sure you want to change the base?
Conversation
@@ -57,7 +57,7 @@ export function getAgentAuthorizationSettings(): SettingsRow[] { | |||
], | |||
}, | |||
{ | |||
type: 'text', | |||
type: 'secret', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this value immediately has the effect of using the "fallback" component that renders a EUiFieldPassword
, but it doesn't affect the functionality - secret_token
keeps being saved as plain text.
I think that this is acceptable but let me know if it's better to change it later when the new APM version with secret: true
will be released.
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Public APIs missing comments
Any counts in public APIs
Async chunks
Public APIs missing exports
Page load bundle
History
cc @criamico |
Pinging @elastic/fleet (Team:Fleet) |
@elasticmachine merge upstream |
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
if ( | ||
packageInfo && | ||
packageInfo.policy_templates && | ||
packageInfo.policy_templates.length > 0 && | ||
'inputs' in packageInfo.policy_templates[0] && | ||
Array.isArray(packageInfo.policy_templates[0].inputs) && | ||
packageInfo.policy_templates[0].inputs.length > 0 && | ||
packageInfo.policy_templates[0].inputs[0].vars | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work instead?
if ( | |
packageInfo && | |
packageInfo.policy_templates && | |
packageInfo.policy_templates.length > 0 && | |
'inputs' in packageInfo.policy_templates[0] && | |
Array.isArray(packageInfo.policy_templates[0].inputs) && | |
packageInfo.policy_templates[0].inputs.length > 0 && | |
packageInfo.policy_templates[0].inputs[0].vars | |
) { | |
if ( | |
packageInfo?.policy_templates?.[0]?.inputs?.[0]?.vars | |
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works per se if I shorten it but the linter is not happy. This looks a bit funky and I don't like it either, but the alternative is
if (
packageInfo &&
packageInfo.policy_templates &&
packageInfo.policy_templates.length > 0 &&
packageInfo.policy_templates[0].inputs.length > 0 &&
packageInfo.policy_templates[0].inputs[0].vars
)
and some ts-ignore
lines here and there. The reason is that inputs
exists only in one of the types of this union type:
https://github.com/criamico/kibana/blob/a60bde8d65ce41f14aced142fb273457ef928e30/x-pack/platform/plugins/shared/fleet/common/types/models/epm.ts#L273-L275
so I had to add the type guard as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could break the condition? Just brainstorming ideas to try to simplify the condition.
const { policy_templates = [] } = packageInfo || {};
const policyTemplate = policy_templates[0];
const inputs = 'inputs' in policy_templates[0] ? policy_templates[0].inputs : undefined;
if (inputs && Array.isArray(inputs) && inputs.length > 0 && inputs[0].vars) {
}
I don't want to block the PR because of this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I broke down the condition as suggested :)
IMO showing a Create API Key button and nudging users to API Key makes sense for the onboarding flow. |
I need to check if there's a way to retrieve the plain text value. Currently we don't do it anywhere in Fleet, we just send the value to the policy and fleet server will read it. The value that is returned in the package policy is like follows, we just see an id that is then internally used to retrieve the value:
Would it be an option to add a warning to the user that they need to write down this value when they enter it - similar to what we do in other areas of the product? I believe it's like that for the main token displayed in serverless onboarding. |
...s/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
Outdated
Show resolved
Hide resolved
...s/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
Outdated
Show resolved
Hide resolved
...s/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
Outdated
Show resolved
Hide resolved
Kibana cannot retrieve Fleet secrets by design - only Fleet Server can read these secret values. If there's a requirement that users can see the secret token, is just rendering these as an input with |
Yeah allowing them to read it back kind of defeats the purpose of making this a secret in the first place. Since this is going out in a minor release version, I just want to ensure that we are not breaking existing workflows. |
I wonder if we can do the same thing we did when introducing Fleet Secrets initially here and have a "first time secret" flow where the current, plain-text value of the token is rendered with a warning that it will automatically be converted to a secret and will no longer be readable, so the user should copy it somewhere safe to maintain access to it. IIRC we have some code in Fleet to detect this with the policy saved objects, @criamico. This might be tough with APM, though, since we automatically upgrade the package behind the scenes today. We want to introduce a user-facing step here where the user must consent to their token being "taken away" and turned into a secret. They need a chance to persist the value. |
@elasticmachine merge upstream |
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
@simitt - Agree that showing a Create API Key button and nudging users to API Key should be incorporated as part of the onboarding flow. |
@kpollich @akhileshpok @simitt I did a local test where I buit the apm version with secret_token marked as ![]() ![]() So I think that this can be a starting point to warn the user when the upgrade is presented. In addition, I'm checking how to build some logic based on this comment:
|
+1 from me - I'm glad the work we did to add generic breaking change handling can be reused at least to some extent here. Since APM is auto-upgraded, I wonder if we could enhance this to flow to notify the user via a toast when the auto-upgrade failed due to a breaking change and direct them to the view you've screenshotted. |
Closes #224063
Summary
Implement secrets in APM policy editor. This implementation mirrors what we currently have in Integrations'
packagePolicyEditor
.❗ In order to work as expected, a new version of APM where secret_token has
secret: true
needs to be releasedIn Fleet:
package_policy_input_var_field
in Fleet so the components are now decoupled andSecretInputField
can be exported to be used by other pluginsuseSecretsStorage
that checks if the requirements to enable secrets are available: Fleet server needs to be available and to have at least version 8.0.0 - below that version fleet server doesn't have the capability to read secrets in package policies.In APM:
secret_token
key assecret: true
and added a new type 'secret' to be able to correctly display any secret fields. I also had to pass down an additional property "packageInfo" to be able to check that an input var is marked as "secret" in the package manifest. This aligns with the general functionality in IntegrationsUI
With


secret: true
enabled and the correct version of Fleet server installed:Fallback UI - displays a password field

View policy:

Testing
Checklist