Skip to content

Commit 0d339e0

Browse files
StephenMolloyHongGit
authored andcommitted
Preview3 (#10)
* Fix potential deadlock with Azure from ASP.Net when not preloading secret names. * Remove -preview dependencies and rev to 'preview3'
1 parent 7096e46 commit 0d339e0

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ There are three additional configuration attributes for this config builder:
101101
(vaultName="MyVaultName" |
102102
uri="https://MyVaultName.vault.azure.net")
103103
[connectionString="connection string"]
104-
[version="secrets version"]
105-
[preloadSecretNames="true"]
104+
[version="secrets version"]
105+
[preloadSecretNames="true"]
106106
type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure" />
107107
```
108108
If your secrets are kept in Azure Key Vault, then this config builder is for you. There are three additional attributes for this config builder. The `vaultName` is
@@ -184,7 +184,7 @@ public class CustomConfigBuilder : KeyValueConfigBuilder
184184
Information on contributing to this repo is in the [Contributing Guide](CONTRIBUTING.md).
185185

186186
## Blog Posts
187-
[Announcing .NET 4.7.1 Tools for the Cloud](https://blogs.msdn.microsoft.com/webdev/2017/11/17/announcing-net-4-7-1-tools-for-the-cloud/)
188-
[.Net Framework 4.7.1 ASP.NET and Configuration features](https://blogs.msdn.microsoft.com/dotnet/2017/09/13/net-framework-4-7-1-asp-net-and-configuration-features/)
187+
[Announcing .NET 4.7.1 Tools for the Cloud](https://blogs.msdn.microsoft.com/webdev/2017/11/17/announcing-net-4-7-1-tools-for-the-cloud/)
188+
[.Net Framework 4.7.1 ASP.NET and Configuration features](https://blogs.msdn.microsoft.com/dotnet/2017/09/13/net-framework-4-7-1-asp-net-and-configuration-features/)
189189
[Modern Configuration for ASP.NET 4.7.1 with ConfigurationBuilders](http://jeffreyfritz.com/2017/11/modern-configuration-for-asp-net-4-7-1-with-configurationbuilders/)
190-
[Service-to-service authentication to Azure Key Vault using .NET](https://docs.microsoft.com/en-us/azure/key-vault/service-to-service-authentication#connection-string-support)
190+
[Service-to-service authentication to Azure Key Vault using .NET](https://docs.microsoft.com/en-us/azure/key-vault/service-to-service-authentication#connection-string-support)

src/Azure/Azure.csproj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
</PropertyGroup>
3838
<ItemGroup>
3939
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
40-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.2.4.0-preview\lib\net452\Microsoft.Azure.KeyVault.dll</HintPath>
40+
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.2.3.2\lib\net452\Microsoft.Azure.KeyVault.dll</HintPath>
4141
</Reference>
4242
<Reference Include="Microsoft.Azure.KeyVault.WebKey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.WebKey.2.1.0-preview\lib\net452\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
43+
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.WebKey.2.0.7\lib\net452\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
4444
</Reference>
4545
<Reference Include="Microsoft.Azure.Services.AppAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46-
<HintPath>..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll</HintPath>
46+
<HintPath>..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.0\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll</HintPath>
4747
</Reference>
4848
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.2.6005, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4949
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
@@ -79,11 +79,9 @@
7979
</ItemGroup>
8080
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8181
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
82-
<Import Project="..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\build\Microsoft.Azure.Services.AppAuthentication.targets" Condition="Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\build\Microsoft.Azure.Services.AppAuthentication.targets')" />
8382
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
8483
<PropertyGroup>
8584
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
8685
</PropertyGroup>
87-
<Error Condition="!Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\build\Microsoft.Azure.Services.AppAuthentication.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\build\Microsoft.Azure.Services.AppAuthentication.targets'))" />
8886
</Target>
8987
</Project>

src/Azure/AzureKeyVaultConfigBuilder.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public override void Initialize(string name, NameValueCollection config)
6868
public override string GetValue(string key)
6969
{
7070
// Azure Key Vault keys are case-insensitive, so this should be fine.
71-
return GetValueAsync(key).Result;
71+
// Also, this is a synchronous method. And in single-threaded contexts like ASP.Net
72+
// it can be bad/dangerous to block on async calls. So lets work some TPL voodoo
73+
// to avoid potential deadlocks.
74+
return Task.Run(async () => { return await GetValueAsync(key); }).Result;
7275
}
7376

7477
public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
@@ -94,14 +97,17 @@ private async Task<string> GetValueAsync(string key)
9497
{
9598
if (!_preload || _allKeys.Contains(key, StringComparer.OrdinalIgnoreCase))
9699
{
97-
if (!String.IsNullOrWhiteSpace(_version))
100+
try
98101
{
99-
var versionedSecret = await _kvClient.GetSecretAsync(_uri, key, _version);
100-
return versionedSecret?.Value;
101-
}
102+
if (!String.IsNullOrWhiteSpace(_version))
103+
{
104+
var versionedSecret = await _kvClient.GetSecretAsync(_uri, key, _version);
105+
return versionedSecret?.Value;
106+
}
102107

103-
var secret = await _kvClient.GetSecretAsync(_uri, key);
104-
return secret?.Value;
108+
var secret = await _kvClient.GetSecretAsync(_uri, key);
109+
return secret?.Value;
110+
} catch { }
105111
}
106112

107113
return null;

src/Azure/packages.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.KeyVault" version="2.4.0-preview" targetFramework="net471" />
4-
<package id="Microsoft.Azure.KeyVault.WebKey" version="2.1.0-preview" targetFramework="net471" />
5-
<package id="Microsoft.Azure.Services.AppAuthentication" version="1.1.0-preview" targetFramework="net471" />
3+
<package id="Microsoft.Azure.KeyVault" version="2.3.2" targetFramework="net471" />
4+
<package id="Microsoft.Azure.KeyVault.WebKey" version="2.0.7" targetFramework="net471" />
5+
<package id="Microsoft.Azure.Services.AppAuthentication" version="1.0" targetFramework="net471" />
66
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.19.2" targetFramework="net471" />
77
<package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net471" />
88
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.10" targetFramework="net471" />

tools/MicrosoftConfigurationBuilders.settings.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Configurable properties-->
88

99
<PropertyGroup>
10-
<BuildQuality Condition="'$(BuildQuality)' == ''">preview2</BuildQuality>
10+
<BuildQuality Condition="'$(BuildQuality)' == ''">preview3</BuildQuality>
1111
<VersionStartYear>2016</VersionStartYear>
1212
<VersionMajor>1</VersionMajor>
1313
<VersionMinor>0</VersionMinor>
@@ -16,7 +16,7 @@
1616
</PropertyGroup>
1717

1818
<PropertyGroup Label="NuGet package dependencies">
19-
<MicrosoftConfigurationBuildersNuGetPackageVersion>1.0.0-preview2</MicrosoftConfigurationBuildersNuGetPackageVersion>
19+
<MicrosoftConfigurationBuildersNuGetPackageVersion>1.0.0-preview3</MicrosoftConfigurationBuildersNuGetPackageVersion>
2020
</PropertyGroup>
2121

2222
<!-- Default properties -->

0 commit comments

Comments
 (0)