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

Detect and prevent the use of mismatched encryption keys #92654

Open
legrego opened this issue Feb 24, 2021 · 9 comments
Open

Detect and prevent the use of mismatched encryption keys #92654

legrego opened this issue Feb 24, 2021 · 9 comments
Labels
discuss enhancement New value added to drive a business result Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@legrego
Copy link
Member

legrego commented Feb 24, 2021

Kibana relies on a number of encryption keys. Arguably the most important key is xpack.encryptedSavedObjects.encryptionKey, as this controls the encryption/decryption of actions, alerts, and other sensitive user data.

Kibana requires that this key is set to the same value across all instances. If two Kibana instances have different encryption keys, then they will be encrypting saved objects that cannot be decrypted by the other instance.

We should attempt to detect if there is a potential encryption key mismatch, and alert consumers of the ESO plugin so that they can take appropriate action.

One potential solution is to save a "canary" saved object, whose sole purpose is to test that it can be successfully decrypted by the current instance. If we cannot decrypt this object, then it stands to reason that this instance is not properly configured. I expect there are scenarios where we'd need to allow the canary to be forcefully replaced, however.

@legrego legrego added discuss Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! enhancement New value added to drive a business result labels Feb 24, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@azasypkin
Copy link
Member

I expect there are scenarios where we'd need to allow the canary to be forcefully replaced, however.

The most obvious scenario is when you just lose your encryption key or you know it has been compromised and you cannot trust your already encrypted objects anymore. In this case it'd be reasonable to assume that you'd just change your key and not put the old one to the decryptionOnlyKeys collection.

Introducing some additional configuration key or using CLI to support this specific use case can make our entire encryption story even more convoluted.

Sorry mostly thinking aloud, don't have a good proposal yet. I believe the consumers already have the tool to detect this scenario and can act properly (aka analyzing error(s) ESO returns), so we have a bit of time to think here.

@pmuellr
Copy link
Member

pmuellr commented Mar 1, 2021

The only detection we have in alerting is that we get an error decrypting the alerting ESOs. Which could be some other problem other than mismatched encryption keys - but it does certainly occur when encountering mismatched keys. So we're left wondering - is it mismatched keys, or alerting? The customer never believes it's mismatched keys :-)

I do think we need some kind of canary. Kibana creates a unique server UUID every time it starts, so in theory we could have each Kibana write an ESO when it starts, with it's server UUID and an ESO with a fixed field. We could then lazily check at startup if we can read all the "recent" ESOs that have been written, or something. And we'd need to "garbage collect" old ones. Probably each Kibana would need to update it's ESO every hour or something.

Ideally I'd like to see some kind of message logged when a mismatched key is detected, but it should probably be even more obvious, in the UI.

@azasypkin
Copy link
Member

Which could be some other problem other than mismatched encryption keys - but it does certainly occur when encountering mismatched keys.

If you get a decryption error (it has a specific EncryptionError type) that means that either encryption key is different or AAD doesn't match, no other reasons should cause EncryptionError. Do you need to distinguish and handle these two cases differently?

I assumed that mismatched AAD is something that should never happen if objects are manipulated with the alerting APIs/UI and if it happens somehow than it should be treated as a critical issue - object may have been tampered with or something else is broken badly and leads to a data loss - either of this requires immediate attention. Or is there a legitimate use case in Alerting that can lead to a mismatched AAD?

@jportner
Copy link
Contributor

jportner commented Nov 17, 2021

Related: #95339, #113928

We have other problems with multiple Kibana instances that do not have other options in sync (security encryption key, reporting encryption key, auth providers) and/or different versions of Kibana.

@jportner
Copy link
Contributor

I met today with @legrego and @azasypkin to discuss this topic.

Our takeaway is that this problem is bigger than just detecting incorrect ESO encryption keys, but "canary objects" are still likely our best way to solve this problem. We'd like to build something with these characteristics:

  • Provided by Core (works across plugins)
  • Can detect if a setting has changed in a way that can break things (for example, encryption key changed and wasn't added to decryption-only keys)
  • Can detect if multiple Kibanas are active with different settings
  • Can detect if different Kibana versions are active

Since we want to take multiple Kibanas into account, we think that using multiple canary objects is our best bet.

Each Kibana does have a server.uuid but it might change on startup, and users can configure this value (so it's not reliably unique), so identifying a single Kibana instance is not trivial. When Kibana starts we could generate a uuid to keep in memory and compare it to canary objects -- we can't definitively say if an object originated from this Kibana, but we can definitively say if it didn't. That should be enough for our purposes.

If the canary object informs us that something is wrong, we can surface this to operators in the server logs. We could also expose this information in a status endpoint. Eventually we could build a UI around it, too.

First, though: this design could get complicated and it is definitely breaking new ground. Because of that, and because we think this is a Core concern, we should make an RFC before moving forward with any implementation.

@lukeelmers
Copy link
Member

this design could get complicated and it is definitely breaking new ground. Because of that, and because we think this is a Core concern, we should make an RFC before moving forward with any implementation.

100% agree with this.

Also, here's a related reporting issue having to do with mismatched configs: #120995


cc @elastic/kibana-core @stacey-gammon

@legrego legrego removed EnableJiraSync loe:small Small Level of Effort impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. labels Aug 18, 2022
@legrego legrego added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc and removed Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! labels Jan 17, 2023
@pgayvallet
Copy link
Contributor

@legrego / @jeramysoucy can this issue be considered part of the "Core encryption" initiative, and if so, can I close it as superseded?

@jeramysoucy
Copy link
Contributor

@pgayvallet Yes, or we could add this issue as a sub-issue. I'll bring it up at our sync this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss enhancement New value added to drive a business result Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

8 participants