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] Support preconfigured output secrets #170259

Merged
merged 24 commits into from Nov 23, 2023

Conversation

hop-dev
Copy link
Contributor

@hop-dev hop-dev commented Oct 31, 2023

Summary

This PR adds support for outputs with secrets preconfigured in the kibana.yml config file.

As Kibana needs to compare the value of the secret to manage updates, a hash of the value is stored in the output's saved object. The implementation follows option 2 in Infosec's recommendations with the Argon2id algorithm.

See here for information about the argon2 Node package and here for the config options. Here, argon2 was configured with the recommended m=19456 (19 MiB), t=2, p=1 (for some reason, timeCost cannot be set to less than 2).

Closes #166360

Testing

  1. Ensure the outputSecretsStorage experimental feature is enabled.
  2. Add the following to your kibana config:
    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: thisissecret
    
  3. Verify the secret has been correctly created, e.g. by issuing a GET .fleet-secrets/_search request in Dev Tools: the secret should be listed there.
  4. Change the preconfigured value and wait for kibana to restart: the secret should be updated with the new value.

@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 jillguyonnet self-assigned this Nov 16, 2023
@jillguyonnet jillguyonnet added Team:Fleet Team label for Observability Data Collection Fleet team v8.12.0 release_note:feature Makes this part of the condensed release notes backport:skip This commit does not require backporting labels Nov 16, 2023
@jillguyonnet jillguyonnet marked this pull request as ready for review November 16, 2023 14:56
@jillguyonnet jillguyonnet requested review from a team as code owners November 16, 2023 14:56
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@kpollich kpollich self-requested a review November 16, 2023 15:12
@jillguyonnet
Copy link
Contributor

@elasticmachine merge upstream

expect.anything()
);
expect(mockedOutputService.update).not.toBeCalled();
// expect(spyAgentPolicyServicBumpAllAgentPoliciesForOutput).not.toBeCalled();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should this line be removed?

@@ -221,6 +338,7 @@ function isPreconfiguredOutputDifferentFromCurrent(
isDifferent(existingOutput.config_yaml, preconfiguredOutput.config_yaml) ||
isDifferent(existingOutput.proxy_id, preconfiguredOutput.proxy_id) ||
isDifferent(existingOutput.allow_edit ?? [], preconfiguredOutput.allow_edit ?? []) ||
kafkaFieldsAreDifferent()
(await kafkaFieldsAreDifferent()) ||
(await logstashFieldsAreDifferent())
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we cover kafka and logstash output changes in unit tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for that @juliaElastic - your suggestion made me realise the tests were not properly testing the comparison of hashes. I pushed a commit that addresses that.

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.

Looks good, added a comment to improve test coverage.

Comment on lines 1832 to 1835
},
"hash": {
"type": "keyword",
"index": false
Copy link
Contributor

Choose a reason for hiding this comment

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

hash field should be excluded from SO mappings as it is not powering any search.

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be missing something here, maybe @juliaElastic can help me clarify.

As I understand, this means removing the hash field from x-pack/plugins/fleet/server/saved_objects/index.ts altogether. This makes sense as we're not searching on the hash, but I'm unsure whether we'll be able to retrieve the hash in all scenarios. FWIW I've tested the repro steps locally and it does work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Solved via Slack - for reference, this tutorial was useful: https://github.com/elastic/kibana/blob/main/dev_docs/tutorials/saved_objects.mdx.

@jillguyonnet
Copy link
Contributor

@elasticmachine merge upstream

@jillguyonnet
Copy link
Contributor

@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.

thanks for the core-related update! changes LGTM

@jillguyonnet
Copy link
Contributor

@elasticmachine merge upstream

@jillguyonnet
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

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

The logic + tests all look great to me. I did have one comment about improving some existing log messages as part of this PR, but otherwise LGTM! 🚀

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

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

cc @jillguyonnet

@jillguyonnet jillguyonnet merged commit 1f7a527 into elastic:main Nov 23, 2023
29 checks passed
@mistic
Copy link
Member

mistic commented Nov 23, 2023

@hop-dev I had the need to reverted this PR at 78f7b80. @pheyos found this commit was breaking tests the QA team have in place on Windows. The reason for this was that this pr added a native module as a production dependency (argon2). Is it possible for you to avoid using a native module dependency and found a replacement for it? We really like to avoid adding new ones other than the re2 we are currently using because of the implications those dependencies have. Otherwise we will have to patch the build process to support this argon2 native module

kibanamachine pushed a commit to XavierM/kibana that referenced this pull request Nov 23, 2023
@hop-dev
Copy link
Contributor Author

hop-dev commented Nov 24, 2023

@jillguyonnet 😓

I have done a search it looks like all node argon2 libraries use the native argon2. It may be worth looking at the other hashes recomended by the security team and see if there is a better lib?

@jillguyonnet
Copy link
Contributor

Hey @hop-dev I'm back from PTO, taking a look at this now 👀

@jillguyonnet
Copy link
Contributor

It looks like we could use scrypt (second recommendation) as it has a built-in implementation within the crypto module.

@mistic @hop-dev Would you have any objections to that?

jillguyonnet added a commit that referenced this pull request Nov 30, 2023
## Summary

Support for outputs with secrets preconfigured in `kibana.yml`. This was
already implemented in #170259,
which had to be reverted as the `argon2` package was causing Windows
tests to test (cf. [this
comment](#170259 (comment))).

The present implementation follows [option 2 in Infosec's
recommendations](elastic/infosec#14853 (comment))
with the Scrypt algorithm using the following params: N=2^14 (16 MiB),
r=8 (1024 bytes), p=5. Note that Scrypt is built-in within the `crypto`
module (see
[here](https://nodejs.org/api/crypto.html#cryptoscryptpassword-salt-keylen-options-callback)
for documentation).

Closes #166360

### Testing

1. Ensure the [`outputSecretsStorage` experimental feature
](https://github.com/elastic/kibana/blob/fd4fdb01bcb011c0968a4ccab7ba739c3195016a/x-pack/plugins/fleet/common/experimental_features.ts#L26)is
enabled.
2. Add the following to your kibana config:
   ```
   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: thisissecret
   ```
3. Verify the secret has been correctly created, e.g. by issuing a `GET
.fleet-secrets/_search` request in Dev Tools: the secret should be
listed there.
4. Change the preconfigured value and wait for kibana to restart: the
secret should be updated with the new value.

---------

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:feature Makes this part of the condensed release notes reverted Team:Fleet Team label for Observability Data Collection Fleet team v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Support preconfigured output secrets
10 participants