Skip to content

Commit f716882

Browse files
authored
Add endpoints for managed HSM (#227)
* managed hsm endpoints * fix
1 parent 6f6aa32 commit f716882

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/Authentication.Abstractions/AzureEnvironment.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
2828
/// A record of metadata necessary to manage assets in a specific azure cloud, including necessary endpoints,
2929
/// location fo service-specific endpoints, and information for bootstrapping authentication
3030
/// </summary>
31-
[Serializable]
31+
[Serializable]
3232
public class AzureEnvironment : IAzureEnvironment, IEquatable<AzureEnvironment>
3333
{
3434
private const string ArmMetadataEnvVariable = "ARM_CLOUD_METADATA_URL";
@@ -238,7 +238,7 @@ private static async Task<List<ArmMetadata>> InitializeEnvironmentsFromArm(strin
238238
/// <param name="azureEnvironments">Collection of AzureEnvironments</param>
239239
private static void SetExtendedProperties(IDictionary<string, AzureEnvironment> azureEnvironments)
240240
{
241-
if(azureEnvironments.ContainsKey(EnvironmentName.AzureCloud))
241+
if (azureEnvironments.ContainsKey(EnvironmentName.AzureCloud))
242242
{
243243
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.OperationalInsightsEndpoint, AzureEnvironmentConstants.AzureOperationalInsightsEndpoint);
244244
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.OperationalInsightsEndpointResourceId, AzureEnvironmentConstants.AzureOperationalInsightsEndpointResourceId);
@@ -248,28 +248,36 @@ private static void SetExtendedProperties(IDictionary<string, AzureEnvironment>
248248
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.AzureAttestationServiceEndpointResourceId, AzureEnvironmentConstants.AzureAttestationServiceEndpointResourceId);
249249
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointSuffix, AzureEnvironmentConstants.AzureSynapseAnalyticsEndpointSuffix);
250250
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, AzureEnvironmentConstants.AzureSynapseAnalyticsEndpointResourceId);
251+
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointResourceId, AzureEnvironmentConstants.AzureManagedHsmServiceEndpointResourceId);
252+
azureEnvironments[EnvironmentName.AzureCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointSuffix, AzureEnvironmentConstants.AzureManagedHsmDnsSuffix);
251253
}
252254

253-
if(azureEnvironments.ContainsKey(EnvironmentName.AzureChinaCloud))
255+
if (azureEnvironments.ContainsKey(EnvironmentName.AzureChinaCloud))
254256
{
255257
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointSuffix, AzureEnvironmentConstants.ChinaAnalysisServicesEndpointSuffix);
256258
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointResourceId, AzureEnvironmentConstants.ChinaAnalysisServicesEndpointResourceId);
257259
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointSuffix, AzureEnvironmentConstants.ChinaSynapseAnalyticsEndpointSuffix);
258260
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, AzureEnvironmentConstants.ChinaSynapseAnalyticsEndpointResourceId);
261+
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointResourceId, AzureEnvironmentConstants.ChineManagedHsmServiceEndpointResourceId);
262+
azureEnvironments[EnvironmentName.AzureChinaCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointSuffix, AzureEnvironmentConstants.ChinaManagedHsmDnsSuffix);
259263
}
260264

261-
if(azureEnvironments.ContainsKey(EnvironmentName.AzureUSGovernment))
265+
if (azureEnvironments.ContainsKey(EnvironmentName.AzureUSGovernment))
262266
{
263267
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.OperationalInsightsEndpoint, AzureEnvironmentConstants.USGovernmentOperationalInsightsEndpoint);
264268
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.OperationalInsightsEndpointResourceId, AzureEnvironmentConstants.USGovernmentOperationalInsightsEndpointResourceId);
265269
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointSuffix, AzureEnvironmentConstants.USGovernmentAnalysisServicesEndpointSuffix);
266270
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointResourceId, AzureEnvironmentConstants.USGovernmentAnalysisServicesEndpointResourceId);
271+
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointResourceId, AzureEnvironmentConstants.USGovernmeneManagedHsmServiceEndpointResourceId);
272+
azureEnvironments[EnvironmentName.AzureUSGovernment].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointSuffix, AzureEnvironmentConstants.USGovernmentManagedHsmDnsSuffix);
267273
}
268274

269-
if(azureEnvironments.ContainsKey(EnvironmentName.AzureGermanCloud))
275+
if (azureEnvironments.ContainsKey(EnvironmentName.AzureGermanCloud))
270276
{
271277
azureEnvironments[EnvironmentName.AzureGermanCloud].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointSuffix, AzureEnvironmentConstants.GermanAnalysisServicesEndpointSuffix);
272278
azureEnvironments[EnvironmentName.AzureGermanCloud].SetProperty(ExtendedEndpoint.AnalysisServicesEndpointResourceId, AzureEnvironmentConstants.GermanAnalysisServicesEndpointResourceId);
279+
azureEnvironments[EnvironmentName.AzureGermanCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointResourceId, AzureEnvironmentConstants.GermanAzureManagedHsmServiceEndpointResourceId);
280+
azureEnvironments[EnvironmentName.AzureGermanCloud].SetProperty(ExtendedEndpoint.ManagedHsmServiceEndpointSuffix, AzureEnvironmentConstants.GermanManagedHsmDnsSuffix);
273281
}
274282
}
275283

@@ -305,11 +313,11 @@ private static AzureEnvironment MapArmToAzureEnvironment(ArmMetadata armMetadata
305313
ContainerRegistryEndpointSuffix = armMetadata.Suffixes.AcrLoginServer
306314
};
307315

308-
// There are mismatches between metadata built in Azure PowerShell/CLI and from ARM endpoint.
316+
// There are mismatches between metadata built in Azure PowerShell/CLI and from ARM endpoint.
309317
// Considering compatibility, below hard coded logic accommodates those mismatches
310318
// SqlDatabaseDnsSuffix requires value leading with period
311319
// ServiceManagementUrl as audience needs to end with slash
312-
if(azureEnvironment.SqlDatabaseDnsSuffix != null && !azureEnvironment.SqlDatabaseDnsSuffix.StartsWith("."))
320+
if (azureEnvironment.SqlDatabaseDnsSuffix != null && !azureEnvironment.SqlDatabaseDnsSuffix.StartsWith("."))
313321
{
314322
azureEnvironment.SqlDatabaseDnsSuffix = "." + azureEnvironment.SqlDatabaseDnsSuffix;
315323
}
@@ -635,6 +643,8 @@ public static class ExtendedEndpoint
635643
{
636644
public const string OperationalInsightsEndpointResourceId = "OperationalInsightsEndpointResourceId",
637645
OperationalInsightsEndpoint = "OperationalInsightsEndpoint",
646+
ManagedHsmServiceEndpointSuffix = "ManagedHsmServiceEndpointSuffix",
647+
ManagedHsmServiceEndpointResourceId = "ManagedHsmServiceEndpointResourceId",
638648
AnalysisServicesEndpointSuffix = "AzureAnalysisServicesEndpointSuffix",
639649
AnalysisServicesEndpointResourceId = "AnalysisServicesEndpointResourceId",
640650
AzureAttestationServiceEndpointSuffix = "AzureAttestationServiceEndpointSuffix",

src/Authentication.Abstractions/AzureEnvironmentConstants.cs

+16
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public static class AzureEnvironmentConstants
112112
public const string USGovernmentKeyVaultDnsSuffix = "vault.usgovcloudapi.net";
113113
public const string GermanKeyVaultDnsSuffix = "vault.microsoftazure.de";
114114

115+
/// <summary>
116+
/// The domain name suffix for azure keyvault managed hsms
117+
/// </summary>
118+
public const string AzureManagedHsmDnsSuffix = "managedhsm.azure.net";
119+
public const string ChinaManagedHsmDnsSuffix = "managedhsm.azure.cn";
120+
public const string USGovernmentManagedHsmDnsSuffix = "managedhsm.usgovcloudapi.net";
121+
public const string GermanManagedHsmDnsSuffix = "managedhsm.microsoftazure.de";
122+
115123
/// <summary>
116124
/// The token audience for authorizing KeyVault requests
117125
/// </summary>
@@ -120,6 +128,14 @@ public static class AzureEnvironmentConstants
120128
public const string USGovernmentKeyVaultServiceEndpointResourceId = "https://vault.usgovcloudapi.net";
121129
public const string GermanAzureKeyVaultServiceEndpointResourceId = "https://vault.microsoftazure.de";
122130

131+
/// <summary>
132+
/// The token audience for authorizing managed hsm requests
133+
/// </summary>
134+
public const string AzureManagedHsmServiceEndpointResourceId = "https://managedhsm.azure.net";
135+
public const string ChineManagedHsmServiceEndpointResourceId = "https://managedhsm.azure.cn";
136+
public const string USGovernmeneManagedHsmServiceEndpointResourceId = "https://managedhsm.usgovcloudapi.net";
137+
public const string GermanAzureManagedHsmServiceEndpointResourceId = "https://managedhsm.microsoftazure.de";
138+
123139
/// <summary>
124140
/// The token audience for Log Analytics Queries
125141
/// </summary>

src/Authentication.Abstractions/Extensions/AzureEnvironmentExtensions.cs

+10
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ public static void SetEndpoint(this IAzureEnvironment environment, string endpoi
289289
case AzureEnvironment.ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId:
290290
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, propertyValue);
291291
break;
292+
case AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointSuffix:
293+
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointSuffix, propertyValue);
294+
break;
295+
case AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointResourceId:
296+
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointResourceId, propertyValue);
297+
break;
292298
}
293299
}
294300
}
@@ -332,6 +338,10 @@ public static string GetTokenAudience(this IAzureEnvironment environment, string
332338
case AzureEnvironment.ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId:
333339
resource = AzureEnvironment.ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId;
334340
break;
341+
case AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointSuffix:
342+
case AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointResourceId:
343+
resource = AzureEnvironment.ExtendedEndpoint.ManagedHsmServiceEndpointResourceId;
344+
break;
335345
default:
336346
resource = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId;
337347
break;

0 commit comments

Comments
 (0)