Skip to content

Commit ee418c1

Browse files
authored
Merge pull request #65 from Keyfactor/government_cloud_debug
Bug fix for government cloud host name resolution
2 parents f671487 + cdd4568 commit ee418c1

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

AzureKeyVault/AkvProperties.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal protected string VaultEndpoint
4545
{
4646
return PrivateEndpoint.TrimStart('.');
4747
}
48-
switch (AzureCloud)
48+
switch (AzureCloud?.Trim()?.ToLowerInvariant())
4949
{
5050
case "china":
5151
return "vault.azure.cn";
@@ -58,6 +58,6 @@ internal protected string VaultEndpoint
5858
}
5959
}
6060
}
61-
internal protected string VaultURL => $"https://{VaultName}.{VaultEndpoint}/";
61+
public string VaultURL => $"https://{VaultName}.{VaultEndpoint}/";
6262
}
6363
}

AzureKeyVault/AzureClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ private Uri AzureCloudEndpoint
3232
{
3333
get
3434
{
35-
switch (VaultProperties.AzureCloud?.ToLower())
35+
logger.LogTrace($"the AzureCloud is {VaultProperties.AzureCloud}, so we will use the following endpoint for authentication: ");
36+
switch (VaultProperties.AzureCloud?.Trim()?.ToLowerInvariant())
3637
{
37-
3838
case "china":
39+
logger.LogTrace(AzureAuthorityHosts.AzureChina.ToString());
3940
return AzureAuthorityHosts.AzureChina;
4041
//case "germany":
4142
// return AzureAuthorityHosts.AzureGermany; // germany is no longer a valid azure authority host as of 2021
4243
case "government":
44+
logger.LogTrace(AzureAuthorityHosts.AzureGovernment.ToString());
4345
return AzureAuthorityHosts.AzureGovernment;
4446
default:
47+
logger.LogTrace(AzureAuthorityHosts.AzurePublicCloud.ToString());
4548
return AzureAuthorityHosts.AzurePublicCloud;
4649
}
4750
}
@@ -92,6 +95,8 @@ internal protected virtual ArmClient getArmClient(string tenantId)
9295
{
9396
TokenCredential credential;
9497
var credentialOptions = new DefaultAzureCredentialOptions { AuthorityHost = AzureCloudEndpoint, AdditionallyAllowedTenants = { "*" } };
98+
logger.LogTrace($"creating an ARM client for management operations with authorityhost {AzureCloudEndpoint.ToString()}");
99+
95100
if (this.VaultProperties.UseAzureManagedIdentity)
96101
{
97102
logger.LogTrace("getting management client for a managed identity");

AzureKeyVault/Jobs/AzureKeyVaultJob.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ public void InitializeStore(dynamic config)
9494
VaultProperties.SubscriptionId = properties.SubscriptionId ?? VaultProperties.SubscriptionId;
9595
VaultProperties.ResourceGroupName = !string.IsNullOrEmpty(properties.ResourceGroupName as string) ? properties.ResourceGroupName : VaultProperties.ResourceGroupName;
9696
VaultProperties.VaultName = properties.VaultName ?? VaultProperties.VaultName; // check the field in case of legacy paths.
97+
9798
VaultProperties.TenantId = !string.IsNullOrEmpty(VaultProperties.TenantId) ? VaultProperties.TenantId : config.CertificateStoreDetails?.ClientMachine; // Client Machine could be null in the case of managed identity. That's ok.
98-
VaultProperties.AzureCloud = !string.IsNullOrEmpty(properties.AzureCloud as string) ? properties.AzureCloud : VaultProperties.AzureCloud;
99-
VaultProperties.PrivateEndpoint = !string.IsNullOrEmpty(properties.PrivateEndpoint as string) ? properties.PrivateEndpoint : VaultProperties.PrivateEndpoint;
100-
99+
VaultProperties.AzureCloud = properties.AzureCloud;
100+
logger.LogTrace($"Azure Cloud: {VaultProperties.AzureCloud}");
101+
VaultProperties.PrivateEndpoint = properties.PrivateEndpoint;
102+
logger.LogTrace($"Private Endpoint: {VaultProperties.PrivateEndpoint}");
101103
string skuType = !string.IsNullOrEmpty(properties.SkuType as string) ? properties.SkuType : null;
102104
VaultProperties.PremiumSKU = skuType?.ToLower() == "premium";
105+
103106
VaultProperties.VaultRegion = !string.IsNullOrEmpty(properties.VaultRegion as string) ? properties.VaultRegion : VaultProperties.VaultRegion;
104107
VaultProperties.VaultRegion = VaultProperties.VaultRegion?.ToLower();
105108
}

AzureKeyVault/Jobs/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
4040

4141
inventoryItems = AzClient.GetCertificatesAsync().Result?.ToList();
4242

43-
logger.LogTrace($"Found {inventoryItems.Count()} Total Certificates in Azure Key Vault.");
43+
logger.LogTrace($"Found {inventoryItems.Count} Total Certificates in Azure Key Vault.");
4444
}
4545

4646
catch (Exception ex)

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- 3.1.9
22
- Added optional entry parameter to indicate that existing tags should be preserved if certificate is replaced
3+
- bug fix for government cloud host name resolution
34

45
- 3.1.8
56
- Fixed bug where enrollment would fail if the CertificateTags field was not defined as an entry parameter

0 commit comments

Comments
 (0)