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

Set ColumnEncryptionKeyCacheTtl to zero when key store provider is registered and used globally #1078

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ private static readonly Dictionary<string, SqlColumnEncryptionKeyStoreProvider>
/// </summary>
private static IReadOnlyDictionary<string, SqlColumnEncryptionKeyStoreProvider> s_globalCustomColumnEncryptionKeyStoreProviders;

private static string s_akvProviderName = "AZURE_KEY_VAULT";

/// <summary>
/// Dictionary object holding trusted key paths for various SQL Servers.
/// Key to the dictionary is a SQL Server Name
Expand Down Expand Up @@ -314,9 +312,10 @@ public static void RegisterColumnEncryptionKeyStoreProviders(IDictionary<string,
throw SQL.CanOnlyCallOnce();
}

if (customProviders.ContainsKey(s_akvProviderName))
// to prevent conflicts between CEK caches, global providers should not use their own CEK caches
foreach (SqlColumnEncryptionKeyStoreProvider provider in customProviders.Values)
{
customProviders[s_akvProviderName].ColumnEncryptionKeyCacheTtl = new TimeSpan(0);
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
provider.ColumnEncryptionKeyCacheTtl = new TimeSpan(0);
}

// Create a temporary dictionary and then add items from the provided dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ private static Dictionary<string, SqlColumnEncryptionKeyStoreProvider> s_systemC
/// </summary>
private static IReadOnlyDictionary<string, SqlColumnEncryptionKeyStoreProvider> s_globalCustomColumnEncryptionKeyStoreProviders;

private static string s_akvProviderName = "AZURE_KEY_VAULT";

/// Instance-level list of custom key store providers. It can be set more than once by the user.
private IReadOnlyDictionary<string, SqlColumnEncryptionKeyStoreProvider> _customColumnEncryptionKeyStoreProviders;

Expand Down Expand Up @@ -149,9 +147,10 @@ static public void RegisterColumnEncryptionKeyStoreProviders(IDictionary<string,
throw SQL.CanOnlyCallOnce();
}

if (customProviders.ContainsKey(s_akvProviderName))
// to prevent conflicts between CEK caches, global providers should not use their own CEK caches
foreach (SqlColumnEncryptionKeyStoreProvider provider in customProviders.Values)
{
customProviders[s_akvProviderName].ColumnEncryptionKeyCacheTtl = new TimeSpan(0);
provider.ColumnEncryptionKeyCacheTtl = new TimeSpan(0);
}

// Create a temporary dictionary and then add items from the provided dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ internal SqlClientSymmetricKey GetKey(SqlEncryptionKeyInfo keyInfo, SqlConnectio
byte[] plaintextKey;
try
{
// to prevent conflicts between CEK caches, global providers should not use their own CEK caches
provider.ColumnEncryptionKeyCacheTtl = new TimeSpan(0);
plaintextKey = provider.DecryptColumnEncryptionKey(keyInfo.keyPath, keyInfo.algorithmName, keyInfo.encryptedKey);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static void CekCacheEntryIsEvictedAfterTtlExpires()
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAKVSetupAvailable))]
public static void CekCacheShouldBeDisabledWhenAkvProviderIsRegisteredGlobally()
public static void CekCacheShouldBeDisabledWhenCustomProviderIsRegisteredGlobally()
{
if (SQLSetupStrategyAzureKeyVault.IsAKVProviderRegistered)
{
Expand Down