Commit Graph

79737 Commits

Author SHA1 Message Date
Tietew
92b8cda4c9
secure_compare: Check byte size instead of length
Match fixed_length_secure_compare's guard clause.

References #39142.
2021-04-02 12:45:29 -04:00
Vladislav
d264276288 RemoteConnection#disconnect: fix ArgumentError on ruby 3.0 2021-04-02 12:24:54 -04:00
Carlos Antonio da Silva
e63f8205d1 Tweak AR Encryption guide for better highlighting [ci skip] 2021-04-02 11:04:28 -03:00
Jorge Manrubia
224c9b34cb
Add Active Record encryption to CHANGELOG 2021-04-02 07:40:00 -04:00
Ryuta Kamizono
7e1820d71b
Merge pull request #41818 from ricardotk002/fix-missing-require
Fix seemingly wrong require "lib"
2021-04-02 19:56:11 +09:00
Ricardo Díaz
27b0180232 Remove print statement / uncomment relevant assertion 2021-04-02 01:03:43 -05:00
Ricardo Díaz
b11645eb2b Fix wrong require
This library is used here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L121

and here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L135

Reference https://buildkite.com/rails/rails/builds/76198#de7db4af-b8ca-46de-986f-0db34b1d4ddc
2021-04-02 01:00:37 -05: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
Jeremy Daer
07c3eee478
Merge pull request #41659 from basecamp/active-record-encryption
Add encryption to Active Record
2021-04-01 14:14:38 -07:00
Guillermo Iguaran
3583d82ea2
Merge pull request #41812 from rokbot/fix/guides-mailer-basics
[ci skip] fix on guides mailer_basics avoid ActiveModel::ForbiddenAttributesError
2021-04-01 13:26:30 -07:00
Jorge Manrubia
5a6352c072 Fix deterministic queries that were broken after #41068
This is adding yet another patch to make them work. This system needs to
be reworked as it's currently very brittle.
2021-04-01 22:10:59 +02:00
Rafael França
3a32f44745
Merge pull request #41809 from bbuchalter/bb.improved_strong_params_logging
Provide context when logging unpermitted parameters
2021-04-01 14:38:45 -04: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
2035138115 Use proper hook for loading fixtures extension 2021-04-01 15:02:15 +02:00
Jorge Manrubia
a61692cf41 Add support for uniqueness validations 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
d35905ccae Add Scheme, a container for encrypted attribute configs
This adds a new class `Scheme` that encapsulates the encryption
properties for a given attribute. This adds a proper code representation
for a domain concept we keep referring to: encryption schemes.

It's in charge of processing the user-passed config properties when
declaring the attribute, as well as of validating those.

This removes the concern of processing properties from
`EncryptableRecord` and `EncryptableAttributeType`. It's also nice to
have a place to group attribute encryption options, versus passing
lists of hashes around.

This is in preparation to upcoming changes that will add new config
options and support for previous encryption schemes.
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
c275b10a0e Show performance tests results now that they are excluded from the build 2021-04-01 15:02:15 +02:00
Jorge Manrubia
bcf6a5fafb Fix test
The .encrypts declaration in `ActionText::Encryption` was making this test
fail. It was failing to load a MySQL error that was being raised when trying
to determine the column limit.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
e4dae63013 Remove before_initialize, I think it's not needed 2021-04-01 15:02:15 +02:00
Jorge Manrubia
a786e34ab2 Move to on_load hook to see if it helps with railty test failing 2021-04-01 15:02:15 +02:00
Jorge Manrubia
bf75702b1c Inline prepend 2021-04-01 15:02:15 +02:00
Jorge Manrubia
9556720527 Wait for active record to be loaded to extend it 2021-04-01 15:02:15 +02:00
Jorge Manrubia
588c972d21 Removes the Action Text dependency from Active Record
Move the Action Text stuff to its own concern in `actiontext`.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
c41b354bf0 Remove mass encryption
I don't think this belong to the library yet. It's more like an util class we used
for building some mass-encryption tasks in HEY.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
26ceb126b9 Override accessors with module
This way users can override them and call #super

https://github.com/rails/rails/pull/41659#discussion_r592624914
2021-04-01 15:02:15 +02:00
Jorge Manrubia
dfa875fec5 Tweak class description 2021-04-01 15:02:15 +02:00
Jorge Manrubia
5cec2eced6 Remove preset env vars for encryption keys
These can be configured as +ActiveRecord::Encryption.config+ keys if you want,
so you can just use your own ENV vars in a config file if you prefer not to use
credentials.
2021-04-01 15:02:15 +02:00
Jorge Manrubia
f9514727af Update activerecord/RUNNING_UNIT_TESTS.rdoc
Co-authored-by: Mark Oleson <fusion2004@hey.com>
2021-04-01 15:02:15 +02:00
Jorge Manrubia
d5625c97df Review class comments
Co-authored-by: Rafael Mendonça França <rafaelmfranca@gmail.com>
2021-04-01 15:02:15 +02:00
Jorge Manrubia
3c379393c3 Split concern inclusion in two lines for clarity
Order is inverted when inlined, which can make things difficult to read.

https://github.com/rails/rails/pull/41659#discussion_r592604925

In this case it doesn't really matter and I think it's better for `Configurable`
to go first, so the change is inverting the previous order deliberately.

[skip ci]
2021-04-01 15:02:15 +02:00
Jorge Manrubia
eada873e4c Make ActiveRecord::Encryption load eagerly along with ActiveRecord
https://github.com/rails/rails/pull/41659#discussion_r592598084
https://github.com/rails/rails/pull/41659#discussion_r592601747

[skip ci]
2021-04-01 15:02:14 +02:00
Jorge Manrubia
f046617853 Temporary change just to confirm this is the problem with some intermittent failures in buildkite
[skip ci]
2021-04-01 15:02:14 +02:00
Jorge Manrubia
c0fa9428e5 Fix test 2021-04-01 15:02:14 +02:00
Jorge Manrubia
7945d4fde3 Make silent by default to prevent output during tests 2021-04-01 15:02:14 +02:00
Jorge Manrubia
9bfca80641 Only run limit-validation tests when the limit exists
SQLite and PostgreSQL won't add a default limit of 255 for string types
2021-04-01 15:02:14 +02:00
Jorge Manrubia
dcbe9cd5e4 Replace class var with class_attribute to prevent child class conflicts with it 2021-04-01 15:02:14 +02:00
Jorge Manrubia
ead2b2bec9 No need to register a type after 75929dfb1c
This was making a test fail, and can make existing code fail too without a good reason.
2021-04-01 15:02:14 +02:00
Jorge Manrubia
826ec6a473 Rename previous_types => previous_encrypted_types
This makes it clear what they are. It was confusing with "cast_type" around.
2021-04-01 15:02:14 +02:00
Jorge Manrubia
0ee7f4a5f1 Use existing support for previous types
This uses the changes from https://github.com/rails/rails/pull/39929. Instead of doing a manual casting of
the previous value as part of the type, it leverages the existing support to do this now.

It also fixes a problem when loading a class with an encrypt declaration that wasn't backed
by a table was failing.

CC @kaspth
2021-04-01 15:02:14 +02:00
Jorge Manrubia
f6e671d423 Fix: memoization that was making tests fail 2021-04-01 15:02:14 +02:00
Jorge Manrubia
36c4787469 Move encryption performance tests out of the main tests pipeline
This adds new rake tasks for these tests. This way, it prevents these
tests from making the build fail.

https://github.com/rails/rails/pull/41659#discussion_r592551649
2021-04-01 15:02:14 +02:00
Jorge Manrubia
997935588d Memoize attributes with a class variable so that child class keep their own list
This was making several tests fail
2021-04-01 15:02:14 +02:00