Commit Graph

42 Commits

Author SHA1 Message Date
Alex Ghiculescu cdebf39e6c
Improve AR Encryption docs 2023-07-13 16:30:22 +10:00
Jorge Manrubia c8d26bb647
Add a encryption option to support previous data encrypted non-deterministically with a SHA1 hash digest (#48530)
* Make sure active record encryption configuration happens after initializers have run

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Add a new option to support previous data encrypted non-deterministically with a hash digest of SHA1

There is currently a problem with Active Record encryption for users updating from 7.0 to 7.1 Before
#44873, data encrypted with non-deterministic encryption was always using SHA-1. The reason is that
`ActiveSupport::KeyGenerator.hash_digest_class` is set in an after_initialize block in the railtie config,
but encryption config was running before that, so it was effectively using the previous default SHA1. That
means that existing users are using SHA256 for non deterministic encryption, and SHA1 for deterministic
encryption.

This adds a new option `use_sha1_digest_for_non_deterministic_data` that
users can enable to support for SHA1 and SHA256 when decrypting existing data.

* Set a default value of true for `support_sha1_for_non_deterministic_encryption` and proper initializer values.

We want to enable the flag existing versions (< 7.1), and we want it to be false moving by
default moving forward.

* Make sure the system to auto-filter params supports different initialization orders

This reworks the system to auto-filter params so that it works when encrypted
attributes are declared before the encryption configuration logic runs.

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
2023-06-25 10:16:22 +02:00
Matt Almeida b02bfa14bf
Link console1984 where mentioned in ARE guide 2023-05-29 14:02:31 -04:00
zzak c3f2b545f8
Introduce markdownlint for guides
This is a follow up to rails#47186, this time for all markdown content.

[markdownlint](https://github.com/markdownlint/markdownlint) is an excellent tool, and I've found it very useful for finding issues in the guides.

Many of the rules are common style issues I'm correcting on PRs, so it will be nice to have that automated.

We should also be able to use the same config with our editors, so that errors show up in real-time 🙏 and will update the contributing docs once this gets merged with how to debug and use mdl appropriately.
2023-03-27 12:14:18 +09:00
Jorge Manrubia 5d7b6d823f
Add option to configure digest algorithm used by Active Record Encryption (#44873)
Before, it was using the configured by Rails. Having a mechanism to configure it
for Active Record encryption makes sense to prevent problems with encrypted content
when the default in Rails changes.

Additionally, there was a bug making AR encryption use the older SHA1 before
`ActiveSupport.hash_digest_class` got initialized to SHA256. This bug was exposed
by https://github.com/rails/rails/pull/44540. We will now set SHA256 as the standard
for 7.1+, and SHA1 for previous versions.
2023-02-27 10:16:41 +01:00
Jean Boussier 185f2d718d Allow to define the default column serializer
YAML has quite a bit of footguns, as such it's desirable
to be able to substitute it for something else or even
simply to force users to define a serializer explictly for
every serialized columns.
2023-02-22 19:32:28 +01:00
Jonathan Hefner 26657f5aa6 Fix typos in guides [ci-skip] 2023-01-08 15:42:29 -06:00
Jonathan Hefner f6a8cb42d8 Fix Active Record Encryption credentials example [ci-skip]
Active Record Encryption uses the `active_record_encryption` credentials
namespace, rather than `active_record`.`encryption`.
2022-11-15 13:57:15 -06:00
Missy Davies d49a3abc01 Capitalize headings to match style guidelines
Fix all headings to follow Rails Guides Guidelines
2022-10-17 17:01:28 -10:00
Jonathan Hefner 9ac01c6a81 Use relative URLs for intra-guide links [ci-skip]
This ensures that the URLs are properly versioned when the guides are
rendered.
2022-08-05 21:36:18 -05:00
Jorge Manrubia 193e155e4b
Fix: incorrect value regarding overhead and encryption 2022-06-27 07:30:22 +02:00
Jorge Manrubia a8171d16eb Document concerns about storage and column size when using encryption 2022-06-24 13:00:49 -07:00
Mikhail Dieterle a80a225085
Fix a typo in Active Record Encryption guide 2022-05-09 13:14:02 +03:00
Jorge Manrubia 67d6183694 Include the model name when filtering encrypted attributes.
For example, when encrypting `Person#name` it will add `person.name` as a filter
parameter, instead of just `name`. This prevents unintended filtering of parameters
with a matching name in other models.

Closes https://github.com/rails/rails/issues/44330
2022-02-21 12:05:04 +01:00
Jonathan Hefner ef5f74ad41 Split AR Encryption config settings into sections [ci-skip]
This splits the table of `config.active_record.encryption.*` settings
into individual linkable sections, similar to the Configuration guide.

This also bumps up the advice about using credentials, adds a few
backticks in the appropriate spots, and fixes a link which always
pointed to the latest version of the Configuration guide.
2022-02-15 15:54:37 -06:00
Stefan Vermaas fd23917081
Fixes a typo in the ActiveRecord encryption documentation 2022-01-25 09:43:43 -05:00
Jacob Herrington 85b2f7f2bd Clarify Active Record Encryption docs
I read quite a bit of this code the other day, so it made sense for me
to read through the guide as well.

While reading through it, I looked for opportunities to increase clarity
and simplify things. I also fixed a few typos!

Co-authored-by: Gannon McGibbon <gannon@hey.com>
2021-11-25 15:11:39 +00:00
Santiago Bartesaghi 8def855876 Fix link in ActiveRecord Encryption guides [ci skip] 2021-09-12 18:50:10 -03:00
Jorge Manrubia f1a684ce99
Add section "Why Encrypt Data at the Application Level" to the guide (#43202)
Ref. #43115
2021-09-10 18:40:49 -07:00
Petrik 4fae79adc3 Improve casing in encryption guide headings
Update the guide to use the casing as defined in the contribution guide.
https://guides.rubyonrails.org/ruby_on_rails_guides_guidelines.html#headings
[ci-skip]

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2021-08-27 21:38:41 -05:00
Philip Lambok ff181c38ba Update docs active record encryption
In the Rotating keys section, the active key was the last key instead of the first one.
2021-06-20 14:50:48 +07:00
Jorge Manrubia abfd2cc7a6
Forced encoding for deterministic encryption and other improvements (#42491)
* Fix: re-encrypting will preserve case when ignore_case is used

The implementation was outdated in relation to the new approach where we
override accessors.

* Add support for exists?(...) when querying encrypted attributes

* Add a new option to force encoding for deterministic attributes

Different encodings result in different ciphertexts. For
deterministically encrypted attributes, this can result in having
attributes with the same value that fails to satisfy uniqueness
constraints due to having different encodings.

This adds a new option `forced_encoding_for_deterministic_encryption:`
that will be UTF-8 by default. User can disabled this new behavior by
setting the option to nil.

* Add changelog entry
2021-06-17 12:30:35 +02:00
Jorge Manrubia 93e4e83771 Rename "master key" -> "primary key" in Active Record encryption
There were a few spots pending after
28145c3cee
2021-04-29 22:26:35 +02:00
John Bampton debab67a85 Lint Markdown blank lines around headings [ci-skip] 2021-04-14 01:17:46 +10:00
John Bampton 542dd9a062 fix whitespace Markdown headings active_record_encryption.md [ci-skip] 2021-04-12 07:51:55 +10:00
Henrik Nyh ad654a8dd3
Encryption guide copy fixes [ci skip]
Co-authored-by: Jacob Herrington <jacobherringtondeveloper@gmail.com>
2021-04-08 16:39:04 -04:00
Carlos Antonio da Silva e63f8205d1 Tweak AR Encryption guide for better highlighting [ci skip] 2021-04-02 11:04:28 -03:00
Ryuta Kamizono 1251703c4d Fix typo [ci skip] 2021-04-02 14:38:00 +09:00
Sampat Badhe 2032daa415
Fix typos encryption doc (#41817)
* fix typo

[ci skip]
2021-04-02 14:24:43 +09:00
Jorge Manrubia 3648c25cad Minor encryption guide tweaks and corrections 2021-04-01 14:52:42 -07:00
Jorge Manrubia e24fb5524a Validate that proper keys are configured when declaring attributes
This enables to disable deterministic encryption by just not setting
deterministic_key.
2021-04-01 18:20:54 +02:00
Jorge Manrubia 575a2c6ce0 Fix credential typo in Guide 2021-04-01 15:07:12 +02:00
Jorge Manrubia fd91dac6f4 Add note about action text 2021-04-01 15:02:15 +02:00
Jorge Manrubia f78a480818 Encourage deterministic encryption to remain unchanged
This implements several changes to encourage deterministic encryption to
remain unchanged. The main motivation is letting you define unique
indexes on deterministically-encrypted columns:

- By default, deterministic encryption will always use the oldest
encryption scheme to encrypt new data, when there are many.
- You can skip this default behavior and make it always use the current
encryption scheme with:

```ruby
deterministic: { fixed: false } # using this should be a rare need
```

- Deterministic encryption still supports previous encryption schemes
normally. So they will be used to add additional values to queries, for
example.
- You can't rotate deterministic encryption keys anymore. We can add
support for that in the future.

This makes for reasonable defaults:

- People using "deterministic: true" will get unique indexes working out
of the box.
- The system will encourage keeping deterministic encryption stable:
  - By always using oldest encryption schemes
  - By forbidding configuring multiple keys

But you can still opt-out of the default if you need to.
2021-04-01 15:02:15 +02:00
Jorge Manrubia 7a1fb99302 Add support to declare previous encryption schemes globally 2021-04-01 15:02:15 +02:00
Jorge Manrubia 28145c3cee Rename master_key => primary_key 2021-04-01 15:02:15 +02:00
Jorge Manrubia fd3fbcc4eb Update guides/source/active_record_encryption.md
Co-authored-by: Connor Shea <connor.james.shea@gmail.com>
2021-04-01 15:02:15 +02:00
Jorge Manrubia 212543deb5 Update guide 2021-04-01 15:02:14 +02:00
Jorge Manrubia 209e62c938 Update guide 2021-04-01 15:02:14 +02:00
Jorge Manrubia 4e1f66f90b Add config options 2021-04-01 15:02:14 +02:00
Jorge Manrubia 795b1c654a Allow list explicit list of allowed properties
The alternative is more brittle
2021-04-01 15:02:14 +02:00
Jorge Manrubia 9aca274042 Encryption guide (WIP) 2021-04-01 15:02:13 +02:00