Commit Graph

43 Commits

Author SHA1 Message Date
Syed Paymaan Raza
48064f6cf1 Make some codeprobes rare (#11607)
* Make BlobGranule code probes rare

* Make encryption related code probes rare

* fixup! Fix formatting
2024-08-26 22:33:38 -07:00
Syed Paymaan Raza
c3e7542cda Update end year in copyright header 2024-08-02 09:40:11 -07:00
Dimitris Apostolou
a88114c222 Fix typos 2024-02-07 01:16:00 +02:00
Zhe Wang
ba30d15dd3 nits for blobcipher test (#11073) 2023-11-17 10:47:27 -08:00
Zhe Wang
f1bf2b38e5 fix blobcipher-test 2023-11-16 15:46:00 -08:00
Zhe Wang
9df517618e enable mutation tracking work with encrption (#11068) 2023-11-16 14:04:18 -08:00
Nim Wijetunga
7f2260bbd2 Add Encryption Related Latency Metrics (#10596)
* add ss and cp latency metrics

* make changes
2023-07-14 11:30:16 -07:00
Ata E Husain Bohra
7779c908b3 EaR: Remove usage of ENABLE_CONFIGURABLE_ENCRYPTION knob (#10570)
Description

Given Configurable encryption has been checked in and being tested via
simulation for more than a month and also to avoid penalty of accessing
KNOBS in inline commit path, patch retires the KNOB and make
ConfigurationEncryption default EaR mode for FDB.

BlobCipher still supports the old format header and encryption semantics,
will remove the dead code as a followup PR.

Testing

devRunCorrectness - 100K
2023-06-30 17:48:09 -07:00
Jay Zhuang
ea52e90f03 Remove unnecessary padding for encrypt/decrypt (#9942)
* No padding is needed for AES CTR mode

https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Padding

* Remove EVP_CIPHER_CTX_reset() so the encryptor could be reused

It's only reused in the unittest. In prod, new encryptor is created for
every new text.
2023-06-14 13:37:29 -07:00
Yi Wu
7048ad21a8 EaR: reduce metrics logging (#10453)
* EaR: reduce metrics logging

BlobCipherMetrics used to break down by usage types (whehter it is for tlog, redwood, backup, etc), and these counters will be printed to trace log even when encryption is not enabled, or the specific usage is not happening on a node (e.g. a node with only stateless roles will also print blob cipher counters for redwood). We are reducing the BlobCipherMetrics loggings by:
1. Default to not breakdown the metrics by usage type, and the behavior is controlled by the knob  `ENCRYPT_KEY_CACHE_ENABLE_DETAIL_LOGGING`
2. When the detail breakdown is enabled, the counters are lazily initialize
3. Even if the counters are initialized, they will not be logged if the count is 0 (so like if a node was recruited as tlog but then drops the tlog role later on, the tlog counter inside BlobCipherMetrics will not be logged anymore).

* buggify BlobCipherMetrics detail logging knob

* format
2023-06-09 12:07:49 -07:00
Ata E Husain Bohra
31aa06cfbc EaR: Add test case to validate decryption with invalid key (#10394)
* EaR: Add test case to validate decryption with invalid key

Description

Extend BlobCipher unit test to provide coverage for the scenario
where buffer got encrypted with a EncryptionKey K, however,
decryption for some reason got attempted with K'.

Testing

EncryptionUnit.toml - 100K

* EaR: Add test case to validate decryption with invalid key

Description

Address review comments

Testing
2023-06-08 22:32:15 -07:00
Ata E Husain Bohra
a099d377fa EaR: Remove unused CODE_PROBE handling encrypiton header flag version (#10020)
Description

Patch removes an unused CODE_PROBE checking the encryption header
being read flag version is valid, given the flag-version is determined
by peeking into std::variant index and we only have version-1 supported,
for now converted the check to an ASSERT

Testing

EncryptionUnitTests.toml
EncryptionOps.toml
BlobGranuleCorrectness/Clean.toml
2023-04-19 18:02:31 -07:00
Ata E Husain Bohra
fe0a4df06a EaR: Implement Key Check Value semantics (#9936)
* EaR: Implement Key Check Value semantics

Description

Key Check Value (KCV) is a checksum of cryptographic encryption key
used to validate encryption keys's integrity. FDB Encryption at-rest
relies on external KMS to supply encryption keys.

Patch proposes following major changes:
1. Implement Sha256 based KCV implementation to protect against
'baseCipher' corruption in two possible scenarios:
 a) potential corruption external to FDB
 b) potential corruption within FDB processes.
2. Scheme persists computed KCV token in block encryption header,
which then gets validated as part of header validation during
decryption.
3. FDB Encryption key derivation uses HMAC_SHA256 digest generation
scheme, which allows max 64 bytes of 'cipher buffer', patch add
required check to ensure 'baseCipher' length are within bounds.
OpenSSL HMAC underlying call ignores extra length if supplied, however,
it weakens the security guarantees, hence, disallowed.

Testing

devRunCorrectness - multiple 500K runs
Valgrind & Asan - BlobCipherUnit, RESTKMSUnit, BlobGranuleCorrectness*,
EncryptionOps, EncryptKeyProxyTest
2023-04-12 14:29:31 -07:00
Ata E Husain Bohra
9d8e8d2f9e Update fdbclient/BlobCipher.cpp
Co-authored-by: A.J. Beamon <aj.beamon@snowflake.com>
2023-04-07 10:34:11 -07:00
Ata E Husain Bohra
e10259f461 Fix Asan reportin gheap overflow
Description

Fix Asan reportin gheap overflow

Testing

BlobCipherUnitTest with failing seed
2023-04-07 10:24:22 -07:00
Ata E Husain Bohra
ecc6d5a712 EaR: Fix BlobCipher cache handling for cipher needs refresh and/or expired (#9845)
* EaR: Fix BlobCipher cache handling for cipher needs refresh and/or expired

Description

Patch proposes BlobCipher cache bug related to handling of cipherKeys
that either 'needsRefresh' and/or 'expired'
Also, adds a unit-test to cover the following usecase:
1. Test refreshAt and expireAt properties of the cipherKey
2. Validate corresponding Counter value increments

Testing

Extend /blobCipher unitest tests
2023-04-06 11:43:10 -07:00
Ata E Husain Bohra
769226e5c0 EaR: Fix heap-over-flow in BlobCipherTest (#9877)
Description

Heap overflow was due to recent upgrade in BlobCipherTest to use
variable size 'baseCipher' buffer.

Testing

BlobCipherUnit test
2023-04-03 12:25:59 -07:00
Ata E Husain Bohra
3f6fcada45 EaR - Misc fixes found using end-to-end integration testing (#9806)
* EaR - Misc fixes found using end-to-end integration testing

Description

Major changes proposed includes:
1. RESTClient filtering of trailing `/`(s) characters from
input URI resource path
2. Avoid EKP exponential backup given RESTClient supports
exponential backoffs retries for all retryable errors.
3. Memory allocation optimizations:
 3.1. BaseCipher key management using Standalone semantics
 in KMSConnector interface endpoints
 3.2. Optimize memcpy while looking encryption-keys in EKP endpoints
4. Avoid delay while starting EKP, given its criticality during
cluster recovery.
5. Update BlobCipher to handle variable size BaseCipher buffer
6. Improved logging

Testing

Setup:
1. External KMS server to supply encryption keys (inhouse)
2. Create cluster with: cluster_aware & domain_aware config

* Fix EncryptionOps test

Description

Testing

* EaR - Misc fixes found using end-to-end integration testing

Description

Major changes:
1. Cleanup EKP driven exponential backup files.
2. Update EKP not to use #1.

Testing

* EaR - Misc fixes found using end-to-end integration testing

Description

Address review comments

Testing

* Fix AES 256 key length value

Description

Testing

* Address review comments

Description

Testing
2023-03-30 22:22:26 -07:00
Jay Zhuang
dba3555635 fix inplaceEncrypt() unittest issue 2023-03-23 15:26:22 -07:00
Jay Zhuang
d9b37e527c Replace EncryptFinal() with CTX_reset() 2023-03-23 15:26:22 -07:00
Jay Zhuang
0efd403e59 Add inplace encryption/decryption API 2023-03-23 15:26:22 -07:00
Yi Wu
eac757d186 EaR: cleanup encryption knobs (#9386)
Changes:
* Cleanup all encryption knobs 
* Update simulated cluster to randomly enable encryption with higher probability
2023-02-18 13:18:20 -08:00
Ata E Husain Bohra
99b23ac04d EaR: Configurable encryption support for Tlog mutations (#9394)
* EaR: Configurable encryption support for TLog mutations

Description

  diff-1 : Address review comments

Major changes includes:
1. Update the code involved in ensuring Tlog mutation encryption to be
compliant with "configurable encryption" feature.
2. Update ENABLE_CONFIGURABLE_ENCRYPTION flag to be 'true' by default
and BUGGIFY it.

Testing

devRunCorrectness - 100K
2023-02-16 19:01:59 -08:00
Nim Wijetunga
e03eca778c Configurable Encryption Support for Backup (#9375)
Snapshot backup configurable encryption support
2023-02-16 15:03:27 -08:00
Junhyun Shim
7f43247b14 Fix Valgrind "conditional jump based on uninitialized value" 2023-02-15 17:53:46 -08:00
Ata E Husain Bohra
8c94b340ce EaR: Update encryption methods to make 'cipherHeaderKey' optional (#9378)
* EaR: Update encryption methods to make 'cipherHeaderKey' optional

Description

 diff-1: Address review comments

Major changes includes:
1. Update BlobCipher Encrypt/Decrypt classes to make 'headerCipher' optional
2. Update GetEncryptionCipherKeys actor methods to make 'headerCipherKey' optional
3. Update the usage across all encryption participant methods

Testing

BlobCipherUnitTest
EnryptedBackupCorrecctness
BlobGranuleCorrectness*

devRunCorrectness - 100K
2023-02-15 08:56:11 -08:00
Yi Wu
3d882a99c5 EaR: Refactor encryption header std::variant serializer and versioning (#9345)
Changes:
1. Make binary serializer natively support `std::variant`. Serialize size is 1 byte (the type index, i.e. `std::variant::index()`), plus the serialize size of the actual type stored in the `std::variant`. Update `BlobCipherEncryptHeaderRef` to use the `std::variant` binary serializer
3. Remove `flagsVersion` and `algoHeaderVersion` from `BlobCipherEncryptHeaderRef`. The former is replaced by `flags.index() + 1`, and the latter is moved into each of the algorithm-specific sub-headers. Each sub-header types will have nesting version-specific subtypes to handle serialization of that specific version (e.g. for `AesCtrNoAuth` it has a `AesCtrNoAuthV1` subtype).
2023-02-14 20:19:27 -08:00
Yi Wu
fe18c87ac6 EaR: commit proxy fetch additional cipher keys post-resolution (#9308)
Commit proxy needs to fetch additional cipher keys post-resolution, since tenant ids for raw access requests and cross-tenant clear ranges are calculated after resolution.
2023-02-14 13:05:51 -08:00
Ata E Husain Bohra
401b9c8918 EaR: Helper routines to support configurable encryption (#9368)
* EaR: Helper routines to support configurable encryption

Description

Add helper methods to BlobCipherEncryptHeaderRef enabling:
1. Extract 'IV' abstracting out underlying algorithm header
1. Extract 'cipherDetails' abstracting out underlying algorithm header

Testing

BlobCipherUnitTest & EncryptionOps are updated - 100K loop

* EaR: Helper routines to support configurable encryption

Description

Add helper methods to BlobCipherEncryptHeaderRef enabling:
1. Extract 'IV' abstracting out underlying algorithm header
1. Extract 'cipherDetails' abstracting out underlying algorithm header

Testing

BlobCipherUnitTest & EncryptionOps are updated - 100K loop
2023-02-14 08:34:41 -08:00
Ata E Husain Bohra
ce49bfb8ac EaR: Fix RandomUnitTest (#9339)
Description

Set `enable_configurable_encryption` knob in the unit test to make
RandomUnitTest runs happy

Testing

BlobCipherUnitTest
EncryptionOps
RandomUnitTest
2023-02-10 10:35:08 -08:00
Ata E Husain Bohra
f30c5a13ac EaR: Configurable Encryption feature support for BlobGranules (#9343)
Description

Patch update BlobGranule encryption code to support Configurable
encryption semantics

Testing

BlobGranuleCorrectness* - 100K
2023-02-09 21:13:56 -08:00
Ata E Husain Bohra
9c649d7880 EaR: Configurable encryption framework (#9271)
* EaR: Configurable encryption framework

Description

EaR implementation only supports fixed size on-disk encryption header format.
One drawback of the scheme is, introducing a newer encryption scheme as well
as updating header format in future may incur data migration restrictions.
Major changes proposed in the patch includes:
1. Flexible Encryption header format allowing the following:
 1.1. Header flags (metadata) can evolve separately from the encryption algorithm
 1.2. Specific encryption algorithm header to allow future extensions.
2. Update the BlobCipher encryption/decryption util classes to work with newer
encryption header format.
3. Continue supporting multiple encryption authentication schemes such as:
HMAC-SHA and AES-CMAC; also, supports no encryption-authentication schemes.
4. Refactor BlobCipher unit test to enable testing of new format.
5. Configuration knobs to control encryption header flags and algorithm
versions.

Note: 
The on-disk header storage footprint savings due to the newer scheme is as follows:
1. No encryption authentication: 54% smaller compared to existing implementation.
3. AES-CMAC: 16% smaller compared to existing implementation.
3. HMAC-SHA encryption authentication: almost same size.


Testing

BlobCipherTest
EncryptionOpsTest
2023-02-08 22:51:05 -08:00
Nim Wijetunga
86f3665514 Handle EKP Tenant Not Found Errors (#9261)
handle EKP tenant not found errors
2023-02-01 19:15:38 -08:00
Sam Gwydir
34b8c5eb2b ENCRYPT_KEY_CACHE_LOGGING_SAMPLE_SIZE -> ENCRYPT_KEY_CACHE_LOGGING_SKETCH_ACCURACY 2022-11-14 10:47:45 -08:00
Josh Slocum
647c6487b4 add client cache size blob metadata latency metrics (#8484) 2022-11-03 16:43:30 -05:00
sfc-gh-tclinkenbeard
74212eeacf Encapsulate CounterCollection 2022-10-25 10:17:15 -07:00
Jingyu Zhou
1bfe00ca61 Merge pull request #8449 from sfc-gh-ahusain/ahusain-auth-token-cleanup
Remove MultiToken Encryption auth-token generation
2022-10-12 17:51:42 -07:00
Yi Wu
ac6aaf3785 encryption: fix some data not being encrypted (#8403)
Changes:
1. Change `isEncryptionOpSupported` to not check against `clientDBInfo.isEncryptionEnabled`, but instead against ENABLE_ENCRYPTION server knob. The problem with clientDBInfo is before its being broadcast to the workers, its content is uninitialized, during which some data (e.g. item 2) is not getting encrypted when they should.
2. Fix CommitProxy not encrypting metadata mutations which are recovered from txnStateStore
3. Fix KeyValueStoreMemory (thus TxnStateStore) partial transaction coming from recovery is not encrypted
4. new CODE_PROBE for the above fixes
5. Logging changes
2022-10-12 14:18:56 -07:00
Ata E Husain Bohra
858d562fce Remove MultiToken Encryption auth-token generation
Description

The current code supports two modes for authentication encryption:
1. Single auth-token mode
2. Multi auth-token mode

The code currently uses SingleAuthToken mode only, the multi-auth
token mode was added to support large file (such as backup files)
encryption assisting encryption authentication by allowing reading
header independently from encrypted payload itself. However, the
backup files are organized as 'chunks' and every chunk is encrypted,
hence, MultiToken mode isn't used in the code.

Removing the usage saves 32 bytes per encryption header, which might
translate to decent storage saving, further, allows lesser encryption
header overhead when encrypting small Key-Value mutations.

Testing

BlobCipher unittests
EncryptionOps.toml
2022-10-11 22:49:53 -07:00
Ata E Husain Bohra
03f1d13be3 Enable encryption authentication configurability (#8312)
* Enable encryption authentication configurability

Description

 diff-1: Remove memcpy due to auth-token computation
         Address review comments

Patch proposes major changes:
1. Enable FDB to choose encryption authentication as a configurable
parameter. Fix issues choosing ENCRYPT_HEADER_AUTH_TOKEN_NONE mode.
2. Introduce AES_CMAC as supported encryption authentication scheme.

Patch allows cluster to govern: if encryption authentication needs to
enabled, if yes, then choose from two supported schemes:
1. HMAC_SHA_256
2. AES_256_CMAC

Testing

devRunCorrectness - 100K
BlobCipher unittests
EncryptionOps.toml
BlobGranuleCorrectness/BlobGranuleCorrectnessClean
2022-09-29 16:18:55 -07:00
Ata E Husain Bohra
8b0f6e2d24 Encryption: Remove memcpy due to computeToken (#8211)
Description

Major changes include:
1. Eliminate memcpy due to authToken
2. Update TraceEvent message format
3. Remove redundant code.

Testing

flow/BlobCipher unit test
EncryptionOps.toml
devRunCorrectness - 100k
2022-09-20 15:58:53 -07:00
Ata E Husain Bohra
d2b82d2c46 Introduce "default encryption domain" (#8139)
* Introduce "default encryption domain"

Description

In current FDB native encryption data at-rest implementation,
an entity getting encrypted (mutation, KV and/or file) is categorized
into one of following encryption domains:
1. Tenant domain, where, Encryption domain == Tenant boundaries
2. FDB system keyspace - FDB metadata encryption domain
3. FDB Encryption Header domain - used to generate digest for
plaintext EncryptionHeader.

The scheme doesn't support encryption if an entity can't be categorized
into any of above mentioned encryption domains, for instance, non-tenant
mutations are NOT supported.

Patch extend the encryption support for mutations for which corresponding
Tenant information can't be obtained (Key length shorter than TenantPrefix)
and/or mutations do not belong to any valid Tenant
(FDB management cluster data) by mapping such mutations to a
"default encryption domain".

TODO

CommitProxy driven TLog encryption implementation requires every transaction
mutation to contain 1 KV, not crossing Tenant-boundaries. Only exception to
this rule is ClearRange mutations. For now ClearRange mutations are mapped
to 'default encryption domain', in subsequent patch appropriate handling
for ClearRange mutations shall be proposed.

Testing

devRunCorrectness - 100k
2022-09-14 10:58:32 -07:00
Yi Wu
d831c87d14 Add encryption metrics (#8070)
Adding the following metrics:
* BlobCipherKeyCache hit/miss
* EKP: KMS requests latencies
* For each component that using encryption, they now need to pass a UsageType enum to the encryption helper methods (GetEncryptCipherKeys/GetLatestEncryptCipherKey/encrypt/decrypt) and those methods will help to log get cipher key latency samples and encryption/decryption cpu times accordingly.
2022-09-09 18:43:09 -07:00