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] Only enable output secrets if all Fleet servers are compatible #173398

Conversation

jillguyonnet
Copy link
Contributor

@jillguyonnet jillguyonnet commented Dec 14, 2023

Summary

Closes #173041

Output secret storage requires that all Fleet servers are on version 8.12.0 or above.

The implementation is similar to package policy secrets: #163627: this PR adds the new output_secret_storage_requirements_met flag on the ingest_manager_settings saved object.

Testing

  1. Define a preconfigured output wit a secret value in your kibana.dev.yml file, e.g.:
    xpack.fleet.outputs:
      - id: my-logstash-output-with-a-secret
        name: preconfigured logstash output with a secret
        type: logstash
        hosts: ['localhost:9999']
        ssl:
          certificate: xxxxxxxxxx
        secrets:
          ssl:
            key: secretLogstashKey
  2. Start ES and Kibana. Do not start a Fleet server.
  3. Go to Fleet settings and inspect the preconfigured output: it should have been created and the secret value should not have been set (optionally, you can check in the Console with GET .fleet-secrets/_search that the secret was not created). However, a plain text equivalent should have been created (in the example above, ssl.key should be set to secretLogstashKey).
  4. Start a Fleet server on version less than 8.12.0. Kibana should update the output. Again, check that the secret value was not set and that the plain text equivalent is set.
  5. Stop the Fleet server and start another one on version 8.12.0 or higher. Kibana should update the output. This time, the secret value should have been set.

Checklist

@apmmachine
Copy link
Contributor

🤖 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!)

@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet jillguyonnet self-assigned this Dec 18, 2023
@jillguyonnet jillguyonnet force-pushed the fleet/173041-output-secrets-fleet-server-check branch from ca07d48 to 2ff0875 Compare December 18, 2023 11:18
@jillguyonnet jillguyonnet added Team:Fleet Team label for Observability Data Collection Fleet team release_note:skip Skip the PR/issue when compiling release notes v8.12.0 labels Dec 18, 2023
@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet
Copy link
Contributor Author

/ci

… src/core/server/integration_tests/ci_checks'
@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet
Copy link
Contributor Author

@elastic/fleet @juliaElastic Can I get some input about the expectation here?

As is, a secret will not be set if the Fleet servers version check fails. This could have the effect that the output is not fully set. Is this sufficient, or should there be added logic to set a plain text value instead?

The Cypress test failures are a reflection of this: for instance, this expectation fails as the secret is not set (this is because there is no Fleet server).

@juliaElastic
Copy link
Contributor

juliaElastic commented Dec 19, 2023

As is, a secret will not be set if the Fleet servers version check fails. This could have the effect that the output is not fully set. Is this sufficient, or should there be added logic to set a plain text value instead?

If the Fleet server version check fails, the logic should fallback to storing plain text secrets (existing behaviour), this is also how it works for policy secrets.

@juliaElastic
Copy link
Contributor

juliaElastic commented Jan 2, 2024

@jillguyonnet Do you think we can get this pr in before the last BC is built on Jan 4? Let me know if you need help.

@jillguyonnet
Copy link
Contributor Author

Hey @juliaElastic - yes tackling this now.

@jillguyonnet
Copy link
Contributor Author

@elasticmachine merge upstream

@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet
Copy link
Contributor Author

/ci

@jillguyonnet jillguyonnet marked this pull request as ready for review January 4, 2024 09:10
@jillguyonnet jillguyonnet requested a review from a team as a code owner January 4, 2024 09:10
@jillguyonnet jillguyonnet requested a review from a team as a code owner January 4, 2024 09:10
updateData.type === outputType.RemoteElasticsearch
) {
if (!data.service_token && data.secrets?.service_token) {
updateData.service_token = data.secrets?.service_token as string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this logic can be extracted, seems very similar to the create method. It could be done in a follow up pr.
Do we have test coverage over this logic?

Also, is it necessary for originalOutput to have the same type as the updated output? It can happen that the type changes, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if this logic can be extracted, seems very similar to the create method. It could be done in a follow up pr.

Agreed. These methods are very long and could use some extracting/refactoring. It's always a little dangerous to leave refactoring for followup, but it might be the right call in this case.

Do we have test coverage over this logic?

We do in the integration tests, I suppose, but absolutely happy to add some unit tests as well.

Also, is it necessary for originalOutput to have the same type as the updated output? It can happen that the type changes, isn't it?

Good point! I guess that is not required (and perhaps even a liability). Perhaps it would be good to add a test with an output type change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have some tests on output type change in cypress tests.

@juliaElastic
Copy link
Contributor

buildkite, test this

Copy link
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.

Tested, and looks good.

There is one scenario which looks expected, though maybe something we should clarify in the docs. Namely how existing outputs can be recreated with secret storage.
Steps to reproduce:

  • Create an output with a secret without fleet server, the output secret is stored as plain text (e.g. remote ES with secret token)
  • Enroll a fleet server 8.12
  • Go back to the existing output to edit
  • Outcome: the service token shows up as a plain text, there is no way to update it to be saved as a secret from the UI, unless creating a new output.
image

@jillguyonnet
Copy link
Contributor Author

Thanks for your review @juliaElastic 🙏

I will address your point regarding originalOutput above, let me know if you would like to see added tests and/or refactor in the PR (otherwise happy to open a followup issue).

Regarding the UI, there is this followup issue that was considered a nice-to-have, although I definitely agree that the docs should reflect the current situation: #171418. WDYT?

I'm also waiting for approval from @elastic/kibana-core.

@juliaElastic
Copy link
Contributor

I will address your point regarding originalOutput above, let me know if you would like to see added tests and/or refactor in the PR (otherwise happy to open a followup issue).

Thanks, I'm fine to leave the refactor as a follow up, to get this in before the next BC build.

Regarding the UI, there is this followup issue that was considered a nice-to-have, although I definitely agree that the docs should reflect the current situation: #171418. WDYT?

Good to know that there is already a follow up for this. We could check if there is already any docs being added on output secrets.

@jillguyonnet
Copy link
Contributor Author

Pushed the fix with a couple of associated unit tests.

I opened #174258 as a followup refactor issue.

Also pinged the core team on Slack, hopefully will get this out now 🤞

@jillguyonnet
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Additional mapping looks good to me! Approving to unblock progress -- although I can't see the new field currently being used for search?

@jillguyonnet
Copy link
Contributor Author

Thanks for approving @jloleysens - it's a good point, I thought the implementation should mirror what was done for policy secrets in #163627.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @jillguyonnet

@jillguyonnet jillguyonnet merged commit 70508b9 into elastic:main Jan 8, 2024
20 checks passed
@jillguyonnet jillguyonnet deleted the fleet/173041-output-secrets-fleet-server-check branch January 8, 2024 09:20
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 8, 2024
elastic#173398)

## Summary

Closes elastic#173041

Output secret storage requires that all Fleet servers are on version
8.12.0 or above.

The implementation is similar to package policy secrets:
elastic#163627: this PR adds the new
`output_secret_storage_requirements_met` flag on the
`ingest_manager_settings` saved object.

### Testing

1. Define a preconfigured output wit a secret value in your
`kibana.dev.yml` file, e.g.:
   ```yml
   xpack.fleet.outputs:
     - id: my-logstash-output-with-a-secret
       name: preconfigured logstash output with a secret
       type: logstash
       hosts: ['localhost:9999']
       ssl:
         certificate: xxxxxxxxxx
       secrets:
         ssl:
           key: secretLogstashKey
   ```
3. Start ES and Kibana. Do not start a Fleet server.
4. Go to Fleet settings and inspect the preconfigured output: it should
have been created and the secret value should not have been set
(optionally, you can check in the Console with `GET
.fleet-secrets/_search` that the secret was not created). However, a
plain text equivalent should have been created (in the example above,
`ssl.key` should be set to `secretLogstashKey`).
5. Start a Fleet server on version less than 8.12.0. Kibana should
update the output. Again, check that the secret value was not set and
that the plain text equivalent is set.
6. Stop the Fleet server and start another one on version 8.12.0 or
higher. Kibana should update the output. This time, the secret value
should have been set.

### Checklist

- [x] [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 <[email protected]>
Co-authored-by: Julia Bardi <[email protected]>
(cherry picked from commit 70508b9)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 8, 2024
…mpatible (#173398) (#174433)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Fleet] Only enable output secrets if all Fleet servers are
compatible (#173398)](#173398)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jill
Guyonnet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-08T09:20:20Z","message":"[Fleet]
Only enable output secrets if all Fleet servers are compatible
(#173398)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/173041\r\n\r\nOutput secret
storage requires that all Fleet servers are on version\r\n8.12.0 or
above.\r\n\r\nThe implementation is similar to package policy
secrets:\r\nhttps://github.com//pull/163627: this PR adds
the new\r\n`output_secret_storage_requirements_met` flag on
the\r\n`ingest_manager_settings` saved object.\r\n\r\n###
Testing\r\n\r\n1. Define a preconfigured output wit a secret value in
your\r\n`kibana.dev.yml` file, e.g.:\r\n ```yml\r\n
xpack.fleet.outputs:\r\n - id: my-logstash-output-with-a-secret\r\n
name: preconfigured logstash output with a secret\r\n type: logstash\r\n
hosts: ['localhost:9999']\r\n ssl:\r\n certificate: xxxxxxxxxx\r\n
secrets:\r\n ssl:\r\n key: secretLogstashKey\r\n ```\r\n3. Start ES and
Kibana. Do not start a Fleet server.\r\n4. Go to Fleet settings and
inspect the preconfigured output: it should\r\nhave been created and the
secret value should not have been set\r\n(optionally, you can check in
the Console with `GET\r\n.fleet-secrets/_search` that the secret was not
created). However, a\r\nplain text equivalent should have been created
(in the example above,\r\n`ssl.key` should be set to
`secretLogstashKey`).\r\n5. Start a Fleet server on version less than
8.12.0. Kibana should\r\nupdate the output. Again, check that the secret
value was not set and\r\nthat the plain text equivalent is set.\r\n6.
Stop the Fleet server and start another one on version 8.12.0
or\r\nhigher. Kibana should update the output. This time, the secret
value\r\nshould have been set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Bardi
<[email protected]>","sha":"70508b957a4860b12fd3a2bb9612cfb8a95092e9","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.12.0","v8.13.0"],"title":"[Fleet]
Only enable output secrets if all Fleet servers are
compatible","number":173398,"url":"https://github.com/elastic/kibana/pull/173398","mergeCommit":{"message":"[Fleet]
Only enable output secrets if all Fleet servers are compatible
(#173398)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/173041\r\n\r\nOutput secret
storage requires that all Fleet servers are on version\r\n8.12.0 or
above.\r\n\r\nThe implementation is similar to package policy
secrets:\r\nhttps://github.com//pull/163627: this PR adds
the new\r\n`output_secret_storage_requirements_met` flag on
the\r\n`ingest_manager_settings` saved object.\r\n\r\n###
Testing\r\n\r\n1. Define a preconfigured output wit a secret value in
your\r\n`kibana.dev.yml` file, e.g.:\r\n ```yml\r\n
xpack.fleet.outputs:\r\n - id: my-logstash-output-with-a-secret\r\n
name: preconfigured logstash output with a secret\r\n type: logstash\r\n
hosts: ['localhost:9999']\r\n ssl:\r\n certificate: xxxxxxxxxx\r\n
secrets:\r\n ssl:\r\n key: secretLogstashKey\r\n ```\r\n3. Start ES and
Kibana. Do not start a Fleet server.\r\n4. Go to Fleet settings and
inspect the preconfigured output: it should\r\nhave been created and the
secret value should not have been set\r\n(optionally, you can check in
the Console with `GET\r\n.fleet-secrets/_search` that the secret was not
created). However, a\r\nplain text equivalent should have been created
(in the example above,\r\n`ssl.key` should be set to
`secretLogstashKey`).\r\n5. Start a Fleet server on version less than
8.12.0. Kibana should\r\nupdate the output. Again, check that the secret
value was not set and\r\nthat the plain text equivalent is set.\r\n6.
Stop the Fleet server and start another one on version 8.12.0
or\r\nhigher. Kibana should update the output. This time, the secret
value\r\nshould have been set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Bardi
<[email protected]>","sha":"70508b957a4860b12fd3a2bb9612cfb8a95092e9"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173398","number":173398,"mergeCommit":{"message":"[Fleet]
Only enable output secrets if all Fleet servers are compatible
(#173398)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/173041\r\n\r\nOutput secret
storage requires that all Fleet servers are on version\r\n8.12.0 or
above.\r\n\r\nThe implementation is similar to package policy
secrets:\r\nhttps://github.com//pull/163627: this PR adds
the new\r\n`output_secret_storage_requirements_met` flag on
the\r\n`ingest_manager_settings` saved object.\r\n\r\n###
Testing\r\n\r\n1. Define a preconfigured output wit a secret value in
your\r\n`kibana.dev.yml` file, e.g.:\r\n ```yml\r\n
xpack.fleet.outputs:\r\n - id: my-logstash-output-with-a-secret\r\n
name: preconfigured logstash output with a secret\r\n type: logstash\r\n
hosts: ['localhost:9999']\r\n ssl:\r\n certificate: xxxxxxxxxx\r\n
secrets:\r\n ssl:\r\n key: secretLogstashKey\r\n ```\r\n3. Start ES and
Kibana. Do not start a Fleet server.\r\n4. Go to Fleet settings and
inspect the preconfigured output: it should\r\nhave been created and the
secret value should not have been set\r\n(optionally, you can check in
the Console with `GET\r\n.fleet-secrets/_search` that the secret was not
created). However, a\r\nplain text equivalent should have been created
(in the example above,\r\n`ssl.key` should be set to
`secretLogstashKey`).\r\n5. Start a Fleet server on version less than
8.12.0. Kibana should\r\nupdate the output. Again, check that the secret
value was not set and\r\nthat the plain text equivalent is set.\r\n6.
Stop the Fleet server and start another one on version 8.12.0
or\r\nhigher. Kibana should update the output. This time, the secret
value\r\nshould have been set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Bardi
<[email protected]>","sha":"70508b957a4860b12fd3a2bb9612cfb8a95092e9"}}]}]
BACKPORT-->

Co-authored-by: Jill Guyonnet <[email protected]>
delanni pushed a commit to delanni/kibana that referenced this pull request Jan 11, 2024
elastic#173398)

## Summary

Closes elastic#173041

Output secret storage requires that all Fleet servers are on version
8.12.0 or above.

The implementation is similar to package policy secrets:
elastic#163627: this PR adds the new
`output_secret_storage_requirements_met` flag on the
`ingest_manager_settings` saved object.

### Testing

1. Define a preconfigured output wit a secret value in your
`kibana.dev.yml` file, e.g.:
   ```yml
   xpack.fleet.outputs:
     - id: my-logstash-output-with-a-secret
       name: preconfigured logstash output with a secret
       type: logstash
       hosts: ['localhost:9999']
       ssl:
         certificate: xxxxxxxxxx
       secrets:
         ssl:
           key: secretLogstashKey
   ```
3. Start ES and Kibana. Do not start a Fleet server.
4. Go to Fleet settings and inspect the preconfigured output: it should
have been created and the secret value should not have been set
(optionally, you can check in the Console with `GET
.fleet-secrets/_search` that the secret was not created). However, a
plain text equivalent should have been created (in the example above,
`ssl.key` should be set to `secretLogstashKey`).
5. Start a Fleet server on version less than 8.12.0. Kibana should
update the output. Again, check that the secret value was not set and
that the plain text equivalent is set.
6. Stop the Fleet server and start another one on version 8.12.0 or
higher. Kibana should update the output. This time, the secret value
should have been set.

### Checklist

- [x] [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 <[email protected]>
Co-authored-by: Julia Bardi <[email protected]>
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
elastic#173398)

## Summary

Closes elastic#173041

Output secret storage requires that all Fleet servers are on version
8.12.0 or above.

The implementation is similar to package policy secrets:
elastic#163627: this PR adds the new
`output_secret_storage_requirements_met` flag on the
`ingest_manager_settings` saved object.

### Testing

1. Define a preconfigured output wit a secret value in your
`kibana.dev.yml` file, e.g.:
   ```yml
   xpack.fleet.outputs:
     - id: my-logstash-output-with-a-secret
       name: preconfigured logstash output with a secret
       type: logstash
       hosts: ['localhost:9999']
       ssl:
         certificate: xxxxxxxxxx
       secrets:
         ssl:
           key: secretLogstashKey
   ```
3. Start ES and Kibana. Do not start a Fleet server.
4. Go to Fleet settings and inspect the preconfigured output: it should
have been created and the secret value should not have been set
(optionally, you can check in the Console with `GET
.fleet-secrets/_search` that the secret was not created). However, a
plain text equivalent should have been created (in the example above,
`ssl.key` should be set to `secretLogstashKey`).
5. Start a Fleet server on version less than 8.12.0. Kibana should
update the output. Again, check that the secret value was not set and
that the plain text equivalent is set.
6. Stop the Fleet server and start another one on version 8.12.0 or
higher. Kibana should update the output. This time, the secret value
should have been set.

### Checklist

- [x] [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 <[email protected]>
Co-authored-by: Julia Bardi <[email protected]>
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 v8.12.0 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Only enable output secrets if all fleet-servers are on 8.12 version
6 participants