Repository navigation
RGW SSE-KMS secrets cache - #61256
Conversation
|
@irq0 what happens, when a new key is set to a bucket? will the key from the cache be used or will the key from the cache be reset? |
This caches right above the call to the KMS using the key id it got from the layer above [1]. Q: Is changing a secret payload mapped from a key id a thing? I expect to rather update the bucket -> key id mapping to a new secret. [1] To test this I used. The cached key id would be 8561... |
|
I'll continue with adding:
|
|
From a security standpoint; this thing is dangerous: anybody who can get a core dump of rgw is going to get all those keys. A couple of things to mitigate that risk: |
I'm not sure I grok that. RGW would store cached secrets encrypted in its memory. When a data encrypt/decrypt (e.g PUT/GET) needs that key it would fetch the encrypted key from its memory and decrypt it with an ephemeral key. Something generated on startup perhaps? There is one other possible leak: Swapping secrets out. I think as a start it makes sense to document a warning about core dumps and have a startup check. Maybe even a check that will exit the daemon if not a config option activates "yes-i-really-mean-it". (BTW: I'm working on integrating Breakpad as an alternative to core dumps in prod systems #61264 ) |
|
vault uses mlock to protect its secrets. It's a bit of a pain to deal with, worth it for vault, but probably not for rgw. In the end this is one of those classic security vs. utility tradeoffs. We ought to have some sort of general statement somewhere that warns that configuration data and core dumps can contain secrets that should be treated as such. I don't think rgw is particularly a special case in this respect, an osd or mon core dump has similar issues. But, to the extent we can protect "data a rest" that is not active, that's useful. Adding a TTL to the LRU cache gets like 80% of the security I'm hopging for, so that's why I think that essential. Adding a specific flush function is in practice most likely to be of help in debugging. So far as an ephemeral key goes, that's where it gets complicated. The desirable goal would be that a core dump (or memory inspection of the running process) at any point in time only allows you to decrypt the objects that are in fact being decrypted at that moment. The complication is that there are lots of ways to do this, with varying properties. So, fior instance: mlock becomes a deployment issue (ie, how doe shis work with vstart or in a container). An ephemeral key in memory just slows an attacker down a bit. Keeping the ephemeral key in an unlinked file dangling off an open file descriptor, and only reading it into memory immediately before use, means most of the time the lru cache is safe. Forking off a helper process, and storing either the LRU cache, or the ephemeral key in the helper process, could make it core-dump safe, at the cost of a bit more complexity. Since this is more complex, you have choices: you don't have to do any of this, or you might find this fascinating and want to do this. Personally, I hope you do this, but a separate PR is ok. So: TTL: that's required. flush: low hanging fruit. ephemeral key wrapping: you decide. |
|
@irq0 @mdw-at-linuxbox I like both the ttl and flush ideas. I think the third option is a bit overkill, at least initially. For people that need absolute security, there is always the option of simply not using this cache. |
👍 My plan right now is to first look into LRU implementations in the codebase. I like the idea of encrypting the cache in memory as it mitigates risk for cases where the memory is persisted that aren't obvious (e.g hibernation files, VMs). I'm with Mark though that it is a bit overkill initially. |
memfd_secret(2) might be a good fit here. https://lwn.net/Articles/836724/ |
b15bb88 to
3fef8f1
Compare
3fef8f1 to
b7035cf
Compare
|
The last push addresses the cache part of the feature. Next on my list is looking into securing the memory the case uses. It adds a new cache that supports TTLs and handles cache stampedes gracefully. The latter is important, because caching KMS secrets is not only about handling requests faster, but to not overload KMS systems with lots of concurrent requests to the same key. The second commit adds benchmarks for concurrent caches in the codebase including the new one. Results from my machine below. I'd really love feedback on the integration bits. The cache uses futures to make concurrent requests to the same key wait for each other. To make this work in the async context the code basically just yields for the average fetch time. Benchmark Resultsweb = the new web cache using lookup() |
7390642 to
edfe31a
Compare
Benchmark results: kernel keyring vs memfd_secret vs plain memory |
|
Yay for benchmarks! 👍 |
cbodley
left a comment
There was a problem hiding this comment.
initial review of just the cache class
|
my takes:
Matt |
afaik none of them support ttl, so we'd have to pick one and extend it i'm not familiar enough with the sieve algorithm to tell whether it actually warrants a new cache class |
Benchmark: - Linux Kernel Key Retention Service (kernel keystore) [0] - memfd_secret(2) - plain memory Tests: - Random reads - (keystore) Write, Read, Remove [0] https://docs.kernel.org/security/keys/core.html Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Add RAII wrapper around the Linux Key Retention Service add_key(2), keyctl_read(3), keyctl_invalidate(3) Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
To allow RGW threads to share possession over process keyring keys the keyring must be created before a child thread adds keys. Since we only use the process keyring for KMS cache secrets, only initialize the keyring if it is enabled on startup. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Add caching section to the RGW Encryption docs. Add cache settings to the RGW configuration reference. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Goal: Support multiple backends and faking / mocking for testing. Add abstract classes Keyring (factory) and KeyringSecret. Add "Unsupported" implementation for non-Linux platforms. Add a get_best factory function that currently returns the LinuxKeyring impl on Linux or Unsupported elsewhere. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Add SSE Key Management System secrets cache to RGW. It is common to have secrets shared by many if not all objects in a bucket. Without RGW-side caching every PUT/GET will cause a request to an external KSM. This not only adds load to the KSM, but also slows down read and writes. Combine WebCache, ceph::async::call_once and LinuxKeyringSecret into KMSCache. WebCache stores async::once_result to wrap results of a KMS secret fetch to mitigate cache stampedes (concurrent cache requests to the same key coalesce into one). The retrieved secrets are stored in the Linux kernel key retention service (LinuxKeyringSecret) for safe keeping and retrial by subsequent requests. KMSCache adds a TTL reaper and life cycle. Cache values and error handling: The cache stores positive fetch results, permanent errors (e.g key does not exists) and transient errors (e.g fetch timeout). Each with a different TTL. Unit tests to cover cached / uncached KMS retrieve and runtime cache disable via config. Add perf counter `kms_fetch_lat` to track KMS fetch request latency and error counters to track permanent, transient and key store errors. Signed-off-by: Marcel Lauhoff <[email protected]> Fixes: https://tracker.ceph.com/issues/68524 On-behalf-of: SAP [email protected]
Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
KMS backends Barbican, Vault KV, and KMIP have a static key per key_id. However, with Vault Transit, each object has a unique DEK wrapped by the transit key. Keying th cache with key_id in Transit mode results in only the first DEK to be cached for all subsequent objects. Fix this by appending a hash of the wrapped DEK to the cache key. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
sieve_expire_erase_unmutexed did not update the sieve hand passed as advertised. Make it return the updated hand and use that to update the global _sieve_hand in expire_erase Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
Reset reaper state to monostate in the async and threaded case. Fixes a possible use after free in the async reaper case. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
1. Don't delete the KMS cache before draining/joining the frontend coroutine threads. They may still depend on the KMS cache. 2. Stop the TTL reaper early to get it off the coroutine pool. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
The testing backend uses a 'keysel' attribute to derive a per object key from the KEK in the config. A single key_id with distinct keysel has different keys and need to be cached as such. Add the keysel to the cache key id to handle these collisions. Signed-off-by: Marcel Lauhoff <[email protected]> On-behalf-of: SAP [email protected]
|
jenkins test make check |
2 similar comments
|
jenkins test make check |
|
jenkins test make check |
@adamemerson Done. The AES GCM change added another call site to a function that needs another param with this PR. |
|
This can merge, mark it for backport for the first point release of Umbrella. |
|
pr testing completed and approved by @ivancich , tracker details : https://tracker.ceph.com/issues/77211 |
Not further testing needed from my side. Who does the merge of these kinds of PRs usually? |
|
@irq0 Please make a backport tracker for this so we can get it into Umbrella at the first point release. |
@adamemerson it doesn't look like an umbrella branch has forked yet. have you seen any announcements about this? |
Add a cache for secrets from key management systems used for server side encryption.
It is common to have secrets shared by many if not all objects in a bucket. Without RGW-side caching every PUT/GET will cause a request to an external KSM. This not only adds load to the KSM, but also slows down read and writes.
References
https://tracker.ceph.com/issues/68524
Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e