Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tomkerkhove/promitor
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a7297fd69783fe706f2bdc768e23dfd39dfcc373
Choose a base ref
..
head repository: tomkerkhove/promitor
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8e0c5c1e6158edd42fb5ed4073412d7fc0bd6e41
Choose a head ref
2 changes: 1 addition & 1 deletion changelog/content/deprecated/authentication-modes.md
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ However, as of Promitor Scraper v2.2.0 & Resource Discovery v0.3.0, users can ch

```yaml
authentication:
# Options are ServicePrincipal, SystemAssignedManagedIdentity, UserAssignedManagedIdentity.
# Options are ServicePrincipal, SystemAssignedManagedIdentity, UserAssignedManagedIdentity , SdkDefault.
mode: ServicePrincipal
identityId: xxxx-xxxx-xxxx
```
Original file line number Diff line number Diff line change
@@ -302,6 +302,8 @@ private string DetermineApplicationId(AzureAuthenticationInfo azureAuthenticatio
return azureAuthenticationInfo.GetIdentityIdOrDefault("externally-configured-user-assigned-identity");
case AuthenticationMode.SystemAssignedManagedIdentity:
return "system-assigned-identity";
case AuthenticationMode.SdkDefault:
return "default-azure-credentials";
default:
throw new ArgumentOutOfRangeException(nameof(azureAuthenticationInfo.Mode));
}
Original file line number Diff line number Diff line change
@@ -5,5 +5,6 @@ public enum AuthenticationMode
ServicePrincipal = 0,
UserAssignedManagedIdentity = 1,
SystemAssignedManagedIdentity = 2,
SdkDefault = 3
}
}
Original file line number Diff line number Diff line change
@@ -74,6 +74,8 @@ private string DetermineApplicationId(AzureAuthenticationInfo azureAuthenticatio
return azureAuthenticationInfo.GetIdentityIdOrDefault("externally-configured-user-assigned-identity");
case AuthenticationMode.SystemAssignedManagedIdentity:
return "system-assigned-identity";
case AuthenticationMode.SdkDefault:
return "default-azure-credentials";
default:
throw new ArgumentOutOfRangeException(nameof(azureAuthenticationInfo.Mode));
}
Original file line number Diff line number Diff line change
@@ -97,6 +97,8 @@ private string DetermineApplicationId(AzureAuthenticationInfo azureAuthenticatio
return azureAuthenticationInfo.GetIdentityIdOrDefault("externally-configured-user-assigned-identity");
case AuthenticationMode.SystemAssignedManagedIdentity:
return "system-assigned-identity";
case AuthenticationMode.SdkDefault:
return "default-azure-credentials";
default:
throw new ArgumentOutOfRangeException(nameof(azureAuthenticationInfo.Mode));
}
Original file line number Diff line number Diff line change
@@ -35,6 +35,26 @@ public void GetConfiguredAzureAuthentication_SystemAssignedManagedIdentityIsVali
Assert.Null(authenticationInfo.Secret);
}

[Fact]
public void GetConfiguredAzureAuthentication_SdkDefaultIsValid_Succeeds()
{
// Arrange
var expectedAuthenticationMode = AuthenticationMode.SdkDefault;
var inMemoryConfiguration = new Dictionary<string, string>
{
{ConfigurationKeys.Authentication.Mode, expectedAuthenticationMode.ToString()},
};
var config = CreateConfiguration(inMemoryConfiguration);

// Act
var authenticationInfo = AzureAuthenticationFactory.GetConfiguredAzureAuthentication(config);

// Assert
Assert.Equal(expectedAuthenticationMode, authenticationInfo.Mode);
Assert.Null(authenticationInfo.IdentityId);
Assert.Null(authenticationInfo.Secret);
}

[Fact]
public void GetConfiguredAzureAuthentication_UserAssignedManagedIdentityIsValid_Succeeds()
{
@@ -309,6 +329,27 @@ public void CreateAzureAuthentication_SystemAssignedManagedIdentityIsValid_Succe
Assert.Null(azureCredentials.ClientId);
}

[Fact]
public void CreateAzureAuthentication_SdkDefaultIsValid_Succeeds()
{
// Arrange
var expectedTenantId = Guid.NewGuid().ToString();
var azureCloud = AzureEnvironment.AzureChinaCloud;
var azureAuthenticationInfo = new AzureAuthenticationInfo
{
Mode = AuthenticationMode.SdkDefault
};
var azureCredentialFactory = new AzureCredentialsFactory();

// Act
var azureCredentials = AzureAuthenticationFactory.CreateAzureAuthentication(azureCloud, expectedTenantId, azureAuthenticationInfo, azureCredentialFactory);

// Assert
Assert.Equal(expectedTenantId, azureCredentials.TenantId);
Assert.Equal(azureCloud, azureCredentials.Environment);
Assert.Null(azureCredentials.ClientId);
}

[Fact]
public void CreateAzureAuthentication_UserAssignedManagedIdentityIsValid_Succeeds()
{
Original file line number Diff line number Diff line change
@@ -304,6 +304,25 @@ public void SystemAssignedManagedIdentity_ValidWithoutApplicationKey_Succeeds()
PromitorAssert.ValidationIsSuccessful(validationResult);
}

[Fact]
public void SdkDefault_ValidWithoutApplicationKey_Succeeds()
{
// Arrange
var inMemoryConfiguration = new Dictionary<string, string>
{
{ConfigurationKeys.Authentication.Mode, AuthenticationMode.SdkDefault.ToString()},
};

var config = CreateConfiguration(inMemoryConfiguration);

// Act
var azureAuthenticationValidationStep = new AzureAuthenticationValidationStep(config, NullLogger<AzureAuthenticationValidationStep>.Instance);
var validationResult = azureAuthenticationValidationStep.Run();

// Assert
PromitorAssert.ValidationIsSuccessful(validationResult);
}

private IConfigurationRoot CreateConfiguration(Dictionary<string, string> inMemoryConfiguration)
{
return new ConfigurationBuilder()