mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Always Encrypted Azure Key Vault Support (#934)
Add support for running queries that require a decryption key from Azure Key Vault when using Always Encrypted.
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -105,6 +106,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConnectionService()
|
||||||
|
{
|
||||||
|
SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(AzureActiveDirectoryAuthenticationCallback);
|
||||||
|
SqlConnection.RegisterColumnEncryptionKeyStoreProviders(customProviders: new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(capacity: 1, comparer: StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
{ SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, sqlColumnEncryptionAzureKeyVaultProvider }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor should be private since it's a singleton class, but we need a constructor
|
/// Default constructor should be private since it's a singleton class, but we need a constructor
|
||||||
@@ -117,6 +127,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
this.LockedDatabaseManager.ConnectionService = this;
|
this.LockedDatabaseManager.ConnectionService = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<string> AzureActiveDirectoryAuthenticationCallback(string authority, string resource, string scope)
|
||||||
|
{
|
||||||
|
RequestSecurityTokenParams message = new RequestSecurityTokenParams()
|
||||||
|
{
|
||||||
|
Authority = authority,
|
||||||
|
Provider = "Azure",
|
||||||
|
Resource = resource,
|
||||||
|
Scope = scope
|
||||||
|
};
|
||||||
|
|
||||||
|
RequestSecurityTokenResponse response = await Instance.ServiceHost.SendRequest(SecurityTokenRequest.Type, message, true);
|
||||||
|
|
||||||
|
return response.Token;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a connection queue for given type
|
/// Returns a connection queue for given type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||||
|
{
|
||||||
|
class RequestSecurityTokenParams
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the address of the authority to issue token.
|
||||||
|
/// </summary>
|
||||||
|
public string Authority { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the provider that indicates the type of linked account to query.
|
||||||
|
/// </summary>
|
||||||
|
public string Provider { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the identifier of the target resource that is the recipient of the requested token.
|
||||||
|
/// </summary>
|
||||||
|
public string Resource { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the scope of the authentication request.
|
||||||
|
/// </summary>
|
||||||
|
public string Scope { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class RequestSecurityTokenResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the key that uniquely identifies a particular linked account.
|
||||||
|
/// </summary>
|
||||||
|
public string AccountKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the access token.
|
||||||
|
/// </summary>
|
||||||
|
public string Token { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SecurityToken Request mapping entry
|
||||||
|
/// </summary>
|
||||||
|
class SecurityTokenRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<RequestSecurityTokenParams, RequestSecurityTokenResponse> Type =
|
||||||
|
RequestType<RequestSecurityTokenParams, RequestSecurityTokenResponse>.Create("account/securityTokenRequest");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="1.0.0" />
|
||||||
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4714.1-preview" />
|
<PackageReference Include="Microsoft.SqlServer.DacFx" Version="150.4714.1-preview" />
|
||||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0-preview3-26501-04" />
|
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0-preview3-26501-04" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<ProjectReference Include="../Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj" />
|
<ProjectReference Include="../Microsoft.SqlTools.ServiceLayer.UnitTests/Microsoft.SqlTools.ServiceLayer.UnitTests.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.1" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||||
<PackageReference Include="xunit" Version="2.2.0" />
|
<PackageReference Include="xunit" Version="2.2.0" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<ProjectReference Include="../Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj" />
|
<ProjectReference Include="../Microsoft.SqlTools.Test.CompletionExtension/Microsoft.SqlTools.Test.CompletionExtension.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.1" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||||
<PackageReference Include="xunit" Version="2.2.0" />
|
<PackageReference Include="xunit" Version="2.2.0" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user