Repository navigation
Closed
Description
Microsoft.Data.SqlClient.EnclaveDelegate+RetryableEnclaveQueryExecutionException: Internal Error. Enclave session is null during query execution. Enclave type is 'SGX' and enclaveAttestationUrl is 'https://xxxxxxxxxxxxx.eus.attest.azure.net'.
---> System.ArgumentException: Internal Error. Enclave session is null during query execution. Enclave type is 'SGX' and enclaveAttestationUrl is 'https://xxxxxxxxxxxxx.eus.attest.azure.net'.
at Microsoft.Data.SqlClient.EnclaveDelegate.GetEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, String enclaveType, EnclaveSessionParameters enclaveSessionParameters, Boolean generateCustomData, SqlEnclaveSession& sqlEnclaveSession, Int64& counter, Byte[]& customData, Int32& customDataLength, Boolean throwIfNull)
at Microsoft.Data.SqlClient.EnclaveDelegate.GenerateEnclavePackage(SqlConnectionAttestationProtocol attestationProtocol, ConcurrentDictionary`2 keysToBeSentToEnclave, String queryText, String enclaveType, EnclaveSessionParameters enclaveSessionParameters, SqlConnection connection, SqlCommand command)
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.EnclaveDelegate.GenerateEnclavePackage(SqlConnectionAttestationProtocol attestationProtocol, ConcurrentDictionary`2 keysToBeSentToEnclave, String queryText, String enclaveType, EnclaveSessionParameters enclaveSessionParameters, SqlConnection connection, SqlCommand command)
at Microsoft.Data.SqlClient.SqlCommand.GenerateEnclavePackage()
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTdsWithTransparentParameterEncryption(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest, Task describeParameterEncryptionTask)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteReaderInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteReaderAsyncCallback(AsyncCallback callback, Object stateObject)
at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
To Reproduce
Behavior occurs intermittently with any command that references an encrypted column.
Further technical details
Microsoft.Data.SqlClient version: 4.0.0
.NET.Core 3.1
AzureSQL
Attestation Protocol: AAS
Metadata
Metadata
Assignees
Labels
No labels


Activity
johnnypham commentedon Dec 7, 2021
Can you provide a repro?
dna495 commentedon Dec 14, 2021
I'm pretty sure it happens when the EnclaveSessionCache expires after 8 hours.
Update the EnclaveSessionCache to 1 minute instead of 8 hours in CreateSession
Run an async query that requires enclave and then come back after a minute and you'll get it. Let me know what else you need from me
dna495 commentedon Dec 14, 2021
dna495 commentedon Dec 27, 2021
@johnnypham thoughts?
dna495@f492b71
johnnypham commentedon Jan 4, 2022
Sorry, I've been away. Thanks for the repro, I'll give it a try asap. It seems odd that the enclave session doesn't automatically refresh after it expires.
johnnypham commentedon Jan 5, 2022
I still have yet to go through the enclave session caching implementation but I wanted to mention that the repro doesn't work for me, even if I change the enclave cache time to 10 seconds.
dna495 commentedon Jan 5, 2022
Not working as in not getting the exception (after updating the CreateSession method in EnclaveSessionCache)?
johnnypham commentedon Jan 5, 2022
Yes. I'm using my own table but that shouldn't make a difference. Everything else is the same. Tried with both 1 minute and 10 seconds.
dna495 commentedon Jan 5, 2022
Do you mind sending me your table/query, so that I can try?
johnnypham commentedon Jan 5, 2022
It's the table created in this article. You can skip the part where you create the CMK/CEK and just use your existing keys.
Query is:
dna495 commentedon Jan 5, 2022
I think the issue is when you use AzureSQL and AAS. The cache refreshes correctly when I connect via SQLServer and HGS.
johnnypham commentedon Jan 5, 2022
Ok thanks, I'll try that next.
Update: able to repro now.
johnnypham commentedon Jan 10, 2022
I only see the exception when using
ExecuteReaderAsync.ExecuteReaderseems to work fine. If possible, can you verify this in your environment?dna495 commentedon Jan 10, 2022
Verified. RunExecuteReader throws when it's async and retries when it's not. FWIW we have been running dna495@f492b71 mentioned above for a couple weeks now w/ no issues.
johnnypham commentedon Jan 11, 2022
Yeah, that seems like the likely solution. But I'm trying to figure out why it only fails with AAS and not HGS. The old async code is making it difficult.
dna495 commentedon Jan 11, 2022
Right right. Let me know if there's anything else I can do to help.
dna495 commentedon Mar 22, 2022
@johnnypham any update, or anything you'd like me to do to help?
johnnypham commentedon Mar 23, 2022
I haven't had the time to work on this. The last thing I figured out is that the client does not request encryption metadata (which would set up a new enclave session) when the current session expires. I think it would be relatively simple to check if the session has expired and get the metadata but it would require some testing but I don't know when I'll have time.
tabi786 commentedon Mar 4, 2023
Hi, I am using it .NET Core API hosted in Azure App Service. My Api failes to search on encrypted columns after almost 8 hours. It remains down almost 5-30 minutes before it automatically comes up. I have included following nuget packages in the project
I am using this code in Startup.cs file. A quick response in this regard will be highly appreciated.
`var tenant = "tenant";
var clientApplicationId = "AADapplicationid";
var clientSecret = "ClientSecret";
var clientSecretCredential = new ClientSecretCredential(tenant, clientApplicationId, clientSecret);
SqlColumnEncryptionAzureKeyVaultProvider akvProvider = new SqlColumnEncryptionAzureKeyVaultProvider(clientSecretCredential);
SqlColumnEncryptionAzureKeyVaultProvider(defaultCredentials);
// Register AKV provider
SqlConnection.RegisterColumnEncryptionKeyStoreProviders(customProviders: new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(capacity: 1, comparer: StringComparer.OrdinalIgnoreCase)
{
{ SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, akvProvider}
});
`
tabi786 commentedon Mar 4, 2023
I am using Azure Sql with latest sql compatibility level. I am actually using Core Api with odata with entity Frameworks, https://learn.microsoft.com/en-us/odata/webapi/first-odata-api
I'll also share in next post. https://learn.microsoft.com/en-us/odata/webapi/first-odata-api
tabi786 commentedon Mar 4, 2023
tabi786 commentedon Mar 4, 2023
dna495 commentedon Mar 5, 2023
@tabi786 looks like same bug. FWIW we have been running the change dna495@f492b71 since 12/2022 w/o issue.
tabi786 commentedon Mar 6, 2023
Hi @dna495,
I have got the code but unfortunately my Azure Encryption code has stopped working now. Any Idea.
Regards.
Aftab Ahmad
tabi786 commentedon Mar 9, 2023
HI @dna495 @johnnypham @DavoudEshtehari @radical,
Can anyone of you guys help? We have the issue in Production Environment and it is blocking completely. Is there any other way to get help, for example from Microsoft support by creating a Support Ticket?
Your quick response in this regard will be highly appreciated.
Regards.
Aftab Ahmad
JRahnama commentedon Mar 9, 2023
@tabi786 in case of any emergency support request contact Microsoft support center.
David-Engel commentedon Apr 26, 2023
The fix for this issue has been merged and released in 5.2.0-preview1.
DavoudEshtehari commentedon Oct 25, 2023
Fixed by #1988