-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] add SodiumMarshaller #35019
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
[Cache] add SodiumMarshaller #35019
Conversation
Cool thanks. Now I'm wondering: how would one use it to encrypt all the cached values? |
@nicolas-grekas I added in the description an example of how to use the And here is the test I did // add an item to cache
public function __invoke(CacheItemPoolInterface $cache)
{
$item = $cache->getItem('framework')->set('symfony');
$cache->save($item);
} The value of our item is encrypted in the filesystem cache. And when we retrieve the item // add an item to cache
public function __invoke(CacheItemPoolInterface $cache)
{
$item = $cache->getItem('framework');
dump($item->isHit()); // true
dump($item->get()); // "symfony"
} |
Great thanks,
next step would be documenting how we generate this content |
I think we could use the keys generated by I don't know if this exists already or not, but what about offering to the user (or just internally) the possibility to generate multiple encrypt/decrypt keys, by having this we can generate and use a specific key for the cache (we can also go far and use a different key for each cache pool). |
Very good point. This means we should handle one (or more) fallback keys that could be used to decrypt values when the main one doesn't work. That would allow rotating keys gracefully. |
So we can have something like that? - __construct(string $decryptionKey, MarshallerInterface $marshaller = null)
+ __construct(string $decryptionKey, MarshallerInterface $marshaller = null, array $fallbackDecryptionKeys = []) I'm wondering now where we will store fallback keys and how the user can manage them |
What about
We'd need to experiment ideas. |
Yes, better than what I suggested.
What do you think about a new command that we can use to generate not only one secret key (as we have now with For example: |
7aee40c
to
a3ffad0
Compare
a3ffad0
to
540d7eb
Compare
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.
We'd need some doc to explain how to generate new key pairs.
We could have a command for that, or we could give a php -r
snippet.
Anyway, that's not a blocker to merge this PR.
Good to go on my side. (I did some tweaks + rebased for master)
Thank you @atailouloute. |
This PR was merged into the 5.1-dev branch. Discussion ---------- [Cache] add SodiumMarshaller | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | Add `SodiumMarshaller` to encrypt cache values To use the `SodiumMarshaller` we can decorate the `cache.default_marshaller`: ```yaml Symfony\Component\Cache\Marshaller\SodiumMarshaller: decorates: cache.default_marshaller arguments: - ['%env(CACHE_DECRYPTION_KEY)%', '%env(OLD_CACHE_DECRYPTION_KEY)%'] - '@symfony\Component\Cache\Marshaller\SodiumMarshaller.inner' ``` The first provided key is used to encrypt and decrypt cached values. In order to allow rotating keys, more keys can be provided - they will be used only to decrypt values. /cc @nicolas-grekas Commits ------- 540d7eb [Cache] add SodiumMarshaller
Add
SodiumMarshaller
to encrypt cache valuesTo use the
SodiumMarshaller
we can decorate thecache.default_marshaller
:The first provided key is used to encrypt and decrypt cached values.
In order to allow rotating keys, more keys can be provided - they will be used only to decrypt values.
/cc @nicolas-grekas