Skip to content

Commit

Permalink
Add Authentication Endpoint to MSI Properties (Azure#9374)
Browse files Browse the repository at this point in the history
* add authentication endpoint to MSI properties + test that properties exist

* change to non async

* put MSI property verification within payload property verification test

* updated tests to wait for asserts + populate msi properties
  • Loading branch information
annzho authored Aug 2, 2023
1 parent 0058f8b commit 08d385e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/WebJobs.Script.WebHost/Models/ManagedServiceIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class ManagedServiceIdentity
public string Certificate { get; set; }

public string PrincipalId { get; set; }

public string AuthenticationEndpoint { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -699,22 +699,89 @@ public async Task SpecializeMsiSidecar_RequiredPropertiesInPayload()
{
SiteName = "TestSite",
MSISecret = "TestSecret1234",
Identities = new[] { new ManagedServiceIdentity() },
SystemAssignedIdentity = new ManagedServiceIdentity(),
DelegatedIdentities = new[] { new ManagedServiceIdentity() },
UserAssignedIdentities = new[] { new ManagedServiceIdentity() },
Identities = new[] { new ManagedServiceIdentity() {
Type = ManagedServiceIdentityType.SystemAssigned,
ClientId = "identityClientId",
TenantId = "identityTenantId",
Thumbprint = "identityThumbprint",
SecretUrl = "identitySecretUrl",
ResourceId = "identityResourceId",
Certificate = "identityCertificate",
PrincipalId = "identityPrincipalId",
AuthenticationEndpoint = "identityAuthEndpoint"
} },
SystemAssignedIdentity = new ManagedServiceIdentity()
{
Type = ManagedServiceIdentityType.SystemAssigned,
ClientId = "saClientId",
TenantId = "saTenantId",
Thumbprint = "saThumbprint",
SecretUrl = "saSecretUrl",
ResourceId = "saResourceId",
Certificate = "saCertificate",
PrincipalId = "saPrincipalId",
AuthenticationEndpoint = "saAuthEndpoint"
},
DelegatedIdentities = new[] { new ManagedServiceIdentity() {
Type = ManagedServiceIdentityType.SystemAssigned,
ClientId = "delegatedClientId",
TenantId = "delegatedTenantId",
Thumbprint = "delegatedThumbprint",
SecretUrl = "delegatedSecretUrl",
ResourceId = "delegatedResourceId",
Certificate = "delegatedCertificate",
PrincipalId = "delegatedPrincipalId",
AuthenticationEndpoint = "delegatedAuthEndpoint"
} },
UserAssignedIdentities = new[] { new ManagedServiceIdentity() {
Type = ManagedServiceIdentityType.UserAssigned,
ClientId = "uaClientId",
TenantId = "uaTenantId",
Thumbprint = "uaThumbprint",
SecretUrl = "uaSecretUrl",
ResourceId = "uaResourceId",
Certificate = "uaCertificate",
PrincipalId = "uaPrincipalId",
AuthenticationEndpoint = "uaAuthEndpoint"
} },
}
};

static void verifyMSIPropertiesHelper(ManagedServiceIdentity msi)
{
Assert.NotNull(msi);
Assert.NotNull(msi.Type);
Assert.NotNull(msi.ClientId);
Assert.NotNull(msi.TenantId);
Assert.NotNull(msi.Thumbprint);
Assert.NotNull(msi.SecretUrl);
Assert.NotNull(msi.ResourceId);
Assert.NotNull(msi.Certificate);
Assert.NotNull(msi.PrincipalId);
Assert.NotNull(msi.AuthenticationEndpoint);
}

static async void verifyProperties(HttpRequestMessage request, CancellationToken token)
static void verifyProperties(HttpRequestMessage request, CancellationToken token)
{
var requestContent = await request.Content.ReadAsStringAsync(token);
var requestContent = request.Content.ReadAsStringAsync(token).GetAwaiter().GetResult();
var msiContext = JsonConvert.DeserializeObject<MSIContext>(requestContent);
Assert.NotNull(msiContext);
Assert.NotNull(msiContext.Identities);
Assert.NotNull(msiContext.SystemAssignedIdentity);
Assert.NotNull(msiContext.UserAssignedIdentities);
Assert.NotNull(msiContext.DelegatedIdentities);

var identityList = new List<ManagedServiceIdentity>();
identityList.AddRange(msiContext.Identities);
identityList.Add(msiContext.SystemAssignedIdentity);
identityList.AddRange(msiContext.UserAssignedIdentities);
identityList.AddRange(msiContext.DelegatedIdentities);

foreach (ManagedServiceIdentity identity in identityList)
{
verifyMSIPropertiesHelper(identity);
}

Assert.True(!string.IsNullOrEmpty(msiContext.MSISecret));
Assert.True(!string.IsNullOrEmpty(msiContext.SiteName));
}
Expand Down

0 comments on commit 08d385e

Please sign in to comment.