Repository navigation
Fix #2957: route enclave AE CEK lookup through SQLServerSymmetricKeyCache - #2964
Muskan Gupta (muskan124947) merged 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2964 +/- ##
============================================
+ Coverage 59.25% 60.07% +0.82%
- Complexity 5047 5131 +84
============================================
Files 153 153
Lines 36350 36353 +3
Branches 6650 6651 +1
============================================
+ Hits 21538 21839 +301
+ Misses 11056 10759 -297
+ Partials 3756 3755 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ache processSDPEv1 previously called the CMK provider directly for the enclave CEK, bypassing the driver-wide symmetric key cache. Combined with the provider-internal cache being disabled when registered system/globally, every enclave query hit the key store (e.g. Azure Key Vault) on every invocation.\n\nThe enclave CEK path now mirrors SQLServerSecurityUtility.decryptSymmetricKey: build an EncryptionKeyInfo and resolve via SQLServerSymmetricKeyCache (or instance-level providers when configured). This restores caching for AE v2 / enclave queries and also brings them under setTrustedMasterKeyPaths enforcement.\n\nAdds EnclaveCacheUnitTest (no SQL Server required) covering both the non-enclave and enclave paths; both confirm exactly one provider decrypt call across many lookups of the same wrapped CEK.
74b5ca2
43b3614 to
74b5ca2
Compare
There was a problem hiding this comment.
Pull request overview
This pull request fixes a performance issue in Always Encrypted (AE v2 / enclave computations) where enclave-requested CEKs were being decrypted via the CMK provider on every execution by routing the enclave CEK lookup through the driver’s existing symmetric key caching path.
Changes:
- Updated
ISQLServerEnclaveProvider.processSDPEv1to resolve enclave-requested CEKs viaSQLServerSymmetricKeyCache(or instance-level provider flow), aligning enclave and non-enclave CEK lookup behavior. - Added a new unit test (
EnclaveCacheUnitTest) to assert that repeated non-enclave and enclave CEK lookups only invokedecryptColumnEncryptionKeyonce.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java | Routes enclave-requested CEK resolution through the same cached path used by non-enclave AE to avoid repeated CMK provider calls. |
| src/test/java/com/microsoft/sqlserver/jdbc/EnclaveCacheUnitTest.java | Adds regression coverage ensuring both paths hit the CEK cache after the first lookup. |
David Engel (David-Engel)
left a comment
There was a problem hiding this comment.
Nice! I bet that hidden gem was fun to find. 🙂
Problem description
Always Encrypted queries that target columns with
ENCLAVE_COMPUTATIONS(AE v2) issue an Azure Key Vault (or other CMK store) round-trip on every execution, even when the same column encryption key (CEK) was just resolved milliseconds earlier. With AKV this adds ~150–400 ms per query and consumes vault throttling quota; under load it dominates query latency and surfaces as429 Too Many Requestsfrom AKV.The non-enclave AE path does not have this problem because it goes through
SQLServerSymmetricKeyCacheviaSQLServerSecurityUtility.decryptSymmetricKey. The enclave path inISQLServerEnclaveProvider.processSDPEv1instead resolves the enclave-requested CEK by callingprovider.decryptColumnEncryptionKey(...)directly, bypassing the cache.In addition, when a CMK provider is registered system-wide or globally (the recommended pattern for AKV), the provider's internal
SimpleTtlCacheis intentionally disabled —SQLServerSymmetricKeyCacheis meant to be the single caching layer. With the enclave path bypassing that single layer, no cache is in effect for enclave queries at all.Fixes existing GitHub issue
Fixes #2957
Fix Description
ISQLServerEnclaveProvider.processSDPEv1("Site 4") now resolves the enclave-requested CEK through the same path as the non-enclave code:EncryptionKeyInfofrom thesp_describe_parameter_encryptionrow.connection.getServerColumnEncryptionVersion()indicates instance-level providers are in scope (shouldUseInstanceLevelProviderFlow), callSQLServerSecurityUtility.getKeyFromLocalProviders(...).SQLServerSymmetricKeyCache.getInstance().getKey(keyInfo, connection).symKey.getRootKey()intoaev2CekEntry.put(...)for delivery to the enclave.Effects:
(server, encrypted-CEK, key-store)triple within the cache TTL.setTrustedMasterKeyPathsenforcement, closing a minor inconsistency with the non-enclave path.Test coverage added:
src/test/java/com/microsoft/sqlserver/jdbc/EnclaveCacheUnitTest.java— pure unit test, no SQL Server required. Uses Mockito to driveprocessSDPEv1with a fabricatedsp_describe_parameter_encryptionresult set and a counting CMK provider.nonEnclavePath_hitsCacheAfterFirstLookup: 50 lookups of the same wrapped CEK → asserts the provider'sdecryptColumnEncryptionKeyis called exactly once.enclavePath_hitsCacheAfterFirstLookup: 25 invocations ofprocessSDPEv1for the same enclave-requested CEK → asserts the provider'sdecryptColumnEncryptionKeyis called exactly once. Without this fix the same test produces ~26 calls.Verified locally with
mvn -P jre25 -Dtest=EnclaveCacheUnitTest test— both tests pass.New Public APIs
None.
Performance Validation
Tested against Azure SQL Database with VBS enclave, AKV-backed CMK, randomized encryption. Query:
SELECT * FROM dbo.TestEnclave WHERE SSN LIKE ?(enclave-required LIKE on randomized column).Without the fix, every run pays the AKV round-trip (~2000+ ms). With the fix, only Run 0 hits AKV; Run 1+ serve from cache (~415 ms, matching non-enclave baseline).