Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Authentication Endpoint to MSI Properties #9374

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -731,6 +731,76 @@ static async void verifyProperties(HttpRequestMessage request, CancellationToken
p => Assert.StartsWith("Specialize MSI sidecar returned OK", p));
}

[Fact]
karshinlin marked this conversation as resolved.
Show resolved Hide resolved
public async Task SpecializeMsiSidecar_RequiredPropertiesInPayloadManagedServiceIdentities()
{
var environment = new Dictionary<string, string>()
{
{ EnvironmentSettingNames.MsiEndpoint, "http://localhost:8081" },
{ EnvironmentSettingNames.MsiSecret, "secret" }
};
var assignmentContext = new HostAssignmentContext
{
SiteId = 1234,
SiteName = "TestSite",
Environment = environment,
IsWarmupRequest = false,
MSIContext = new MSIContext()
{
SiteName = "TestSite",
MSISecret = "TestSecret1234",
Identities = new[] { new ManagedServiceIdentity() },
SystemAssignedIdentity = new ManagedServiceIdentity(),
DelegatedIdentities = new[] { new ManagedServiceIdentity() },
UserAssignedIdentities = new[] { new ManagedServiceIdentity() },
}
};

static async 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 verifyMSIProperties(HttpRequestMessage request, CancellationToken token)
{
var requestContent = await request.Content.ReadAsStringAsync(token);
var msiContext = JsonConvert.DeserializeObject<MSIContext>(requestContent);
Assert.NotNull(msiContext);

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);
}
}

var instanceManager = GetInstanceManagerForMSISpecialization(assignmentContext, HttpStatusCode.OK, null, customAction: verifyMSIProperties);

string error = await instanceManager.SpecializeMSISidecar(assignmentContext);
Assert.Null(error);

var logs = _loggerProvider.GetAllLogMessages().Select(p => p.FormattedMessage).ToArray();
Assert.Collection(logs,
p => Assert.StartsWith("MSI enabled status: True", p),
p => Assert.StartsWith("Specializing sidecar at http://localhost:8081", p),
p => Assert.StartsWith("Specialize MSI sidecar returned OK", p));
}


[Fact]
public async Task SpecializeMSISidecar_NoOp_ForWarmup_Request()
{
Expand Down