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

Encrypt cache values via Solid Cache config #174

Merged
merged 3 commits into from
Aug 20, 2024
Merged

Encrypt cache values via Solid Cache config #174

merged 3 commits into from
Aug 20, 2024

Conversation

djmb
Copy link
Collaborator

@djmb djmb commented May 1, 2024

Allows you to enable encryption of cache values with:

# config/solid_cache.yml
production:
  encrypt: true

or

# application.rb
config.solid_cache.encrypt = true

Requires Active Record Encryption to be configured already.

Solid Cache by default uses a custom encryptor and message serializer that are optimised for it.

Firstly it disabled compression with the encryptor ActiveRecord::Encryption::Encryptor.new(compress: false) - the cache already compresses the data.

Secondly it uses ActiveRecord::Encryption::MessagePackMessageSerializer.new as the serializer. This serializer can only be used for binary columns, but can store about 40% more data than the standard serializer.

Or allow custom context properties to be set:

# application.rb
config.solid_cache.encryption_context_properties = {
  encryptor: ActiveRecord::Encryption::Encryptor.new,
  message_serializer: ActiveRecord::Encryption::MessageSerializer.new
}

@djmb djmb added the v1.0 label May 1, 2024
@djmb djmb force-pushed the encrypt branch 3 times, most recently from 75d8332 to c12f746 Compare August 13, 2024 14:42
djmb added 2 commits August 20, 2024 14:13
Allows you to enable encryption of cache values with:

```yaml
\# config/solid_cache.yml
production:
  encrypt: true
```
or
```ruby
\# application.rb
config.solid_cache.encrypt = true
```

Requires Active Record Encryption to be configured already.

Solid Cache by default uses a custom encryptor and message serializer
that are optimised for it.

Firstly it disabled compression with the encryptor
`ActiveRecord::Encryption::Encryptor.new(compress: false)` - the cache
already compresses the data.

Secondly it uses `ActiveRecord::Encryption::MessagePackMessageSerializer.new`
as the serializer. This serializer can only be used for binary columns,
but can store about 40% more data than the standard serializer.

Or allow custom context properties to be set:

```ruby
\# application.rb
config.solid_cache.encryption_context_properties = {
  encryptor: ActiveRecord::Encryption::Encryptor.new,
  message_serializer: ActiveRecord::Encryption::MessageSerializer.new
}
```
Add 170 bytes to the estimated size of each entry when encryption is
enabled. This assumes that the default context properties are used.
@djmb djmb force-pushed the encrypt branch 2 times, most recently from a51973a to 2133d72 Compare August 20, 2024 13:45
This will need to wait for Rails to support binary encrypted columns -
see rails/rails#52650.
@djmb djmb merged commit 94ffc03 into main Aug 20, 2024
19 checks passed
@djmb djmb deleted the encrypt branch August 20, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant