-
Notifications
You must be signed in to change notification settings - Fork 289
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
Intermittent enclave session error using Always Encrypted w/ secure enclaves. #1422
Comments
Can you provide a repro? |
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 |
|
@johnnypham thoughts? |
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. |
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. |
Not working as in not getting the exception (after updating the CreateSession method in EnclaveSessionCache)? |
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. |
Do you mind sending me your table/query, so that I can try? |
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: SELECT [SSN], [FirstName], [LastName], [Salary]
FROM [HR].[Employees]
WHERE [SSN] LIKE @SSNPattern AND [Salary] > @MinSalary;
`` |
I think the issue is when you use AzureSQL and AAS. The cache refreshes correctly when I connect via SQLServer and HGS. |
Ok thanks, I'll try that next. Update: able to repro now. |
I only see the exception when using |
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.
|
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. |
Right right. Let me know if there's anything else I can do to help. |
@johnnypham any update, or anything you'd like me to do to help? |
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. |
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 clientSecretCredential = new ClientSecretCredential(tenant, clientApplicationId, clientSecret); SqlColumnEncryptionAzureKeyVaultProvider(defaultCredentials); // Register AKV provider |
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 |
Hi Dave,
I have put the repos at tabi786/Test.WebAPI (github.com)<https://github.com/tabi786/Test.WebAPI>
If I restart Azure Web App, then it starts working again.
Regards.
Aftab Ahmad
From: Dave ***@***.***>
Sent: 4. marts 2023 15:10
To: dotnet/SqlClient ***@***.***>
Cc: tabi786 ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/SqlClient] Intermittent enclave session error using Always Encrypted w/ secure enclaves. (Issue #1422)
@tabi786<https://github.com/tabi786> are you using SQL Server or Azure SQL, and can you please provide repro?
—
Reply to this email directly, view it on GitHub<#1422 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AC3L7HBVBWSVN5Y2TZH3ZTLW2NEMXANCNFSM5JPXCWRQ>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
Hi again,
I have the exact error message. Now it is happening very quickly, after every second hour.
Microsoft.Data.SqlClient.EnclaveDelegate+RetryableEnclaveQueryExecutionException: Internal Error. Enclave session is null during query execution. Enclave type is 'SGX' and enclaveAttestationUrl is 'https://xxxxxxxx.neu.attest.azure.net'.
---> System.ArgumentException: Internal Error. Enclave session is null during query execution. Enclave type is 'SGX' and enclaveAttestationUrl is 'https://xxxxxxxxxxx.neu.attest.azure.net'.
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.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__209_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at System.Text.Json.Serialization.Converters.IAsyncEnumerableOfTConverter`2.OnWriteResume(Utf8JsonWriter writer, TAsyncEnumerable value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Test.Web.API.Startup.<Configure>b__5_1(HttpContext context, Func`1 next) in C:\Users\aa\source\repos\Test.Web.API\Test.Web.API\Startup.cs:line 175
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
HEADERS
=======
Accept: */*
Accept-Encoding: gzip, deflate, br
Authorization: Bearer XXXX
Cache-Control: no-cache
Content-Length: 0
Host: api.test.ltd
Max-Forwards: 10
User-Agent: PostmanRuntime/7.31.1
Postman-Token: 984262a3-6fe1-4e52-b751-513ebb2aeb5b
X-ARR-LOG-ID: b3af3b85-cba7-4fea-aba4-1f5dda4b46bb
CLIENT-IP: 54.86.50.139:10241
DISGUISED-HOST: api.test.ltd
X-SITE-DEPLOYMENT-ID: testprodapi
WAS-DEFAULT-HOSTNAME: testprodapi.azurewebsites.net
X-Forwarded-Proto: https
X-AppService-Proto: https
X-ARR-SSL: 8192|256|CN=Sectigo RSA Domain Validation Secure Server CA, O=Sectigo Limited, L=Salford, S=Greater Manchester, C=GB|CN=*.test.ltd
X-Forwarded-TlsVersion: 1.2
X-Forwarded-For: 54.86.50.139:10241
X-Original-URL: ***@***.******@***.******@***.******@***.***%27%20and%20Usertype%20eq%202&$select=Id&$top=1&$orderby=CreatedOn%20desc>
X-WAWS-Unencoded-URL: ***@***.******@***.******@***.******@***.***%27%20and%20Usertype%20eq%202&$select=Id&$top=1&$orderby=CreatedOn%20desc>
X-MS-CLIENT-PRINCIPAL-NAME: Thomas Peter
X-MS-CLIENT-PRINCIPAL-ID: d679531a-be60-424c-a3bc-11bb1dd42c72
X-MS-CLIENT-PRINCIPAL-IDP: aad
X-MS-CLIENT-PRINCIPAL: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
HEADERS
=======
Accept: */*
Accept-Encoding: gzip, deflate, br
Authorization: Bearer XXXX
Cache-Control: no-cache
Content-Length: 0
Host: api.test.ltd
Max-Forwards: 10
User-Agent: PostmanRuntime/7.31.1
Postman-Token: 984262a3-6fe1-4e52-b751-513ebb2aeb5b
X-ARR-LOG-ID: b3af3b85-cba7-4fea-aba4-1f5dda4b46bb
CLIENT-IP: 54.86.50.139:10241
DISGUISED-HOST: api.test.ltd
X-SITE-DEPLOYMENT-ID: testprodapi
WAS-DEFAULT-HOSTNAME: testprodapi.azurewebsites.net
X-Forwarded-Proto: https
X-AppService-Proto: https
X-ARR-SSL: 8192|256|CN=Sectigo RSA Domain Validation Secure Server CA, O=Sectigo Limited, L=Salford, S=Greater Manchester, C=GB|CN=*.test.ltd
X-Forwarded-TlsVersion: 1.2
X-Forwarded-For: 54.86.50.139:10241
X-Original-URL: ***@***.******@***.******@***.******@***.***%27%20and%20Usertype%20eq%202&$select=Id&$top=1&$orderby=CreatedOn%20desc>
X-WAWS-Unencoded-URL: ***@***.******@***.******@***.******@***.***%27%20and%20Usertype%20eq%202&$select=Id&$top=1&$orderby=CreatedOn%20desc>
X-MS-CLIENT-PRINCIPAL-NAME: Thomas Peter
X-MS-CLIENT-PRINCIPAL-ID: d679531a-be60-424c-a3bc-11bb1dd42c72
X-MS-CLIENT-PRINCIPAL-IDP: aad
X-MS-CLIENT-PRINCIPAL: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Regards.
Aftab Ahmad
From: Aftab Ahmad
Sent: 4. marts 2023 22:44
To: dotnet/SqlClient ***@***.***>; dotnet/SqlClient ***@***.***>
Cc: Mention ***@***.***>; Dennis Rohde ***@***.***>
Subject: RE: [dotnet/SqlClient] Intermittent enclave session error using Always Encrypted w/ secure enclaves. (Issue #1422)
Hi Dave,
I have put the repos at tabi786/Test.WebAPI (github.com)<https://github.com/tabi786/Test.WebAPI>
Regards.
Aftab Ahmad
From: Dave ***@***.******@***.***>>
Sent: 4. marts 2023 15:10
To: dotnet/SqlClient ***@***.******@***.***>>
Cc: tabi786 ***@***.******@***.***>>; Mention ***@***.******@***.***>>
Subject: Re: [dotnet/SqlClient] Intermittent enclave session error using Always Encrypted w/ secure enclaves. (Issue #1422)
@tabi786<https://github.com/tabi786> are you using SQL Server or Azure SQL, and can you please provide repro?
—
Reply to this email directly, view it on GitHub<#1422 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AC3L7HBVBWSVN5Y2TZH3ZTLW2NEMXANCNFSM5JPXCWRQ>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
@tabi786 looks like same bug. FWIW we have been running the change dna495@f492b71 since 12/2022 w/o issue. |
Hi @dna495, I have got the code but unfortunately my Azure Encryption code has stopped working now. Any Idea. Regards. Aftab Ahmad |
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 |
@tabi786 in case of any emergency support request contact Microsoft support center. |
The fix for this issue has been merged and released in 5.2.0-preview1. |
Fixed by #1988 |
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
The text was updated successfully, but these errors were encountered: